main: auto logrotate on small /mars

This commit is contained in:
Thomas Schoebel-Theuer 2017-10-23 17:07:41 +02:00
parent dedf7f3cdc
commit 42543656dc
1 changed files with 8 additions and 2 deletions

View File

@ -2797,6 +2797,7 @@ int make_log_init(void *buf, struct mars_dent *dent)
const char *parent_path;
const char *replay_path = NULL;
const char *aio_path = NULL;
loff_t logrot_limit;
bool switch_on;
int status = 0;
@ -2976,9 +2977,14 @@ int make_log_init(void *buf, struct mars_dent *dent)
}
MARS_DBG("logfile '%s' size = %lld\n", aio_path, rot->aio_info.current_size);
logrot_limit = raw_total_space / (1024ll * 1024 / 32);
if (logrot_limit <= 0)
logrot_limit = 1;
if (logrot_limit > global_logrot_auto)
logrot_limit = global_logrot_auto;
if (rot->is_primary &&
global_logrot_auto > 0 &&
unlikely(rot->aio_info.current_size >= (loff_t)global_logrot_auto * 1024 * 1024 * 1024)) {
logrot_limit > 0 &&
unlikely(rot->aio_info.current_size >= logrot_limit * 1024 * 1024 * 1024)) {
char *new_path = path_make("%s/log-%09d-%s", parent_path, aio_dent->d_serial + 1, my_id());
if (likely(new_path && !mars_find_dent(global, new_path))) {
MARS_INF("old logfile size = %lld, creating new logfile '%s'\n", rot->aio_info.current_size, new_path);