From: Marco Bettini Date: Tue, 6 Dec 2022 11:31:21 +0000 (+0000) Subject: lib-index: Shorten mail_cache_unaccessed_field_drop effective value to 1/4 while... X-Git-Tag: 2.4.0~3269 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19890c0d30d1c4270831e1ed42dfc6569bd086b9;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Shorten mail_cache_unaccessed_field_drop effective value to 1/4 while cache header count is saturated This is done to help the cache to converge quicker to the intended state. --- diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index 477f80d2a3..789689f854 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -675,10 +675,16 @@ void mail_cache_purge_drop_init(struct mail_cache *cache, if (hdr->day_stamp != 0) { const struct mail_index_cache_optimization_settings *opt = &cache->index->optimization_set.cache; - ctx_r->max_yes_downgrade_time = hdr->day_stamp - - opt->unaccessed_field_drop_secs; - ctx_r->max_temp_drop_time = hdr->day_stamp - - 2 * opt->unaccessed_field_drop_secs; + long threshold = opt->unaccessed_field_drop_secs; + + /* While cache max headers count is saturated, shrink the actual + value of this parameter to 1/4, so that the cache can return + quicker to the intended state. */ + if (mail_cache_headers_check_capped(cache)) + threshold /= 4; + + ctx_r->max_yes_downgrade_time = hdr->day_stamp - threshold; + ctx_r->max_temp_drop_time = hdr->day_stamp - 2 * threshold; } } diff --git a/src/lib-index/test-mail-cache-purge.c b/src/lib-index/test-mail-cache-purge.c index 790226eda6..54086af0dd 100644 --- a/src/lib-index/test-mail-cache-purge.c +++ b/src/lib-index/test-mail-cache-purge.c @@ -1042,6 +1042,42 @@ static void test_mail_cache_update_need_purge_deleted_records2(void) test_end(); } +static void test_mail_cache_purge_deadlines(void) +{ + static const uint32_t BASE_TIME = 1000; + static const uint32_t DROP_SECS = 100; + + struct mail_cache cache; + struct mail_index index; + struct mail_index_header hdr; + struct mail_cache_purge_drop_ctx ctx; + + i_zero(&cache); + i_zero(&index); + i_zero(&hdr); + i_zero(&ctx); + + hdr.day_stamp = BASE_TIME; + index.optimization_set.cache.unaccessed_field_drop_secs = DROP_SECS; + index.optimization_set.cache.max_headers_count = 1; + cache.index = &index; + + test_begin("mail cache purge deadlines"); + + mail_cache_purge_drop_init(&cache, &hdr, &ctx); + test_assert_cmp(cache.headers_capped, ==, FALSE); + test_assert_cmp(ctx.max_yes_downgrade_time, ==, BASE_TIME - DROP_SECS); + test_assert_cmp(ctx.max_temp_drop_time, ==, BASE_TIME - DROP_SECS - DROP_SECS); + + cache.headers_capped = TRUE; + mail_cache_purge_drop_init(&cache, &hdr, &ctx); + test_assert_cmp(cache.headers_capped, ==, TRUE); + test_assert_cmp(ctx.max_yes_downgrade_time, ==, BASE_TIME - DROP_SECS/4); + test_assert_cmp(ctx.max_temp_drop_time, ==, BASE_TIME - DROP_SECS/4 - DROP_SECS/4); + + test_end(); +} + int main(void) { static void (*const test_functions[])(void) = { @@ -1070,6 +1106,7 @@ int main(void) test_mail_cache_update_need_purge_continued_records2, test_mail_cache_update_need_purge_deleted_records, test_mail_cache_update_need_purge_deleted_records2, + test_mail_cache_purge_deadlines, NULL }; return test_run(test_functions);