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

@ -69,6 +69,8 @@ INSERT INTO t2 VALUES (5, "i1a");
connection server_4; connection server_4;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;
a b a b
@ -89,6 +91,8 @@ connection server_2;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_4; connection server_4;
UPDATE t2 SET b="j1a" WHERE a=5; UPDATE t2 SET b="j1a" WHERE a=5;
@ -117,6 +121,8 @@ include/save_master_gtid.inc
connection server_3; connection server_3;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
include/sync_with_master_gtid.inc include/sync_with_master_gtid.inc
SELECT * FROM t2 ORDER BY a; SELECT * FROM t2 ORDER BY a;

View File

@ -26,4 +26,9 @@ connection master;
CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='', CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='',
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH=''; MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0; CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
"Usage of CURRENT_POS in CHANGE MASTER MASTER_USE_GTID is dreprecated.
CHANGE MASTER TO MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
include/rpl_end.inc include/rpl_end.inc

View File

@ -48,7 +48,11 @@ INSERT INTO t2 VALUES (2, "switch1");
INSERT INTO t3 VALUES (202, "switch1 b"); INSERT INTO t3 VALUES (202, "switch1 b");
connection slave2; connection slave2;
CHANGE MASTER 'slave1' TO master_port=MYPORT_1, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos; CHANGE MASTER 'slave1' TO master_port=MYPORT_1, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
CHANGE MASTER 'slave2' TO master_port=MYPORT_2, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos; CHANGE MASTER 'slave2' TO master_port=MYPORT_2, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET default_master_connection = 'slave1'; SET default_master_connection = 'slave1';
START SLAVE; START SLAVE;
include/wait_for_slave_to_start.inc include/wait_for_slave_to_start.inc
@ -76,6 +80,8 @@ connection slave2;
include/sync_with_master_gtid.inc include/sync_with_master_gtid.inc
connection slave1; connection slave1;
CHANGE MASTER TO master_port=MYPORT_4, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos; CHANGE MASTER TO master_port=MYPORT_4, master_host='127.0.0.1', master_user='root', master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;
a b a b

View File

@ -191,17 +191,17 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR
FROM performance_schema.events_statements_summary_by_digest FROM performance_schema.events_statements_summary_by_digest
ORDER BY DIGEST_TEXT; ORDER BY DIGEST_TEXT;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR
test 27a9ab161a63050c84a63c6f77ebeb33 EXPLAIN SELECT * FROM `test` . `v1` 1 test 333a53e537d74bf74dd28c78ad5b23dd EXPLAIN SELECT * FROM `test` . `v1` 1
test ab0ab27c04f3a294feb86bede4331f86 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1 test 1fb578da66e6583bae8e64061486f1b1 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test 2e722346a5c2ef820946bcd04ccac208 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1 test 923bca939a55826e231e1335016ba418 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test 07baf2264db30b6b25302603436ebe82 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1 test 6fa6d75432fd499d1c7d6f964c8310a2 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1
test 3a7dbc963635ab0de6e160e0a4212bce EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1 test 3421da1ec8ecb8cac97e12a0609f73cb EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1
test 6b845c2e3a7421997e3b610d14b5c842 SELECT * FROM `test` . `v1` 1 test c2f68fd41bfbf3acd52eb5e7306b0c00 SELECT * FROM `test` . `v1` 1
test cb2ee099edbf6e0e5ee6ae14f3b1498a SELECT * FROM `test` . `v1` WHERE `a` = ? 1 test dd68812cbe4c1ed5a38921222981f8c5 SELECT * FROM `test` . `v1` WHERE `a` = ? 1
test e2dc5a300d2ba54ebb987a2ca6b90d93 SELECT * FROM `test` . `v1` WHERE `b` > ? 1 test 7563bcc32c6d0d872c8d9f0bf7717e6a SELECT * FROM `test` . `v1` WHERE `b` > ? 1
test c68e0f99323f7bb7732c7b5cf32c0ec2 SELECT `a` , `b` FROM `test` . `v1` 1 test 0817c53833dc6adbca581e8fe4c598c7 SELECT `a` , `b` FROM `test` . `v1` 1
test 43c5de955c9a72d2bb6f49db5c0ad3e7 SELECT `b` , `a` FROM `test` . `v1` 1 test a5f13903c70812ae08fa8c084e9cd503 SELECT `b` , `a` FROM `test` . `v1` 1
test 1678258ba15f7ccc63fd7b833763914a TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 test 66b14a14f2a42e1335dd28dfad8ea084 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
DROP TABLE test.v1; DROP TABLE test.v1;
CREATE VIEW test.v1 AS SELECT * FROM test.t1; CREATE VIEW test.v1 AS SELECT * FROM test.t1;
EXPLAIN SELECT * from test.v1; EXPLAIN SELECT * from test.v1;
@ -248,19 +248,19 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR
FROM performance_schema.events_statements_summary_by_digest FROM performance_schema.events_statements_summary_by_digest
ORDER BY DIGEST_TEXT; ORDER BY DIGEST_TEXT;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR
test 342cd5e41944d5f857f92b1e374857de CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1 test 98531b331031b84ddfbb2de8b601a704 CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1
test 2653f30030efcb6125121daa8eadf418 DROP TABLE `test` . `v1` 1 test 5352d7d117e97fecd312e354e9e290ce DROP TABLE `test` . `v1` 1
test 27a9ab161a63050c84a63c6f77ebeb33 EXPLAIN SELECT * FROM `test` . `v1` 2 test 333a53e537d74bf74dd28c78ad5b23dd EXPLAIN SELECT * FROM `test` . `v1` 2
test ab0ab27c04f3a294feb86bede4331f86 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2 test 1fb578da66e6583bae8e64061486f1b1 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test 2e722346a5c2ef820946bcd04ccac208 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2 test 923bca939a55826e231e1335016ba418 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test 07baf2264db30b6b25302603436ebe82 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2 test 6fa6d75432fd499d1c7d6f964c8310a2 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2
test 3a7dbc963635ab0de6e160e0a4212bce EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2 test 3421da1ec8ecb8cac97e12a0609f73cb EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2
test 6b845c2e3a7421997e3b610d14b5c842 SELECT * FROM `test` . `v1` 2 test c2f68fd41bfbf3acd52eb5e7306b0c00 SELECT * FROM `test` . `v1` 2
test cb2ee099edbf6e0e5ee6ae14f3b1498a SELECT * FROM `test` . `v1` WHERE `a` = ? 2 test dd68812cbe4c1ed5a38921222981f8c5 SELECT * FROM `test` . `v1` WHERE `a` = ? 2
test e2dc5a300d2ba54ebb987a2ca6b90d93 SELECT * FROM `test` . `v1` WHERE `b` > ? 2 test 7563bcc32c6d0d872c8d9f0bf7717e6a SELECT * FROM `test` . `v1` WHERE `b` > ? 2
test a13cfeda6d474d29546719d76dcfa831 SELECT SCHEMA_NAME , `DIGEST` , `DIGEST_TEXT` , `COUNT_STAR` FROM `performance_schema` . `events_statements_summary_by_digest` ORDER BY `DIGEST_TEXT` 1 test 21c19dd7ef5b894f3e32d0585cb3007f SELECT SCHEMA_NAME , `DIGEST` , `DIGEST_TEXT` , `COUNT_STAR` FROM `performance_schema` . `events_statements_summary_by_digest` ORDER BY `DIGEST_TEXT` 1
test c68e0f99323f7bb7732c7b5cf32c0ec2 SELECT `a` , `b` FROM `test` . `v1` 2 test 0817c53833dc6adbca581e8fe4c598c7 SELECT `a` , `b` FROM `test` . `v1` 2
test 43c5de955c9a72d2bb6f49db5c0ad3e7 SELECT `b` , `a` FROM `test` . `v1` 2 test a5f13903c70812ae08fa8c084e9cd503 SELECT `b` , `a` FROM `test` . `v1` 2
test 1678258ba15f7ccc63fd7b833763914a TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 test 66b14a14f2a42e1335dd28dfad8ea084 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1
DROP VIEW test.v1; DROP VIEW test.v1;
DROP TABLE test.t1; DROP TABLE test.t1;

