mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 01:34:17 +01:00
MDEV-19371: Implement binlog_expire_logs_seconds for purging of binary logs
Part1: Functional changes Backporting upstream changes. commit a7e1ef858ee82493dd8ad9a76bc9c22fe3b8c05b Author: Neha Kumari <neha.n.kumari@oracle.com> Note: From the upstream patch only the new option binlog_expire_logs_seconds specific changes are taken. * Unlike in the upstream patch 'binlog_expire_logs_seconds' does not replace the "old" 'expire_logs_days', to preserve backward-compatibility. * Datatype of 'expire_logs_days' variable is changed to double. * Default value of 'binlog_expire_logs_seconds=0' similar to 'expire_logs_days'. * The purge_time can be specified in days with the micro-day precision. Eg: expire_logs_days=1 is the same as expire_logs_days=1.000000 to make binlog_expire_logs_seconds=86400. binlog_expire_logs_seconds=1 is the same as expire_logs_days=0.000012. * If binary log is disabled and option 'expire_logs_days' or 'binlog_expire_logs_seconds' used with purge_time > 0 a warning will be issued.
This commit is contained in:
parent
4205078b41
commit
49ff2cbff4
4 changed files with 72 additions and 11 deletions
|
@ -7033,12 +7033,14 @@ void MYSQL_BIN_LOG::purge()
|
|||
{
|
||||
mysql_mutex_assert_not_owner(&LOCK_log);
|
||||
#ifdef HAVE_REPLICATION
|
||||
if (expire_logs_days)
|
||||
if (binlog_expire_logs_seconds)
|
||||
{
|
||||
DEBUG_SYNC(current_thd, "at_purge_logs_before_date");
|
||||
time_t purge_time= my_time(0) - expire_logs_days*24*60*60;
|
||||
time_t purge_time= my_time(0) - binlog_expire_logs_seconds;
|
||||
DBUG_EXECUTE_IF("expire_logs_always", { purge_time = my_time(0); });
|
||||
if (purge_time >= 0)
|
||||
{
|
||||
ha_flush_logs();
|
||||
purge_logs_before_date(purge_time);
|
||||
}
|
||||
DEBUG_SYNC(current_thd, "after_purge_logs_before_date");
|
||||
|
|
|
@ -511,7 +511,9 @@ ulong current_pid;
|
|||
ulong slow_launch_threads = 0;
|
||||
uint sync_binlog_period= 0, sync_relaylog_period= 0,
|
||||
sync_relayloginfo_period= 0, sync_masterinfo_period= 0;
|
||||
ulong expire_logs_days = 0;
|
||||
double expire_logs_days = 0;
|
||||
ulong binlog_expire_logs_seconds = 0;
|
||||
|
||||
/**
|
||||
Soft upper limit for number of sp_head objects that can be stored
|
||||
in the sp_cache for one connection.
|
||||
|
@ -725,6 +727,8 @@ char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
|
|||
char *opt_logname, *opt_slow_logname, *opt_bin_logname;
|
||||
char *opt_binlog_index_name=0;
|
||||
|
||||
|
||||
|
||||
/* Static variables */
|
||||
|
||||
my_bool opt_stack_trace;
|
||||
|
@ -5283,11 +5287,20 @@ static int init_server_components()
|
|||
}
|
||||
|
||||
#ifdef HAVE_REPLICATION
|
||||
if (opt_bin_log && expire_logs_days)
|
||||
if (opt_bin_log)
|
||||
{
|
||||
time_t purge_time= server_start_time - expire_logs_days*24*60*60;
|
||||
if (purge_time >= 0)
|
||||
mysql_bin_log.purge_logs_before_date(purge_time);
|
||||
if (binlog_expire_logs_seconds)
|
||||
{
|
||||
time_t purge_time= server_start_time - binlog_expire_logs_seconds;
|
||||
if (purge_time >= 0)
|
||||
mysql_bin_log.purge_logs_before_date(purge_time);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (binlog_expire_logs_seconds)
|
||||
sql_print_warning("You need to use --log-bin to make --expire-logs-days "
|
||||
"or --binlog-expire-logs-seconds work.");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -7911,6 +7924,17 @@ mysqld_get_one_option(const struct my_option *opt, const char *argument,
|
|||
}
|
||||
break;
|
||||
}
|
||||
case (int)OPT_EXPIRE_LOGS_DAYS:
|
||||
{
|
||||
binlog_expire_logs_seconds= (ulong)(expire_logs_days*24*60*60);
|
||||
break;
|
||||
}
|
||||
case (int)OPT_BINLOG_EXPIRE_LOGS_SECONDS:
|
||||
{
|
||||
expire_logs_days= (binlog_expire_logs_seconds/double (24*60*60));
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef HAVE_REPLICATION
|
||||
case (int)OPT_REPLICATE_IGNORE_DB:
|
||||
{
|
||||
|
|
|
@ -155,7 +155,8 @@ extern bool opt_endinfo, using_udf_functions;
|
|||
extern my_bool locked_in_memory;
|
||||
extern bool opt_using_transactions;
|
||||
extern ulong current_pid;
|
||||
extern ulong expire_logs_days;
|
||||
extern double expire_logs_days;
|
||||
extern ulong binlog_expire_logs_seconds;
|
||||
extern my_bool relay_log_recovery;
|
||||
extern uint sync_binlog_period, sync_relaylog_period,
|
||||
sync_relayloginfo_period, sync_masterinfo_period;
|
||||
|
@ -777,6 +778,8 @@ enum options_mysqld
|
|||
OPT_BINLOG_IGNORE_DB,
|
||||
OPT_BIN_LOG,
|
||||
OPT_BOOTSTRAP,
|
||||
OPT_EXPIRE_LOGS_DAYS,
|
||||
OPT_BINLOG_EXPIRE_LOGS_SECONDS,
|
||||
OPT_CONSOLE,
|
||||
OPT_DEBUG_SYNC_TIMEOUT,
|
||||
OPT_REMOVED_OPTION,
|
||||
|
|
|
@ -1156,14 +1156,46 @@ static Sys_var_enum Sys_event_scheduler(
|
|||
ON_CHECK(event_scheduler_check), ON_UPDATE(event_scheduler_update));
|
||||
#endif
|
||||
|
||||
static Sys_var_on_access_global<Sys_var_ulong,
|
||||
static bool copy_to_expire_logs_days(sys_var *, THD *,
|
||||
enum_var_type type)
|
||||
{
|
||||
expire_logs_days= binlog_expire_logs_seconds / (double)(24 * 60 * 60);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool copy_to_binlog_expire_logs_seconds(sys_var *, THD *,
|
||||
enum_var_type type)
|
||||
{
|
||||
binlog_expire_logs_seconds= (ulong)(expire_logs_days * 24 * 60 * 60);
|
||||
return false;
|
||||
}
|
||||
|
||||
static Sys_var_on_access_global<Sys_var_double,
|
||||
PRIV_SET_SYSTEM_GLOBAL_VAR_EXPIRE_LOGS_DAYS>
|
||||
Sys_expire_logs_days(
|
||||
"expire_logs_days",
|
||||
"If non-zero, binary logs will be purged after expire_logs_days "
|
||||
"days; possible purges happen at startup and at binary log rotation",
|
||||
"days; It and binlog_expire_logs_seconds are aliases, such that "
|
||||
"changes in one are converted into the other, presentable as a "
|
||||
"decimal value with 1/1000000 of the day precision; possible "
|
||||
"purges happen at startup and at binary log rotation",
|
||||
GLOBAL_VAR(expire_logs_days),
|
||||
CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 99), DEFAULT(0), BLOCK_SIZE(1));
|
||||
CMD_LINE(REQUIRED_ARG, OPT_EXPIRE_LOGS_DAYS), VALID_RANGE(0, 99),
|
||||
DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
|
||||
ON_UPDATE(copy_to_binlog_expire_logs_seconds));
|
||||
|
||||
static Sys_var_on_access_global<Sys_var_ulong,
|
||||
PRIV_SET_SYSTEM_GLOBAL_VAR_EXPIRE_LOGS_DAYS>
|
||||
Sys_binlog_expire_logs_seconds(
|
||||
"binlog_expire_logs_seconds",
|
||||
"If non-zero, binary logs will be purged after "
|
||||
"binlog_expire_logs_seconds seconds; It and expire_logs_days are "
|
||||
"aliases, such that changes in one are converted into the other. "
|
||||
"Possible purges happen at startup and at binary log rotation.",
|
||||
GLOBAL_VAR(binlog_expire_logs_seconds),
|
||||
CMD_LINE(REQUIRED_ARG, OPT_BINLOG_EXPIRE_LOGS_SECONDS),
|
||||
VALID_RANGE(0, 0xFFFFFFFF), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
|
||||
NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(copy_to_expire_logs_days));
|
||||
|
||||
static Sys_var_mybool Sys_flush(
|
||||
"flush", "Flush MyISAM tables to disk between SQL commands",
|
||||
|
|
Loading…
Add table
Reference in a new issue