]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Flush/fsync newly saved mail data before locking map.
authorTimo Sirainen <tss@iki.fi>
Mon, 4 Jun 2012 11:03:47 +0000 (14:03 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 4 Jun 2012 11:03:47 +0000 (14:03 +0300)
This reduced the amount of time the map needs to be locked.

src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-map.h
src/lib-storage/index/dbox-multi/mdbox-save.c

index edca35d42a969e33ed249f50452cbb61c5ff95d2..0873d499bc9cc68839003e07c8744a82c7aefe67 100644 (file)
@@ -1369,6 +1369,21 @@ int mdbox_map_append_move(struct mdbox_map_append_context *ctx,
        return 0;
 }
 
+int mdbox_map_append_flush(struct mdbox_map_append_context *ctx)
+{
+       struct dbox_file_append_context **file_appends;
+       unsigned int i, count;
+
+       i_assert(ctx->trans == NULL);
+
+       file_appends = array_get_modifiable(&ctx->file_appends, &count);
+       for (i = 0; i < count; i++) {
+               if (dbox_file_append_flush(file_appends[i]) < 0)
+                       return -1;
+       }
+       return 0;
+}
+
 int mdbox_map_append_commit(struct mdbox_map_append_context *ctx)
 {
        struct dbox_file_append_context **file_appends;
index 0c68e4420cebd4897568faf76ce584f6b65a59d3..58f570c32332463ae6aecc5ee3bedce6ee580cd9 100644 (file)
@@ -115,6 +115,8 @@ int mdbox_map_append_assign_map_uids(struct mdbox_map_append_context *ctx,
 int mdbox_map_append_move(struct mdbox_map_append_context *ctx,
                          const ARRAY_TYPE(uint32_t) *map_uids,
                          const ARRAY_TYPE(seq_range) *expunge_map_uids);
+/* Flush/fsync appends. */
+int mdbox_map_append_flush(struct mdbox_map_append_context *ctx);
 /* Returns 0 if ok, -1 if error. */
 int mdbox_map_append_commit(struct mdbox_map_append_context *ctx);
 void mdbox_map_append_free(struct mdbox_map_append_context **ctx);
index 452bda23ab8a5280cbe48fbbdb22622c72151848..015166943e2d033209c72e4aeec2b895f98a6f8f 100644 (file)
@@ -287,6 +287,12 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
 
        i_assert(ctx->ctx.finished);
 
+       /* flush/fsync writes to m.* files before locking the map */
+       if (mdbox_map_append_flush(ctx->append_ctx) < 0) {
+               mdbox_transaction_save_rollback(_ctx);
+               return -1;
+       }
+
        /* make sure the map gets locked */
        if (mdbox_map_atomic_lock(ctx->atomic) < 0) {
                mdbox_transaction_save_rollback(_ctx);