dovecot-2.2: lib-index: Avoid writing tail offset update to tran...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 11 16:24:00 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/03b3b97b84aa
changeset: 18843:03b3b97b84aa
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 11 19:21:16 2015 +0300
description:
lib-index: Avoid writing tail offset update to transaction log if it's not necessary.
This should avoid extra writes that do nothing but update the tail offset.
mdbox's map requires this behavior, so disable it for it. For others it
might cause the next sync to read more data unnecessarily, but it should be
worth the extra cost of write most of the times.

diffstat:

 src/lib-index/mail-index-sync.c              |  14 +++++++++++---
 src/lib-index/mail-index.h                   |   5 ++++-
 src/lib-storage/index/dbox-multi/mdbox-map.c |   3 ++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diffs (66 lines):

diff -r ffecdb676c53 -r 03b3b97b84aa src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Thu Jun 11 19:08:13 2015 +0300
+++ b/src/lib-index/mail-index-sync.c	Thu Jun 11 19:21:16 2015 +0300
@@ -26,6 +26,7 @@
 	uint32_t last_tail_seq, last_tail_offset;
 
 	unsigned int no_warning:1;
+	unsigned int seen_nonexternal_transactions:1;
 };
 
 static void mail_index_sync_add_expunge(struct mail_index_sync_ctx *ctx)
@@ -173,6 +174,7 @@
 	mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
 					       &seq, &offset);
 
+	ctx->seen_nonexternal_transactions = TRUE;
 	ctx->last_tail_seq = seq;
 	ctx->last_tail_offset = offset + ctx->hdr->size + sizeof(*ctx->hdr);
 }
@@ -763,9 +765,15 @@
 	mail_transaction_log_set_mailbox_sync_pos(ctx->index->log, seq, offset);
 
 	/* If tail offset has changed, make sure it gets written to
-	   transaction log. do this only if we're required to changes. */
-	if (ctx->last_tail_seq != seq ||
-	    ctx->last_tail_offset < offset) {
+	   transaction log. do this only if we're required to make changes.
+
+	   avoid writing a new tail offset if all the transactions were
+	   external, because that wouldn't change effective the tail offset.
+	   except e.g. mdbox map requires this to happen, so do it
+	   optionally. */
+	if ((ctx->last_tail_seq != seq || ctx->last_tail_offset < offset) &&
+	    (ctx->seen_nonexternal_transactions ||
+	     (ctx->flags & MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET) != 0)) {
 		ctx->ext_trans->log_updates = TRUE;
 		ctx->ext_trans->tail_offset_changed = TRUE;
 	}
diff -r ffecdb676c53 -r 03b3b97b84aa src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Thu Jun 11 19:08:13 2015 +0300
+++ b/src/lib-index/mail-index.h	Thu Jun 11 19:21:16 2015 +0300
@@ -167,7 +167,10 @@
 	/* Same as MAIL_INDEX_SYNC_FLAG_DELETING_INDEX, but finish index
 	   deletion only once and fail the rest (= avoid race conditions when
 	   multiple processes try to mark the index deleted) */
-	MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX	= 0x40
+	MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX	= 0x40,
+	/* Update header's tail_offset to head_offset, even if it's the only
+	   thing we do and there's no strict need for it. */
+	MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET	= 0x80
 };
 
 enum mail_index_view_sync_flags {
diff -r ffecdb676c53 -r 03b3b97b84aa src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Thu Jun 11 19:08:13 2015 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Thu Jun 11 19:21:16 2015 +0300
@@ -497,7 +497,8 @@
 	/* use syncing to lock the transaction log, so that we always see
 	   log's head_offset = tail_offset */
 	ret = mail_index_sync_begin(atomic->map->index, &atomic->sync_ctx,
-				    &atomic->sync_view, &atomic->sync_trans, 0);
+				    &atomic->sync_view, &atomic->sync_trans,
+				    MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET);
 	if (mail_index_reset_fscked(atomic->map->index))
 		mdbox_storage_set_corrupted(atomic->map->storage);
 	if (ret <= 0) {


More information about the dovecot-cvs mailing list