]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_set_log_rotation()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 23 Nov 2016 21:12:29 +0000 (23:12 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 25 Nov 2016 13:28:22 +0000 (15:28 +0200)
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

index 2a4055ba7a2b26e51c004181b4156de067c152f5..10360958dd83848a47bb4295e940e9ba8ca64de9 100644 (file)
@@ -171,6 +171,10 @@ 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;
+
        pool_t extension_pool;
        ARRAY(struct mail_index_registered_ext) extensions;
 
index fb404007dc5d1a9ef6767552328a3b9ce8e2aa2b..b93b839d2c5b97498f155fee43dbef911655a1bf 100644 (file)
@@ -16,7 +16,7 @@
 #include "mail-index-view-private.h"
 #include "mail-index-sync-private.h"
 #include "mail-index-modseq.h"
-#include "mail-transaction-log.h"
+#include "mail-transaction-log-private.h"
 #include "mail-transaction-log-view-private.h"
 #include "mail-cache.h"
 
@@ -50,6 +50,15 @@ struct mail_index *mail_index_alloc(const char *dir, const char *prefix)
        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->keywords_ext_id =
                mail_index_ext_register(index, MAIL_INDEX_EXT_KEYWORDS,
                                        128, 2, 1);
@@ -113,6 +122,17 @@ 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)
+{
+       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;
+}
+
 void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
                                  const void *data, size_t size)
 {
index c519adae4f24ecb3c54b1c7420aa60f00bdbc77a..b0221b55d4c068f0728972c92e5d173d648b9a90 100644 (file)
@@ -246,6 +246,14 @@ 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);
 /* 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 a6ea4175a12e786c87f61196b271303ea49989a5..74166a877181a470437b4f2e28ec73c17058fb10 100644 (file)
@@ -12,14 +12,14 @@ struct dotlock_settings;
 #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_MIN_SIZE (1024*32)
+#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_MAX_SIZE (1024*1024)
-#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
+#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_STALE_SECS (60*60*24*2)
+#define MAIL_TRANSACTION_LOG2_DEFAULT_STALE_SECS (60*60*24*2)
 
 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
 
index e48eb6b4d7084672d1bf619d70663e339be915dc..9e45acca897f0c0d559a1ff42616d6fa42723806 100644 (file)
@@ -51,7 +51,7 @@ static void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
                return;
        }
 
-       if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time &&
+       if (st.st_mtime + log->index->log_rotate_log2_stale_secs <= ioloop_time &&
            !log->index->readonly)
                i_unlink_if_exists(log->filepath2);
 }
@@ -215,10 +215,10 @@ void mail_transaction_logs_clean(struct mail_transaction_log *log)
 }
 
 #define LOG_WANT_ROTATE(file) \
-       (((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE && \
+       (((file)->sync_offset > (file)->log->index->log_rotate_min_size && \
          (time_t)(file)->hdr.create_stamp < \
-          ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_TIME) || \
-        ((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE))
+          ioloop_time - (file)->log->index->log_rotate_min_created_ago_secs) || \
+        ((file)->sync_offset > (file)->log->index->log_rotate_max_size))
 
 bool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
 {