]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: If cache file is compressed during transaction, discard only flushed records
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 26 Mar 2020 14:44:26 +0000 (16:44 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
Cache records that are still in memory can be written to the new file.

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

index 936fa0033d1590b7902d6c0c6fd8335e5a8ee0e7..953172ec9e5a7af711743b3a529c3a4c87ecb742 100644 (file)
@@ -134,7 +134,7 @@ void mail_cache_decision_add(struct mail_cache_view *view, uint32_t seq,
 
        i_assert(field < cache->fields_count);
 
-       if (MAIL_CACHE_IS_UNUSABLE(cache) || view->no_decision_updates)
+       if (view->no_decision_updates)
                return;
 
        if (cache->fields[field].field.decision != MAIL_CACHE_DECISION_NO) {
index d24ca3ed2f9c37a00209ee22a426dc756f7b206b..383bfbce8a4d2137dfe6fb9f8d3af80efa19027e 100644 (file)
@@ -200,7 +200,9 @@ mail_cache_transaction_compress(struct mail_cache_transaction_ctx *ctx)
                        mail_cache_compress_unlock(&lock);
        }
        mail_index_view_close(&view);
-       mail_cache_transaction_reset(ctx);
+       /* already written cache records must be forgotten, but records in
+          memory can still be written to the new cache file */
+       mail_cache_transaction_forget_flushed(ctx);
        return ret;
 }
 
@@ -295,10 +297,10 @@ static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx)
        if (ctx->cache_file_seq == 0)
                ctx->cache_file_seq = cache->hdr->file_seq;
        else if (ctx->cache_file_seq != cache->hdr->file_seq) {
-               if (mail_cache_unlock(cache) < 0)
-                       return -1;
-               mail_cache_transaction_reset(ctx);
-               return 0;
+               /* already written cache records must be forgotten, but records
+                  in memory can still be written to the new cache file */
+               mail_cache_transaction_forget_flushed(ctx);
+               i_assert(ctx->cache_file_seq == cache->hdr->file_seq);
        }
        return 1;
 }
@@ -750,13 +752,9 @@ void mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq,
            (MAIL_CACHE_DECISION_NO | MAIL_CACHE_DECISION_FORCED))
                return;
 
-       if (MAIL_CACHE_IS_UNUSABLE(ctx->cache) && !ctx->tried_compression) {
-               /* Cache file isn't created yet. Create it using compression
-                  before anything is added to transaction, so fields aren't
-                  lost when compression causes transaction to be reset.
-                  FIXME: get rid of this in later commits */
-               (void)mail_cache_transaction_compress(ctx);
-       }
+       /* If the cache file exists, make sure the caching decisions have been
+          read. */
+       mail_cache_transaction_open_if_needed(ctx);
 
        mail_cache_decision_add(ctx->view, seq, field_idx);