]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix checking if cache should be compressed because it's getting too large
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 31 Mar 2020 13:43:07 +0000 (16:43 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
Most importantly fixed updating last_stat_size whenever cache is locked.
This now guarantees that it's always fully up-to-date when it's being
checked. Most of the other places updating last_stat_size are now
unnecessary, but I left them in case they'll be useful in the future.

Fixed also off-by-one where purging was done also when cache was exactly at
its maximum size.

src/lib-index/mail-cache-transaction.c
src/lib-index/mail-cache.c

index 0fe554058364e6ca13f0be4d436dd7658d09d92d..bb40023c3c98c9df7d59dd8379076f7ca5921d96 100644 (file)
@@ -214,7 +214,7 @@ static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx)
        i_assert(!MAIL_CACHE_IS_UNUSABLE(cache));
 
        if (!ctx->tried_compression && ctx->cache_data != NULL &&
-           cache->last_stat_size + ctx->cache_data->used >= cache_max_size) {
+           cache->last_stat_size + ctx->cache_data->used > cache_max_size) {
                /* Looks like cache file is becoming too large. Try to compress
                   it to free up some space. */
                if (cache->hdr->continued_record_count > 0 ||
index de81bcbebaf8124222cf267ede149af4de711afe..763e8ba558f6f720cab0b7b99739fcad3ff3912c 100644 (file)
@@ -180,6 +180,7 @@ static bool mail_cache_need_reopen(struct mail_cache *cache)
                mail_cache_set_syscall_error(cache, "stat()");
                return TRUE;
        }
+       cache->last_stat_size = st.st_size;
 
        if (st.st_ino != cache->st_ino ||
            !CMP_DEV_T(st.st_dev, cache->st_dev)) {