dovecot: Don't sync mailbox immediately when committing transact...

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 22 13:55:43 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/a62923d3c969
changeset: 6452:a62923d3c969
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 22 13:44:37 2007 +0300
description:
Don't sync mailbox immediately when committing transactions. When it's done
later, make sure we sync the mailbox if there are pending changes in
transaction log.

diffstat:

3 files changed, 41 insertions(+), 47 deletions(-)
src/lib-storage/index/maildir/maildir-sync.c        |   83 +++++++++----------
src/lib-storage/index/maildir/maildir-sync.h        |    2 
src/lib-storage/index/maildir/maildir-transaction.c |    3 

diffs (161 lines):

diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c	Sat Sep 22 13:42:25 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Sat Sep 22 13:44:37 2007 +0300
@@ -659,27 +659,43 @@ static bool move_recent_messages(struct 
 		maildir_uidlist_get_next_uid(ctx->mbox->uidlist);
 }
 
+static int maildir_sync_get_changes(struct maildir_sync_context *ctx,
+				    bool *new_changed_r, bool *cur_changed_r)
+{
+	enum mail_index_sync_flags flags = 0;
+
+	if (maildir_sync_quick_check(ctx->mbox, ctx->new_dir, ctx->cur_dir,
+				     new_changed_r, cur_changed_r) < 0)
+		return -1;
+
+	if (*new_changed_r || *cur_changed_r)
+		return 1;
+
+	if (move_recent_messages(ctx)) {
+		*new_changed_r = TRUE;
+		return 1;
+	}
+
+	if (!ctx->mbox->ibox.keep_recent)
+		flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
+
+	return mail_index_sync_have_any(ctx->mbox->ibox.index, flags) ? 1 : 0;
+}
+
 static int maildir_sync_context(struct maildir_sync_context *ctx, bool forced,
-				bool sync_last_commit)
-{
-	bool new_changed, cur_changed, full_rescan = FALSE;
+				bool *lost_files_r)
+{
+	bool new_changed, cur_changed;
 	int ret;
 
-	if (sync_last_commit) {
-		new_changed = cur_changed = FALSE;
-	} else if (!forced) {
-		if (maildir_sync_quick_check(ctx->mbox,
-					     ctx->new_dir, ctx->cur_dir,
-					     &new_changed, &cur_changed) < 0)
-			return -1;
-
-		if (!new_changed && !cur_changed) {
-			if (!move_recent_messages(ctx))
-				return 1;
-			new_changed = TRUE;
-		}
-	} else {
+	*lost_files_r = FALSE;
+
+	if (forced)
 		new_changed = cur_changed = TRUE;
+	else {
+		ret = maildir_sync_get_changes(ctx, &new_changed, &cur_changed);
+		if (ret <= 0)
+			return ret;
 	}
 
 	/*
@@ -781,42 +797,24 @@ static int maildir_sync_context(struct m
 		if (ret < 0)
 			return -1;
 		if (ret == 0)
-			full_rescan = TRUE;
+			*lost_files_r = TRUE;
 
 		i_assert(maildir_uidlist_is_locked(ctx->mbox->uidlist));
 	}
 
-	ret = maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx);
-	return ret < 0 ? -1 : (full_rescan ? 0 : 1);
+	return maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx);
 }
 
 int maildir_storage_sync_force(struct maildir_mailbox *mbox)
 {
         struct maildir_sync_context *ctx;
+	bool lost_files;
 	int ret;
 
 	ctx = maildir_sync_context_new(mbox);
-	ret = maildir_sync_context(ctx, TRUE, FALSE);
+	ret = maildir_sync_context(ctx, TRUE, &lost_files);
 	maildir_sync_deinit(ctx);
-	return ret < 0 ? -1 : 0;
-}
-
-int maildir_sync_last_commit(struct maildir_mailbox *mbox)
-{
-        struct maildir_sync_context *ctx;
-	int ret = 0;
-
-	if (mbox->ibox.commit_log_file_seq != 0) {
-		ctx = maildir_sync_context_new(mbox);
-		ret = maildir_sync_context(ctx, FALSE, TRUE);
-		maildir_sync_deinit(ctx);
-	}
-
-	if (ret == 0) {
-		if (maildir_uidlist_update(mbox->uidlist) < 0)
-			ret = -1;
-	}
-	return ret < 0 ? -1 : 0;
+	return ret;
 }
 
 struct mailbox_sync_context *
@@ -824,6 +822,7 @@ maildir_storage_sync_init(struct mailbox
 {
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
 	struct maildir_sync_context *ctx;
+	bool lost_files;
 	int ret = 0;
 
 	if (!box->opened)
@@ -835,13 +834,13 @@ maildir_storage_sync_init(struct mailbox
 		mbox->ibox.sync_last_check = ioloop_time;
 
 		ctx = maildir_sync_context_new(mbox);
-		ret = maildir_sync_context(ctx, FALSE, FALSE);
+		ret = maildir_sync_context(ctx, FALSE, &lost_files);
 		maildir_sync_deinit(ctx);
 
 		i_assert(!maildir_uidlist_is_locked(mbox->uidlist) ||
 			 mbox->ibox.keep_locked);
 
-		if (ret == 0) {
+		if (lost_files) {
 			/* lost some files from new/, see if thery're in cur/ */
 			ret = maildir_storage_sync_force(mbox);
 		}
diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-sync.h
--- a/src/lib-storage/index/maildir/maildir-sync.h	Sat Sep 22 13:42:25 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.h	Sat Sep 22 13:44:37 2007 +0300
@@ -32,8 +32,6 @@ int maildir_sync_index_finish(struct mai
 int maildir_sync_index_finish(struct maildir_index_sync_context **sync_ctx,
 			      bool failed, bool cancel);
 
-int maildir_sync_last_commit(struct maildir_mailbox *mbox);
-
 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);
diff -r cbfce8bbc917 -r a62923d3c969 src/lib-storage/index/maildir/maildir-transaction.c
--- a/src/lib-storage/index/maildir/maildir-transaction.c	Sat Sep 22 13:42:25 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-transaction.c	Sat Sep 22 13:44:37 2007 +0300
@@ -40,9 +40,6 @@ static int maildir_transaction_commit(st
 
 	if (save_ctx != NULL)
 		maildir_transaction_save_commit_post(save_ctx);
-
-	if (ret == 0 && !syncing)
-		ret = maildir_sync_last_commit(mbox);
 	return ret;
 }
 


More information about the dovecot-cvs mailing list