changeset 9620:a0b8777ac846 HEAD

More fixes to cache changes.
author Timo Sirainen <tss@iki.fi>
date Mon, 13 Jul 2009 19:41:23 -0400
parents 430832cf3cf0
children 8c17eb6c28d6
files src/lib-index/mail-cache-transaction.c src/lib-index/mail-cache.h src/lib-storage/index/index-transaction.c src/lib-storage/index/maildir/maildir-save.c
diffstat 4 files changed, 41 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-transaction.c	Mon Jul 13 19:26:07 2009 -0400
+++ b/src/lib-index/mail-cache-transaction.c	Mon Jul 13 19:41:23 2009 -0400
@@ -52,6 +52,8 @@
 static MODULE_CONTEXT_DEFINE_INIT(cache_mail_index_transaction_module,
 				  &mail_index_module_register);
 
+static void
+mail_cache_transaction_free_reservations(struct mail_cache_transaction_ctx *ctx);
 static int mail_cache_link_unlocked(struct mail_cache *cache,
 				    uint32_t old_offset, uint32_t new_offset);
 
@@ -60,7 +62,7 @@
 	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
 	struct mail_index_transaction_vfuncs super = ctx->super;
 
-	mail_cache_transaction_rollback(&ctx);
+	mail_cache_transaction_reset(ctx);
 	super.reset(t);
 }
 
@@ -90,7 +92,10 @@
 mail_cache_get_transaction(struct mail_cache_view *view,
 			   struct mail_index_transaction *t)
 {
-	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
+	struct mail_cache_transaction_ctx *ctx;
+
+	ctx = !cache_mail_index_transaction_module.id.module_id_set ? NULL :
+		CACHE_TRANS_CONTEXT(t);
 
 	if (ctx != NULL)
 		return ctx;
@@ -114,8 +119,10 @@
 	return ctx;
 }
 
-static void mail_cache_transaction_reset(struct mail_cache_transaction_ctx *ctx)
+void mail_cache_transaction_reset(struct mail_cache_transaction_ctx *ctx)
 {
+	mail_cache_transaction_free_reservations(ctx);
+
 	ctx->cache_file_seq = MAIL_CACHE_IS_UNUSABLE(ctx->cache) ? 0 :
 		ctx->cache->hdr->file_seq;
 	mail_index_ext_set_reset_id(ctx->trans, ctx->cache->ext_id,
@@ -492,6 +499,31 @@
 	}
 }
 
+static void
+mail_cache_transaction_free_reservations(struct mail_cache_transaction_ctx *ctx)
+{
+	const struct mail_cache_reservation *reservations;
+	unsigned int count;
+
+	if (ctx->reserved_space == 0 && array_count(&ctx->reservations) == 0)
+		return;
+
+	if (mail_cache_transaction_lock(ctx) <= 0)
+		return;
+
+	reservations = array_get(&ctx->reservations, &count);
+
+	/* free flushed data as well. do it from end to beginning so we have
+	   a better chance of updating used_file_size instead of adding holes */
+	while (count > 0) {
+		count--;
+		mail_cache_free_space(ctx->cache,
+				      reservations[count].offset,
+				      reservations[count].size);
+	}
+	(void)mail_cache_unlock(ctx->cache);
+}
+
 static int
 mail_cache_transaction_free_space(struct mail_cache_transaction_ctx *ctx)
 {
@@ -787,29 +819,8 @@
 void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **_ctx)
 {
 	struct mail_cache_transaction_ctx *ctx = *_ctx;
-	struct mail_cache *cache = ctx->cache;
-	const struct mail_cache_reservation *reservations;
-	unsigned int count;
 
-	if ((ctx->reserved_space > 0 || array_count(&ctx->reservations) > 0) &&
-	    !MAIL_CACHE_IS_UNUSABLE(cache)) {
-		if (mail_cache_transaction_lock(ctx) > 0) {
-			reservations = array_get(&ctx->reservations, &count);
-
-			/* free flushed data as well. do it from end to
-			   beginning so we have a better chance of
-			   updating used_file_size instead of adding
-			   holes */
-			while (count > 0) {
-				count--;
-				mail_cache_free_space(ctx->cache,
-					reservations[count].offset,
-					reservations[count].size);
-			}
-			(void)mail_cache_unlock(cache);
-		}
-	}
-
+	mail_cache_transaction_free_reservations(ctx);
 	mail_cache_transaction_free(_ctx);
 }
 
--- a/src/lib-index/mail-cache.h	Mon Jul 13 19:26:07 2009 -0400
+++ b/src/lib-index/mail-cache.h	Mon Jul 13 19:41:23 2009 -0400
@@ -71,6 +71,7 @@
 mail_cache_get_transaction(struct mail_cache_view *view,
 			   struct mail_index_transaction *t);
 
+void mail_cache_transaction_reset(struct mail_cache_transaction_ctx *ctx);
 int mail_cache_transaction_commit(struct mail_cache_transaction_ctx **ctx);
 void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **ctx);
 
--- a/src/lib-storage/index/index-transaction.c	Mon Jul 13 19:26:07 2009 -0400
+++ b/src/lib-storage/index/index-transaction.c	Mon Jul 13 19:41:23 2009 -0400
@@ -8,7 +8,6 @@
 void index_transaction_init(struct index_transaction_context *t,
 			    struct index_mailbox *ibox)
 {
-	t->super = t->trans->v;
 	t->mailbox_ctx.box = &ibox->box;
 	t->ibox = ibox;
 
@@ -18,6 +17,9 @@
 	t->trans_view = mail_index_transaction_open_updated_view(t->trans);
 	t->cache_view = mail_cache_view_open(ibox->cache, t->trans_view);
 	t->cache_trans = mail_cache_get_transaction(t->cache_view, t->trans);
+
+	/* mail_cache_get_transaction() changes trans->v */
+	t->super = t->trans->v;
 }
 
 static void index_transaction_free(struct index_transaction_context *t)
--- a/src/lib-storage/index/maildir/maildir-save.c	Mon Jul 13 19:26:07 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-save.c	Mon Jul 13 19:41:23 2009 -0400
@@ -688,9 +688,7 @@
 	for (seq = ctx->seq; seq >= ctx->first_seq; seq--)
 		mail_index_expunge(ctx->trans, seq);
 
-	mail_cache_transaction_rollback(&t->ictx.cache_trans);
-	t->ictx.cache_trans = mail_cache_get_transaction(t->ictx.cache_view,
-							 t->ictx.trans);
+	mail_cache_transaction_reset(t->ictx.cache_trans);
 }
 
 static int