Debian Codegraph @

mysql-test/suite/multi_source/gtid.test

raw
1 --source include/not_embedded.inc
2 --source include/have_innodb.inc
3
4 #
5 # Test GTID with multi-source
6 #
7
8 --connect (slave1,127.0.0.1,root,,,$SERVER_MYPORT_3)
9 --connect (slave2,127.0.0.1,root,,,$SERVER_MYPORT_4)
10 --connect (master1,127.0.0.1,root,,,$SERVER_MYPORT_1)
11 --connect (master2,127.0.0.1,root,,,$SERVER_MYPORT_2)
12
13 --connection slave1
14 --replace_result $SERVER_MYPORT_1 MYPORT_1
15 eval CHANGE MASTER 'slave1' TO master_port=$SERVER_MYPORT_1, master_host='127.0.0.1', master_user='root', master_ssl_verify_server_cert=0;
16 --replace_result $SERVER_MYPORT_2 MYPORT_2
17 eval CHANGE MASTER 'slave2' TO master_port=$SERVER_MYPORT_2, master_host='127.0.0.1', master_user='root', master_ssl_verify_server_cert=0;
18 set default_master_connection = 'slave1';
19 START SLAVE;
20 --source include/wait_for_slave_to_start.inc
21 set default_master_connection = 'slave2';
22 START SLAVE;
23 --source include/wait_for_slave_to_start.inc
24 set default_master_connection = '';
25
26 --connection slave2
27 --replace_result $SERVER_MYPORT_3 MYPORT_3
28 eval CHANGE MASTER TO master_port=$SERVER_MYPORT_3, master_host='127.0.0.1', master_ssl_verify_server_cert=0, master_user='root';
29 start all slaves;
30 --source include/wait_for_slave_to_start.inc
31
32 --connection master1
33 SET GLOBAL gtid_domain_id= 1;
34 SET SESSION gtid_domain_id= 1;
35 CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
36 CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10));
37 INSERT INTO t1 VALUES (1, "initial");
38 INSERT INTO t3 VALUES (101, "initial 1");
39
40 # Make sure we have CREATE TABLE t3 from master1 before replicating INSERT INTO
41 # t3 from master2.
42 --connection slave1
43 --let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.tables WHERE table_name = "t3" AND table_schema = "test"
44 --source include/wait_condition.inc
45
46 --connection master2
47 SET GLOBAL gtid_domain_id= 2;
48 SET SESSION gtid_domain_id= 2;
49 CREATE TABLE t2 (a INT PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
50 INSERT INTO t2 VALUES (1, "initial");
51 SET SQL_LOG_BIN=0;
52 CREATE TABLE t3 (a INT PRIMARY KEY, b VARCHAR(10));
53 SET SQL_LOG_BIN=1;
54 INSERT INTO t3 VALUES (201, "initial 2");
55
56 --connection slave2
57 --let $wait_condition= SELECT COUNT(*)=3 FROM information_schema.tables WHERE table_name IN ("t1", "t2", "t3") AND table_schema = "test"
58 --source include/wait_condition.inc
59 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=1 AND (SELECT COUNT(*) FROM t2)=1 AND (SELECT COUNT(*) FROM t3)=2
60 --source include/wait_condition.inc
61
62 --echo *** Now move slave2 to replicate from both master1 and master2 instead of just slave1 ***
63 STOP ALL SLAVES;
64
65 # Let us have a couple extra transactions on the masters to check that
66 # we resume replication at the right place even in the middle of the logs.
67 --connection master1
68 INSERT INTO t1 VALUES (2, "switch1");
69 INSERT INTO t3 VALUES (102, "switch1 a");
70 --connection master2
71 INSERT INTO t2 VALUES (2, "switch1");
72 INSERT INTO t3 VALUES (202, "switch1 b");
73
74 --connection slave2
75 --replace_result $SERVER_MYPORT_1 MYPORT_1
76 eval CHANGE MASTER 'slave1' TO master_port=$SERVER_MYPORT_1, master_host='127.0.0.1', master_ssl_verify_server_cert=0, master_user='root';
77 --replace_result $SERVER_MYPORT_2 MYPORT_2
78 eval CHANGE MASTER 'slave2' TO master_port=$SERVER_MYPORT_2, master_host='127.0.0.1', master_ssl_verify_server_cert=0, master_user='root';
79 SET default_master_connection = 'slave1';
80 START SLAVE;
81 --source include/wait_for_slave_to_start.inc
82 SET default_master_connection = 'slave2';
83 START SLAVE;
84 --source include/wait_for_slave_to_start.inc
85 set default_master_connection = '';
86 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=2 AND (SELECT COUNT(*) FROM t2)=2 AND (SELECT COUNT(*) FROM t3)=4
87 --source include/wait_condition.inc
88
89
90 --echo *** Move slave1 to replicate from slave2 instead of from master1 and master2 ***
91 --connection slave1
92 # Set up so that slave1 will have to start from two different positions
93 # in the slave2 binlog (one for each domain_id).
94 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=2 AND (SELECT COUNT(*) FROM t2)=2 AND (SELECT COUNT(*) FROM t3)=4
95 --source include/wait_condition.inc
96 STOP SLAVE 'slave1';
97
98 --connection master1
99 INSERT INTO t1 VALUES (3, "switch 2");
100 INSERT INTO t3 VALUES (103, "switch 2 a");
101
102 --connection slave2
103 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=3 AND (SELECT COUNT(*) FROM t2)=2 AND (SELECT COUNT(*) FROM t3)=5
104 --source include/wait_condition.inc
105
106 --connection master2
107 INSERT INTO t2 VALUES (3, "switch 2");
108 INSERT INTO t3 VALUES (203, "switch 2 b");
109 --source include/save_master_gtid.inc
110
111 --connection slave1
112 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=2 AND (SELECT COUNT(*) FROM t2)=3 AND (SELECT COUNT(*) FROM t3)=5
113 --source include/wait_condition.inc
114 STOP SLAVE 'slave2';
115
116 --connection master2
117 INSERT INTO t2 VALUES (4, "switch 3");
118 INSERT INTO t3 VALUES (204, "switch 3 b");
119
120 --connection slave2
121 # Make sure that slave2 has replicated far enough before connecting slave1 to
122 # it (otherwise we get an error that slave1 requested to start from a GTID
123 # which is not in slave2's binlogs).
124 --source include/sync_with_master_gtid.inc
125
126 --connection slave1
127 --replace_result $SERVER_MYPORT_4 MYPORT_4
128 eval CHANGE MASTER TO master_port=$SERVER_MYPORT_4, master_host='127.0.0.1', master_user='root', master_ssl_verify_server_cert=0;
129 START SLAVE;
130 --let $wait_condition= SELECT (SELECT COUNT(*) FROM t1)=3 AND (SELECT COUNT(*) FROM t2)=4 AND (SELECT COUNT(*) FROM t3)=7
131 --source include/wait_condition.inc
132 SELECT * FROM t1 ORDER BY a;
133 SELECT * FROM t2 ORDER BY a;
134 SELECT * FROM t3 ORDER BY a;
135
136 # Cleanup.
137 --connection master1
138 DROP TABLE t1;
139 SET SQL_LOG_BIN=0;
140 DROP TABLE t3;
141 SET SQL_LOG_BIN=1;
142
143 --connection master2
144 DROP TABLE t2;
145 DROP TABLE t3;
146
147 --connection slave1
148 SET GLOBAL gtid_domain_id=0;
149 --let $wait_condition= SELECT COUNT(*)=0 FROM information_schema.tables WHERE table_name IN ("t1", "t2", "t3") AND table_schema = "test"
150 --source include/wait_condition.inc
151 --sorted_result
152 STOP ALL SLAVES;
153 --source include/reset_master_slave.inc
154 --disconnect slave1
155
156 --connection slave2
157 SET GLOBAL gtid_domain_id=0;
158 --sorted_result
159 STOP ALL SLAVES;
160 --source include/reset_master_slave.inc
161 --disconnect slave2
162
163 --connection master1
164 SET GLOBAL gtid_domain_id=0;
165 --source include/reset_master_slave.inc
166 --disconnect master1
167
168 --connection master2
169 SET GLOBAL gtid_domain_id=0;
170 --source include/reset_master_slave.inc
171 --disconnect master2