changeset 22609:b7e049f3aa16

lib-index: Replace mail_index_set_log_rotation() with mail_index_set_optimization_settings() This allows more easily adding optimization-related settings.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 09 Oct 2017 15:15:08 +0300
parents 3cdf8b140c3c
children bf758ce6ee6d
files src/lib-index/mail-index-private.h src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-index/mail-transaction-log-private.h src/lib-index/mail-transaction-log.c src/lib-storage/list/mailbox-list-index.c
diffstat 6 files changed, 59 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-index/mail-index-private.h	Mon Oct 09 15:15:08 2017 +0300
@@ -171,9 +171,7 @@
 	gid_t gid;
 	char *gid_origin;
 
-	uoff_t log_rotate_min_size, log_rotate_max_size;
-	unsigned int log_rotate_min_created_ago_secs;
-	unsigned int log_rotate_log2_stale_secs;
+	struct mail_index_optimization_settings optimization_set;
 	uint32_t pending_log2_rotate_time;
 
 	pool_t extension_pool;
--- a/src/lib-index/mail-index.c	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-index/mail-index.c	Mon Oct 09 15:15:08 2017 +0300
@@ -29,6 +29,15 @@
 
 static void mail_index_close_nonopened(struct mail_index *index);
 
+static const struct mail_index_optimization_settings default_optimization_set = {
+	.log = {
+		.min_size = 32 * 1024,
+		.max_size = 1024 * 1024,
+		.min_age_secs = 5 * 60,
+		.log2_max_age_secs = 3600 * 24 * 2,
+	},
+};
+
 struct mail_index *mail_index_alloc(const char *dir, const char *prefix)
 {
 	struct mail_index *index;
@@ -49,15 +58,7 @@
 	index->gid = (gid_t)-1;
 	index->lock_method = FILE_LOCK_METHOD_FCNTL;
 	index->max_lock_timeout_secs = UINT_MAX;
-
-	index->log_rotate_min_size =
-		MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_MIN_SIZE;
-	index->log_rotate_max_size =
-		MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_MAX_SIZE;
-	index->log_rotate_min_created_ago_secs =
-		MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_TIME;
-	index->log_rotate_log2_stale_secs =
-		MAIL_TRANSACTION_LOG2_DEFAULT_STALE_SECS;
+	index->optimization_set = default_optimization_set;
 
 	index->keywords_ext_id =
 		mail_index_ext_register(index, MAIL_INDEX_EXT_KEYWORDS,
@@ -156,15 +157,20 @@
 	index->max_lock_timeout_secs = max_timeout_secs;
 }
 
-void mail_index_set_log_rotation(struct mail_index *index,
-				 uoff_t min_size, uoff_t max_size,
-				 unsigned int min_created_ago_secs,
-				 unsigned int log2_stale_secs)
+void mail_index_set_optimization_settings(struct mail_index *index,
+	const struct mail_index_optimization_settings *set)
 {
-	index->log_rotate_min_size = min_size;
-	index->log_rotate_max_size = max_size;
-	index->log_rotate_min_created_ago_secs = min_created_ago_secs;
-	index->log_rotate_log2_stale_secs = log2_stale_secs;
+	struct mail_index_optimization_settings *dest =
+		&index->optimization_set;
+
+	if (set->log.min_size != 0)
+		dest->log.min_size = set->log.min_size;
+	if (set->log.max_size != 0)
+		dest->log.max_size = set->log.max_size;
+	if (set->log.min_age_secs != 0)
+		dest->log.min_age_secs = set->log.min_age_secs;
+	if (set->log.log2_max_age_secs != 0)
+		dest->log.log2_max_age_secs = set->log.log2_max_age_secs;
 }
 
 void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
--- a/src/lib-index/mail-index.h	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-index/mail-index.h	Mon Oct 09 15:15:08 2017 +0300
@@ -237,6 +237,22 @@
 	unsigned int ignored_modseq_changes;
 };
 
+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. */
+	uoff_t min_size;
+	uoff_t max_size;
+	unsigned int min_age_secs;
+
+	/* Delete .log.2 when it's older than log2_stale_secs. Don't be too
+	   eager, because older files are useful for QRESYNC and dsync. */
+	unsigned int log2_max_age_secs;
+};
+
+struct mail_index_optimization_settings {
+	struct mail_index_log_optimization_settings log;
+};
+
 struct mail_index;
 struct mail_index_map;
 struct mail_index_view;
@@ -262,14 +278,10 @@
 void mail_index_set_lock_method(struct mail_index *index,
 				enum file_lock_method lock_method,
 				unsigned int max_timeout_secs);
-/* Rotate transaction log after it's a) min_size or larger and it was created
-   at least min_created_ago_secs or b) larger than max_size. Delete .log.2 when
-   it's older than log2_stale_secs. The defaults are min_size=32kB, max_size=1M,
-   min_created_ago_secs=5min, log2_stale_secs=2d. */
-void mail_index_set_log_rotation(struct mail_index *index,
-				 uoff_t min_size, uoff_t max_size,
-				 unsigned int min_created_ago_secs,
-				 unsigned int log2_stale_secs);
+/* Override the default optimization-related settings. Anything set to 0 will
+   use the default. */
+void mail_index_set_optimization_settings(struct mail_index *index,
+	const struct mail_index_optimization_settings *set);
 /* When creating a new index file or reseting an existing one, add the given
    extension header data immediately to it. */
 void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
