]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
maildir: Log a warning if scanning new/ or cur/ takes over 60s.
authorTimo Sirainen <tss@iki.fi>
Tue, 23 Nov 2010 16:23:31 +0000 (16:23 +0000)
committerTimo Sirainen <tss@iki.fi>
Tue, 23 Nov 2010 16:23:31 +0000 (16:23 +0000)
src/lib-storage/index/maildir/maildir-sync-index.c
src/lib-storage/index/maildir/maildir-sync.c
src/lib-storage/index/maildir/maildir-sync.h

index 7e710619ec374cca939eebe8a0182087ce7b63fb..f9764b9ab8ebe5d1afc6cc916e085faf3cba35ab 100644 (file)
@@ -15,8 +15,6 @@
 #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;
index 0c5bf027763fb61b797793c638fc63ab28527e57..0a7b224ae84f1d2dc310330a56521a2816ff0b3f 100644 (file)
@@ -363,8 +363,8 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final)
        struct dirent *dp;
        struct stat st;
        enum maildir_uidlist_rec_flag flags;
-       unsigned int i = 0, move_count = 0;
-       time_t now;
+       unsigned int time_diff, i, readdir_count = 0, move_count = 0;
+       time_t start_time;
        int ret = 1;
        bool move_new, dir_changed = FALSE;
 
@@ -404,13 +404,13 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final)
        }
 #endif
 
-       now = time(NULL);
+       start_time = time(NULL);
        if (new_dir) {
-               ctx->mbox->maildir_hdr.new_check_time = now;
+               ctx->mbox->maildir_hdr.new_check_time = start_time;
                ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
                ctx->mbox->maildir_hdr.new_mtime_nsecs = ST_MTIME_NSEC(st);
        } else {
-               ctx->mbox->maildir_hdr.cur_check_time = now;
+               ctx->mbox->maildir_hdr.cur_check_time = start_time;
                ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
                ctx->mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st);
        }
@@ -468,8 +468,8 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final)
                                MAILDIR_UIDLIST_REC_FLAG_RECENT;
                }
 
-               i++;
-               if ((i % MAILDIR_SLOW_CHECK_COUNT) == 0)
+               readdir_count++;
+               if ((readdir_count % MAILDIR_SLOW_CHECK_COUNT) == 0)
                        maildir_sync_notify(ctx);
 
                ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx,
@@ -510,23 +510,29 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final)
 
        if (dir_changed) {
                /* save the exact new times. the new mtimes should be >=
-                  "now", but just in case something weird happens and mtime
-                  doesn't update, use "now". */
+                  "start_time", but just in case something weird happens and
+                  mtime doesn't update, use "start_time". */
                if (stat(ctx->new_dir, &st) == 0) {
                        ctx->mbox->maildir_hdr.new_check_time =
-                               I_MAX(st.st_mtime, now);
+                               I_MAX(st.st_mtime, start_time);
                        ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
                        ctx->mbox->maildir_hdr.new_mtime_nsecs =
                                ST_MTIME_NSEC(st);
                }
                if (stat(ctx->cur_dir, &st) == 0) {
                        ctx->mbox->maildir_hdr.new_check_time =
-                               I_MAX(st.st_mtime, now);
+                               I_MAX(st.st_mtime, start_time);
                        ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
                        ctx->mbox->maildir_hdr.cur_mtime_nsecs =
                                ST_MTIME_NSEC(st);
                }
        }
+       time_diff = time(NULL) - start_time;
+       if (time_diff >= MAILDIR_SYNC_TIME_WARN_SECS) {
+               i_warning("Maildir: Scanning %s took %u seconds "
+                         "(%u readdir()s, %u rename()s to cur/)",
+                         path, time_diff, readdir_count, move_count);
+       }
 
        return ret < 0 ? -1 :
                (move_count <= MAILDIR_RENAME_RESCAN_COUNT || final ? 0 : 1);
index 44c72895c10ee528938e49741573f5275e16b0e1..a9d6c8a27fe002e64a6ac12790bfaddbe4f4d62f 100644 (file)
@@ -11,6 +11,8 @@
 /* readdir() should be pretty fast to do, but check anyway every n files
    to see if we need to touch the uidlist lock. */
 #define MAILDIR_SLOW_CHECK_COUNT 10000
+/* If syncing takes longer than this, log a warning. */
+#define MAILDIR_SYNC_TIME_WARN_SECS 60
 
 struct maildir_mailbox;