Skip to content

Commit

Permalink
lib-index: Replace mail_index_set_log_rotation() with mail_index_set_…
Browse files Browse the repository at this point in the history
…optimization_settings()

This allows more easily adding optimization-related settings.
  • Loading branch information
sirainen authored and villesavolainen committed Oct 13, 2017
1 parent 0cc07f8 commit b959b76
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 49 deletions.
4 changes: 1 addition & 3 deletions src/lib-index/mail-index-private.h
Expand Up @@ -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;
Expand Down
40 changes: 23 additions & 17 deletions src/lib-index/mail-index.c
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 20 additions & 8 deletions src/lib-index/mail-index.h
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions src/lib-index/mail-transaction-log-private.h
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/lib-index/mail-transaction-log.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions src/lib-storage/list/mailbox-list-index.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b959b76

Please sign in to comment.