Debian Codegraph @

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

raw
1 --source include/have_innodb.inc
2 --let $rpl_topology=1->2
3 --source include/rpl_init.inc
4
5 --echo *** Test connecting with empty GTID state to start from very beginning of binlog ***
6 --connection server_2
7 --source include/stop_slave.inc
8 RESET MASTER;
9 RESET SLAVE;
10
11 --connection server_1
12 RESET MASTER;
13 # Create an empty binlog file, to check that empty binlog state is handled correctly.
14 FLUSH LOGS;
15 CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
16 --save_master_pos
17
18 --connection server_2
19 SET GLOBAL gtid_slave_pos="";
20 --replace_result $MASTER_MYPORT MASTER_PORT
21 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT,
22 MASTER_USE_GTID=SLAVE_POS;
23 --source include/start_slave.inc
24 --sync_with_master
25 SELECT * FROM t1;
26
27 --connection server_1
28 INSERT INTO t1 VALUES (1);
29 --save_master_pos
30
31 --connection server_2
32 --sync_with_master
33 SELECT * FROM t1;
34 --source include/stop_slave.inc
35
36 --echo *** Test that master gives error when slave asks for empty gtid pos and binlog files have been purged. ***
37 --connection server_1
38 FLUSH LOGS;
39 INSERT INTO t1 VALUES (2);
40 --save_master_pos
41 --let $purge_binlogs_to=master-bin.000003
42 --source include/wait_for_purge.inc
43 --source include/show_binary_logs.inc
44
45 --connection server_2
46 SET GLOBAL gtid_slave_pos="";
47 --replace_result $MASTER_MYPORT MASTER_PORT
48 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT,
49 MASTER_USE_GTID=SLAVE_POS;
50 START SLAVE;
51 --let $slave_io_errno= 1236
52 --source include/wait_for_slave_io_error.inc
53 --source include/stop_slave_sql.inc
54
55 --replace_result $MASTER_MYPORT MASTER_PORT
56 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT,
57 MASTER_LOG_FILE="master-bin.000003", MASTER_LOG_POS=4, MASTER_USE_GTID=NO;
58 --source include/start_slave.inc
59 --sync_with_master
60 SELECT * FROM t1 ORDER BY a;
61 SET sql_log_bin=0;
62 call mtr.add_suppression('Could not find GTID state requested by slave in any binlog files');
63 SET sql_log_bin=1;
64
65 --echo *** Test that we give warning when explict @@gtid_slave_pos=xxx that conflicts with what is in our binary log ***
66 --source include/stop_slave.inc
67
68 --connection server_1
69 INSERT INTO t1 VALUES(3);
70 --source include/save_master_gtid.inc
71
72 --connection server_2
73 SET GLOBAL gtid_slave_pos='0-1-3';
74 --replace_result $MASTER_MYPORT MASTER_PORT
75 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT,
76 MASTER_USE_GTID=SLAVE_POS;
77 --source include/start_slave.inc
78 --source include/sync_with_master_gtid.inc
79 SELECT * FROM t1 ORDER by a;
80 --source include/stop_slave.inc
81
82 --connection server_1
83 INSERT INTO t1 VALUES (4);
84 --source include/save_master_gtid.inc
85
86 --connection server_2
87 # Now add some local transactions that conflict with the GTID position
88 # being set for @@gtid_slave_pos.
89 INSERT INTO t1 VALUES (10);
90 DELETE FROM t1 WHERE a=10;
91 SET GLOBAL gtid_slave_pos='0-1-4';
92
93 # Try again after RESET MASTER to remove the conflicting binlog.
94 RESET MASTER;
95 SET GLOBAL gtid_slave_pos='0-1-4';
96 START SLAVE;
97 --source include/sync_with_master_gtid.inc
98 SELECT * FROM t1 ORDER by a;
99
100 --connection server_1
101 DROP TABLE t1;
102 --save_master_pos
103
104 --connection server_2
105 --sync_with_master
106
107
108 --echo *** MDEV-4275: I/O thread restart duplicates events in relay log ***
109
110 --connection server_2
111 --source include/stop_slave.inc
112 RESET SLAVE ALL;
113 RESET MASTER;
114
115 --connection server_1
116 RESET MASTER;
117
118 --connection server_2
119 SET GLOBAL gtid_slave_pos='';
120 --replace_result $MASTER_MYPORT MASTER_PORT
121 eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$MASTER_MYPORT, master_user='root', master_use_gtid=slave_pos;
122 --source include/start_slave.inc
123
124 --connection server_1
125 CREATE TABLE t1 (a INT PRIMARY KEY);
126 INSERT INTO t1 VALUES (1);
127 --save_master_pos
128
129 --connection server_2
130 --sync_with_master
131 SELECT * FROM t1;
132
133 --source include/stop_slave_io.inc
134 START SLAVE IO_THREAD;
135 --source include/wait_for_slave_io_to_start.inc
136
137 --connection server_1
138 INSERT INTO t1 VALUES (2);
139 --save_master_pos
140
141 --connection server_2
142 --sync_with_master
143
144 SELECT * FROM t1 ORDER BY a;
145
146
147 --echo *** MDEV-4329: GTID_SLAVE_POS='' is not checked for conflicts with binlog ***
148
149 # Test starting the slave completely from scratch, deleting all tables and
150 # replicating from the start of the master's binlog. This requires RESET
151 # MASTER is run on the slave to avoid old junk in the binlog. The bug was
152 # that the code did not catch the error of missing RESET MASTER when an
153 # empty GTID_SLAVE_POS='' was specified.
154
155 --connection server_2
156 --source include/stop_slave.inc
157 DROP TABLE t1;
158 RESET SLAVE;
159 SET GLOBAL gtid_slave_pos="";
160 RESET MASTER;
161 SET GLOBAL gtid_slave_pos="";
162
163 --source include/start_slave.inc
164 --sync_with_master
165 SELECT * FROM t1 ORDER BY a;
166
167
168 # Same thing, but this time using SQL_LOG_BIN=0 to avoid polluting the
169 # slave binlog.
170
171 --connection server_2
172 --source include/stop_slave.inc
173 SET SQL_LOG_BIN=0;
174 DROP TABLE t1;
175 SET SQL_LOG_BIN=1;
176 RESET SLAVE;
177 SET GLOBAL gtid_slave_pos="";
178 # Ensure that the slave fails because of missing table to be dropped
179 SET @save_slave_ddl_exec_mode=@@global.slave_ddl_exec_mode;
180 SET GLOBAL slave_ddl_exec_mode=STRICT;
181
182 --source include/start_slave.inc
183 --sync_with_master
184 SELECT * FROM t1 ORDER BY a;
185
186 --echo *** Test that RESET SLAVE clears the Using_Gtid flag. ***
187 --source include/stop_slave.inc
188 --let $master_use_gtid_option= No
189 --source include/reset_slave.inc
190 --let $status_items= Using_Gtid
191 --source include/show_slave_status.inc
192
193 # Starting the slave now reverts to old-style position which defaults to
194 # the first non-purged binlog file on the master.
195 # This should give error due to table already existing.
196 START SLAVE;
197 --let $slave_sql_errno= 1050
198 --source include/wait_for_slave_sql_error.inc
199
200 # Going back to using GTID should fix things.
201 STOP SLAVE IO_THREAD;
202 CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
203 --source include/start_slave.inc
204
205 --connection server_1
206 INSERT INTO t1 VALUES(3);
207 --source include/save_master_gtid.inc
208
209 --connection server_2
210 --source include/sync_with_master_gtid.inc
211 SELECT * FROM t1 ORDER BY a;
212 SET SQL_LOG_BIN=0;
213 call mtr.add_suppression("Slave: Table 't1' already exists error.* 1050");
214 SET SQL_LOG_BIN=1;
215
216
217 --echo *** Test reconnecting slave with GTID after purge logs on master. ***
218
219 --connection server_1
220 FLUSH LOGS;
221 INSERT INTO t1 VALUES (4);
222 --source include/save_master_gtid.inc
223
224 --connection server_2
225 --source include/sync_with_master_gtid.inc
226 --source include/stop_slave.inc
227
228 --connection server_1
229 FLUSH LOGS;
230 FLUSH LOGS;
231 --let $purge_binlogs_to=master-bin.000004
232 --source include/wait_for_purge.inc
233 --source include/show_binary_logs.inc
234 INSERT INTO t1 VALUES (5);
235 --source include/save_master_gtid.inc
236
237 --connection server_2
238 --replace_result $MASTER_MYPORT MASTER_PORT
239 eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT;
240 --source include/start_slave.inc
241 --source include/sync_with_master_gtid.inc
242 SELECT * FROM t1 ORDER BY a;
243
244
245 --echo *** Test modifying binlog on slave and the effect on GTID state. ***
246
247 --connection server_2
248 --source include/stop_slave.inc
249 RESET MASTER;
250 SET GLOBAL gtid_slave_pos="";
251
252 --connection server_1
253 RESET MASTER;
254 TRUNCATE TABLE t1;
255 INSERT INTO t1 VALUES (10); # Will be GTID 0-1-2
256 --source include/save_master_gtid.inc
257
258 --connection server_2
259 --source include/start_slave.inc
260 --source include/sync_with_master_gtid.inc
261
262 SELECT * FROM t1;
263 --let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1)
264 eval SELECT '$value' AS Using_Gtid;
265 --let $value= query_get_value(SHOW ALL SLAVES STATUS, "Gtid_Slave_Pos", 1)
266 eval SELECT '$value' AS Gtid_Slave_Pos;
267
268 UPDATE t1 SET a=9 WHERE a=10;
269 UPDATE t1 SET a=10 WHERE a=9;
270
271 --let $value= query_get_value(SHOW ALL SLAVES STATUS, "Gtid_Slave_Pos", 1)
272 eval SELECT '$value' AS Gtid_Slave_Pos;
273
274 --source include/stop_slave.inc
275 SET GLOBAL gtid_slave_pos='0-1-2';
276 RESET MASTER;
277 --let $value= query_get_value(SHOW ALL SLAVES STATUS, "Gtid_Slave_Pos", 1)
278 eval SELECT '$value' AS Gtid_Slave_Pos;
279 SET GLOBAL gtid_slave_pos='0-1-2';
280 --source include/start_slave.inc
281 --let $value= query_get_value(SHOW ALL SLAVES STATUS, "Gtid_Slave_Pos", 1)
282 eval SELECT '$value' AS Gtid_Slave_Pos;
283
284
285 --echo *** MDEV-4483: Slave loses traditional master coordinates immediately on CHANGE MASTER TO MASTER_USE_GTID = 1 ***
286 --connection server_2
287 --source include/stop_slave.inc
288 DROP TABLE t1;
289 RESET SLAVE ALL;
290 CHANGE MASTER TO MASTER_USE_GTID=NO;
291 RESET MASTER;
292 SET GLOBAL gtid_slave_pos= "";
293
294 # Set up old-style replication. The bug was that CHANGE MASTER would clear
295 # out the old-style binlog/relaylog coordinates when it should not.
296
297 --replace_result $MASTER_MYPORT MASTER_PORT
298 eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$MASTER_MYPORT, master_user='root', master_use_gtid=no, master_log_file="", master_log_pos= 4;
299
300 --connection server_1
301 DROP TABLE t1;
302 RESET MASTER;
303
304 CREATE TABLE t1 (a INT PRIMARY KEY);
305 --save_master_pos
306
307 --connection server_2
308 --source include/start_slave.inc
309 --sync_with_master
310
311 --source include/stop_slave.inc
312
313 --connection server_1
314 INSERT INTO t1 VALUES (1);
315 --let $log_file1= query_get_value(SHOW MASTER STATUS, "File", 1)
316 --let $log_pos1= query_get_value(SHOW MASTER STATUS, "Position", 1)
317 INSERT INTO t1 VALUES (2);
318 --let $log_file2= query_get_value(SHOW MASTER STATUS, "File", 1)
319 --let $log_pos2= query_get_value(SHOW MASTER STATUS, "Position", 1)
320 --save_master_pos
321
322 --connection server_2
323 # Get the slave to a point where the IO thread has fetched one event ahead
324 # of the SQL thread (we want to test that CHANGE MASTER does not mess with
325 # existing relay logs).
326 --replace_result $log_file1 LOG_FILE1 $log_pos1 LOG_POS1
327 eval START SLAVE UNTIL master_log_file='$log_file1', master_log_pos=$log_pos1;
328 --source include/wait_for_slave_sql_to_stop.inc
329 SELECT * FROM t1;
330 --let $slave_param= Read_Master_Log_Pos
331 --let $slave_param_value= $log_pos2
332 --source include/wait_for_slave_param.inc
333 --source include/stop_slave_io.inc
334
335 # Test that we can change to GTID and back without loosing our
336 # old-style slave position.
337 CHANGE MASTER TO master_use_gtid=slave_pos;
338 # Unknown GTID, so slave will fail to connect.
339 SET GLOBAL gtid_slave_pos="0-42-42";
340 SET sql_log_bin=0;
341 call mtr.add_suppression("Error: connecting slave requested to start from GTID");
342 SET sql_log_bin=1;
343 START SLAVE;
344 --let $slave_io_errno= 1236
345 --source include/wait_for_slave_io_error.inc
346 STOP SLAVE SQL_THREAD;
347 --source include/wait_for_slave_sql_to_stop.inc
348 CHANGE MASTER TO master_use_gtid=no;
349
350 --source include/start_slave.inc
351 --sync_with_master
352 SELECT * FROM t1 ORDER BY a;
353
354 # Clean up.
355 --connection server_1
356 DROP TABLE t1;
357 --connection server_2
358 set @@global.slave_ddl_exec_mode=@save_slave_ddl_exec_mode;
359
360 --source include/rpl_end.inc