From 43955c82f9f52c969c777b3da00bc170183dfdf2 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 23 Nov 2010 16:23:31 +0000 Subject: [PATCH] maildir: Log a warning if scanning new/ or cur/ takes over 60s. --- .../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(-) diff --git a/src/lib-storage/index/maildir/maildir-sync-index.c b/src/lib-storage/index/maildir/maildir-sync-index.c index 7e710619ec..f9764b9ab8 100644 --- a/src/lib-storage/index/maildir/maildir-sync-index.c +++ b/src/lib-storage/index/maildir/maildir-sync-index.c @@ -15,8 +15,6 @@ #include #include -#define MAILDIR_SYNC_TIME_WARN_SECS 60 - struct maildir_index_sync_context { struct maildir_mailbox *mbox; struct maildir_sync_context *maildir_sync_ctx; diff --git a/src/lib-storage/index/maildir/maildir-sync.c b/src/lib-storage/index/maildir/maildir-sync.c index 0c5bf02776..0a7b224ae8 100644 --- a/src/lib-storage/index/maildir/maildir-sync.c +++ b/src/lib-storage/index/maildir/maildir-sync.c @@ -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); diff --git a/src/lib-storage/index/maildir/maildir-sync.h b/src/lib-storage/index/maildir/maildir-sync.h index 44c72895c1..a9d6c8a27f 100644 --- a/src/lib-storage/index/maildir/maildir-sync.h +++ b/src/lib-storage/index/maildir/maildir-sync.h @@ -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; -- 2.47.3