]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_cache_compress_with_trans() - Don't return lock anymore
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 27 Mar 2020 11:02:37 +0000 (13:02 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
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.

src/lib-index/mail-cache-compress.c
src/lib-index/mail-cache.h
src/lib-index/mail-index-sync.c
src/lib-storage/index/index-rebuild.c

index 5225defbbc127f5891d7cf8be25d40797bd60688..906904bf6b8bf6f191164ec5a18f0a5b2dff2abb 100644 (file)
@@ -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 &&
index b1ce97cae1d2074909484425b9d1d95a074caa2e..7e6338e14cfb283c25992b92199136955936f840 100644 (file)
@@ -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. */
index 247bd1d352f56c2abd58819accf839106c796c6f..b5da09cb0f5c1b472fa401954d11a882783e5d88 100644 (file)
@@ -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
index 01d2028d6f624874788c3f7884cafdf181e68847..713e6b59fcdc8cd5d116720bee1951c139b01410 100644 (file)
@@ -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) {