View File

@ -8,5 +8,5 @@ SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
#################################### ####################################
SELECT event_name, digest, digest_text, sql_text FROM events_statements_history_long; SELECT event_name, digest, digest_text, sql_text FROM events_statements_history_long;
event_name digest digest_text sql_text event_name digest digest_text sql_text
statement/sql/select 1fd0cdb6b5aa22bd0809a39b2dc2ac70 SELECT ? + ? + SELECT ... statement/sql/select 96a6bb95edaf100857f09c968aca354b SELECT ? + ? + SELECT ...
statement/sql/truncate 0a9c405cebde6df4be315dae86ff398a TRUNCATE TABLE truncat... statement/sql/truncate c1d647bb870f2c63c22a16707bb8aee3 TRUNCATE TABLE truncat...

View 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

View File

@ -5,6 +5,8 @@ SET GLOBAL LOG_WARNINGS=2;
connection slave; connection slave;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO MASTER_USE_GTID=current_pos; CHANGE MASTER TO MASTER_USE_GTID=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection master; connection master;
"Test Case 1: Start binlog_dump to slave_server(#), pos(master-bin.000001, ###), using_gtid(1), gtid('')" "Test Case 1: Start binlog_dump to slave_server(#), pos(master-bin.000001, ###), using_gtid(1), gtid('')"

View File

@ -26,4 +26,9 @@ connection master;
CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='', CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='',
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH=''; MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0; CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
"Usage of CURRENT_POS in CHANGE MASTER MASTER_USE_GTID is dreprecated.
CHANGE MASTER TO MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
include/rpl_end.inc include/rpl_end.inc

View File

