Mercurial > dovecot > core-2.2
changeset 9611:546adc9dd14b HEAD
Isolated all cache transaction handling code to a single file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 13 Jul 2009 13:04:24 -0400 |
parents | cf930dc6a7fe |
children | 2cab7f501986 |
files | src/lib-index/mail-cache-transaction.c src/lib-index/mail-index-transaction-private.h src/lib-index/mail-index-transaction.c |
diffstat | 3 files changed, 61 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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; + struct mail_cache_transaction_ctx *ctx = CACHE_TRANS_CONTEXT(t); - if (t->cache_trans_ctx != NULL) - return t->cache_trans_ctx; + if (ctx != NULL) + return ctx; ctx = i_new(struct mail_cache_transaction_ctx, 1); ctx->cache = view->cache; @@ -64,7 +105,12 @@ 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 @@ *_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;
--- 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_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); @@ -68,8 +69,6 @@ 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, union mail_index_transaction_module_context *);
--- 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 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 @@ 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 @@ 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 @@ 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 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 @@ } static struct mail_index_transaction_vfuncs trans_vfuncs = { + mail_index_transaction_reset_v, mail_index_transaction_commit_v, mail_index_transaction_rollback_v };