]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Shorten mail_cache_unaccessed_field_drop effective value to 1/4 while...
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 6 Dec 2022 11:31:21 +0000 (11:31 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 16 Dec 2022 17:31:01 +0000 (17:31 +0000)
This is done to help the cache to converge quicker to the intended state.

src/lib-index/mail-cache-purge.c
src/lib-index/test-mail-cache-purge.c

index 477f80d2a3cee48fd1f45f71a95e4ebb7f69c249..789689f85478ed7c1cb38482c8270cf4f35eb503 100644 (file)
@@ -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;
        }
 }
 
index 790226eda63f393e7b1ffc030962c5d4eafc3613..54086af0dd45fe15e8721c23b85f6029433376a4 100644 (file)
@@ -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);