@ -0,0 +1,684 @@
include/master-slave.inc
[connection master]
connection slave;
include/stop_slave.inc
change master to master_use_gtid=slave_pos;
include/start_slave.inc
include/sync_with_master_gtid.inc
#
# Test Case 1: When both gtid_binlog_pos and gtid_slave_pos are
# empty, MASTER_DEMOTE_TO_SLAVE=1 results in no change to replication
# state.
#
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS
GTID_CURRENT_POS
GTID_SLAVE_POS
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS
GTID_CURRENT_POS
GTID_SLAVE_POS
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS
GTID_CURRENT_POS 0-2-3
GTID_SLAVE_POS 0-2-3
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 2: If gtid_slave_pos is empty, gtid_binlog_pos will
# completely overwrite it with MASTER_DEMOTE_TO_SLAVE=1.
#
connection slave;
include/stop_slave.inc
RESET MASTER;
set @@global.gtid_slave_pos="";
include/start_slave.inc
connection master;
RESET MASTER;
set @@global.gtid_slave_pos="";
set session gtid_domain_id= 0;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1);
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-2
GTID_CURRENT_POS 0-1-2
GTID_SLAVE_POS
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-2
GTID_CURRENT_POS 0-1-2
GTID_SLAVE_POS 0-1-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-2
GTID_CURRENT_POS 0-2-5
GTID_SLAVE_POS 0-2-5
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 3: Using a single domain id, if neither gtid_slave_pos nor
# gtid_binlog_pos are empty, and gtid_binlog_pos is more recent, then
# gtid_binlog_pos will overwrite gtid_slave_pos when
# MASTER_DEMOTE_TO_SLAVE=1.
#
connection master;
INSERT INTO t1 VALUES (2);
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-6
GTID_CURRENT_POS 0-1-6
GTID_SLAVE_POS 0-2-5
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-6
GTID_CURRENT_POS 0-1-6
GTID_SLAVE_POS 0-1-6
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-6
GTID_CURRENT_POS 0-2-9
GTID_SLAVE_POS 0-2-9
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 4: If gtid_slave_pos and gtid_binlog_pos are equivalent,
# MASTER_DEMOTE_TO_SLAVE=1 will not change gtid_slave_pos.
#
connection master;
# update gtid_binlog_pos and demote it (we have proven this works)
INSERT INTO t1 VALUES (3);
# Update to account for statements to verify replication in include file
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
RESET SLAVE ALL;
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-10
GTID_CURRENT_POS 0-1-10
GTID_SLAVE_POS 0-1-10
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-10
GTID_CURRENT_POS 0-1-10
GTID_SLAVE_POS 0-1-10
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-10
GTID_CURRENT_POS 0-2-13
GTID_SLAVE_POS 0-2-13
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 5: If a new domain id is added into gtid_binlog_pos while
# gtid_slave_pos already has a state, MASTER_DEMOTE_TO_SLAVE=1 will
# append a new GTID to gtid_slave_pos with the latest seq_no from that
# domain.
#
connection master;
# Domain_id
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (4);
set session gtid_domain_id= 1;
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (1);
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-14,1-1-2
GTID_CURRENT_POS 0-1-14,1-1-2
GTID_SLAVE_POS 0-2-13
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-14,1-1-2
GTID_CURRENT_POS 0-1-14,1-1-2
GTID_SLAVE_POS 0-1-14,1-1-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-14,1-1-2
GTID_CURRENT_POS 0-2-17,1-1-2
GTID_SLAVE_POS 0-2-17,1-1-2
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 6: If gtid_slave_pos has multiple GTID positions and
# gtid_binlog_pos contains updates on existing domain ids, new
# domains, and differing server_ids, MASTER_DEMOTE_TO_SLAVE=1 will
# update gtid_slave_pos such that it will have the seq_nos only from
# the GTIDs last applied by this server. In other words, any GTIDs
# with server ids that don't match that of the demoting server will be
# ignored in the update.
#
connection master;
# Update to account for statements to verify replication in include file
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (5);
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
RESET SLAVE ALL;
set session gtid_domain_id= 1;
INSERT INTO t2 VALUES (2);
set session gtid_domain_id= 2;
CREATE TABLE t3 (a int);
INSERT INTO t3 VALUES (1);
# The following events have a different server_id and should not go into
# gtid_slave_pos
set @old_server_id = @@server_id;
set session gtid_domain_id= 1;
set session server_id= 3;
INSERT INTO t2 VALUES (3);
set session gtid_domain_id= 4;
set session server_id= 3;
CREATE TABLE t5 (a int);
INSERT INTO t5 VALUES (1);
set session server_id= @old_server_id;
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-2,4-3-2
GTID_CURRENT_POS 0-1-18,1-1-2,2-1-2
GTID_SLAVE_POS 0-1-18,1-1-2
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 ;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-2,4-3-2
GTID_CURRENT_POS 0-1-18,1-1-2,2-1-2
GTID_SLAVE_POS 0-1-18,1-1-2,2-1-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-2,4-3-2
GTID_CURRENT_POS 0-2-21,1-3-4,2-1-2,4-3-2
GTID_SLAVE_POS 0-2-21,1-3-4,2-1-2,4-3-2
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 7: If MASTER_DEMOTE_TO_SLAVE=1 is combined with
# IGNORE_DOMAIN_IDS such that gtid_binlog_pos has more recent GTIDs
# than gtid_slave_pos in ignored domains, the CHANGE MASTER TO command
# will still update gtid_slave_pos with the most recent transactions
# from gtid_binlog_pos, despite being ignored by CHANGE MASTER TO
# because they were already applied on the server.
#
connection master;
set session gtid_domain_id= 2;
INSERT INTO t3 VALUES (2);
set session gtid_domain_id= 3;
CREATE TABLE t4 (a int);
INSERT INTO t4 VALUES (1);
include/save_master_gtid.inc
connection slave;
include/sync_with_master_gtid.inc
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-21,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-21,1-3-4,2-1-2,4-3-2
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 , ignore_domain_ids=(2,3);
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-21,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-21,1-3-4,2-1-3,3-1-2,4-3-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-18,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-24,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-24,1-3-4,2-1-3,3-1-2,4-3-2
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
#
# Test Case 8: If gtid_binlog_pos is more recent than gtid_slave_pos,
# and MASTER_DEMOTE_TO_SLAVE=1 is combined with a later call to
# START SLAVE UNTIL master_gtid_pos=<G> such that
# gtid_slave_pos < G < gtid_binlog_pos, then the slave should stop
# immediately after SSU because gtid_slave_pos should be updated to be
# after G.
#
connection master;
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (6);
# Tagging ssu_middle_binlog_pos here to be used for START SLAVE UNTIL
INSERT INTO t1 VALUES (7);
include/save_master_gtid.inc
# Ensure slave is up-to-date with master and then disable slave status
connection slave;
include/sync_with_master_gtid.inc
include/stop_slave.inc
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' ORDER BY VARIABLE_NAME ASC;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-24,1-3-4,2-1-3,3-1-2,4-3-2
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=1;
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
# GTID ssu_middle_binlog_pos should be considered in the past because
# gtid_slave_pos should be updated using the latest binlog gtids.
# The following call to sync_with_master_gtid.inc uses the latest
# binlog position and should still succeed despite the SSU stop
# position pointing to a previous event (because
# master_demote_to_slave=1 merges gtid_binlog_pos into gtid_slave_pos).
START SLAVE UNTIL master_gtid_pos="ssu_middle_binlog_pos";
Warnings:
Note 1278 It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you will get problems if you get an unexpected slave's mariadbd restart
# Slave needs time to start and stop automatically
# Validating neither SQL nor IO threads are running..
# ..success
# Clean slave state of master
RESET SLAVE ALL;
#
# Test Case 9: If gtid_slave_pos is more recent than gtid_binlog_pos
# when demoting the master to become a slave, the replication state
# should be preserved.
#
# rpl_change_master_demote.inc should force
# gtid_slave_pos > gtid_binlog_pos in domain 0 (due to the step which
# validates replication works)
connection master;
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 , ignore_domain_ids=(2,3);
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
Warnings:
Note 1255 Slave already has been stopped
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
# Demote master to slave with the more recent gtid_slave_pos
connection master;
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
# Validating gtid_slave_pos is unchanged..
# ..success
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
# Clean slave state of master
RESET SLAVE ALL;
#
# Test Case 10: MASTER_DEMOTE_TO_SLAVE=0 should not change replication
# state, regardless of gtid_slave_pos in comparison to gtid_binlog_pos.
#
# In domain 0, make gtid_slave_pos > gtid_binlog_pos
connection master;
include/rpl_change_master_demote.inc
##############################################
# Connection semantics change:
# * True primary is now connection 'slave'
# * True replica is now connection 'master'
##############################################
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
# First ensure gtid_slave_pos after master_demote_to_slave matches
# gtid_current_pos calculation
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 , ignore_domain_ids=(2,3);
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-29,1-3-4,2-1-3,3-1-2,4-3-2
# Validating gtid_slave_pos == gtid_binlog_pos..
# ..success
connection slave;
# 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);
connection master;
# Validating that replication works..
# ..success
# Cleaning up replication check data
connection slave;
DROP TABLE repl_t;
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;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-3-4,2-1-3,3-1-2,4-3-2
GTID_CURRENT_POS 0-2-32,1-3-4,2-1-3,3-1-2,4-3-2
GTID_SLAVE_POS 0-2-32,1-3-4,2-1-3,3-1-2,4-3-2
##############################################
# Connection semantics change:
# * True primary is back to connection 'master'
# * True replica is back to connection 'slave'
##############################################
connection master;
connection slave;
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
# Tag gtid_slave_pos now (before binlog updates) for later comparison
connection master;
# In domain 1, make gtid_slave_pos < gtid_binlog_pos
set session gtid_domain_id= 1;
INSERT INTO t2 VALUES (4);
# In domains 2, 3 and 4, gtid_slave_pos == gtid_binlog_pos
# Include a new domain id (5)
set session gtid_domain_id= 5;
CREATE TABLE t6 (a int);
INSERT INTO t6 VALUES (1);
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-1-5,2-1-3,3-1-2,4-3-2,5-1-2
GTID_SLAVE_POS 0-2-32,1-3-4,2-1-3,3-1-2,4-3-2
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=0;
# Validating gtid_slave_pos is unchanged..
# ..success
# Clean slave state of master
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1;
RESET SLAVE ALL;
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
VARIABLE_NAME GLOBAL_VALUE
GTID_BINLOG_POS 0-1-26,1-1-5,2-1-3,3-1-2,4-3-2,5-1-2
GTID_SLAVE_POS 0-2-32,1-1-5,2-1-3,3-1-2,4-3-2,5-1-2
#
#
# Stop slave for error test cases
connection slave;
include/stop_slave.inc
#
# Error Case 1: MASTER_DEMOTE_TO_SLAVE=1 combined with
# MASTER_USE_GTID=NO should result in an error.
#
connection master;
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=no, master_demote_to_slave=1;
ERROR HY000: CHANGE MASTER TO option 'MASTER_DEMOTE_TO_SLAVE=TRUE' is missing requirement Using_Gtid=Slave_Pos
#
# Error Case 2: Error when MASTER_DEMOTE_TO_SLAVE=1 is used without
# binary logging enabled.
#
connection master;
# Restarting master without binary log
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=1;
ERROR HY000: You are not using binary logging
# Restarting master to re-enable binary log
connection server_1;
connection default;
#
# Error Case 3: Error when MASTER_DEMOTE_TO_SLAVE is provided a
# non-boolean value.
#
connection master;
CHANGE MASTER TO master_host='127.0.0.1', master_port=SLAVE_PORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=invalid;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'invalid' at line 1
#
# Cleanup
#
connection master;
DROP TABLE t1, t2, t3, t4, t5, t6;
include/save_master_gtid.inc
connection slave;
include/start_slave.inc
include/sync_with_master_gtid.inc
include/rpl_end.inc
#
### End rpl_change_master_demote.test

