1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-18450 Slaves wait shutdown

The patches features an optional shutdown behavior to hold on until
after all connected slaves have been sent the last binlogged event.
The connected slave is one whose START SLAVE has been acknowledged and
that was not stopped since that though it could be technically
reconnecting in background.

The solution therefore disallows killing the dump thread until is has
found EOF of the latest binlog file.  It is up to the shutdown
requester (DBA) to set up a sufficiently large shutdown timeout value
for shudown to wait patiently until lagging behind slaves have been
synchronized. On the other hand if a specific slave needs exclusion
from synchronization the DBA would have to stop it manually which
would terminate its dump thread.

`mysqladmin shutdown' is extended with a `--wait_for_all_slaves' option
which translates to `SHUTDOW WAIT FOR ALL SLAVES' sql query
to enable the feature on the client side.

The patch also performs a small refactoring of the server shutdown
around close_connections() to introduce kill thread phases which
are two as of current.
This commit is contained in:
Sergey Vojtovich
2019-03-07 08:12:26 +04:00
committed by Andrei Elkin
parent e450527938
commit 3568427d11
19 changed files with 459 additions and 54 deletions

View File

@ -506,6 +506,22 @@ static enum enum_binlog_checksum_alg get_binlog_checksum_value_at_connect(THD *
DBUG_RETURN(ret);
}
/**
Set current_linfo
Setting current_linfo needs to be done with LOCK_thd_data to ensure that
adjust_linfo_offsets doesn't use a structure that may be deleted.
*/
void THD::set_current_linfo(LOG_INFO *linfo)
{
mysql_mutex_lock(&LOCK_thd_data);
current_linfo= linfo;
mysql_mutex_unlock(&LOCK_thd_data);
}
/*
Adjust the position pointer in the binary log file for all running slaves
@ -2125,9 +2141,8 @@ static int init_binlog_sender(binlog_send_info *info,
// set current pos too
linfo->pos= *pos;
// note: publish that we use file, before we open it
thd->current_linfo= linfo;
thd->set_current_linfo(linfo);
if (check_start_offset(info, linfo->log_file_name, *pos))
return 1;
@ -2365,14 +2380,15 @@ static int send_format_descriptor_event(binlog_send_info *info, IO_CACHE *log,
DBUG_RETURN(0);
}
static bool should_stop(binlog_send_info *info)
static bool should_stop(binlog_send_info *info, bool kill_server_check= false)
{
return
info->net->error ||
info->net->vio == NULL ||
info->thd->killed ||
info->error != 0 ||
info->should_stop;
info->net->error ||
info->net->vio == NULL ||
(info->thd->killed &&
(info->thd->killed != KILL_SERVER || kill_server_check)) ||
info->error != 0 ||
info->should_stop;
}
/**
@ -2393,7 +2409,7 @@ static int wait_new_events(binlog_send_info *info, /* in */
&stage_master_has_sent_all_binlog_to_slave,
&old_stage);
while (!should_stop(info))
while (!should_stop(info, true))
{
*end_pos_ptr= mysql_bin_log.get_binlog_end_pos(binlog_end_pos_filename);
if (strcmp(linfo->log_file_name, binlog_end_pos_filename) != 0)
@ -2745,6 +2761,14 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
info->error= ER_UNKNOWN_ERROR;
goto err;
}
DBUG_EXECUTE_IF("simulate_delay_at_shutdown",
{
const char act[]=
"now "
"WAIT_FOR greetings_from_kill_mysql";
DBUG_ASSERT(!debug_sync_set_action(thd,
STRING_WITH_LEN(act)));
};);
/*
heartbeat_period from @master_heartbeat_period user variable
@ -3952,7 +3976,7 @@ bool mysql_show_binlog_events(THD* thd)
goto err;
}
thd->current_linfo= &linfo;
thd->set_current_linfo(&linfo);
if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0)
goto err;