]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Try to compress cache when it's about to become too large
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 10 Feb 2020 16:19:34 +0000 (18:19 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 14 Feb 2020 08:42:53 +0000 (08:42 +0000)
src/lib-index/mail-cache-transaction.c

index 0ff2545c4a94a234abd850cf2d6500e33d34d4dd..43779ba62defc948fdbc0849470fa688d630c2a4 100644 (file)
@@ -254,10 +254,21 @@ mail_cache_transaction_open_if_needed(struct mail_cache_transaction_ctx *ctx)
 static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx)
 {
        struct mail_cache *cache = ctx->cache;
+       const uoff_t cache_max_size =
+               cache->index->optimization_set.cache.max_size;
        int ret;
 
        mail_cache_transaction_open_if_needed(ctx);
 
+       if (!ctx->tried_compression && ctx->cache_data != NULL &&
+           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 ||
+                   cache->hdr->deleted_record_count > 0)
+                       (void)mail_cache_transaction_compress(ctx);
+       }
+
        if ((ret = mail_cache_lock(cache)) <= 0) {
                if (ret < 0)
                        return -1;