From: Timo Sirainen Date: Mon, 30 Mar 2009 20:18:25 +0000 (-0400) Subject: Write to main index file less often. X-Git-Tag: 2.0.alpha1~1038^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=686c00553a7cea22272548d9fb8c888170965ec9;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 1a843d18c3..4af66c56ad 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) @@ -227,6 +232,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 cae0a978ed..329b33aeb6 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -811,6 +811,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 d30c46b2cf..b5b746c104 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -731,7 +731,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) @@ -780,6 +781,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);