]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Added mail_index_sync_set_reason() to improve lock wait log warnings
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 09:46:13 +0000 (11:46 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 09:46:13 +0000 (11:46 +0200)
src/lib-index/mail-index-sync.c
src/lib-index/mail-index.h

index 023e54fa1c8a48a22ce0b5ec76279b9e11922771..34a9c78c6b8441f4d4a99f6469ee4bbe5046d4d1 100644 (file)
@@ -16,6 +16,7 @@ struct mail_index_sync_ctx {
        struct mail_index_transaction *sync_trans, *ext_trans;
        struct mail_index_transaction_commit_result *sync_commit_result;
        enum mail_index_sync_flags flags;
+       char *reason;
 
        const struct mail_transaction_header *hdr;
        const void *data;
@@ -732,22 +733,36 @@ void mail_index_sync_no_warning(struct mail_index_sync_ctx *ctx)
        ctx->no_warning = TRUE;
 }
 
+void mail_index_sync_set_reason(struct mail_index_sync_ctx *ctx,
+                               const char *reason)
+{
+       i_free(ctx->reason);
+       ctx->reason = i_strdup(reason);
+}
+
 static void mail_index_sync_end(struct mail_index_sync_ctx **_ctx)
 {
         struct mail_index_sync_ctx *ctx = *_ctx;
+       const char *lock_reason;
 
        i_assert(ctx->index->syncing);
 
        *_ctx = NULL;
 
        ctx->index->syncing = FALSE;
-       mail_transaction_log_sync_unlock(ctx->index->log,
-               ctx->no_warning ? NULL : "Mailbox was synchronized");
+       if (ctx->no_warning)
+               lock_reason = NULL;
+       else if (ctx->reason != NULL)
+               lock_reason = ctx->reason;
+       else
+               lock_reason = "Mailbox was synchronized";
+       mail_transaction_log_sync_unlock(ctx->index->log, lock_reason);
 
        mail_index_view_close(&ctx->view);
        mail_index_transaction_rollback(&ctx->sync_trans);
        if (array_is_created(&ctx->sync_list))
                array_free(&ctx->sync_list);
+       i_free(ctx->reason);
        i_free(ctx);
 }
 
index a5ed11fcbcda5015fe13b196ef455a77dda65f25..bf4620db0ee782f602a89f5ff3d7137c43137cf7 100644 (file)
@@ -386,6 +386,11 @@ void mail_index_sync_set_commit_result(struct mail_index_sync_ctx *ctx,
    MAIL_TRANSACTION_LOG_LOCK_WARN_SECS seconds. Usually this is called because
    the caller itself already logged a warning about it. */
 void mail_index_sync_no_warning(struct mail_index_sync_ctx *ctx);
+/* If a warning is logged because syncing took over
+   MAIL_TRANSACTION_LOG_LOCK_WARN_SECS seconds, log this as the reason for the
+   syncing. */
+void mail_index_sync_set_reason(struct mail_index_sync_ctx *ctx,
+                               const char *reason);
 /* Commit synchronization by writing all changes to mail index file. */
 int mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
 /* Rollback synchronization - none of the changes listed by sync_next() are