Debian Codegraph @

mysql-test/suite/rpl/t/rpl_gtid_until.test

raw
1 --source include/have_innodb.inc
2 --let $rpl_topology=1->2
3 --source include/rpl_init.inc
4
5 --connection server_2
6 --source include/stop_slave.inc
7 CHANGE MASTER TO MASTER_USE_GTID=NO;
8 --source include/start_slave.inc
9
10 --connection server_1
11 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
12 # Function to extract one GTID from a list.
13 delimiter |;
14 CREATE FUNCTION extract_gtid(d VARCHAR(100), s VARCHAR(100))
15 RETURNS VARCHAR(100) DETERMINISTIC
16 BEGIN
17 SET s= CONCAT(",", s, ",");
18 SET s= SUBSTR(s FROM LOCATE(CONCAT(",", d, "-"), s) + 1);
19 SET s= SUBSTR(s FROM 1 FOR LOCATE(",", s) - 1);
20 RETURN s;
21 END|
22 delimiter ;|
23 --save_master_pos
24
25 --connection server_2
26 --sync_with_master
27 # Restart SQL thread to pick up ALTER TABLE of mysql.gtid_slave_pos.
28 --source include/stop_slave.inc
29 --source include/start_slave.inc
30
31 # Both replication threads must be stopped for UNTIL master_gtid_pos.
32 --error ER_SLAVE_WAS_RUNNING
33 START SLAVE UNTIL master_gtid_pos = "";
34 --source include/stop_slave_io.inc
35 --error ER_SLAVE_WAS_RUNNING
36 START SLAVE UNTIL master_gtid_pos = "";
37 START SLAVE IO_THREAD;
38 --source include/wait_for_slave_io_to_start.inc
39 --source include/stop_slave_sql.inc
40 --error ER_SLAVE_WAS_RUNNING
41 START SLAVE UNTIL master_gtid_pos = "";
42 --source include/stop_slave_io.inc
43 # UNTIL master_gtid_pos only valid if GTID is used.
44
45 --error ER_UNTIL_REQUIRES_USING_GTID
46 START SLAVE UNTIL master_gtid_pos = "";
47
48 CHANGE MASTER TO master_use_gtid=slave_pos;
49
50 --connection server_1
51 CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
52 INSERT INTO t1 VALUES(1);
53 --let $gtid_pos=`SELECT @@GLOBAL.gtid_binlog_pos`
54 INSERT INTO t1 VALUES(2);
55
56 --connection server_2
57
58 # Test various incorrect syntax for UNTIL master_gtid_pos.
59 --error ER_DUPLICATE_GTID_DOMAIN
60 START SLAVE UNTIL master_gtid_pos = "0-1-100,1-1-100,2-2-200,1-3-100,4-4-400";
61 --error ER_PARSE_ERROR
62 START SLAVE UNTIL master_log_file = "master-bin.000001", master_log_pos = 4, master_gtid_pos = "";
63 --error ER_BAD_SLAVE_UNTIL_COND
64 START SLAVE IO_THREAD UNTIL master_gtid_pos = "";
65 --error ER_BAD_SLAVE_UNTIL_COND
66 START SLAVE SQL_THREAD UNTIL master_gtid_pos = "";
67
68 eval START SLAVE UNTIL master_gtid_pos = '$gtid_pos';
69
70 --source include/wait_for_slave_to_stop.inc
71 SELECT * FROM t1;
72
73 --source include/start_slave.inc
74
75 --connection server_1
76 --save_master_pos
77
78 --connection server_2
79 --sync_with_master
80 SELECT * FROM t1 ORDER BY a;
81
82 # Test showing the UNTIL condition in SHOW SLAVE STATUS.
83 --source include/stop_slave.inc
84 START SLAVE UNTIL master_gtid_pos = "1-10-100,2-20-200,0-1-300";
85 --source include/wait_for_slave_to_start.inc
86 --let $status_items= Using_Gtid,Until_Condition
87 --source include/show_slave_status.inc
88
89 # Clear the UNTIL condition.
90 # Note that we need to wait for a transaction to get through from the master.
91 # Otherwise the IO thread may still be in get_master_version_and_clock()
92 # (wait_for_slave_to_start.inc returns as soon as the IO thread is connected),
93 # and we can get test failures from warnings in the log about IO thread being
94 # killed in the middle of setting @@gtid_strict_mode or similar (MDEV-7940).
95 --connection server_1
96 INSERT INTO t1 VALUES (3);
97 DELETE FROM t1 WHERE a=3;
98 --save_master_pos
99
100 --connection server_2
101 --sync_with_master
102 --source include/stop_slave.inc
103
104
105 --echo *** Test UNTIL condition in an earlier binlog than the start GTID. ***
106 --connection server_2
107
108 --connection server_1
109 SET gtid_domain_id = 1;
110 INSERT INTO t1 VALUES (3);
111 SET gtid_domain_id = 2;
112 CREATE TABLE t2 (a INT);
113 INSERT INTO t2 VALUES (3);
114 --let $d1_point1= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)`
115 --let $d2_point1= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)`
116 FLUSH LOGS;
117 SET gtid_domain_id = 1;
118 INSERT INTO t1 VALUES (4);
119 SET gtid_domain_id = 2;
120 INSERT INTO t2 VALUES (4);
121 FLUSH LOGS;
122 SET gtid_domain_id = 1;
123 INSERT INTO t1 VALUES (5);
124 --let $d1_point2= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)`
125 --let $d2_point2= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)`
126 SET gtid_domain_id = 2;
127 INSERT INTO t2 VALUES (5);
128 FLUSH LOGS;
129 SET gtid_domain_id = 1;
130 INSERT INTO t1 VALUES (6);
131 --let $d1_point3= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)`
132 --let $d2_point3= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)`
133 SET gtid_domain_id = 2;
134 INSERT INTO t2 VALUES (6);
135 SET gtid_domain_id = 0;
136 --source include/show_binary_logs.inc
137 --save_master_pos
138
139 --connection server_2
140 # Let the slave reach an middle point in domain 1 and a late point in domain 2.
141 eval START SLAVE UNTIL master_gtid_pos='$d1_point2,$d2_point3';
142 --source include/wait_for_slave_to_stop.inc
143 SELECT * FROM t1 ORDER BY a;
144 SELECT * FROM t2 ORDER BY a;
145 # Now test starting at a middle point in the binlogs when the stop position in
146 # one domain (domain 2) is early.
147 eval START SLAVE UNTIL master_gtid_pos='$d1_point3,$d2_point1';
148 --source include/wait_for_slave_to_stop.inc
149 SELECT * FROM t1 ORDER BY a;
150 SELECT * FROM t2 ORDER BY a;
151 # Test that one UNTIL domain empty means stop that domain immediately.
152 eval START SLAVE UNTIL master_gtid_pos='$d1_point2';
153 --source include/wait_for_slave_to_stop.inc
154 SELECT * FROM t1 ORDER BY a;
155 SELECT * FROM t2 ORDER BY a;
156
157 --source include/start_slave.inc
158 --sync_with_master
159 SELECT * FROM t1 ORDER BY a;
160 SELECT * FROM t2 ORDER BY a;
161
162 --echo *** Test when the UNTIL position is right at the end of the binlog file prior to the starting position ***
163
164 --connection server_2
165 --source include/stop_slave.inc
166
167 --connection server_1
168 FLUSH LOGS;
169 SET gtid_domain_id = 1;
170 INSERT INTO t1 VALUES (7);
171 SET gtid_domain_id = 0;
172 --save_master_pos
173
174 --connection server_2
175 eval START SLAVE UNTIL master_gtid_pos='$d1_point3';
176 --source include/wait_for_slave_to_stop.inc
177 # This should not show row 7, as we requested stop just before it.
178 SELECT * FROM t1 ORDER BY a;
179 --source include/start_slave.inc
180 --sync_with_master
181 SELECT * FROM t1 ORDER BY a;
182
183
184 --echo *** Test when UNTIL condition is after a stand-alone event (not a transaction). ***
185
186 --connection server_2
187 --source include/stop_slave.inc
188
189 --connection server_1
190 CREATE TABLE t3 (a INT);
191 --let $until_condition=`SELECT @@GLOBAL.gtid_binlog_pos`
192 DROP TABLE t3;
193 --save_master_pos
194
195 --connection server_2
196 --replace_result $until_condition UNTIL_CONDITION
197 eval START SLAVE UNTIL master_gtid_pos='$until_condition';
198 --source include/wait_for_slave_to_stop.inc
199 SHOW CREATE TABLE t3;
200 --source include/start_slave.inc
201 --sync_with_master
202
203 --echo *** Test UNTIL condition that has not yet been logged. ***
204
205 --connection server_2
206 --source include/stop_slave.inc
207 RESET SLAVE ALL;
208 RESET MASTER;
209 SET GLOBAL gtid_slave_pos='';
210
211 --connection server_1
212 # Do it once to compute the right GTID, then throw it away and do it again
213 # for the actual test.
214 RESET MASTER;
215 INSERT INTO t1 VALUES (10);
216 INSERT INTO t1 VALUES (11);
217 --let $until_condition=`SELECT @@GLOBAL.gtid_binlog_pos`
218 INSERT INTO t1 VALUES (12);
219 DELETE FROM t1 WHERE a >= 10;
220
221 RESET MASTER;
222 INSERT INTO t1 VALUES (10);
223
224 --connection server_2
225 --replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1
226 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_1,
227 master_user = "root", master_use_gtid = slave_pos;
228 eval START SLAVE UNTIL master_gtid_pos = '$until_condition';
229 --source include/wait_for_slave_to_start.inc
230
231 --connection server_1
232 INSERT INTO t1 VALUES (11);
233 INSERT INTO t1 VALUES (12);
234 --save_master_pos
235
236 --connection server_2
237 # This then should wait until it gets the row (11) and then stop, not
238 # yet having the row (12).
239 --source include/wait_for_slave_to_stop.inc
240 SELECT * FROM t1 ORDER BY a;
241 --source include/start_slave.inc
242 --sync_with_master
243 # And now the row (12) should be there.
244 SELECT * FROM t1 ORDER BY a;
245
246
247 # Clean up.
248 --connection server_1
249 DROP TABLE t1;
250 DROP TABLE t2;
251 DROP FUNCTION extract_gtid;
252
253 --source include/rpl_end.inc