From: Timo Sirainen Date: Mon, 30 Mar 2009 20:18:25 +0000 (-0400) Subject: Write to main index file less often. X-Git-Tag: 1.2.rc1~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bea219e4f944cd17a9ccd1131b7fe081d1bb0a7;p=thirdparty%2Fdovecot%2Fcore.git Write to main index file less often. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-private.h b/src/lib-index/mail-index-private.h index fb0a8b242a..f1a9f6b770 100644 --- a/src/lib-index/mail-index-private.h +++ b/src/lib-index/mail-index-private.h @@ -22,6 +22,11 @@ struct mail_index_sync_map_ctx; 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 --git a/src/lib-index/mail-index-sync-update.c b/src/lib-index/mail-index-sync-update.c index d82613d352..6cb1f86b7b 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -786,6 +786,15 @@ int mail_index_sync_map(struct mail_index_map **_map, 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 --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index 131b0207a6..725d672cd4 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -710,7 +710,8 @@ static bool mail_index_sync_want_index_write(struct mail_index *index) 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_index_sync_ctx **_ctx) 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);