changeset 22610:bf758ce6ee6d

lib-index: Add mail_index_base_optimization_settings
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 09 Oct 2017 15:24:45 +0300
parents b7e049f3aa16
children 65ada9976a7f
files src/lib-index/mail-index-private.h src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-sync.c src/lib-index/mail-index.c src/lib-index/mail-index.h
diffstat 5 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h	Mon Oct 09 15:15:08 2017 +0300
+++ b/src/lib-index/mail-index-private.h	Mon Oct 09 15:24:45 2017 +0300
@@ -23,11 +23,6 @@
    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)
 
--- a/src/lib-index/mail-index-sync-update.c	Mon Oct 09 15:15:08 2017 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Mon Oct 09 15:24:45 2017 +0300
@@ -973,7 +973,7 @@
 	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) {
+	    		index->optimization_set.index.rewrite_min_log_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;
--- a/src/lib-index/mail-index-sync.c	Mon Oct 09 15:15:08 2017 +0300
+++ b/src/lib-index/mail-index-sync.c	Mon Oct 09 15:24:45 2017 +0300
@@ -820,8 +820,9 @@
 
 	log_diff = index->map->hdr.log_file_tail_offset -
 		index->last_read_log_file_tail_offset;
-	if (log_diff > MAIL_INDEX_MAX_WRITE_BYTES ||
-	    (index->index_min_write && log_diff > MAIL_INDEX_MIN_WRITE_BYTES))
+	if (log_diff > index->optimization_set.index.rewrite_max_log_bytes ||
+	    (index->index_min_write &&
+	     log_diff > index->optimization_set.index.rewrite_min_log_bytes))
 		return TRUE;
 
 	if (index->need_recreate)
--- a/src/lib-index/mail-index.c	Mon Oct 09 15:15:08 2017 +0300
+++ b/src/lib-index/mail-index.c	Mon Oct 09 15:24:45 2017 +0300
@@ -30,6 +30,10 @@
 static void mail_index_close_nonopened(struct mail_index *index);
 
 static const struct mail_index_optimization_settings default_optimization_set = {
+	.index = {
+		.rewrite_min_log_bytes = 8 * 1024,
+		.rewrite_max_log_bytes = 128 * 1024,
+	},
 	.log = {
 		.min_size = 32 * 1024,
 		.max_size = 1024 * 1024,
@@ -163,6 +167,13 @@
 	struct mail_index_optimization_settings *dest =
 		&index->optimization_set;
 
+	/* index */
+	if (set->index.rewrite_min_log_bytes != 0)
+		dest->index.rewrite_min_log_bytes = set->index.rewrite_min_log_bytes;
+	if (set->index.rewrite_max_log_bytes != 0)
+		dest->index.rewrite_max_log_bytes = set->index.rewrite_max_log_bytes;
+
+	/* log */
 	if (set->log.min_size != 0)
 		dest->log.min_size = set->log.min_size;
 	if (set->log.max_size != 0)
--- a/src/lib-index/mail-index.h	Mon Oct 09 15:15:08 2017 +0300
+++ b/src/lib-index/mail-index.h	Mon Oct 09 15:24:45 2017 +0300
@@ -237,6 +237,13 @@
 	unsigned int ignored_modseq_changes;
 };
 
+struct mail_index_base_optimization_settings {
+	/* Rewrite the index when the number of bytes that needs to be read
+	   from the .log on refresh is between these min/max values. */
+	uoff_t rewrite_min_log_bytes;
+	uoff_t rewrite_max_log_bytes;
+};
+
 struct mail_index_log_optimization_settings {
 	/* Rotate transaction log after it's a) min_size or larger and it was
 	   created at least min_age_secs or b) larger than max_size. */
@@ -250,6 +257,7 @@
 };
 
 struct mail_index_optimization_settings {
+	struct mail_index_base_optimization_settings index;
 	struct mail_index_log_optimization_settings log;
 };