]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
maildir: Log a warning if mailbox synchronization takes longer than 1 min.
authorTimo Sirainen <tss@iki.fi>
Thu, 23 Sep 2010 17:39:22 +0000 (18:39 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 23 Sep 2010 17:39:22 +0000 (18:39 +0100)
src/lib-storage/index/maildir/maildir-save.c
src/lib-storage/index/maildir/maildir-sync-index.c
src/lib-storage/index/maildir/maildir-sync.h

index ee5978bbde818dfcdea980e3dbfb31e6b1e0f38e..130f9066c2acfac2651baed5c737152267aedb26 100644 (file)
@@ -863,6 +863,7 @@ maildir_save_move_files_to_newcur(struct maildir_save_context *ctx)
                prev_mf = mf;
        }
 
+       maildir_sync_set_new_msgs_count(ctx->sync_ctx, array_count(&files));
        return maildir_transaction_fsync_dirs(ctx, new_changed, cur_changed);
 }
 
index ce685c375c809aa9ad412d5997658c6af3a29b29..c7e4d440233ad523965cf87b44fc6da7d69a776b 100644 (file)
@@ -15,6 +15,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#define MAILDIR_SYNC_TIME_WARN_SECS 60
+
 struct maildir_index_sync_context {
         struct maildir_mailbox *mbox;
        struct maildir_sync_context *maildir_sync_ctx;
@@ -31,6 +33,9 @@ struct maildir_index_sync_context {
 
        uint32_t uid;
        bool update_maildir_hdr_cur;
+
+       time_t start_time;
+       unsigned int flag_change_count, expunge_count, new_msgs_count;
 };
 
 struct maildir_keywords_sync_ctx *
@@ -39,6 +44,12 @@ maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx)
        return ctx->keywords_sync_ctx;
 }
 
+void maildir_sync_set_new_msgs_count(struct maildir_index_sync_context *ctx,
+                                    unsigned int count)
+{
+       ctx->new_msgs_count = count;
+}
+
 static bool
 maildir_expunge_is_valid_guid(struct maildir_index_sync_context *ctx,
                              uint32_t uid, const char *filename,
@@ -76,6 +87,8 @@ static int maildir_expunge(struct maildir_mailbox *mbox, const char *path,
 {
        struct mailbox *box = &mbox->box;
 
+       ctx->expunge_count++;
+
        if (unlink(path) == 0) {
                if (box->v.sync_notify != NULL) {
                        box->v.sync_notify(box, ctx->uid,
@@ -100,6 +113,8 @@ static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path,
        enum mail_index_sync_type sync_type;
        uint8_t flags8;
 
+       ctx->flag_change_count++;
+
        fname = strrchr(path, '/');
        i_assert(fname != NULL);
        fname++;
@@ -228,6 +243,7 @@ int maildir_sync_index_begin(struct maildir_mailbox *mbox,
        ctx->sync_changes =
                index_sync_changes_init(ctx->sync_ctx, ctx->view, ctx->trans,
                                        mbox->box.backend_readonly);
+       ctx->start_time = time(NULL);
 
        *ctx_r = ctx;
        return 0;
@@ -286,8 +302,19 @@ static int maildir_sync_index_finish(struct maildir_index_sync_context *ctx,
                                     bool success)
 {
        struct maildir_mailbox *mbox = ctx->mbox;
+       unsigned int time_diff;
        int ret = success ? 0 : -1;
 
+       time_diff = time(NULL) - ctx->start_time;
+       if (time_diff >= MAILDIR_SYNC_TIME_WARN_SECS) {
+               i_warning("Maildir %s: Synchronization took %u seconds "
+                         "(%u new msgs, %u flag change attempts, "
+                         "%u expunge attempts)",
+                         ctx->mbox->box.path, time_diff,
+                         ctx->new_msgs_count, ctx->flag_change_count,
+                         ctx->expunge_count);
+       }
+
        if (ret < 0)
                mail_index_sync_rollback(&ctx->sync_ctx);
        else {
index 375d04916d33a298307b5d7ccef810bd57cd9851..44c72895c10ee528938e49741573f5275e16b0e1 100644 (file)
@@ -37,6 +37,8 @@ void maildir_sync_index_rollback(struct maildir_index_sync_context **_ctx);
 struct maildir_keywords_sync_ctx *
 maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx);
 void maildir_sync_notify(struct maildir_sync_context *ctx);
+void maildir_sync_set_new_msgs_count(struct maildir_index_sync_context *ctx,
+                                    unsigned int count);
 
 int maildir_list_index_has_changed(struct mailbox *box,
                                   struct mail_index_view *list_view,