From: Timo Sirainen Date: Tue, 31 Mar 2020 13:43:07 +0000 (+0300) Subject: lib-index: Fix checking if cache should be compressed because it's getting too large X-Git-Tag: 2.3.11.2~407 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32b7c2a821b77e91b5b63fd6827a90532b768e18;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix checking if cache should be compressed because it's getting too large 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. --- diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index 0fe5540583..bb40023c3c 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -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 || diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index de81bcbeba..763e8ba558 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -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)) {