dovecot-1.0: maildir_storage_sync_force(): Don't wait on trying ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 1 09:31:56 EET 2007


details:   http://hg.dovecot.org/dovecot-1.0/rev/d754a1b673fa
changeset: 5472:d754a1b673fa
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 01 09:31:52 2007 +0200
description:
maildir_storage_sync_force(): Don't wait on trying to lock uidlist. Just try
once and if it fails, find the changed filenames and do nothing else.

diffstat:

3 files changed, 36 insertions(+), 14 deletions(-)
src/lib-storage/index/maildir/maildir-sync.c    |   29 +++++++++++++++--------
src/lib-storage/index/maildir/maildir-uidlist.c |   18 +++++++++++---
src/lib-storage/index/maildir/maildir-uidlist.h |    3 +-

diffs (145 lines):

diff -r b63f48fbeb2a -r d754a1b673fa src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c	Sat Dec 01 09:25:39 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Sat Dec 01 09:31:52 2007 +0200
@@ -215,13 +215,15 @@ struct maildir_sync_context {
 struct maildir_sync_context {
         struct maildir_mailbox *mbox;
 	const char *new_dir, *cur_dir;
-	bool partial;
 
 	unsigned int move_count, check_count;
 	time_t last_touch, last_notify;
 
 	struct maildir_uidlist_sync_ctx *uidlist_sync_ctx;
         struct maildir_index_sync_context *index_sync_ctx;
+
+	unsigned int partial:1;
+	unsigned int locked:1;
 };
 
 struct maildir_index_sync_context {
@@ -800,7 +802,7 @@ static int maildir_scan_dir(struct maild
 
 	ctx->move_count = 0;
 	move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) &&
-		!ctx->mbox->ibox.keep_recent;
+		!ctx->mbox->ibox.keep_recent && ctx->locked;
 	while ((dp = readdir(dirp)) != NULL) {
 		if (dp->d_name[0] == '.')
 			continue;
@@ -1412,18 +1414,25 @@ static int maildir_sync_context(struct m
 	   problem rarely happens except under high amount of modifications.
 	*/
 
-	ctx->partial = !cur_changed;
-	sync_flags = ctx->partial ? MAILDIR_UIDLIST_SYNC_PARTIAL : 0;
+	if (!cur_changed || forced) {
+		ctx->partial = TRUE;
+		sync_flags = MAILDIR_UIDLIST_SYNC_PARTIAL;
+		if (forced)
+			sync_flags |= MAILDIR_UIDLIST_SYNC_FORCE;
+	} else {
+		ctx->partial = FALSE;
+		sync_flags = 0;
+	}
 	ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, sync_flags,
 					&ctx->uidlist_sync_ctx);
 	if (ret <= 0) {
-		/* failure / timeout. if forced is TRUE, we could still go
-		   forward and check only for renamed files, but is it worth
-		   the trouble? .. */
+		/* failure / timeout */
+		i_assert(ret < 0 || !forced);
 		return ret;
 	}
-
-	if (!ctx->mbox->syncing_commit) {
+	ctx->locked = maildir_uidlist_is_locked(ctx->mbox->uidlist);
+
+	if (!ctx->mbox->syncing_commit && ctx->locked) {
 		if (maildir_sync_index_begin(ctx->mbox,
 					     &ctx->index_sync_ctx) < 0)
 			return -1;
@@ -1454,7 +1463,7 @@ static int maildir_sync_context(struct m
 		maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx);
 	}
 
-	if (!ctx->mbox->syncing_commit) {
+	if (!ctx->mbox->syncing_commit && ctx->locked) {
 		/* NOTE: index syncing here might cause a re-sync due to
 		   files getting lost, so this function might be called
 		   re-entrantly. FIXME: and that breaks in
diff -r b63f48fbeb2a -r d754a1b673fa src/lib-storage/index/maildir/maildir-uidlist.c
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Sat Dec 01 09:25:39 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Sat Dec 01 09:31:52 2007 +0200
@@ -74,6 +74,7 @@ struct maildir_uidlist_sync_ctx {
 	unsigned int partial:1;
 	unsigned int finished:1;
 	unsigned int failed:1;
+	unsigned int locked:1;
 };
 
 struct maildir_uidlist_iter_ctx {
@@ -805,13 +806,19 @@ int maildir_uidlist_sync_init(struct mai
 	size_t size;
 	int ret;
 
-	if ((ret = maildir_uidlist_lock(uidlist)) <= 0)
-		return ret;
+	if ((sync_flags & MAILDIR_UIDLIST_SYNC_FORCE) == 0) {
+		if ((ret = maildir_uidlist_lock(uidlist)) <= 0)
+			return ret;
+	} else {
+		if ((ret = maildir_uidlist_try_lock(uidlist)) < 0)
+			return -1;
+	}
 
 	*sync_ctx_r = ctx = i_new(struct maildir_uidlist_sync_ctx, 1);
 	ctx->uidlist = uidlist;
 	ctx->sync_flags = sync_flags;
 	ctx->partial = (sync_flags & MAILDIR_UIDLIST_SYNC_PARTIAL) != 0;
+	ctx->locked = ret > 0;
 
 	if (ctx->partial) {
 		/* initially mark all nonsynced */
@@ -842,6 +849,10 @@ maildir_uidlist_sync_next_partial(struct
 	i_assert(rec != NULL || UIDLIST_IS_LOCKED(uidlist));
 
 	if (rec == NULL) {
+		if (!ctx->locked) {
+			/* we can't add it, so just ignore it */
+			return 1;
+		}
 		if (ctx->new_files_count == 0) {
 			ctx->first_new_pos =
 				buffer_get_used_size(uidlist->record_buf) /
@@ -1089,6 +1100,7 @@ int maildir_uidlist_sync_deinit(struct m
 			   the rewrite */
 			ctx->uidlist->need_rewrite = TRUE;
 		} else {
+			i_assert(ctx->locked);
 			t_push();
 			ret = maildir_uidlist_rewrite(ctx->uidlist);
 			t_pop();
@@ -1099,7 +1111,7 @@ int maildir_uidlist_sync_deinit(struct m
 		}
 	}
 
-	if (!unlocked)
+	if (!unlocked && ctx->locked)
 		maildir_uidlist_unlock(ctx->uidlist);
 
 	if (ctx->files != NULL)
diff -r b63f48fbeb2a -r d754a1b673fa src/lib-storage/index/maildir/maildir-uidlist.h
--- a/src/lib-storage/index/maildir/maildir-uidlist.h	Sat Dec 01 09:25:39 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.h	Sat Dec 01 09:31:52 2007 +0200
@@ -6,7 +6,8 @@ struct maildir_uidlist_sync_ctx;
 struct maildir_uidlist_sync_ctx;
 
 enum maildir_uidlist_sync_flags {
-	MAILDIR_UIDLIST_SYNC_PARTIAL	= 0x01
+	MAILDIR_UIDLIST_SYNC_PARTIAL	= 0x01,
+	MAILDIR_UIDLIST_SYNC_FORCE	= 0x02
 };
 
 enum maildir_uidlist_rec_flag {


More information about the dovecot-cvs mailing list