mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +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:
89
mysql-test/suite/rpl/include/rpl_change_master_demote.inc
Normal file
89
mysql-test/suite/rpl/include/rpl_change_master_demote.inc
Normal file
@@ -0,0 +1,89 @@
|
||||
#
|
||||
# This file tests that a master can be demoted to a slave using
|
||||
# CHANGE MASTER TO MASTER_DEMOTE_TO_SLAVE=1 and replication will work correctly
|
||||
# afterwards.
|
||||
#
|
||||
# param $ignore_domain_ids : List of GTID domain ids to use for
|
||||
# CHANGE MASTER TO IGNORE_DOMAIN_IDS
|
||||
#
|
||||
|
||||
--let $include_filename= rpl_change_master_demote.inc
|
||||
--source include/begin_include_file.inc
|
||||
|
||||
--echo ##############################################
|
||||
--echo # Connection semantics change:
|
||||
--echo # * True primary is now connection 'slave'
|
||||
--echo # * True replica is now connection 'master'
|
||||
--echo ##############################################
|
||||
|
||||
--connection master
|
||||
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC;
|
||||
|
||||
--let $extra_cm_args=
|
||||
if (`SELECT strcmp("$ignore_domain_ids","") != 0`)
|
||||
{
|
||||
--let $extra_cm_args=, ignore_domain_ids=($ignore_domain_ids)
|
||||
}
|
||||
|
||||
--echo # First ensure gtid_slave_pos after master_demote_to_slave matches
|
||||
--echo # gtid_current_pos calculation
|
||||
--let $current_pos= `SELECT @@gtid_current_pos`
|
||||
--replace_result $SLAVE_MYPORT SLAVE_PORT
|
||||
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 $extra_cm_args
|
||||
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC;
|
||||
--let $slave_pos= `SELECT @@gtid_slave_pos`
|
||||
--echo # Validating gtid_slave_pos == gtid_binlog_pos..
|
||||
if ($slave_pos != $current_pos)
|
||||
{
|
||||
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC;
|
||||
die gtid_slave_pos calculation after master_demote_to_slave=1 differs from gtid_current_pos;
|
||||
}
|
||||
--echo # ..success
|
||||
|
||||
--source include/start_slave.inc
|
||||
|
||||
--connection slave
|
||||
--source include/stop_slave.inc
|
||||
|
||||
--echo # Ensuring replication works correctly after role swap
|
||||
--connection slave
|
||||
set session gtid_domain_id= 0;
|
||||
CREATE TABLE repl_t (a int);
|
||||
INSERT INTO repl_t VALUES (1);
|
||||
--source include/save_master_gtid.inc
|
||||
|
||||
--connection master
|
||||
--source include/sync_with_master_gtid.inc
|
||||
--echo # Validating that replication works..
|
||||
--let $n_replicated_rows= query_get_value(SELECT COUNT(*) FROM repl_t, COUNT(*), 1)
|
||||
if ($n_replicated_rows != 1)
|
||||
{
|
||||
die "Replication is broken";
|
||||
}
|
||||
--echo # ..success
|
||||
|
||||
--echo # Cleaning up replication check data
|
||||
--connection slave
|
||||
DROP TABLE repl_t;
|
||||
--source include/save_master_gtid.inc
|
||||
|
||||
--connection master
|
||||
--source include/sync_with_master_gtid.inc
|
||||
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC;
|
||||
|
||||
--echo ##############################################
|
||||
--echo # Connection semantics change:
|
||||
--echo # * True primary is back to connection 'master'
|
||||
--echo # * True replica is back to connection 'slave'
|
||||
--echo ##############################################
|
||||
|
||||
--connection master
|
||||
--source include/stop_slave.inc
|
||||
|
||||
--connection slave
|
||||
--replace_result $MASTER_MYPORT MASTER_PORT
|
||||
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$MASTER_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1
|
||||
--source include/start_slave.inc
|
||||
|
||||
--let $include_filename= rpl_change_master_demote.inc
|
||||
--source include/end_include_file.inc
|
Reference in New Issue
Block a user