diff --git a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result index 4e17669605f..99eda3b61a0 100644 --- a/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result +++ b/mysql-test/suite/binlog_encryption/rpl_gtid_basic.result @@ -69,6 +69,8 @@ INSERT INTO t2 VALUES (5, "i1a"); connection server_4; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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 SELECT * FROM t1 ORDER BY a; a b @@ -89,6 +91,8 @@ connection server_2; include/stop_slave.inc CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, 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 connection server_4; UPDATE t2 SET b="j1a" WHERE a=5; @@ -117,6 +121,8 @@ include/save_master_gtid.inc connection server_3; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, 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/sync_with_master_gtid.inc SELECT * FROM t2 ORDER BY a; diff --git a/mysql-test/suite/engines/funcs/r/rpl_change_master.result b/mysql-test/suite/engines/funcs/r/rpl_change_master.result index 48cec72d917..88801b07bba 100644 --- a/mysql-test/suite/engines/funcs/r/rpl_change_master.result +++ b/mysql-test/suite/engines/funcs/r/rpl_change_master.result @@ -26,4 +26,9 @@ connection master; CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='', MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH=''; 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 diff --git a/mysql-test/suite/multi_source/gtid.result b/mysql-test/suite/multi_source/gtid.result index 0ed1062b70f..dde53ca67b4 100644 --- a/mysql-test/suite/multi_source/gtid.result +++ b/mysql-test/suite/multi_source/gtid.result @@ -48,7 +48,11 @@ INSERT INTO t2 VALUES (2, "switch1"); INSERT INTO t3 VALUES (202, "switch1 b"); connection slave2; 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; +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'; START SLAVE; include/wait_for_slave_to_start.inc @@ -76,6 +80,8 @@ connection slave2; include/sync_with_master_gtid.inc connection slave1; 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; SELECT * FROM t1 ORDER BY a; a b diff --git a/mysql-test/suite/perfschema/r/digest_view.result b/mysql-test/suite/perfschema/r/digest_view.result index a5996cc0083..3fd7a090459 100644 --- a/mysql-test/suite/perfschema/r/digest_view.result +++ b/mysql-test/suite/perfschema/r/digest_view.result @@ -191,17 +191,17 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR FROM performance_schema.events_statements_summary_by_digest ORDER BY DIGEST_TEXT; SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR -test 27a9ab161a63050c84a63c6f77ebeb33 EXPLAIN SELECT * FROM `test` . `v1` 1 -test ab0ab27c04f3a294feb86bede4331f86 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1 -test 2e722346a5c2ef820946bcd04ccac208 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1 -test 07baf2264db30b6b25302603436ebe82 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1 -test 3a7dbc963635ab0de6e160e0a4212bce EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1 -test 6b845c2e3a7421997e3b610d14b5c842 SELECT * FROM `test` . `v1` 1 -test cb2ee099edbf6e0e5ee6ae14f3b1498a SELECT * FROM `test` . `v1` WHERE `a` = ? 1 -test e2dc5a300d2ba54ebb987a2ca6b90d93 SELECT * FROM `test` . `v1` WHERE `b` > ? 1 -test c68e0f99323f7bb7732c7b5cf32c0ec2 SELECT `a` , `b` FROM `test` . `v1` 1 -test 43c5de955c9a72d2bb6f49db5c0ad3e7 SELECT `b` , `a` FROM `test` . `v1` 1 -test 1678258ba15f7ccc63fd7b833763914a TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 +test 333a53e537d74bf74dd28c78ad5b23dd EXPLAIN SELECT * FROM `test` . `v1` 1 +test 1fb578da66e6583bae8e64061486f1b1 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 1 +test 923bca939a55826e231e1335016ba418 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 1 +test 6fa6d75432fd499d1c7d6f964c8310a2 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 1 +test 3421da1ec8ecb8cac97e12a0609f73cb EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 1 +test c2f68fd41bfbf3acd52eb5e7306b0c00 SELECT * FROM `test` . `v1` 1 +test dd68812cbe4c1ed5a38921222981f8c5 SELECT * FROM `test` . `v1` WHERE `a` = ? 1 +test 7563bcc32c6d0d872c8d9f0bf7717e6a SELECT * FROM `test` . `v1` WHERE `b` > ? 1 +test 0817c53833dc6adbca581e8fe4c598c7 SELECT `a` , `b` FROM `test` . `v1` 1 +test a5f13903c70812ae08fa8c084e9cd503 SELECT `b` , `a` FROM `test` . `v1` 1 +test 66b14a14f2a42e1335dd28dfad8ea084 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 DROP TABLE test.v1; CREATE VIEW test.v1 AS SELECT * FROM test.t1; 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 ORDER BY DIGEST_TEXT; SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR -test 342cd5e41944d5f857f92b1e374857de CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1 -test 2653f30030efcb6125121daa8eadf418 DROP TABLE `test` . `v1` 1 -test 27a9ab161a63050c84a63c6f77ebeb33 EXPLAIN SELECT * FROM `test` . `v1` 2 -test ab0ab27c04f3a294feb86bede4331f86 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2 -test 2e722346a5c2ef820946bcd04ccac208 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2 -test 07baf2264db30b6b25302603436ebe82 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2 -test 3a7dbc963635ab0de6e160e0a4212bce EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2 -test 6b845c2e3a7421997e3b610d14b5c842 SELECT * FROM `test` . `v1` 2 -test cb2ee099edbf6e0e5ee6ae14f3b1498a SELECT * FROM `test` . `v1` WHERE `a` = ? 2 -test e2dc5a300d2ba54ebb987a2ca6b90d93 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 c68e0f99323f7bb7732c7b5cf32c0ec2 SELECT `a` , `b` FROM `test` . `v1` 2 -test 43c5de955c9a72d2bb6f49db5c0ad3e7 SELECT `b` , `a` FROM `test` . `v1` 2 -test 1678258ba15f7ccc63fd7b833763914a TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 +test 98531b331031b84ddfbb2de8b601a704 CREATE VIEW `test` . `v1` AS SELECT * FROM `test` . `t1` 1 +test 5352d7d117e97fecd312e354e9e290ce DROP TABLE `test` . `v1` 1 +test 333a53e537d74bf74dd28c78ad5b23dd EXPLAIN SELECT * FROM `test` . `v1` 2 +test 1fb578da66e6583bae8e64061486f1b1 EXPLAIN SELECT * FROM `test` . `v1` WHERE `a` = ? 2 +test 923bca939a55826e231e1335016ba418 EXPLAIN SELECT * FROM `test` . `v1` WHERE `b` > ? 2 +test 6fa6d75432fd499d1c7d6f964c8310a2 EXPLAIN SELECT `a` , `b` FROM `test` . `v1` 2 +test 3421da1ec8ecb8cac97e12a0609f73cb EXPLAIN SELECT `b` , `a` FROM `test` . `v1` 2 +test c2f68fd41bfbf3acd52eb5e7306b0c00 SELECT * FROM `test` . `v1` 2 +test dd68812cbe4c1ed5a38921222981f8c5 SELECT * FROM `test` . `v1` WHERE `a` = ? 2 +test 7563bcc32c6d0d872c8d9f0bf7717e6a SELECT * FROM `test` . `v1` WHERE `b` > ? 2 +test 21c19dd7ef5b894f3e32d0585cb3007f SELECT SCHEMA_NAME , `DIGEST` , `DIGEST_TEXT` , `COUNT_STAR` FROM `performance_schema` . `events_statements_summary_by_digest` ORDER BY `DIGEST_TEXT` 1 +test 0817c53833dc6adbca581e8fe4c598c7 SELECT `a` , `b` FROM `test` . `v1` 2 +test a5f13903c70812ae08fa8c084e9cd503 SELECT `b` , `a` FROM `test` . `v1` 2 +test 66b14a14f2a42e1335dd28dfad8ea084 TRUNCATE TABLE `performance_schema` . `events_statements_summary_by_digest` 1 DROP VIEW test.v1; DROP TABLE test.t1; diff --git a/mysql-test/suite/perfschema/r/start_server_low_digest_sql_length.result b/mysql-test/suite/perfschema/r/start_server_low_digest_sql_length.result index 13b51569b60..ff554155f33 100644 --- a/mysql-test/suite/perfschema/r/start_server_low_digest_sql_length.result +++ b/mysql-test/suite/perfschema/r/start_server_low_digest_sql_length.result @@ -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; event_name digest digest_text sql_text -statement/sql/select 1fd0cdb6b5aa22bd0809a39b2dc2ac70 SELECT ? + ? + SELECT ... -statement/sql/truncate 0a9c405cebde6df4be315dae86ff398a TRUNCATE TABLE truncat... +statement/sql/select 96a6bb95edaf100857f09c968aca354b SELECT ? + ? + SELECT ... +statement/sql/truncate c1d647bb870f2c63c22a16707bb8aee3 TRUNCATE TABLE truncat... diff --git a/mysql-test/suite/rpl/include/rpl_change_master_demote.inc b/mysql-test/suite/rpl/include/rpl_change_master_demote.inc new file mode 100644 index 00000000000..4c563454a5b --- /dev/null +++ b/mysql-test/suite/rpl/include/rpl_change_master_demote.inc @@ -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 diff --git a/mysql-test/suite/rpl/r/rpl_binlog_dump_slave_gtid_state_info.result b/mysql-test/suite/rpl/r/rpl_binlog_dump_slave_gtid_state_info.result index 98688df7273..96b14bc1d9c 100644 --- a/mysql-test/suite/rpl/r/rpl_binlog_dump_slave_gtid_state_info.result +++ b/mysql-test/suite/rpl/r/rpl_binlog_dump_slave_gtid_state_info.result @@ -5,6 +5,8 @@ SET GLOBAL LOG_WARNINGS=2; connection slave; include/stop_slave.inc 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 connection master; "Test Case 1: Start binlog_dump to slave_server(#), pos(master-bin.000001, ###), using_gtid(1), gtid('')" diff --git a/mysql-test/suite/rpl/r/rpl_change_master.result b/mysql-test/suite/rpl/r/rpl_change_master.result index 48cec72d917..88801b07bba 100644 --- a/mysql-test/suite/rpl/r/rpl_change_master.result +++ b/mysql-test/suite/rpl/r/rpl_change_master.result @@ -26,4 +26,9 @@ connection master; CHANGE MASTER TO MASTER_USER='root', MASTER_SSL=0, MASTER_SSL_CA='', MASTER_SSL_CERT='', MASTER_SSL_KEY='', MASTER_SSL_CRL='', MASTER_SSL_CRLPATH=''; 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 diff --git a/mysql-test/suite/rpl/r/rpl_change_master_demote.result b/mysql-test/suite/rpl/r/rpl_change_master_demote.result new file mode 100644 index 00000000000..a5e801eeac4 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_change_master_demote.result @@ -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= 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 diff --git a/mysql-test/suite/rpl/r/rpl_gtid_basic.result b/mysql-test/suite/rpl/r/rpl_gtid_basic.result index 32df09789cc..fc7505e144f 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_basic.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_basic.result @@ -69,6 +69,8 @@ INSERT INTO t2 VALUES (5, "i1a"); connection server_4; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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 SELECT * FROM t1 ORDER BY a; a b @@ -89,6 +91,8 @@ connection server_2; include/stop_slave.inc CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, 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 connection server_4; UPDATE t2 SET b="j1a" WHERE a=5; @@ -117,6 +121,8 @@ include/save_master_gtid.inc connection server_3; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_4, 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/sync_with_master_gtid.inc SELECT * FROM t2 ORDER BY a; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_crash.result b/mysql-test/suite/rpl/r/rpl_gtid_crash.result index 153081d9ca5..fc8e69af861 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_crash.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_crash.result @@ -15,6 +15,8 @@ SET sql_log_bin=1; include/stop_slave.inc CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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; INSERT INTO t1 VALUES (2,1); INSERT INTO t1 VALUES (3,1); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result index 54156685806..32f39278dc2 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result @@ -74,6 +74,8 @@ INSERT INTO t1 VALUES (2); SET sql_log_bin = 1; INSERT INTO t1 VALUES (3); 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; SET GLOBAL gtid_slave_pos = "100-100-100"; ERROR 25000: You are not allowed to execute this command in a transaction diff --git a/mysql-test/suite/rpl/r/rpl_gtid_excess_initial_delay.result b/mysql-test/suite/rpl/r/rpl_gtid_excess_initial_delay.result index 641d186ab78..302bf182ac2 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_excess_initial_delay.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_excess_initial_delay.result @@ -4,6 +4,8 @@ CREATE TABLE t1 (i INT); connection slave; include/stop_slave.inc 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 connection master; INSERT INTO t1 VALUES (1); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_master_promote.result b/mysql-test/suite/rpl/r/rpl_gtid_master_promote.result index 1901e341103..19229a3c6c2 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_master_promote.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_master_promote.result @@ -13,15 +13,23 @@ END| connection server_2; include/stop_slave.inc 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; include/stop_slave.inc 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; include/stop_slave.inc 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; include/stop_slave.inc 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; SET gtid_domain_id= 1; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; @@ -340,6 +348,8 @@ a b connection server_1; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, 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 SELECT * FROM t1 ORDER BY a; a diff --git a/mysql-test/suite/rpl/r/rpl_gtid_mdev4473.result b/mysql-test/suite/rpl/r/rpl_gtid_mdev4473.result index 644add9280e..e61df488d62 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_mdev4473.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_mdev4473.result @@ -13,6 +13,8 @@ reset slave all; connection server_1; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, 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/wait_for_slave_to_start.inc connection server_2; @@ -23,6 +25,8 @@ flush logs; connection server_3; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, 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 select * from t1 order by n; n @@ -58,11 +62,15 @@ Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'Cur connection server_2; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_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 include/start_slave.inc connection server_3; include/stop_slave.inc CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_1, 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 connection server_1; drop table t1; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_mdev4820.result b/mysql-test/suite/rpl/r/rpl_gtid_mdev4820.result index 665fc536df6..cea5aaaeacd 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_mdev4820.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_mdev4820.result @@ -45,6 +45,8 @@ SET GLOBAL gtid_slave_pos= '0-2-10'; connection server_1; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_2, 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; connection server_2; INSERT INTO t1 VALUES (11); @@ -74,6 +76,8 @@ connection server_2; INSERT INTO t1 VALUES (22); CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_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; 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"); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_misc.result b/mysql-test/suite/rpl/r/rpl_gtid_misc.result index a5c61759ed6..ad77aa2350e 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_misc.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_misc.result @@ -10,6 +10,8 @@ SET sql_log_bin= 0; INSERT INTO t1 VALUES (1); SET sql_log_bin= 1; 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; CREATE TEMPORARY TABLE t2 LIKE t1; INSERT INTO t2 VALUE (1); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_nobinlog.result b/mysql-test/suite/rpl/r/rpl_gtid_nobinlog.result index 76694a2e72d..de5f30696fe 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_nobinlog.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_nobinlog.result @@ -22,6 +22,8 @@ include/stop_slave.inc connection server_1; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SLAVE_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 START SLAVE; include/wait_for_slave_to_start.inc connection server_2; @@ -54,6 +56,8 @@ include/save_master_gtid.inc connection server_2; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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; include/sync_with_master_gtid.inc SELECT * FROM t1 ORDER BY a; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result b/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result index 4f50d7c6d85..6282e116733 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result @@ -2,6 +2,8 @@ include/rpl_init.inc [topology=1->2] connection server_2; include/stop_slave.inc 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 connection server_1; CREATE TABLE t1 (a INT); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_sort.result b/mysql-test/suite/rpl/r/rpl_gtid_sort.result index 34c0fd32766..bb1fb28e0e9 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_sort.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_sort.result @@ -59,6 +59,8 @@ Variable_name Value gtid_binlog_state CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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 SHOW VARIABLES LIKE 'gtid_binlog_pos'; Variable_name Value diff --git a/mysql-test/suite/rpl/r/rpl_gtid_startpos.result b/mysql-test/suite/rpl/r/rpl_gtid_startpos.result index fcbabd17b11..846854f8668 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_startpos.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_startpos.result @@ -12,6 +12,8 @@ connection server_2; SET GLOBAL gtid_slave_pos=""; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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 SELECT * FROM t1; a @@ -34,6 +36,8 @@ connection server_2; SET GLOBAL gtid_slave_pos=""; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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; include/wait_for_slave_io_error.inc [errno=1236] include/stop_slave.inc @@ -56,6 +60,8 @@ connection server_2; SET GLOBAL gtid_slave_pos='0-1-3'; CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, 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/sync_with_master_gtid.inc SELECT * FROM t1 ORDER by a; @@ -98,6 +104,8 @@ RESET MASTER; connection server_2; 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; +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 connection server_1; CREATE TABLE t1 (a INT PRIMARY KEY); @@ -155,6 +163,8 @@ START SLAVE; include/wait_for_slave_sql_error.inc [errno=1050] STOP SLAVE IO_THREAD; 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 connection server_1; INSERT INTO t1 VALUES(3); diff --git a/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result b/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result index 00f3a48e805..2bdfcb14123 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result @@ -8,6 +8,8 @@ include/stop_slave.inc Master_Log_File = 'master-bin.000001' Using_Gtid = 'Slave_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; connection server_1; FLUSH LOGS; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_until.result b/mysql-test/suite/rpl/r/rpl_gtid_until.result index 353e64bd3e3..d33d4a66380 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_until.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_until.result @@ -30,6 +30,8 @@ include/stop_slave_io.inc START SLAVE UNTIL master_gtid_pos = ""; ERROR HY000: START SLAVE UNTIL master_gtid_pos requires that slave is using GTID 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; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES(1); @@ -218,6 +220,8 @@ INSERT INTO t1 VALUES (10); connection server_2; CHANGE MASTER TO master_host = '127.0.0.1', master_port = SERVER_MYPORT_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 UNTIL master_gtid_pos = '0-1-2'; include/wait_for_slave_to_start.inc connection server_1; diff --git a/mysql-test/suite/rpl/r/rpl_mdev6386.result b/mysql-test/suite/rpl/r/rpl_mdev6386.result index d0e5144857a..d62543d8488 100644 --- a/mysql-test/suite/rpl/r/rpl_mdev6386.result +++ b/mysql-test/suite/rpl/r/rpl_mdev6386.result @@ -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); SET sql_log_bin= 1; 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: SELECT * FROM t1 ORDER BY a; a b diff --git a/mysql-test/suite/rpl/r/rpl_parallel_mdev6589.result b/mysql-test/suite/rpl/r/rpl_parallel_mdev6589.result index 47cdb3496da..ed297d10f2a 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel_mdev6589.result +++ b/mysql-test/suite/rpl/r/rpl_parallel_mdev6589.result @@ -5,6 +5,8 @@ SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; include/stop_slave.inc SET GLOBAL slave_parallel_threads=10; 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 *** MDEV-6589: Incorrect relay log start position when restarting SQL thread after error in parallel replication *** connection server_1; diff --git a/mysql-test/suite/rpl/r/rpl_parallel_multilevel2.result b/mysql-test/suite/rpl/r/rpl_parallel_multilevel2.result index 674cd7a32b4..13508815877 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel_multilevel2.result +++ b/mysql-test/suite/rpl/r/rpl_parallel_multilevel2.result @@ -18,11 +18,15 @@ SET @old_updates= @@GLOBAL.binlog_direct_non_transactional_updates; SET GLOBAL binlog_direct_non_transactional_updates=OFF; SET SESSION binlog_direct_non_transactional_updates=OFF; 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; SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; include/stop_slave.inc SET GLOBAL slave_parallel_threads=10; 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; BEGIN; CREATE TEMPORARY TABLE t2 (a INT PRIMARY KEY) ENGINE=MEMORY; diff --git a/mysql-test/suite/rpl/r/rpl_parallel_temptable.result b/mysql-test/suite/rpl/r/rpl_parallel_temptable.result index 1a1c12f836d..9519bffaa27 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel_temptable.result +++ b/mysql-test/suite/rpl/r/rpl_parallel_temptable.result @@ -5,6 +5,8 @@ SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; include/stop_slave.inc SET GLOBAL slave_parallel_threads=5; 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 connection server_1; CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(100) CHARACTER SET utf8); diff --git a/mysql-test/suite/rpl/r/rpl_perfschema_connect_config.result b/mysql-test/suite/rpl/r/rpl_perfschema_connect_config.result index 4ace84ffac4..27cb29d3968 100644 --- a/mysql-test/suite/rpl/r/rpl_perfschema_connect_config.result +++ b/mysql-test/suite/rpl/r/rpl_perfschema_connect_config.result @@ -87,6 +87,8 @@ include/assert.inc [Value returned by SSS and PS table for Using_Gtid should be change master to master_user = 'root', 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.] # 3) Test for Auto_position= SLAVE_POS diff --git a/mysql-test/suite/rpl/r/rpl_start_alter_mysqlbinlog_1.result b/mysql-test/suite/rpl/r/rpl_start_alter_mysqlbinlog_1.result index 4faa25ebd08..93c3b3cc81f 100644 --- a/mysql-test/suite/rpl/r/rpl_start_alter_mysqlbinlog_1.result +++ b/mysql-test/suite/rpl/r/rpl_start_alter_mysqlbinlog_1.result @@ -5,6 +5,8 @@ set global binlog_alter_two_phase=true; connection slave; include/stop_slave.inc 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; # Legacy Master Slave connect master_node,127.0.0.1,root,,$db_name, $M_port; diff --git a/mysql-test/suite/rpl/r/rpl_start_alter_options.result b/mysql-test/suite/rpl/r/rpl_start_alter_options.result index 30854b12be1..4c6135aaf5e 100644 --- a/mysql-test/suite/rpl/r/rpl_start_alter_options.result +++ b/mysql-test/suite/rpl/r/rpl_start_alter_options.result @@ -3,6 +3,8 @@ include/master-slave.inc connection slave; stop slave; 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_mode=optimistic; set global gtid_strict_mode=1; @@ -94,6 +96,8 @@ include/start_slave.inc connection slave; stop slave; 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_mode=optimistic; set global gtid_strict_mode=1; @@ -185,6 +189,8 @@ include/start_slave.inc connection slave; stop slave; 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_mode=optimistic; set global gtid_strict_mode=1; @@ -315,6 +321,8 @@ include/start_slave.inc connection slave; stop slave; 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_mode=optimistic; set global gtid_strict_mode=1; @@ -406,6 +414,8 @@ include/start_slave.inc connection slave; stop slave; 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_mode=optimistic; set global gtid_strict_mode=1; diff --git a/mysql-test/suite/rpl/r/rpl_upgrade_master_info.result b/mysql-test/suite/rpl/r/rpl_upgrade_master_info.result index ffa041efd27..e58ea5eb0f2 100644 --- a/mysql-test/suite/rpl/r/rpl_upgrade_master_info.result +++ b/mysql-test/suite/rpl/r/rpl_upgrade_master_info.result @@ -4,6 +4,8 @@ include/master-slave.inc connection slave; include/stop_slave.inc 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_start_server.inc [server_number=2] connection master; diff --git a/mysql-test/suite/rpl/r/rpl_using_gtid_default.result b/mysql-test/suite/rpl/r/rpl_using_gtid_default.result index c0e9b3add00..e077bcd91a4 100644 --- a/mysql-test/suite/rpl/r/rpl_using_gtid_default.result +++ b/mysql-test/suite/rpl/r/rpl_using_gtid_default.result @@ -58,6 +58,8 @@ include/start_slave.inc # to its default of Slave_Pos after RESET SLAVE. include/stop_slave.inc 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/stop_slave.inc RESET SLAVE; diff --git a/mysql-test/suite/rpl/t/rpl_change_master.test b/mysql-test/suite/rpl/t/rpl_change_master.test index 9ab49a585e6..2758f9d6e27 100644 --- a/mysql-test/suite/rpl/t/rpl_change_master.test +++ b/mysql-test/suite/rpl/t/rpl_change_master.test @@ -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=''; 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 diff --git a/mysql-test/suite/rpl/t/rpl_change_master_demote.test b/mysql-test/suite/rpl/t/rpl_change_master_demote.test new file mode 100644 index 00000000000..b428ea2a0c9 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_change_master_demote.test @@ -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= 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= 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 diff --git a/sql/lex.h b/sql/lex.h index 4ce88ccc2ee..18519d1f8d1 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -385,6 +385,7 @@ SYMBOL symbols[] = { { "MASTER_SSL_VERIFY_SERVER_CERT", SYM(MASTER_SSL_VERIFY_SERVER_CERT_SYM)}, { "MASTER_USER", SYM(MASTER_USER_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)}, { "MATCH", SYM(MATCH)}, { "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)}, diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index fa3327873c4..e026ec60340 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -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. */ 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 diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 5647484e286..23015933303 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -498,6 +498,7 @@ struct LEX_MASTER_INFO uint port, connect_retry; float heartbeat_period; int sql_delay; + bool is_demotion_opt; /* Enum is used for making it possible to detect if the user 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; use_gtid_opt= LEX_GTID_UNCHANGED; sql_delay= -1; + is_demotion_opt= 0; } }; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index d4a455e9034..352d5ab8ae9 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3822,7 +3822,13 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_SLAVE_POS) mi->using_gtid= Master_info::USE_GTID_SLAVE_POS; else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_CURRENT_POS) + { mi->using_gtid= Master_info::USE_GTID_CURRENT_POS; + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT, + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX), + "master_use_gtid=current_pos", "master_demote_to_slave=1"); + } else if (lex_mi->use_gtid_opt == LEX_MASTER_INFO::LEX_GTID_NO || lex_mi->log_file_name || lex_mi->pos || lex_mi->relay_log_name || lex_mi->relay_log_pos) @@ -3913,6 +3919,40 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) strmake_buf(mi->master_log_name, mi->rli.group_master_log_name); } + /* + MASTER_DEMOTE_TO_SLAVE is set. Merge gtid_binlog_pos into gtid_slave_pos. + */ + if (lex_mi->is_demotion_opt) + { + String new_gtid_state; + + if (mi->using_gtid != Master_info::USE_GTID_SLAVE_POS) + { + my_error(ER_CM_OPTION_MISSING_REQUIREMENT, MYF(0), + "MASTER_DEMOTE_TO_SLAVE", "TRUE", "Using_Gtid=Slave_Pos"); + ret= TRUE; + goto err; + } + + if (!mysql_bin_log.is_open()) + { + my_error(ER_NO_BINARY_LOGGING, MYF(0)); + ret= TRUE; + goto err; + } + + if ((ret= rpl_append_gtid_state(&new_gtid_state, true))) + goto err; + + if (rpl_global_gtid_slave_state->load( + thd, new_gtid_state.ptr(), new_gtid_state.length(), true, true)) + { + my_error(ER_FAILED_GTID_STATE_INIT, MYF(0)); + ret= TRUE; + goto err; + } + } + /* Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never a slave before). diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 5416cec49b5..6f7bc8e4306 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -936,6 +936,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token MASTER_USER_SYM %token MASTER_USE_GTID_SYM %token MASTER_HEARTBEAT_PERIOD_SYM +%token MASTER_DEMOTE_TO_SLAVE_SYM %token MAX_CONNECTIONS_PER_HOUR %token MAX_QUERIES_PER_HOUR %token MAX_ROWS @@ -2292,6 +2293,10 @@ master_file_def: my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid")); 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: