From: Timo Sirainen Date: Fri, 27 Mar 2020 11:02:37 +0000 (+0200) Subject: lib-index: mail_cache_compress_with_trans() - Don't return lock anymore X-Git-Tag: 2.3.11.2~409 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41dceb66ad4ccffa7d10039680e6afaae783ae35;p=thirdparty%2Fdovecot%2Fcore.git lib-index: mail_cache_compress_with_trans() - Don't return lock anymore Now that transaction log is always locked during cache compression, it doesn't matter if the cache is unlocked before or after the transaction log commit. --- diff --git a/src/lib-index/mail-cache-compress.c b/src/lib-index/mail-cache-compress.c index 5225defbbc..906904bf6b 100644 --- a/src/lib-index/mail-cache-compress.c +++ b/src/lib-index/mail-cache-compress.c @@ -24,10 +24,6 @@ struct mail_cache_copy_context { bool new_msg; }; -struct mail_cache_compress_lock { - struct dotlock *dotlock; -}; - static void mail_cache_merge_bitmask(struct mail_cache_copy_context *ctx, const struct mail_cache_iterate_field *field) @@ -497,8 +493,7 @@ static int mail_cache_compress_locked(struct mail_cache *cache, static int mail_cache_compress_full(struct mail_cache *cache, struct mail_index_transaction *trans, - uint32_t compress_file_seq, - struct mail_cache_compress_lock **lock_r) + uint32_t compress_file_seq) { struct dotlock *dotlock = NULL; bool unlock = FALSE; @@ -507,12 +502,8 @@ mail_cache_compress_full(struct mail_cache *cache, i_assert(!cache->compressing); i_assert(cache->index->log_sync_locked); - *lock_r = NULL; - - if (MAIL_INDEX_IS_IN_MEMORY(cache->index) || cache->index->readonly) { - *lock_r = i_new(struct mail_cache_compress_lock, 1); + if (MAIL_INDEX_IS_IN_MEMORY(cache->index) || cache->index->readonly) return 0; - } /* compression isn't very efficient with small read()s */ if (cache->map_with_read) { @@ -552,32 +543,27 @@ mail_cache_compress_full(struct mail_cache *cache, if (mail_cache_unlock(cache) < 0) ret = -1; } + if (dotlock != NULL) + file_dotlock_delete(&dotlock); if (ret < 0) { - if (dotlock != NULL) - file_dotlock_delete(&dotlock); /* the fields may have been updated in memory already. reverse those changes by re-reading them from file. */ (void)mail_cache_header_fields_read(cache); - } else { - *lock_r = i_new(struct mail_cache_compress_lock, 1); - (*lock_r)->dotlock = dotlock; } return ret; } int mail_cache_compress_with_trans(struct mail_cache *cache, struct mail_index_transaction *trans, - uint32_t compress_file_seq, - struct mail_cache_compress_lock **lock_r) + uint32_t compress_file_seq) { - return mail_cache_compress_full(cache, trans, compress_file_seq, lock_r); + return mail_cache_compress_full(cache, trans, compress_file_seq); } int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq) { struct mail_index_view *view; struct mail_index_transaction *trans; - struct mail_cache_compress_lock *lock; bool lock_log; int ret; @@ -599,12 +585,11 @@ int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq) MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); if (ret < 0) ; - else if ((ret = mail_cache_compress_full(cache, trans, compress_file_seq, &lock)) < 0) + else if ((ret = mail_cache_compress_full(cache, trans, compress_file_seq)) < 0) mail_index_transaction_rollback(&trans); else { if (mail_index_transaction_commit(&trans) < 0) ret = -1; - mail_cache_compress_unlock(&lock); } mail_index_view_close(&view); if (lock_log) { @@ -614,17 +599,6 @@ int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq) return ret; } -void mail_cache_compress_unlock(struct mail_cache_compress_lock **_lock) -{ - struct mail_cache_compress_lock *lock = *_lock; - - *_lock = NULL; - - if (lock->dotlock != NULL) - file_dotlock_delete(&lock->dotlock); - i_free(lock); -} - bool mail_cache_need_compress(struct mail_cache *cache) { return cache->need_compress_file_seq != 0 && diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index b1ce97cae1..7e6338e14c 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -8,7 +8,6 @@ struct mail_cache; struct mail_cache_view; struct mail_cache_transaction_ctx; -struct mail_cache_compress_lock; enum mail_cache_decision_type { /* Not needed currently */ @@ -77,10 +76,8 @@ bool mail_cache_need_compress(struct mail_cache *cache); done always regardless of file_seq. */ int mail_cache_compress_with_trans(struct mail_cache *cache, struct mail_index_transaction *trans, - uint32_t compress_file_seq, - struct mail_cache_compress_lock **lock_r); + uint32_t compress_file_seq); int mail_cache_compress(struct mail_cache *cache, uint32_t compress_file_seq); -void mail_cache_compress_unlock(struct mail_cache_compress_lock **lock); /* Returns TRUE if there is at least something in the cache. */ bool mail_cache_exists(struct mail_cache *cache); /* Open and read cache header. Returns 0 if ok, -1 if error/corrupted. */ diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index 247bd1d352..b5da09cb0f 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -875,7 +875,6 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) { struct mail_index_sync_ctx *ctx = *_ctx; struct mail_index *index = ctx->index; - struct mail_cache_compress_lock *cache_lock = NULL; const char *reason = NULL; uint32_t next_uid; bool want_rotate, index_undeleted, delete_index; @@ -949,13 +948,11 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) 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, - &cache_lock) < 0) + 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); - mail_cache_compress_unlock(&cache_lock); /* 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 diff --git a/src/lib-storage/index/index-rebuild.c b/src/lib-storage/index/index-rebuild.c index 01d2028d6f..713e6b59fc 100644 --- a/src/lib-storage/index/index-rebuild.c +++ b/src/lib-storage/index/index-rebuild.c @@ -235,20 +235,12 @@ void index_index_rebuild_deinit(struct index_rebuild_context **_ctx, index_rebuild_generate_uidvalidity_t *cb) { struct index_rebuild_context *ctx = *_ctx; - struct mail_cache_compress_lock *lock = NULL; *_ctx = NULL; /* initialize cache file with the old field decisions */ (void)mail_cache_compress_with_trans(ctx->box->cache, ctx->trans, - (uint32_t)-1, &lock); - if (lock != NULL) { - /* FIXME: this is a bit too early. ideally we should return it - from this function and unlock only after the transaction is - committed, but it would be an API change and this rebuilding - isn't happening normally anyway. */ - mail_cache_compress_unlock(&lock); - } + (uint32_t)-1); index_rebuild_header(ctx, cb); index_rebuild_box_name_header(ctx); if (ctx->backup_index != NULL) {