--- a/src/lib-index/mail-transaction-log-private.h	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-index/mail-transaction-log-private.h	Mon Oct 09 15:15:08 2017 +0300
@@ -11,16 +11,6 @@
 #define MAIL_TRANSACTION_LOG_LOCK_TIMEOUT (3*60)
 #define MAIL_TRANSACTION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
 
-/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
-#define MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_MIN_SIZE (1024*32)
-/* If log is larger than MAX_SIZE, rotate regardless of the time */
-#define MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_MAX_SIZE (1024*1024)
-#define MAIL_TRANSACTION_LOG_ROTATE_DEFAULT_TIME (60*5)
-
-/* Delete .log.2 files older than this many seconds. Don't be too eager,
-   older files are useful for QRESYNC and dsync. */
-#define MAIL_TRANSACTION_LOG2_DEFAULT_STALE_SECS (60*60*24*2)
-
 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
 
 #define LOG_FILE_MODSEQ_CACHE_SIZE 10
--- a/src/lib-index/mail-transaction-log.c	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-index/mail-transaction-log.c	Mon Oct 09 15:15:08 2017 +0300
@@ -57,7 +57,7 @@
 	}
 
 	if (log2_rotate_time != (uint32_t)-1 &&
-	    ioloop_time - (time_t)log2_rotate_time >= (time_t)log->index->log_rotate_log2_stale_secs &&
+	    ioloop_time - (time_t)log2_rotate_time >= (time_t)log->index->optimization_set.log.log2_max_age_secs &&
 	    !log->index->readonly) {
 		i_unlink_if_exists(log->filepath2);
 		log2_rotate_time = (uint32_t)-1;
@@ -244,17 +244,17 @@
 		return TRUE;
 	}
 
-	if (file->sync_offset > log->index->log_rotate_max_size) {
+	if (file->sync_offset > log->index->optimization_set.log.max_size) {
 		/* file is too large, definitely rotate */
 		return TRUE;
 	}
-	if (file->sync_offset < log->index->log_rotate_min_size) {
+	if (file->sync_offset < log->index->optimization_set.log.min_size) {
 		/* file is still too small */
 		return FALSE;
 	}
 	/* rotate if the timestamp is old enough */
 	return file->hdr.create_stamp <
-		ioloop_time - log->index->log_rotate_min_created_ago_secs;
+		ioloop_time - log->index->optimization_set.log.min_age_secs;
 }
 
 int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset)
--- a/src/lib-storage/list/mailbox-list-index.c	Fri Oct 06 18:33:24 2017 +0300
+++ b/src/lib-storage/list/mailbox-list-index.c	Mon Oct 09 15:15:08 2017 +0300
@@ -15,8 +15,8 @@
 /* dovecot.list.index.log doesn't have to be kept for that long. */
 #define MAILBOX_LIST_INDEX_LOG_ROTATE_MIN_SIZE (8*1024)
 #define MAILBOX_LIST_INDEX_LOG_ROTATE_MAX_SIZE (64*1024)
-#define MAILBOX_LIST_INDEX_LOG_ROTATE_SECS_AGO (5*60)
-#define MAILBOX_LIST_INDEX_LOG2_STALE_SECS (10*60)
+#define MAILBOX_LIST_INDEX_LOG_ROTATE_MIN_AGE_SECS (5*60)
+#define MAILBOX_LIST_INDEX_LOG2_MAX_AGE_SECS (10*60)
 
 static void mailbox_list_index_init_finish(struct mailbox_list *list);
 
@@ -84,11 +84,15 @@
 					   perm.file_create_gid,
 					   perm.file_create_gid_origin);
 	}
-	mail_index_set_log_rotation(ilist->index,
-				    MAILBOX_LIST_INDEX_LOG_ROTATE_MIN_SIZE,
-				    MAILBOX_LIST_INDEX_LOG_ROTATE_MAX_SIZE,
-				    MAILBOX_LIST_INDEX_LOG_ROTATE_SECS_AGO,
-				    MAILBOX_LIST_INDEX_LOG2_STALE_SECS);
+	const struct mail_index_optimization_settings optimize_set = {
+		.log = {
+			.min_size = MAILBOX_LIST_INDEX_LOG_ROTATE_MIN_SIZE,
+			.max_size = MAILBOX_LIST_INDEX_LOG_ROTATE_MAX_SIZE,
+			.min_age_secs = MAILBOX_LIST_INDEX_LOG_ROTATE_MIN_AGE_SECS,
+			.log2_max_age_secs = MAILBOX_LIST_INDEX_LOG2_MAX_AGE_SECS,
+		},
+	};
+	mail_index_set_optimization_settings(ilist->index, &optimize_set);
 
 	mail_index_set_fsync_mode(ilist->index, set->parsed_fsync_mode, 0);
 	mail_index_set_lock_method(ilist->index, set->parsed_lock_method,