dovecot: Fixes to handling cache file syncs and expunging.

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 10 17:53:40 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/e78c51d6305f
changeset: 6756:e78c51d6305f
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 10 17:53:35 2007 +0200
description:
Fixes to handling cache file syncs and expunging.

diffstat:

4 files changed, 20 insertions(+), 10 deletions(-)
src/lib-index/mail-cache-sync-update.c |   10 ++--------
src/lib-index/mail-index-private.h     |    1 +
src/lib-index/mail-index-sync.c        |    7 +++++++
src/lib-index/mail-index-transaction.c |   12 ++++++++++--

diffs (94 lines):

diff -r b3de2053937f -r e78c51d6305f src/lib-index/mail-cache-sync-update.c
--- a/src/lib-index/mail-cache-sync-update.c	Sat Nov 10 17:40:11 2007 +0200
+++ b/src/lib-index/mail-cache-sync-update.c	Sat Nov 10 17:53:35 2007 +0200
@@ -91,10 +91,7 @@ int mail_cache_expunge_handler(struct ma
 	if (*cache_offset == 0)
 		return 0;
 
-	if (MAIL_CACHE_IS_UNUSABLE(cache))
-		return 0;
-
-	ctx = mail_cache_handler_init(context);
+	ctx = mail_cache_handler_init(sync_context);
 	ret = mail_cache_handler_lock(ctx, cache);
 	if (ret <= 0)
 		return ret;
@@ -128,11 +125,8 @@ int mail_cache_sync_handler(struct mail_
 		return 1;
 	}
 
-	if (MAIL_CACHE_IS_UNUSABLE(cache))
-		return 1;
-
 	ctx = mail_cache_handler_init(context);
-	if (cache->file_cache != NULL) {
+	if (cache->file_cache != NULL && !MAIL_CACHE_IS_UNUSABLE(cache)) {
 		/* flush attribute cache only once per sync */
 		if (!ctx->nfs_attr_cache_flushed && cache->index->nfs_flush) {
 			ctx->nfs_attr_cache_flushed = TRUE;
diff -r b3de2053937f -r e78c51d6305f src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Sat Nov 10 17:40:11 2007 +0200
+++ b/src/lib-index/mail-index-private.h	Sat Nov 10 17:53:35 2007 +0200
@@ -213,6 +213,7 @@ struct mail_index {
 	unsigned int nfs_flush:1;
 	unsigned int readonly:1;
 	unsigned int mapping:1;
+	unsigned int syncing:1;
 	unsigned int need_recreate:1;
 };
 
diff -r b3de2053937f -r e78c51d6305f src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Sat Nov 10 17:40:11 2007 +0200
+++ b/src/lib-index/mail-index-sync.c	Sat Nov 10 17:53:35 2007 +0200
@@ -324,6 +324,8 @@ int mail_index_sync_begin_to(struct mail
 	uoff_t offset;
 	int ret;
 
+	i_assert(!index->syncing);
+
 	if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0)
 		return -1;
 
@@ -406,6 +408,8 @@ int mail_index_sync_begin_to(struct mail
 		trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES;
 	ctx->ext_trans = mail_index_transaction_begin(ctx->view, trans_flags);
 
+	index->syncing = TRUE;
+
 	*ctx_r = ctx;
 	*view_r = ctx->view;
 	*trans_r = ctx->ext_trans;
@@ -609,8 +613,11 @@ static void mail_index_sync_end(struct m
 {
         struct mail_index_sync_ctx *ctx = *_ctx;
 
+	i_assert(ctx->index->syncing);
+
 	*_ctx = NULL;
 
+	ctx->index->syncing = FALSE;
 	mail_transaction_log_sync_unlock(ctx->index->log);
 
 	mail_index_view_close(&ctx->view);
diff -r b3de2053937f -r e78c51d6305f src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c	Sat Nov 10 17:40:11 2007 +0200
+++ b/src/lib-index/mail-index-transaction.c	Sat Nov 10 17:53:35 2007 +0200
@@ -546,8 +546,16 @@ static int mail_index_transaction_commit
 						  log_file_offset_r);
 	}
 
-	if (ret == 0) {
-		/* we always want to have the latest changes in index map */
+	if (ret == 0 && !t->view->index->syncing) {
+		/* if we're committing a normal transaction, we want to
+		   have those changes in the index mapping immediately. this
+		   is especially important when committing cache offset
+		   updates.
+
+		   however if we're syncing the index now, the mapping must
+		   be done later as MAIL_INDEX_SYNC_HANDLER_FILE so that
+		   expunge handlers get run for the newly expunged messages
+		   (and sync handlers that require HANDLER_FILE as well). */
 		(void)mail_index_refresh(t->view->index);
 	}
 


More information about the dovecot-cvs mailing list