View File

@ -69,6 +69,8 @@ INSERT INTO t2 VALUES (5, "i1a");
connection server_4; connection server_4;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;
a b a b
@ -89,6 +91,8 @@ connection server_2;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_4; connection server_4;
UPDATE t2 SET b="j1a" WHERE a=5; UPDATE t2 SET b="j1a" WHERE a=5;
@ -117,6 +121,8 @@ include/save_master_gtid.inc
connection server_3; connection server_3;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
include/sync_with_master_gtid.inc include/sync_with_master_gtid.inc
SELECT * FROM t2 ORDER BY a; SELECT * FROM t2 ORDER BY a;

View File

@ -15,6 +15,8 @@ SET sql_log_bin=1;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_1; connection server_1;
INSERT INTO t1 VALUES (2,1); INSERT INTO t1 VALUES (2,1);
INSERT INTO t1 VALUES (3,1); INSERT INTO t1 VALUES (3,1);

View File

@ -74,6 +74,8 @@ INSERT INTO t1 VALUES (2);
SET sql_log_bin = 1; SET sql_log_bin = 1;
INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (3);
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
BEGIN; BEGIN;
SET GLOBAL gtid_slave_pos = "100-100-100"; SET GLOBAL gtid_slave_pos = "100-100-100";
ERROR 25000: You are not allowed to execute this command in a transaction ERROR 25000: You are not allowed to execute this command in a transaction

View File

@ -4,6 +4,8 @@ CREATE TABLE t1 (i INT);
connection slave; connection slave;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO MASTER_USE_GTID= current_pos, MASTER_DELAY= 10; CHANGE MASTER TO MASTER_USE_GTID= current_pos, MASTER_DELAY= 10;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection master; connection master;
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);

View File

@ -13,15 +13,23 @@ END|
connection server_2; connection server_2;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_3; connection server_3;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_4; connection server_4;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_5; connection server_5;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_1; connection server_1;
SET gtid_domain_id= 1; SET gtid_domain_id= 1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
@ -340,6 +348,8 @@ a b
connection server_1; connection server_1;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2,
master_user = "root", master_use_gtid = current_pos; master_user = "root", master_use_gtid = current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;
a a

View File

@ -13,6 +13,8 @@ reset slave all;
connection server_1; connection server_1;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2,
master_user='root', MASTER_USE_GTID=CURRENT_POS; master_user='root', MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
include/wait_for_slave_to_start.inc include/wait_for_slave_to_start.inc
connection server_2; connection server_2;
@ -23,6 +25,8 @@ flush logs;
connection server_3; connection server_3;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
select * from t1 order by n; select * from t1 order by n;
n n
@ -58,11 +62,15 @@ Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'Cur
connection server_2; connection server_2;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1,
master_user = 'root', MASTER_USE_GTID=CURRENT_POS; master_user = 'root', MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_3; connection server_3;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_1; connection server_1;
drop table t1; drop table t1;

View File

@ -45,6 +45,8 @@ SET GLOBAL gtid_slave_pos= '0-2-10';
connection server_1; connection server_1;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2,
master_user= 'root', master_use_gtid=CURRENT_POS; master_user= 'root', master_use_gtid=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
connection server_2; connection server_2;
INSERT INTO t1 VALUES (11); INSERT INTO t1 VALUES (11);
@ -74,6 +76,8 @@ connection server_2;
INSERT INTO t1 VALUES (22); INSERT INTO t1 VALUES (22);
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1,
master_user= 'root', master_use_gtid=CURRENT_POS; master_user= 'root', master_use_gtid=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
SET sql_log_bin= 0; SET sql_log_bin= 0;
CALL mtr.add_suppression("which is not in the master's binlog. Since the master's binlog contains GTIDs with higher sequence numbers, it probably means that the slave has diverged"); CALL mtr.add_suppression("which is not in the master's binlog. Since the master's binlog contains GTIDs with higher sequence numbers, it probably means that the slave has diverged");

View File

@ -10,6 +10,8 @@ SET sql_log_bin= 0;
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
SET sql_log_bin= 1; SET sql_log_bin= 1;
CHANGE MASTER TO master_use_gtid= current_pos; CHANGE MASTER TO master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection master; connection master;
CREATE TEMPORARY TABLE t2 LIKE t1; CREATE TEMPORARY TABLE t2 LIKE t1;
INSERT INTO t2 VALUE (1); INSERT INTO t2 VALUE (1);

View File

@ -22,6 +22,8 @@ include/stop_slave.inc
connection server_1; connection server_1;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SLAVE_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SLAVE_PORT,
master_user = 'root', master_use_gtid = current_pos; master_user = 'root', master_use_gtid = current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
include/wait_for_slave_to_start.inc include/wait_for_slave_to_start.inc
connection server_2; connection server_2;
@ -54,6 +56,8 @@ include/save_master_gtid.inc
connection server_2; connection server_2;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
master_use_gtid = current_pos; master_use_gtid = current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
include/sync_with_master_gtid.inc include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;

View File

@ -2,6 +2,8 @@ include/rpl_init.inc [topology=1->2]
connection server_2; connection server_2;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid= current_pos; CHANGE MASTER TO master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_1; connection server_1;
CREATE TABLE t1 (a INT); CREATE TABLE t1 (a INT);

View File

@ -59,6 +59,8 @@ Variable_name Value
gtid_binlog_state gtid_binlog_state
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
SHOW VARIABLES LIKE 'gtid_binlog_pos'; SHOW VARIABLES LIKE 'gtid_binlog_pos';
Variable_name Value Variable_name Value

View File

