]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Replace mail_index_set_log_rotation() with mail_index_set_optimization_set...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 9 Oct 2017 12:15:08 +0000 (15:15 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 13 Oct 2017 06:14:20 +0000 (09:14 +0300)
This allows more easily adding optimization-related settings.

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

index 453ef94c24b72139cd76849a9b40e8cf1ef0abab..632f78abf0adcf81ab06201d17435f50795091ef 100644 (file)
@@ -171,9 +171,7 @@ struct mail_index {
        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;
index 49f863b6a931fd4ce74517306c5b04e78c959bb1..ec93634df6524bb3e78eea5cddd41b896dac91dc 100644 (file)
@@ -29,6 +29,15 @@ struct mail_index_module_register mail_index_module_register = { 0 };
 
 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 @@ struct mail_index *mail_index_alloc(const char *dir, const char *prefix)
        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 @@ void mail_index_set_lock_method(struct mail_index *index,
        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,
index 604076d4934d8ca6d7e4d3b9c41b2f889cea5ea0..c78116513f9cb7b37d5e9d4188ad460f49783606 100644 (file)
@@ -237,6 +237,22 @@ struct mail_index_transaction_commit_result {
        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_permissions(struct mail_index *index,
 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,
index cba0b6b5bc60f2886687b4494ba16b2cf7e97433..49a02e97e9210abc0f70e0ed4393ec6e622b89c2 100644 (file)
@@ -11,16 +11,6 @@ struct dotlock_settings;
 #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
index a7789318771b1d00b331b40ec50855708b0e7538..3c1b9c7c35eff6a4bc20c7183632c6a06d4d7e42 100644 (file)
@@ -57,7 +57,7 @@ static void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
        }
 
        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 @@ bool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
                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)
index c85308faf2f76f8247eebd944a4bbda8d95dffe2..6e6af7f3ee9b71c6e7a9f171b0bd7fb39419548b 100644 (file)
@@ -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 @@ int mailbox_list_index_index_open(struct mailbox_list *list)
                                           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,