From: Timo Sirainen Date: Wed, 23 Nov 2016 21:12:29 +0000 (+0200) Subject: lib-index: Add mail_index_set_log_rotation() X-Git-Tag: 2.3.0.rc1~2534 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b66a207ddcfc72a634186ec7e9a82df28ffc1d4e;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Add mail_index_set_log_rotation() --- diff --git a/src/lib-index/mail-index-private.h b/src/lib-index/mail-index-private.h index d5d9a25944..cbb114e4a5 100644 --- a/src/lib-index/mail-index-private.h +++ b/src/lib-index/mail-index-private.h @@ -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; diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index fb404007dc..b93b839d2c 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -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) { diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index 1df57b181d..cfcdf481f0 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -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, diff --git a/src/lib-index/mail-transaction-log-private.h b/src/lib-index/mail-transaction-log-private.h index a03939a5e9..b002d687bb 100644 --- a/src/lib-index/mail-transaction-log-private.h +++ b/src/lib-index/mail-transaction-log-private.h @@ -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) diff --git a/src/lib-index/mail-transaction-log.c b/src/lib-index/mail-transaction-log.c index e48eb6b4d7..9e45acca89 100644 --- a/src/lib-index/mail-transaction-log.c +++ b/src/lib-index/mail-transaction-log.c @@ -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) {