Debian Codegraph @

mysql-test/suite/rpl/include/rpl_change_master_demote.inc

raw
1 #
2 # This file tests that a master can be demoted to a slave using
3 # CHANGE MASTER TO MASTER_DEMOTE_TO_SLAVE=1 and replication will work correctly
4 # afterwards.
5 #
6 # param $ignore_domain_ids : List of GTID domain ids to use for
7 # CHANGE MASTER TO IGNORE_DOMAIN_IDS
8 #
9
10 --let $include_filename= rpl_change_master_demote.inc
11 --source include/begin_include_file.inc
12
13 --echo ##############################################
14 --echo # Connection semantics change:
15 --echo # * True primary is now connection 'slave'
16 --echo # * True replica is now connection 'master'
17 --echo ##############################################
18
19 --connection master
20 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;
21
22 --let $extra_cm_args=
23 if (`SELECT strcmp("$ignore_domain_ids","") != 0`)
24 {
25 --let $extra_cm_args=, ignore_domain_ids=($ignore_domain_ids)
26 }
27
28 --echo # First ensure gtid_slave_pos after master_demote_to_slave matches
29 --echo # gtid_current_pos calculation
30 --let $current_pos= `SELECT @@gtid_current_pos`
31 --replace_result $SLAVE_MYPORT SLAVE_PORT
32 --eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_ssl_verify_server_cert=0, master_use_gtid=slave_pos, master_demote_to_slave=1 $extra_cm_args
33 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;
34 --let $slave_pos= `SELECT @@gtid_slave_pos`
35 --echo # Validating gtid_slave_pos == gtid_binlog_pos..
36 if ($slave_pos != $current_pos)
37 {
38 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;
39 die gtid_slave_pos calculation after master_demote_to_slave=1 differs from gtid_current_pos;
40 }
41 --echo # ..success
42
43 --source include/start_slave.inc
44
45 --connection slave
46 --source include/stop_slave.inc
47
48 --echo # Ensuring replication works correctly after role swap
49 --connection slave
50 set session gtid_domain_id= 0;
51 CREATE TABLE repl_t (a int);
52 INSERT INTO repl_t VALUES (1);
53 --source include/save_master_gtid.inc
54
55 --connection master
56 --source include/sync_with_master_gtid.inc
57 --echo # Validating that replication works..
58 --let $n_replicated_rows= query_get_value(SELECT COUNT(*) FROM repl_t, COUNT(*), 1)
59 if ($n_replicated_rows != 1)
60 {
61 die "Replication is broken";
62 }
63 --echo # ..success
64
65 --echo # Cleaning up replication check data
66 --connection slave
67 DROP TABLE repl_t;
68 --source include/save_master_gtid.inc
69
70 --connection master
71 --source include/sync_with_master_gtid.inc
72 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;
73
74 --echo ##############################################
75 --echo # Connection semantics change:
76 --echo # * True primary is back to connection 'master'
77 --echo # * True replica is back to connection 'slave'
78 --echo ##############################################
79
80 --connection master
81 --source include/stop_slave.inc
82
83 --connection slave
84 --replace_result $MASTER_MYPORT MASTER_PORT
85 --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
86 --source include/start_slave.inc
87
88 # Ensure master is ready to start sending new transactions. That is, because
89 # the master does not have log_slave_updates, the slave's transactions of
90 # repl_t are not binlogged, and its state is behind. If the master binlogs
91 # any new transactions before the slaves connection is matured,
92 # ER_GTID_POSITION_NOT_FOUND_IN_BINLOG2 can be reported to the slave
93 # FIXME: We shouldn't need to do this, rather, the master should use
94 # log-slave-updates and gtid-strict-mode
95 --connection master
96 --let $wait_condition= SELECT COUNT(*) > 0 FROM information_schema.processlist WHERE State like '%Master has sent all binlog to slave%'
97 --source include/wait_condition.inc
98
99 --let $include_filename= rpl_change_master_demote.inc
100 --source include/end_include_file.inc