@ -12,6 +12,8 @@ connection server_2;
SET GLOBAL gtid_slave_pos=""; SET GLOBAL gtid_slave_pos="";
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
SELECT * FROM t1; SELECT * FROM t1;
a a
@ -34,6 +36,8 @@ connection server_2;
SET GLOBAL gtid_slave_pos=""; SET GLOBAL gtid_slave_pos="";
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE; START SLAVE;
include/wait_for_slave_io_error.inc [errno=1236] include/wait_for_slave_io_error.inc [errno=1236]
include/stop_slave.inc include/stop_slave.inc
@ -56,6 +60,8 @@ connection server_2;
SET GLOBAL gtid_slave_pos='0-1-3'; SET GLOBAL gtid_slave_pos='0-1-3';
CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT,
MASTER_USE_GTID=CURRENT_POS; MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
include/sync_with_master_gtid.inc include/sync_with_master_gtid.inc
SELECT * FROM t1 ORDER by a; SELECT * FROM t1 ORDER by a;
@ -98,6 +104,8 @@ RESET MASTER;
connection server_2; connection server_2;
SET GLOBAL gtid_slave_pos=''; SET GLOBAL gtid_slave_pos='';
CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=current_pos; CHANGE MASTER TO master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root', master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_1; connection server_1;
CREATE TABLE t1 (a INT PRIMARY KEY); CREATE TABLE t1 (a INT PRIMARY KEY);
@ -155,6 +163,8 @@ START SLAVE;
include/wait_for_slave_sql_error.inc [errno=1050] include/wait_for_slave_sql_error.inc [errno=1050]
STOP SLAVE IO_THREAD; STOP SLAVE IO_THREAD;
CHANGE MASTER TO MASTER_USE_GTID=CURRENT_POS; CHANGE MASTER TO MASTER_USE_GTID=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_1; connection server_1;
INSERT INTO t1 VALUES(3); INSERT INTO t1 VALUES(3);

View File

@ -8,6 +8,8 @@ include/stop_slave.inc
Master_Log_File = 'master-bin.000001' Master_Log_File = 'master-bin.000001'
Using_Gtid = 'Slave_Pos' Using_Gtid = 'Slave_Pos'
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
FLUSH LOGS; FLUSH LOGS;
connection server_1; connection server_1;
FLUSH LOGS; FLUSH LOGS;

View File

@ -30,6 +30,8 @@ include/stop_slave_io.inc
START SLAVE UNTIL master_gtid_pos = ""; START SLAVE UNTIL master_gtid_pos = "";
ERROR HY000: START SLAVE UNTIL master_gtid_pos requires that slave is using GTID ERROR HY000: START SLAVE UNTIL master_gtid_pos requires that slave is using GTID
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_1; connection server_1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1); INSERT INTO t1 VALUES(1);
@ -218,6 +220,8 @@ INSERT INTO t1 VALUES (10);
connection server_2; connection server_2;
CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1, CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1,
master_user = "root", master_use_gtid = current_pos; master_user = "root", master_use_gtid = current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
START SLAVE UNTIL master_gtid_pos = '0-1-2'; START SLAVE UNTIL master_gtid_pos = '0-1-2';
include/wait_for_slave_to_start.inc include/wait_for_slave_to_start.inc
connection server_1; connection server_1;

View File

@ -11,6 +11,8 @@ CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on w
INSERT INTO t1 VALUES (1, 2); INSERT INTO t1 VALUES (1, 2);
SET sql_log_bin= 1; SET sql_log_bin= 1;
CHANGE MASTER TO master_use_gtid= current_pos; CHANGE MASTER TO master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
Contents on slave before: Contents on slave before:
SELECT * FROM t1 ORDER BY a; SELECT * FROM t1 ORDER BY a;
a b a b

View File

@ -5,6 +5,8 @@ SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
include/stop_slave.inc include/stop_slave.inc
SET GLOBAL slave_parallel_threads=10; SET GLOBAL slave_parallel_threads=10;
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
*** MDEV-6589: Incorrect relay log start position when restarting SQL thread after error in parallel replication *** *** MDEV-6589: Incorrect relay log start position when restarting SQL thread after error in parallel replication ***
connection server_1; connection server_1;

View File

@ -18,11 +18,15 @@ SET @old_updates= @@GLOBAL.binlog_direct_non_transactional_updates;
SET GLOBAL binlog_direct_non_transactional_updates=OFF; SET GLOBAL binlog_direct_non_transactional_updates=OFF;
SET SESSION binlog_direct_non_transactional_updates=OFF; SET SESSION binlog_direct_non_transactional_updates=OFF;
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_3; connection server_3;
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
include/stop_slave.inc include/stop_slave.inc
SET GLOBAL slave_parallel_threads=10; SET GLOBAL slave_parallel_threads=10;
CHANGE MASTER TO master_use_gtid=current_pos; CHANGE MASTER TO master_use_gtid=current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
connection server_1; connection server_1;
BEGIN; BEGIN;
CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY) ENGINE=MEMORY; CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY) ENGINE=MEMORY;

View File

@ -5,6 +5,8 @@ SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
include/stop_slave.inc include/stop_slave.inc
SET GLOBAL slave_parallel_threads=5; SET GLOBAL slave_parallel_threads=5;
CHANGE MASTER TO master_use_gtid= current_pos; CHANGE MASTER TO master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
connection server_1; connection server_1;
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(100) CHARACTER SET utf8); CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(100) CHARACTER SET utf8);

View File

