Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # Verify that START SLAVE UNTIL replicates until the given binlog
4 # position but not longer. Verify that START SLAVE UNTIL with various
5 # incorrect arguments gives an error.
6 #
7 # ==== Method ====
8 #
9 # On master, create a table and insert some rows. On slave, START
10 # SLAVE UNTIL so that it reads one event at a time, and check the
11 # table and the slave status each time.
12 #
13 # Then, on slave, run START SLAVE UNTIL with incorrect arguments and
14 # verify that it gives an error.
15 #
16 # ==== Related bugs ====
17 #
18 # Bug in this test: BUG#37717: rpl.rpl_stm_until 'stmt' fails sporadically on pushbuild
19
20 --source include/have_binlog_format_mixed_or_statement.inc
21 --source include/master-slave.inc
22
23 # Test is dependent on binlog positions
24
25 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
26
27 # prepare version for substitutions
28 let $VERSION=`select version()`;
29
30 # Stop slave before it starts replication. Also sync with master
31 # to avoid nondeterministic behaviour.
32 --echo [on slave]
33 --source include/sync_slave_sql_with_master.inc
34 --source include/stop_slave.inc
35
36 --echo ==== Create some events on master ====
37
38 --echo [on master]
39 connection master;
40 create table t1(n int not null auto_increment primary key);
41 insert into t1 values (1),(2),(3),(4);
42 let $master_log_pos_1= query_get_value(SHOW MASTER STATUS, Position, 1);
43 let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1);
44 drop table t1;
45 create table t2(n int not null auto_increment primary key);
46 insert into t2 values (1),(2);
47 let $master_log_pos_2= query_get_value(SHOW MASTER STATUS, Position, 1);
48 insert into t2 values (3),(4);
49 drop table t2;
50
51 --echo ==== Replicate one event at a time on slave ====
52
53 # try to replicate all queries until drop of t1
54 --echo [on slave]
55 connection slave;
56 --replace_result $master_log_file MASTER_LOG_FILE $master_log_pos_1 MASTER_LOG_POS
57 eval start slave until SOURCE_LOG_FILE='$master_log_file', SOURCE_LOG_POS=$master_log_pos_1;
58 --source include/wait_for_slave_io_to_start.inc
59 --source include/wait_for_slave_sql_to_stop.inc
60 # here table should be still not deleted
61 select * from t1;
62 --let $slave_param= Exec_Master_Log_Pos
63 --let $slave_param_value= $master_log_pos_1
64 --source include/check_slave_param.inc
65
66 # this should fail right after start
67 --replace_result 291 MASTER_LOG_POS
68 start slave until SOURCE_LOG_FILE='master-no-such-bin.000001', SOURCE_LOG_POS=291;
69 --source include/wait_for_slave_io_to_start.inc
70 --source include/wait_for_slave_sql_to_stop.inc
71 # again this table should be still not deleted
72 select * from t1;
73 --let $slave_param= Exec_Master_Log_Pos
74 --let $slave_param_value= $master_log_pos_1
75 --source include/check_slave_param.inc
76
77 let $relay_log_file= slave-relay-bin.000003;
78 let $master_log_pos= $master_log_pos_2;
79 source include/get_relay_log_pos.inc;
80 # try replicate all up to and not including the second insert to t2;
81 --replace_result $relay_log_pos RELAY_LOG_POS
82 eval start slave until relay_log_file='$relay_log_file', relay_log_pos=$relay_log_pos;
83 --source include/wait_for_slave_io_to_start.inc
84 --source include/wait_for_slave_sql_to_stop.inc
85 select * from t2;
86 --let $slave_param= Exec_Master_Log_Pos
87 --let $slave_param_value= $master_log_pos
88 --source include/check_slave_param.inc
89
90 # clean up
91 start slave;
92 --echo [on master]
93 connection master;
94 --echo [on slave]
95 --source include/sync_slave_sql_with_master.inc
96 --source include/stop_slave.inc
97
98 --let $exec_log_pos_1= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1)
99 # this should stop immediately as we are already there
100 --replace_result $master_log_file MASTER_LOG_FILE $master_log_pos_2 MASTER_LOG_POS
101 eval start slave until SOURCE_LOG_FILE='$master_log_file', SOURCE_LOG_POS=$master_log_pos_2;
102 --source include/wait_for_slave_io_to_start.inc
103 --source include/wait_for_slave_sql_to_stop.inc
104 --let $slave_param= Exec_Master_Log_Pos
105 --let $slave_param_value= $exec_log_pos_1
106 --source include/check_slave_param.inc
107
108 --echo ==== Test various error conditions ====
109
110 --replace_result 561 MASTER_LOG_POS
111 --error 1277
112 start slave until SOURCE_LOG_FILE='master-bin', SOURCE_LOG_POS=561;
113 --replace_result 561 MASTER_LOG_POS 12 RELAY_LOG_POS
114 --error 1277
115 start slave until SOURCE_LOG_FILE='master-bin.000001', SOURCE_LOG_POS=561, relay_log_pos=12;
116 --error 1277
117 start slave until SOURCE_LOG_FILE='master-bin.000001';
118 --error 1277
119 start slave until relay_log_file='slave-relay-bin.000002';
120 --replace_result 561 MASTER_LOG_POS
121 --error 1277
122 start slave until relay_log_file='slave-relay-bin.000002', SOURCE_LOG_POS=561;
123 # Warning should be given for second command
124 start slave sql_thread;
125 --replace_result 776 MASTER_LOG_POS
126 start slave until SOURCE_LOG_FILE='master-bin.000001', SOURCE_LOG_POS=776;
127
128 #
129 # Note: The test for START SLAVE UNTIL SQL_AFTER_MTS_GAPS is located
130 # in rpl_parallel_start_stop.test
131 #
132
133 #
134 # bug#47210 first execution of "start slave until" stops too early
135 #
136 # testing that a slave rotate event that is caused by stopping the slave
137 # does not intervene anymore in UNTIL condition.
138 #
139
140 connection slave;
141 source include/stop_slave.inc;
142 --disable_warnings
143 drop table if exists t1;
144 --enable_warnings
145 reset slave;
146 RESET MASTER;
147 --replace_result $MASTER_MYPORT MASTER_PORT
148 eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root';
149
150 connection master;
151 --disable_warnings
152 drop table if exists t1;
153 --enable_warnings
154 reset master;
155 create table t1 (a int primary key auto_increment);
156 save_master_pos;
157 let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1);
158
159 connection slave;
160 start slave;
161 sync_with_master;
162
163 # at this point slave will close the relay log stamping it with its own
164 # Rotate log event. This event won't be examined on matter of the master
165 # UNTIL pos anymore.
166 source include/stop_slave.inc;
167 let $slave_exec_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1);
168
169 --echo master and slave are in sync now
170 let $diff_pos= `select $master_pos - $slave_exec_pos`;
171 eval select $diff_pos as zero;
172
173 connection master;
174 insert into t1 set a=null;
175 let $until_pos= query_get_value(SHOW MASTER STATUS, Position, 1);
176 insert into t1 set a=null;
177 select count(*) as two from t1;
178
179 connection slave;
180 --replace_result $master_log_file MASTER_LOG_FILE $until_pos UNTIL_POS;
181 eval start slave until SOURCE_LOG_FILE='$master_log_file', SOURCE_LOG_POS= $until_pos;
182 source include/wait_for_slave_sql_to_stop.inc;
183 let $slave_exec_pos= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1);
184 --echo slave stopped at the prescribed position
185 let $diff_pos= `select $until_pos - $slave_exec_pos`;
186 eval select $diff_pos as zero;
187 select count(*) as one from t1;
188
189
190 connection master;
191 drop table t1;
192
193 connection slave;
194 start slave;
195 sync_with_master;
196
197 #
198 # Bug #19010820 START SLAVE UNTIL WILL TIMEOUT IF WAITING FOR
199 # THE LAST TRANSACTION IN RELAYLOG
200 #
201 # This part of the test verifies correctness and effectiveness of the
202 # until-stopping when the position used is inside the last group/transaction
203 # in the relaylog.
204 #
205 # It will create a single event transaction (if GTIDs are disabled)
206 # or a two events transaction (if GTIDs are enabled), and will start
207 # the SQL thread using the UNTIL MASTER_LOG_FILE/POS and RELAY_LOG_FILE/POS,
208 # pointing to the first or last byte of the created transaction.
209 #
210 # The test expects that, after issuing the START SLAVE SQL_THREAD with the
211 # UNTIL clause, the SQL thread will apply the created transaction and will
212 # update its position before stopping. The test will verify the
213 # binlog/relaylog file, the position, and finally will wait for the SQL
214 # thread to stop.
215 #
216
217 --source include/rpl_connection_master.inc
218 --echo # Make sure the master will put the new events in a new binlog file
219 FLUSH LOGS;
220
221 # Check if SQL thread stops correctly
222 # after executing the last event of the master binlog
223 # based on master binlog file and position
224 --echo # Testing the execution until the last transaction of the master binlog
225
226 # Stop the SQL thread after syncing
227 --source include/sync_slave_sql_with_master.inc
228 --source include/stop_slave_sql.inc
229
230 # Create a table in the master (one event without GTIDS, two with GTIDS)
231 --source include/rpl_connection_master.inc
232 CREATE TABLE t1 (a INT) ENGINE=InnoDB;
233
234 # Save master position to use on UNTIL clause of START SLAVE
235 --let $master_file= query_get_value(SHOW MASTER STATUS, File, 1)
236 --let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
237 --dec $master_pos
238
239 # Sync the IO thread with the master
240 --source include/sync_slave_io_with_master.inc
241
242 --echo # Start SQL thread until it executed the CREATE TABLE
243 --replace_result $master_file MASTER_FILE $master_pos MASTER_POS
244 eval START SLAVE SQL_THREAD UNTIL SOURCE_LOG_FILE = "$master_file", SOURCE_LOG_POS = $master_pos;
245
246 --echo # Wait until SQL thread reaches last master binlog file
247 --let $slave_param= Relay_Master_Log_File
248 --let $slave_param_value= $master_file
249 --let $slave_param_comparison= =
250 --source include/wait_for_slave_param.inc
251
252 --echo # Wait until SQL thread reaches desired master binlog position
253 --let $slave_param= Exec_Master_Log_Pos
254 --let $slave_param_value= $master_pos
255 --let $slave_param_comparison= >=
256 --source include/wait_for_slave_param.inc
257
258 --echo # If the desired position was reached, SQL thread should stop.
259 --source include/wait_for_slave_sql_to_stop.inc
260
261 --let $assert_cond= "[SHOW TABLES LIKE "t1"]" = "t1"
262 --let $assert_text= t1 should be replicated
263 --source include/assert.inc
264 #
265 # Check if SQL thread stops correctly
266 # after executing the last event of the slave relaylog
267 # based on slave relaylog file and position
268 --echo # Testing the execution until the last transaction of the slave relaylog
269
270 # Save slave position to use on UNTIL clause of START SLAVE
271 --let $slave_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1)
272 --let $slave_pos= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1)
273 --inc $slave_pos
274
275 # Create a table in the master
276 # (one event if GTID_MODE=OFF; two events if GTID_MODE=ON)
277 --source include/rpl_connection_master.inc
278 CREATE TABLE t2 (a INT) ENGINE=InnoDB;
279
280 # Sync the IO thread with the master
281 --source include/sync_slave_io_with_master.inc
282
283 --echo # Start SQL thread until it executed the CREATE TABLE
284 --replace_result $slave_file SLAVE_FILE $slave_pos SLAVE_POS
285 eval START SLAVE SQL_THREAD UNTIL RELAY_LOG_FILE = "$slave_file", RELAY_LOG_POS = $slave_pos;
286
287 --echo # Wait until SQL thread reaches last slave relaylog file
288 --let $slave_param= Relay_Log_File
289 --let $slave_param_value= $slave_file
290 --let $slave_param_comparison= =
291 --source include/wait_for_slave_param.inc
292
293 --echo # Wait until SQL thread reaches desired slave relaylog position
294 --let $slave_param= Relay_Log_Pos
295 --let $slave_param_value= $slave_pos
296 --let $slave_param_comparison= >=
297 --source include/wait_for_slave_param.inc
298
299 --echo # If the desired position was reached, SQL thread should stop.
300 --source include/wait_for_slave_sql_to_stop.inc
301
302 --let $assert_cond= "[SHOW TABLES LIKE "t2"]" = "t2"
303 --let $assert_text= t2 should be replicated
304 --source include/assert.inc
305
306 # Cleanup
307 --source include/start_slave_sql.inc
308 --source include/rpl_connection_master.inc
309 DROP TABLE t1, t2;
310
311 # End of tests
312 --source include/rpl_end.inc