From: Timo Sirainen Date: Thu, 26 Mar 2020 14:44:26 +0000 (+0200) Subject: lib-index: If cache file is compressed during transaction, discard only flushed records X-Git-Tag: 2.3.11.2~424 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7647aefc81fd9576741c8155014edafe4697dec5;p=thirdparty%2Fdovecot%2Fcore.git lib-index: If cache file is compressed during transaction, discard only flushed records Cache records that are still in memory can be written to the new file. --- diff --git a/src/lib-index/mail-cache-decisions.c b/src/lib-index/mail-cache-decisions.c index 936fa0033d..953172ec9e 100644 --- a/src/lib-index/mail-cache-decisions.c +++ b/src/lib-index/mail-cache-decisions.c @@ -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) { diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index d24ca3ed2f..383bfbce8a 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -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);