dovecot-2.0: maildir: Log a warning if scanning new/ or cur/ tak...

dovecot at dovecot.org dovecot at dovecot.org
Tue Nov 23 18:23:35 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/69efe4b2bc80
changeset: 12460:69efe4b2bc80
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Nov 23 16:23:31 2010 +0000
description:
maildir: Log a warning if scanning new/ or cur/ takes over 60s.

diffstat:

 src/lib-storage/index/maildir/maildir-sync-index.c |   2 --
 src/lib-storage/index/maildir/maildir-sync.c       |  28 +++++++++++++++++-----------
 src/lib-storage/index/maildir/maildir-sync.h       |   2 ++
 3 files changed, 19 insertions(+), 13 deletions(-)

diffs (100 lines):

diff -r 94fd6fee57a1 -r 69efe4b2bc80 src/lib-storage/index/maildir/maildir-sync-index.c
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Tue Nov 23 16:11:15 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Tue Nov 23 16:23:31 2010 +0000
@@ -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;
diff -r 94fd6fee57a1 -r 69efe4b2bc80 src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c	Tue Nov 23 16:11:15 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Tue Nov 23 16:23:31 2010 +0000
@@ -363,8 +363,8 @@
 	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 @@
 	}
 #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_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 @@
 
 	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);
diff -r 94fd6fee57a1 -r 69efe4b2bc80 src/lib-storage/index/maildir/maildir-sync.h
--- a/src/lib-storage/index/maildir/maildir-sync.h	Tue Nov 23 16:11:15 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-sync.h	Tue Nov 23 16:23:31 2010 +0000
@@ -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;
 


More information about the dovecot-cvs mailing list