dovecot-2.0: More fixes to cache changes.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jul 14 02:58:04 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/a0b8777ac846
changeset: 9620:a0b8777ac846
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 13 19:41:23 2009 -0400
description:
More fixes to cache changes.
diffstat:
4 files changed, 43 insertions(+), 31 deletions(-)
src/lib-index/mail-cache-transaction.c | 65 +++++++++++++++-----------
src/lib-index/mail-cache.h | 1
src/lib-storage/index/index-transaction.c | 4 +
src/lib-storage/index/maildir/maildir-save.c | 4 -
diffs (156 lines):
diff -r 430832cf3cf0 -r a0b8777ac846 src/lib-index/mail-cache-transaction.c
--- 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_
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 @@ static void mail_index_transaction_cache
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_c
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 @@ mail_cache_get_transaction(struct mail_c
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,
@@ -490,6 +497,31 @@ mail_cache_free_space(struct mail_cache
cache->hdr_copy.hole_offset = offset;
cache->hdr_modified = TRUE;
}
+}
+
+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
@@ -787,29 +819,8 @@ void mail_cache_transaction_rollback(str
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);
}
diff -r 430832cf3cf0 -r a0b8777ac846 src/lib-index/mail-cache.h
--- 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_c
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);
diff -r 430832cf3cf0 -r a0b8777ac846 src/lib-storage/index/index-transaction.c
--- 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
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 @@ void index_transaction_init(struct index
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)
diff -r 430832cf3cf0 -r a0b8777ac846 src/lib-storage/index/maildir/maildir-save.c
--- 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 @@ maildir_save_rollback_index_changes(stru
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
More information about the dovecot-cvs
mailing list