dovecot-2.0: Isolated all cache transaction handling code to a s...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 13 20:06:14 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/546adc9dd14b
changeset: 9611:546adc9dd14b
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jul 13 13:04:24 2009 -0400
description:
Isolated all cache transaction handling code to a single file.

diffstat:

3 files changed, 62 insertions(+), 18 deletions(-)
src/lib-index/mail-cache-transaction.c         |   60 +++++++++++++++++++++---
src/lib-index/mail-index-transaction-private.h |    3 -
src/lib-index/mail-index-transaction.c         |   17 ++----

diffs (200 lines):

diff -r cf930dc6a7fe -r 546adc9dd14b src/lib-index/mail-cache-transaction.c
--- a/src/lib-index/mail-cache-transaction.c	Mon Jul 27 16:43:59 2009 -0400
+++ b/src/lib-index/mail-cache-transaction.c	Mon Jul 13 13:04:24 2009 -0400
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "array.h"
 #include "buffer.h"
+#include "module-context.h"
 #include "file-cache.h"
 #include "file-set-size.h"
 #include "read-full.h"
@@ -16,12 +17,18 @@
 
 #define MAIL_CACHE_WRITE_BUFFER 32768
 
+#define CACHE_TRANS_CONTEXT(obj) \
+	MODULE_CONTEXT(obj, cache_mail_index_transaction_module)
+
 struct mail_cache_reservation {
 	uint32_t offset;
 	uint32_t size;
 };
 
 struct mail_cache_transaction_ctx {
+	union mail_index_transaction_module_context module_ctx;
+	struct mail_index_transaction_vfuncs super;
+
 	struct mail_cache *cache;
 	struct mail_cache_view *view;
 	struct mail_index_transaction *trans;
@@ -42,17 +49,51 @@ struct mail_cache_transaction_ctx {
 	unsigned int changes:1;
 };
 
+static MODULE_CONTEXT_DEFINE_INIT(cache_mail_index_transaction_module,
+				  &mail_index_module_register);
+
 static int mail_cache_link_unlocked(struct mail_cache *cache,
 				    uint32_t old_offset, uint32_t new_offset);
+
+static void mail_index_transaction_cache_reset(struct mail_index_transaction *t)
+{
+	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
+	struct mail_index_transaction_vfuncs super = ctx->super;
+
+	mail_cache_transaction_rollback(&ctx);
+	super.reset(t);
+}
+
+static int
+mail_index_transaction_cache_commit(struct mail_index_transaction *t,
+				    uint32_t *log_file_seq_r,
+				    uoff_t *log_file_offset_r)
+{
+	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
+	struct mail_index_transaction_vfuncs super = ctx->super;
+
+	mail_cache_transaction_commit(&ctx);
+	return super.commit(t, log_file_seq_r, log_file_offset_r);
+}
+
+static void
+mail_index_transaction_cache_rollback(struct mail_index_transaction *t)
+{
+	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
+	struct mail_index_transaction_vfuncs super = ctx->super;
+
+	mail_cache_transaction_rollback(&ctx);
+	super.rollback(t);
+}
 
 struct mail_cache_transaction_ctx *
 mail_cache_get_transaction(struct mail_cache_view *view,
 			   struct mail_index_transaction *t)
 {
-	struct mail_cache_transaction_ctx *ctx;
-
-	if (t->cache_trans_ctx != NULL)
-		return t->cache_trans_ctx;
+	struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t);
+
+	if (ctx != NULL)
+		return ctx;
 
 	ctx = i_new(struct mail_cache_transaction_ctx, 1);
 	ctx->cache = view->cache;
@@ -64,7 +105,12 @@ mail_cache_get_transaction(struct mail_c
 	view->transaction = ctx;
 	view->trans_view = mail_index_transaction_open_updated_view(t);
 
-	t->cache_trans_ctx = ctx;
+	ctx->super = t->v;
+	t->v.reset = mail_index_transaction_cache_reset;
+	t->v.commit = mail_index_transaction_cache_commit;
+	t->v.rollback = mail_index_transaction_cache_rollback;
+
+	MODULE_CONTEXT_SET(t, cache_mail_index_transaction_module, ctx);
 	return ctx;
 }
 
@@ -97,7 +143,9 @@ mail_cache_transaction_free(struct mail_
 
 	*_ctx = NULL;
 
-	ctx->trans->cache_trans_ctx = NULL;
+	MODULE_CONTEXT_UNSET(ctx->trans, cache_mail_index_transaction_module);
+	ctx->trans->v = ctx->super;
+
 	ctx->view->transaction = NULL;
 	ctx->view->trans_seq1 = ctx->view->trans_seq2 = 0;
 
diff -r cf930dc6a7fe -r 546adc9dd14b src/lib-index/mail-index-transaction-private.h
--- a/src/lib-index/mail-index-transaction-private.h	Mon Jul 27 16:43:59 2009 -0400
+++ b/src/lib-index/mail-index-transaction-private.h	Mon Jul 13 13:04:24 2009 -0400
@@ -19,6 +19,7 @@ struct mail_index_transaction_ext_hdr_up
 };
 
 struct mail_index_transaction_vfuncs {
+	void (*reset)(struct mail_index_transaction *t);
 	int (*commit)(struct mail_index_transaction *t,
 		      uint32_t *log_file_seq_r, uoff_t *log_file_offset_r);
 	void (*rollback)(struct mail_index_transaction *t);
@@ -67,8 +68,6 @@ struct mail_index_transaction {
 
 	uint64_t max_modseq;
 	ARRAY_TYPE(seq_range) *conflict_seqs;
-
-        struct mail_cache_transaction_ctx *cache_trans_ctx;
 
 	/* Module-specific contexts. */
 	ARRAY_DEFINE(module_contexts,
diff -r cf930dc6a7fe -r 546adc9dd14b src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c	Mon Jul 27 16:43:59 2009 -0400
+++ b/src/lib-index/mail-index-transaction.c	Mon Jul 13 13:04:24 2009 -0400
@@ -10,7 +10,6 @@
 #include "bsearch-insert-pos.h"
 #include "mail-index-private.h"
 #include "mail-transaction-log-private.h"
-#include "mail-cache.h"
 #include "mail-index-transaction-private.h"
 
 void (*hook_mail_index_transaction_created)
@@ -19,7 +18,7 @@ static bool
 static bool
 mail_index_transaction_has_ext_changes(struct mail_index_transaction *t);
 
-void mail_index_transaction_reset(struct mail_index_transaction *t)
+static void mail_index_transaction_reset_v(struct mail_index_transaction *t)
 {
 	ARRAY_TYPE(seq_array) *recs;
 	struct mail_index_transaction_ext_hdr_update *ext_hdrs;
@@ -89,9 +88,6 @@ void mail_index_transaction_reset(struct
 	memset(t->pre_hdr_mask, 0, sizeof(t->pre_hdr_mask));
 	memset(t->post_hdr_mask, 0, sizeof(t->post_hdr_mask));
 
-	if (t->cache_trans_ctx != NULL)
-		mail_cache_transaction_rollback(&t->cache_trans_ctx);
-
 	t->appends_nonsorted = FALSE;
 	t->pre_hdr_changed = FALSE;
 	t->post_hdr_changed = FALSE;
@@ -233,6 +229,11 @@ uint32_t mail_index_transaction_get_next
 	return next_uid;
 }
 
+void mail_index_transaction_reset(struct mail_index_transaction *t)
+{
+	t->v.reset(t);
+}
+
 static int
 mail_transaction_log_file_refresh(struct mail_index_transaction *t,
 				  struct mail_transaction_log_append_ctx *ctx)
@@ -353,9 +354,6 @@ static int mail_index_transaction_commit
 	i_assert(t->first_new_seq >
 		 mail_index_view_get_messages_count(t->view));
 
-	if (t->cache_trans_ctx != NULL)
-		mail_cache_transaction_commit(&t->cache_trans_ctx);
-
 	if (array_is_created(&t->appends))
 		mail_index_update_day_headers(t);
 
@@ -387,8 +385,6 @@ static int mail_index_transaction_commit
 
 static void mail_index_transaction_rollback_v(struct mail_index_transaction *t)
 {
-	if (t->cache_trans_ctx != NULL)
-		mail_cache_transaction_rollback(&t->cache_trans_ctx);
         mail_index_transaction_unref(&t);
 }
 
@@ -1388,6 +1384,7 @@ void mail_index_transaction_set_max_mods
 }
 
 static struct mail_index_transaction_vfuncs trans_vfuncs = {
+	mail_index_transaction_reset_v,
 	mail_index_transaction_commit_v,
 	mail_index_transaction_rollback_v
 };


More information about the dovecot-cvs mailing list