@ -87,6 +87,8 @@ include/assert.inc [Value returned by SSS and PS table for Using_Gtid should be
change master to change master to
master_user = 'root', master_user = 'root',
master_use_gtid= CURRENT_POS; master_use_gtid= CURRENT_POS;
Warnings:
Warning #### 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/assert.inc [Value returned by SSS and PS table for Using_Gtid should be same.] include/assert.inc [Value returned by SSS and PS table for Using_Gtid should be same.]
# 3) Test for Auto_position= SLAVE_POS # 3) Test for Auto_position= SLAVE_POS

View File

@ -5,6 +5,8 @@ set global binlog_alter_two_phase=true;
connection slave; connection slave;
include/stop_slave.inc include/stop_slave.inc
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
set global gtid_strict_mode=1; set global gtid_strict_mode=1;
# Legacy Master Slave # Legacy Master Slave
connect master_node,127.0.0.1,root,,$db_name, $M_port; connect master_node,127.0.0.1,root,,$db_name, $M_port;

View File

@ -3,6 +3,8 @@ include/master-slave.inc
connection slave; connection slave;
stop slave; stop slave;
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET GLOBAL slave_parallel_threads=4; SET GLOBAL slave_parallel_threads=4;
set global slave_parallel_mode=optimistic; set global slave_parallel_mode=optimistic;
set global gtid_strict_mode=1; set global gtid_strict_mode=1;
@ -94,6 +96,8 @@ include/start_slave.inc
connection slave; connection slave;
stop slave; stop slave;
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET GLOBAL slave_parallel_threads=4; SET GLOBAL slave_parallel_threads=4;
set global slave_parallel_mode=optimistic; set global slave_parallel_mode=optimistic;
set global gtid_strict_mode=1; set global gtid_strict_mode=1;
@ -185,6 +189,8 @@ include/start_slave.inc
connection slave; connection slave;
stop slave; stop slave;
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET GLOBAL slave_parallel_threads=4; SET GLOBAL slave_parallel_threads=4;
set global slave_parallel_mode=optimistic; set global slave_parallel_mode=optimistic;
set global gtid_strict_mode=1; set global gtid_strict_mode=1;
@ -315,6 +321,8 @@ include/start_slave.inc
connection slave; connection slave;
stop slave; stop slave;
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET GLOBAL slave_parallel_threads=4; SET GLOBAL slave_parallel_threads=4;
set global slave_parallel_mode=optimistic; set global slave_parallel_mode=optimistic;
set global gtid_strict_mode=1; set global gtid_strict_mode=1;
@ -406,6 +414,8 @@ include/start_slave.inc
connection slave; connection slave;
stop slave; stop slave;
change master to master_use_gtid= current_pos; change master to master_use_gtid= current_pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
SET GLOBAL slave_parallel_threads=4; SET GLOBAL slave_parallel_threads=4;
set global slave_parallel_mode=optimistic; set global slave_parallel_mode=optimistic;
set global gtid_strict_mode=1; set global gtid_strict_mode=1;

View File

@ -4,6 +4,8 @@ include/master-slave.inc
connection slave; connection slave;
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO master_use_gtid=CURRENT_POS; CHANGE MASTER TO master_use_gtid=CURRENT_POS;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/rpl_stop_server.inc [server_number=2] include/rpl_stop_server.inc [server_number=2]
include/rpl_start_server.inc [server_number=2] include/rpl_start_server.inc [server_number=2]
connection master; connection master;

View File

@ -58,6 +58,8 @@ include/start_slave.inc
# to its default of Slave_Pos after RESET SLAVE. # to its default of Slave_Pos after RESET SLAVE.
include/stop_slave.inc include/stop_slave.inc
CHANGE MASTER TO MASTER_USE_GTID=Current_Pos; CHANGE MASTER TO MASTER_USE_GTID=Current_Pos;
Warnings:
Warning 1681 'master_use_gtid=current_pos' is deprecated and will be removed in a future release. Please use master_demote_to_slave=1 instead
include/start_slave.inc include/start_slave.inc
include/stop_slave.inc include/stop_slave.inc
RESET SLAVE; RESET SLAVE;

View File

@ -108,4 +108,10 @@ CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_
MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH=''; MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH='';
CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0; CHANGE MASTER TO MASTER_USER='root', MASTER_PASSWORD='', MASTER_SSL=0;
# MDEV-20122: Deprecate MASTER_USE_GTID=Current_Pos to favor new MASTER_DEMOTE_TO_SLAVE option
--echo "Usage of CURRENT_POS in CHANGE MASTER MASTER_USE_GTID is dreprecated.
CHANGE MASTER TO MASTER_USE_GTID=CURRENT_POS;
CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
--source include/rpl_end.inc --source include/rpl_end.inc

View File

@ -0,0 +1,467 @@
#
# Purpose:
#
# This test suite ensures that the MASTER_DEMOTE_TO_SLAVE option of
# CHANGE MASTER TO will merge the binlog GTID position (gtid_binlog_pos) into
# the replication state (gtid_slave_pos).
#
#
# Methodology:
#
# A series of test cases validate that MASTER_DEMOTE_TO_SLAVE correctly
# merges the binlog GTID state into the replication state. Each test case
# sets up the context in which it will demote the master to a slave, and then
# calls into an include file to perform the actual demotion and validation.
# Specifically, the include file will demote the master to be the slave,
# promote the slave to be the master, ensure that gtid_slave_pos matches
# gtid_current_pos, ensure replication works correctly in this new
# configuration, and return the master and slave to their previous roles.
#
# The test cases are as follows:
# 1) When both gtid_binlog_pos and gtid_slave_pos are empty,
# MASTER_DEMOTE_TO_SLAVE=1 results in no change to replication state.
#
# 2) If gtid_slave_pos is empty, gtid_binlog_pos will completely
# overwrite it with MASTER_DEMOTE_TO_SLAVE=1.
#
# 3) Using a single domain id, if neither gtid_slave_pos nor
# gtid_binlog_pos are empty, and gtid_binlog_pos is more recent, then
# gtid_binlog_pos will overwrite gtid_slave_pos when MASTER_DEMOTE_TO_SLAVE=1.
#
# 4) If gtid_slave_pos and gtid_binlog_pos are equivalent,
# MASTER_DEMOTE_TO_SLAVE=1 will not change gtid_slave_pos.
#
# 5) If multiple new domain ids are added into gtid_binlog_pos while
# gtid_slave_pos already has a state, MASTER_DEMOTE_TO_SLAVE=1 will append
# new GTIDs to gtid_slave_pos with the latest seq_no from each domain.
#
# 6) If gtid_slave_pos has multiple GTID positions and gtid_binlog_pos
# contains updates on existing domain ids, new domains, and differing
# server_ids, MASTER_DEMOTE_TO_SLAVE=1 will update gtid_slave_pos such that
# it will have the seq_nos only from the GTIDs last applied by this server.
# In other words, any GTIDs with server ids that don't match that of the
# demoting server will be ignored in the update.
#
# 7) If MASTER_DEMOTE_TO_SLAVE=1 is combined with IGNORE_DOMAIN_IDS such
# that gtid_binlog_pos has more recent GTIDs than gtid_slave_pos in ignored
# domains, the CHANGE MASTER TO command will still update gtid_slave_pos with
# the most recent transactions from gtid_binlog_pos, despite being ignored by
# CHANGE MASTER TO because they were already applied on the server.
#
# 8) If gtid_binlog_pos is more recent than gtid_slave_pos, and
# MASTER_DEMOTE_TO_SLAVE=1 is combined with a later call to
# START SLAVE UNTIL master_gtid_pos=<G> such that
# gtid_slave_pos < G < gtid_binlog_pos, then the slave should stop
# immediately after SSU because gtid_slave_pos should already be after the
# UNTIL GTID.
#
# 9) If gtid_slave_pos is more recent than gtid_binlog_pos when demoting
# the master to become a slave, the replication state should be preserved.
#
# 10) MASTER_DEMOTE_TO_SLAVE=0 should not change replication state,
# regardless of gtid_slave_pos in comparison to gtid_binlog_pos.
#
#
# Error cases:
# Error Case 1) MASTER_DEMOTE_TO_SLAVE=1 combined with
# MASTER_USE_GTID=NO should result in an error.
#
# Error Case 2) Error when MASTER_DEMOTE_TO_SLAVE=1 is used without
# binary logging enabled.
#
# Error Case 3) Error when MASTER_DEMOTE_TO_SLAVE is provided a
# non-boolean value.
#
#
# References:
# MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based
# replication is used by default if master supports it
#
--source include/master-slave.inc
--source include/have_log_bin.inc
--source include/have_binlog_format_mixed.inc
--connection slave
--source include/stop_slave.inc
change master to master_use_gtid=slave_pos;
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
--echo #
--echo # Test Case 1: When both gtid_binlog_pos and gtid_slave_pos are
--echo # empty, MASTER_DEMOTE_TO_SLAVE=1 results in no change to replication
--echo # state.
--echo #
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 2: If gtid_slave_pos is empty, gtid_binlog_pos will
--echo # completely overwrite it with MASTER_DEMOTE_TO_SLAVE=1.
--echo #
--connection slave
--source include/stop_slave.inc
RESET MASTER;
set @@global.gtid_slave_pos="";
--source include/start_slave.inc
--connection master
RESET MASTER;
set @@global.gtid_slave_pos="";
set session gtid_domain_id= 0;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1);
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 3: Using a single domain id, if neither gtid_slave_pos nor
--echo # gtid_binlog_pos are empty, and gtid_binlog_pos is more recent, then
--echo # gtid_binlog_pos will overwrite gtid_slave_pos when
--echo # MASTER_DEMOTE_TO_SLAVE=1.
--echo #
--connection master
INSERT INTO t1 VALUES (2);
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 4: If gtid_slave_pos and gtid_binlog_pos are equivalent,
--echo # MASTER_DEMOTE_TO_SLAVE=1 will not change gtid_slave_pos.
--echo #
--connection master
--echo # update gtid_binlog_pos and demote it (we have proven this works)
INSERT INTO t1 VALUES (3);
--echo # Update to account for statements to verify replication in include file
--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
RESET SLAVE ALL;
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 5: If a new domain id is added into gtid_binlog_pos while
--echo # gtid_slave_pos already has a state, MASTER_DEMOTE_TO_SLAVE=1 will
--echo # append a new GTID to gtid_slave_pos with the latest seq_no from that
--echo # domain.
--echo #
--connection master
--echo # Domain_id
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (4);
set session gtid_domain_id= 1;
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (1);
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 6: If gtid_slave_pos has multiple GTID positions and
--echo # gtid_binlog_pos contains updates on existing domain ids, new
--echo # domains, and differing server_ids, MASTER_DEMOTE_TO_SLAVE=1 will
--echo # update gtid_slave_pos such that it will have the seq_nos only from
--echo # the GTIDs last applied by this server. In other words, any GTIDs
--echo # with server ids that don't match that of the demoting server will be
--echo # ignored in the update.
--echo #
--connection master
--echo # Update to account for statements to verify replication in include file
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (5);
--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
RESET SLAVE ALL;
set session gtid_domain_id= 1;
INSERT INTO t2 VALUES (2);
set session gtid_domain_id= 2;
CREATE TABLE t3 (a int);
INSERT INTO t3 VALUES (1);
--echo # The following events have a different server_id and should not go into
--echo # gtid_slave_pos
set @old_server_id = @@server_id;
set session gtid_domain_id= 1;
set session server_id= 3;
INSERT INTO t2 VALUES (3);
set session gtid_domain_id= 4;
set session server_id= 3;
CREATE TABLE t5 (a int);
INSERT INTO t5 VALUES (1);
set session server_id= @old_server_id;
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 7: If MASTER_DEMOTE_TO_SLAVE=1 is combined with
--echo # IGNORE_DOMAIN_IDS such that gtid_binlog_pos has more recent GTIDs
--echo # than gtid_slave_pos in ignored domains, the CHANGE MASTER TO command
--echo # will still update gtid_slave_pos with the most recent transactions
--echo # from gtid_binlog_pos, despite being ignored by CHANGE MASTER TO
--echo # because they were already applied on the server.
--echo #
--connection master
set session gtid_domain_id= 2;
INSERT INTO t3 VALUES (2);
set session gtid_domain_id= 3;
CREATE TABLE t4 (a int);
INSERT INTO t4 VALUES (1);
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--let $ignore_domain_ids=2,3
--source include/rpl_change_master_demote.inc
--echo #
--echo # Test Case 8: If gtid_binlog_pos is more recent than gtid_slave_pos,
--echo # and MASTER_DEMOTE_TO_SLAVE=1 is combined with a later call to
--echo # START SLAVE UNTIL master_gtid_pos=<G> such that
--echo # gtid_slave_pos < G < gtid_binlog_pos, then the slave should stop
--echo # immediately after SSU because gtid_slave_pos should be updated to be
--echo # after G.
--echo #
--connection master
set session gtid_domain_id= 0;
INSERT INTO t1 VALUES (6);
--let $ssu_middle_binlog_pos= `SELECT @@GLOBAL.gtid_binlog_pos`
--echo # Tagging ssu_middle_binlog_pos here to be used for START SLAVE UNTIL
INSERT INTO t1 VALUES (7);
--source include/save_master_gtid.inc
--echo # Ensure slave is up-to-date with master and then disable slave status
--connection slave
--source include/sync_with_master_gtid.inc
--source include/stop_slave.inc
--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' ORDER BY VARIABLE_NAME ASC;
--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
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
--echo # GTID ssu_middle_binlog_pos should be considered in the past because
--echo # gtid_slave_pos should be updated using the latest binlog gtids.
--echo # The following call to sync_with_master_gtid.inc uses the latest
--echo # binlog position and should still succeed despite the SSU stop
--echo # position pointing to a previous event (because
--echo # master_demote_to_slave=1 merges gtid_binlog_pos into gtid_slave_pos).
--replace_result $ssu_middle_binlog_pos ssu_middle_binlog_pos
eval START SLAVE UNTIL master_gtid_pos="$ssu_middle_binlog_pos";
--echo # Slave needs time to start and stop automatically
# Note sync_with_master_gtid.inc, wait_for_slave_to_start.inc, and
# wait_for_slave_to_stop.inc won't work due to replication state and race
# conditions
--sleep 1
--echo # Validating neither SQL nor IO threads are running..
--let $io_state= query_get_value("SHOW SLAVE STATUS", Slave_IO_State, 1)
if (`SELECT strcmp("$io_state","") != 0`)
{
die "IO thread should not be running after START SLAVE UNTIL master_gtid_pos using a pre-existing GTID";
}
--let $sql_state= query_get_value("SHOW SLAVE STATUS", Slave_SQL_Running_State, 1)
if (`SELECT strcmp("$sql_state","") != 0`)
{
die "SQL thread should not be running after START SLAVE UNTIL master_gtid_pos using a pre-existing GTID";
}
--echo # ..success
--echo # Clean slave state of master
RESET SLAVE ALL;
--echo #
--echo # Test Case 9: If gtid_slave_pos is more recent than gtid_binlog_pos
--echo # when demoting the master to become a slave, the replication state
--echo # should be preserved.
--echo #
--echo # rpl_change_master_demote.inc should force
--echo # gtid_slave_pos > gtid_binlog_pos in domain 0 (due to the step which
--echo # validates replication works)
--connection master
--source include/rpl_change_master_demote.inc
--let $current_pos= `SELECT @@gtid_current_pos`
--echo # Demote master to slave with the more recent gtid_slave_pos
--connection master
--let $old_slave_pos= `SELECT @@gtid_slave_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
--let $new_slave_pos= `SELECT @@gtid_slave_pos`
--echo # Validating gtid_slave_pos is unchanged..
if ($old_slave_pos != $new_slave_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 should not change when MASTER_DEMOTE_TO_SLAVE=0";
}
--echo # ..success
--echo # Validating gtid_slave_pos == gtid_binlog_pos..
if ($new_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
--echo # Clean slave state of master
RESET SLAVE ALL;
--echo #
--echo # Test Case 10: MASTER_DEMOTE_TO_SLAVE=0 should not change replication
--echo # state, regardless of gtid_slave_pos in comparison to gtid_binlog_pos.
--echo #
--echo # In domain 0, make gtid_slave_pos > gtid_binlog_pos
--connection master
--source include/rpl_change_master_demote.inc
--echo # Tag gtid_slave_pos now (before binlog updates) for later comparison
--let $old_slave_pos= `SELECT @@gtid_slave_pos`
--connection master
--echo # In domain 1, make gtid_slave_pos < gtid_binlog_pos
set session gtid_domain_id= 1;
INSERT INTO t2 VALUES (4);
--echo # In domains 2, 3 and 4, gtid_slave_pos == gtid_binlog_pos
--echo # Include a new domain id (5)
set session gtid_domain_id= 5;
CREATE TABLE t6 (a int);
INSERT INTO t6 VALUES (1);
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
--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=0
--echo # Validating gtid_slave_pos is unchanged..
--let $new_slave_pos= `SELECT @@gtid_slave_pos`
if ($old_slave_pos != $new_slave_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' ORDER BY VARIABLE_NAME ASC;
die gtid_slave_pos should not change when MASTER_DEMOTE_TO_SLAVE=0;
}
--echo # ..success
--echo # Clean slave state of master
--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
RESET SLAVE ALL;
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC;
--echo #
--echo #
--echo # Stop slave for error test cases
--connection slave
--source include/stop_slave.inc
--echo #
--echo # Error Case 1: MASTER_DEMOTE_TO_SLAVE=1 combined with
--echo # MASTER_USE_GTID=NO should result in an error.
--echo #
--connection master
--replace_result $SLAVE_MYPORT SLAVE_PORT
--error 4191
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=no, master_demote_to_slave=1
--echo #
--echo # Error Case 2: Error when MASTER_DEMOTE_TO_SLAVE=1 is used without
--echo # binary logging enabled.
--echo #
--connection master
--echo # Restarting master without binary log
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart: --skip-slave-start=1 --skip-log-bin
EOF
--enable_reconnect
--source include/wait_until_connected_again.inc
--replace_result $SLAVE_MYPORT SLAVE_PORT
--error 1381
--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
--echo # Restarting master to re-enable binary log
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF
--shutdown_server
--source include/wait_until_disconnected.inc
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart: --skip-slave-start=1
EOF
--enable_reconnect
--source include/wait_until_connected_again.inc
--connection server_1
--enable_reconnect
--source include/wait_until_connected_again.inc
--connection default
--enable_reconnect
--source include/wait_until_connected_again.inc
--echo #
--echo # Error Case 3: Error when MASTER_DEMOTE_TO_SLAVE is provided a
--echo # non-boolean value.
--echo #
--connection master
--replace_result $SLAVE_MYPORT SLAVE_PORT
--error 1064
--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=invalid
--echo #
--echo # Cleanup
--echo #
--connection master
DROP TABLE t1, t2, t3, t4, t5, t6;
--source include/save_master_gtid.inc
--connection slave
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
--source include/rpl_end.inc
--echo #
--echo ### End rpl_change_master_demote.test

View File

@ -385,6 +385,7 @@ SYMBOL symbols[] = {
{ "MASTER_SSL_VERIFY_SERVER_CERT", SYM(MASTER_SSL_VERIFY_SERVER_CERT_SYM)}, { "MASTER_SSL_VERIFY_SERVER_CERT", SYM(MASTER_SSL_VERIFY_SERVER_CERT_SYM)},
{ "MASTER_USER", SYM(MASTER_USER_SYM)}, { "MASTER_USER", SYM(MASTER_USER_SYM)},
{ "MASTER_USE_GTID", SYM(MASTER_USE_GTID_SYM)}, { "MASTER_USE_GTID", SYM(MASTER_USE_GTID_SYM)},
{ "MASTER_DEMOTE_TO_SLAVE", SYM(MASTER_DEMOTE_TO_SLAVE_SYM)},
{ "MASTER_HEARTBEAT_PERIOD", SYM(MASTER_HEARTBEAT_PERIOD_SYM)}, { "MASTER_HEARTBEAT_PERIOD", SYM(MASTER_HEARTBEAT_PERIOD_SYM)},
{ "MATCH", SYM(MATCH)}, { "MATCH", SYM(MATCH)},
{ "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)}, { "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)},

View File

@ -368,6 +368,14 @@ class Master_info : public Slave_reporting_capability
Cache the value so future RESET SLAVE commands don't revert to Slave_Pos. Cache the value so future RESET SLAVE commands don't revert to Slave_Pos.
*/ */
bool master_supports_gtid; bool master_supports_gtid;
/*
When TRUE, transition this server from being an active master to a slave.
This updates the replication state to account for any transactions which
were committed into the binary log. In particular, it merges
gtid_binlog_pos into gtid_slave_pos.
*/
bool is_demotion;
}; };
struct start_alter_thd_args struct start_alter_thd_args

View File

@ -498,6 +498,7 @@ struct LEX_MASTER_INFO
uint port, connect_retry; uint port, connect_retry;
float heartbeat_period; float heartbeat_period;
int sql_delay; int sql_delay;
bool is_demotion_opt;
/* /*
Enum is used for making it possible to detect if the user Enum is used for making it possible to detect if the user
changed variable or if it should be left at old value changed variable or if it should be left at old value
@ -540,6 +541,7 @@ struct LEX_MASTER_INFO
gtid_pos_str= null_clex_str; gtid_pos_str= null_clex_str;
use_gtid_opt= LEX_GTID_UNCHANGED; use_gtid_opt= LEX_GTID_UNCHANGED;
sql_delay= -1; sql_delay= -1;
is_demotion_opt= 0;
} }
}; };

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) if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_SLAVE_POS)
mi->using_gtid= Master_info::USE_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) else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_CURRENT_POS)
{
mi->using_gtid= Master_info::USE_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 || else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_NO ||
lex_mi->log_file_name || lex_mi->pos || lex_mi->log_file_name || lex_mi->pos ||
lex_mi->relay_log_name || lex_mi->relay_log_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); 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 Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
a slave before). a slave before).

View File

@ -936,6 +936,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%token <kwd> MASTER_USER_SYM %token <kwd> MASTER_USER_SYM
%token <kwd> MASTER_USE_GTID_SYM %token <kwd> MASTER_USE_GTID_SYM
%token <kwd> MASTER_HEARTBEAT_PERIOD_SYM %token <kwd> MASTER_HEARTBEAT_PERIOD_SYM
%token <kwd> MASTER_DEMOTE_TO_SLAVE_SYM
%token <kwd> MAX_CONNECTIONS_PER_HOUR %token <kwd> MAX_CONNECTIONS_PER_HOUR
%token <kwd> MAX_QUERIES_PER_HOUR %token <kwd> MAX_QUERIES_PER_HOUR
%token <kwd> MAX_ROWS %token <kwd> MAX_ROWS
@ -2292,6 +2293,10 @@ master_file_def:
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid")); my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_NO; Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_NO;
} }
| MASTER_DEMOTE_TO_SLAVE_SYM '=' bool
{
Lex->mi.is_demotion_opt= (bool) $3;
}
; ;
optional_connection_name: optional_connection_name: