1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-20122: Deprecate MASTER_USE_GTID=Current_Pos to favor new MASTER_DEMOTE_TO_SLAVE option

New Feature:
========
This feature adds a safe replacement to the
MASTER_USE_GTID=Current_Pos option for CHANGE MASTER TO as
MASTER_DEMOTE_TO_SLAVE=<bool>. The use case of Current_Pos is to
transition a master to become a slave; however, can break
replication state if the slave executes local transactions due to
actively updating gtid_current_pos with gtid_binlog_pos and
gtid_slave_pos.

MASTER_DEMOTE_TO_SLAVE changes this use case by forcing users to set
Using_Gtid=Slave_Pos and merging gtid_binlog_pos into gtid_slave_pos
once at CHANGE MASTER TO time. Note that if gtid_slave_pos is more
recent than gtid_binlog_pos (as in the case of chain replication),
the replication state should be preserved.

Additionally, deprecate the `Current_Pos` option of MASTER_USE_GTID
to suggest the safe alternative option MASTER_DEMOTE_TO_SLAVE=TRUE.

Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
This commit is contained in:
Brandon Nesterenko
2022-06-07 20:06:42 -06:00
parent 5ab5ff08b0
commit 90c3b2835d
39 changed files with 1441 additions and 27 deletions

View File

@ -3822,7 +3822,13 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_SLAVE_POS)
mi->using_gtid= Master_info::USE_GTID_SLAVE_POS;
else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_CURRENT_POS)
{
mi->using_gtid= Master_info::USE_GTID_CURRENT_POS;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT,
ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
"master_use_gtid=current_pos", "master_demote_to_slave=1");
}
else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_NO ||
lex_mi->log_file_name || lex_mi->pos ||
lex_mi->relay_log_name || lex_mi->relay_log_pos)
@ -3913,6 +3919,40 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
strmake_buf(mi->master_log_name, mi->rli.group_master_log_name);
}
/*
MASTER_DEMOTE_TO_SLAVE is set. Merge gtid_binlog_pos into gtid_slave_pos.
*/
if (lex_mi->is_demotion_opt)
{
String new_gtid_state;
if (mi->using_gtid != Master_info::USE_GTID_SLAVE_POS)
{
my_error(ER_CM_OPTION_MISSING_REQUIREMENT, MYF(0),
"MASTER_DEMOTE_TO_SLAVE", "TRUE", "Using_Gtid=Slave_Pos");
ret= TRUE;
goto err;
}
if (!mysql_bin_log.is_open())
{
my_error(ER_NO_BINARY_LOGGING, MYF(0));
ret= TRUE;
goto err;
}
if ((ret= rpl_append_gtid_state(&new_gtid_state, true)))
goto err;
if (rpl_global_gtid_slave_state->load(
thd, new_gtid_state.ptr(), new_gtid_state.length(), true, true))
{
my_error(ER_FAILED_GTID_STATE_INIT, MYF(0));
ret= TRUE;
goto err;
}
}
/*
Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
a slave before).