dovecot-1.2: Write to main index file less often.

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 31 00:27:46 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/6cc8ee6080ed
changeset: 8874:6cc8ee6080ed
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Mar 30 16:18:25 2009 -0400
description:
Write to main index file less often.

diffstat:

3 files changed, 18 insertions(+), 1 deletion(-)
src/lib-index/mail-index-private.h     |    6 ++++++
src/lib-index/mail-index-sync-update.c |    9 +++++++++
src/lib-index/mail-index-sync.c        |    4 +++-

diffs (63 lines):

diff -r a514df3e20db -r 6cc8ee6080ed src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Mon Mar 30 17:26:40 2009 -0400
+++ b/src/lib-index/mail-index-private.h	Mon Mar 30 16:18:25 2009 -0400
@@ -21,6 +21,11 @@ struct mail_index_sync_map_ctx;
 /* Large extension header sizes are probably caused by file corruption, so
    try to catch them by limiting the header size. */
 #define MAIL_INDEX_EXT_HEADER_MAX_SIZE (1024*1024*16-1)
+
+/* Write to main index file when bytes-to-be-read-from-log is between these
+   values. */
+#define MAIL_INDEX_MIN_WRITE_BYTES (1024*8)
+#define MAIL_INDEX_MAX_WRITE_BYTES (1024*128)
 
 #define MAIL_INDEX_IS_IN_MEMORY(index) \
 	((index)->dir == NULL)
@@ -226,6 +231,7 @@ struct mail_index {
 	unsigned int mapping:1;
 	unsigned int syncing:1;
 	unsigned int need_recreate:1;
+	unsigned int index_min_write:1;
 	unsigned int modseqs_enabled:1;
 	unsigned int initial_create:1;
 	unsigned int initial_mapped:1;
diff -r a514df3e20db -r 6cc8ee6080ed src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c	Mon Mar 30 17:26:40 2009 -0400
+++ b/src/lib-index/mail-index-sync-update.c	Mon Mar 30 16:18:25 2009 -0400
@@ -786,6 +786,15 @@ int mail_index_sync_map(struct mail_inde
 		return 0;
 	}
 
+	mail_transaction_log_get_head(index->log, &prev_seq, &prev_offset);
+	if (prev_seq != map->hdr.log_file_seq ||
+	    prev_offset - map->hdr.log_file_tail_offset >
+	    				MAIL_INDEX_MIN_WRITE_BYTES) {
+		/* we're reading more from log than we would have preferred.
+		   remember that we probably want to rewrite index soon. */
+		index->index_min_write = TRUE;
+	}
+
 	/* view referenced the map. avoid unnecessary map cloning by
 	   unreferencing the map while view exists. */
 	map->refcount--;
diff -r a514df3e20db -r 6cc8ee6080ed src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Mon Mar 30 17:26:40 2009 -0400
+++ b/src/lib-index/mail-index-sync.c	Mon Mar 30 16:18:25 2009 -0400
@@ -710,7 +710,8 @@ static bool mail_index_sync_want_index_w
 
 	log_diff = index->map->hdr.log_file_tail_offset -
 		index->last_read_log_file_tail_offset;
-	if (log_diff > 1024)
+	if (log_diff > MAIL_INDEX_MAX_WRITE_BYTES ||
+	    (index->index_min_write && log_diff > MAIL_INDEX_MIN_WRITE_BYTES))
 		return TRUE;
 
 	if (index->need_recreate)
@@ -760,6 +761,7 @@ int mail_index_sync_commit(struct mail_i
 	if (ret == 0 &&
 	    (want_rotate || mail_index_sync_want_index_write(index))) {
 		index->need_recreate = FALSE;
+		index->index_min_write = FALSE;
 		mail_index_write(index, want_rotate);
 	}
 	mail_index_sync_end(_ctx);


More information about the dovecot-cvs mailing list