From: Timo Sirainen Date: Wed, 1 Apr 2020 13:31:32 +0000 (+0300) Subject: lib-index: Cache compression could have lost data for recently added mails X-Git-Tag: 2.3.11.2~383 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbd1549ed4136cd4299e5f4406ceb4f5cb6f3b11;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Cache compression could have lost data for recently added mails mail_index_sync_ctx.view may not have seen all the newly added mails, which caused compression to skip those mails. Use a whole new view instead, which guarantees that all mails are seen. --- diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index b5da09cb0f..f5ce512133 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -940,29 +940,19 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) record_count and deleted_record_count. That also has a side effect of updating whether cache needs to be compressed. */ if (ret == 0 && mail_cache_need_compress(index->cache)) { - struct mail_index_transaction *cache_trans; - enum mail_index_transaction_flags trans_flags; - - trans_flags = MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; - if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_FSYNC) != 0) - trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_FSYNC; - cache_trans = mail_index_transaction_begin(ctx->view, trans_flags); - if (mail_cache_compress_with_trans(index->cache, cache_trans, - index->cache->need_compress_file_seq) < 0) - mail_index_transaction_rollback(&cache_trans); - else { - /* can't really do anything if index commit fails */ - (void)mail_index_transaction_commit(&cache_trans); - /* Make sure the newly committed cache record offsets - are updated to the current index. This is important - if the dovecot.index gets recreated below, because - rotation of dovecot.index.log also re-maps the index - to make sure everything is up-to-date. But if it - wasn't, mail_index_write() will just assert-crash - because log_file_head_offset changed. */ - if (mail_index_map(ctx->index, MAIL_INDEX_SYNC_HANDLER_FILE) <= 0) - ret = -1; + if (mail_cache_compress(index->cache, + index->cache->need_compress_file_seq) < 0) { + /* can't really do anything if it fails */ } + /* Make sure the newly committed cache record offsets are + updated to the current index. This is important if the + dovecot.index gets recreated below, because rotation of + dovecot.index.log also re-maps the index to make sure + everything is up-to-date. But if it wasn't, + mail_index_write() will just assert-crash because + log_file_head_offset changed. */ + if (mail_index_map(ctx->index, MAIL_INDEX_SYNC_HANDLER_FILE) <= 0) + ret = -1; } /* Log rotation is allowed only if everything was synced. Note that