#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"
#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;
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;
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;
}
*_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;
#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)
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;
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;
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)
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);
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);
}
}
static struct mail_index_transaction_vfuncs trans_vfuncs = {
+ mail_index_transaction_reset_v,
mail_index_transaction_commit_v,
mail_index_transaction_rollback_v
};