Debian Codegraph @

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

raw
1 #
2 # This include file is used by more than one test suite
3 # (currently rpl and binlog_encryption).
4 # Please check all dependent tests after modifying it
5 #
6 # Usage:
7 # --let $binlog_limit= X[,Y] # optional
8 #
9 # Semantics of the value is the same as in include/show_binlog_events.inc
10 # which the script calls as a part of the test flow.
11 # The goal is to print the event demonstrating the triggered error,
12 # so normally Y should be 1 (print the exact event only);
13 # however, depending on test-specific server options, the offset X
14 # can be different.
15 #
16
17 # BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
18 # when generating new name.
19 #
20 # WHY
21 # ===
22 #
23 # We want to check whether error is reported or not when
24 # new_file_impl fails (this may happen when rotation is not
25 # possible because there is some problem finding an
26 # unique filename).
27 #
28 # HOW
29 # ===
30 #
31 # Test cases are documented inline.
32
33 -- source include/have_innodb.inc
34 -- source include/have_debug.inc
35 -- source include/master-slave.inc
36
37 -- echo #######################################################################
38 -- echo ####################### PART 1: MASTER TESTS ##########################
39 -- echo #######################################################################
40
41
42 ### ACTION: stopping slave as it is not needed for the first part of
43 ### the test
44
45 -- connection slave
46 -- source include/stop_slave.inc
47 -- connection master
48
49 call mtr.add_suppression("Can't generate a unique log-filename");
50 call mtr.add_suppression("Writing one row to the row-based binary log failed.*");
51 call mtr.add_suppression("Error writing file .*");
52 call mtr.add_suppression("Could not use master-bin for logging");
53
54 SET @old_debug= @@global.debug_dbug;
55
56 ### ACTION: create a large file (> 4096 bytes) that will be later used
57 ### in LOAD DATA INFILE to check binlog errors in its vacinity
58 -- let $load_file= $MYSQLTEST_VARDIR/tmp/bug_46166.data
59 -- let $MYSQLD_DATADIR= `select @@datadir`
60 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
61 -- eval SELECT repeat('x',8192) INTO OUTFILE '$load_file'
62
63 ### ACTION: create a small file (< 4096 bytes) that will be later used
64 ### in LOAD DATA INFILE to check for absence of binlog errors
65 ### when file loading this file does not force flushing and
66 ### rotating the binary log
67 -- let $load_file2= $MYSQLTEST_VARDIR/tmp/bug_46166-2.data
68 -- let $MYSQLD_DATADIR= `select @@datadir`
69 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
70 -- eval SELECT repeat('x',10) INTO OUTFILE '$load_file2'
71
72 RESET MASTER;
73
74 -- echo ###################### TEST #1
75
76 ### ASSERTION: no problem flushing logs (should show two binlogs)
77 FLUSH LOGS;
78 -- echo # assert: must show two binlogs
79 -- source include/show_binary_logs.inc
80
81 -- echo ###################### TEST #2
82
83 ### ASSERTION: check that FLUSH LOGS actually fails and reports
84 ### failure back to the user if find_uniq_filename fails
85 ### (should show just one binlog)
86
87 RESET MASTER;
88 SET @@global.debug_dbug="d,error_unique_log_filename";
89 -- error ER_NO_UNIQUE_LOGFILE
90 FLUSH LOGS;
91 -- echo # assert: must show one binlog
92 -- source include/show_binary_logs.inc
93
94 ### ACTION: clean up and move to next test
95 SET @@global.debug_dbug=@old_debug;
96 RESET MASTER;
97
98 -- echo ###################### TEST #3
99
100 ### ACTION: create some tables (t1, t2, t4) and insert some values in
101 ### table t1
102 CREATE TABLE t1 (a INT);
103 CREATE TABLE t2 (a VARCHAR(16384)) Engine=InnoDB CHARSET=latin1;
104 CREATE TABLE t4 (a VARCHAR(16384)) CHARSET=latin1;
105 INSERT INTO t1 VALUES (1);
106 RESET MASTER;
107
108 ### ASSERTION: we force rotation of the binary log because it exceeds
109 ### the max_binlog_size option (should show two binary
110 ### logs)
111
112 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
113 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t2
114
115 # shows two binary logs
116 -- echo # assert: must show two binlog
117 -- source include/show_binary_logs.inc
118
119 # clean up the table and the binlog to be used in next part of test
120 SET @@global.debug_dbug=@old_debug;
121 DELETE FROM t2;
122 RESET MASTER;
123
124 -- echo ###################### TEST #4
125
126 ### ASSERTION: load the big file into a transactional table and check
127 ### that it reports error. The table will contain the
128 ### changes performed despite the fact that it reported an
129 ### error.
130
131 SET @@global.debug_dbug="d,error_unique_log_filename";
132 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
133 -- error ER_NO_UNIQUE_LOGFILE
134 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t2
135
136 # show table
137 -- echo # assert: must show one entry
138 SELECT count(*) FROM t2;
139
140 # clean up the table and the binlog to be used in next part of test
141 SET @@global.debug_dbug=@old_debug;
142 DELETE FROM t2;
143 RESET MASTER;
144
145 -- echo ###################### TEST #5
146
147 ### ASSERTION: load the small file into a transactional table and
148 ### check that it succeeds
149
150 SET @@global.debug_dbug="d,error_unique_log_filename";
151 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
152 -- eval LOAD DATA INFILE '$load_file2' INTO TABLE t2
153
154 # show table
155 -- echo # assert: must show one entry
156 SELECT count(*) FROM t2;
157
158 # clean up the table and the binlog to be used in next part of test
159 SET @@global.debug_dbug=@old_debug;
160 DELETE FROM t2;
161 RESET MASTER;
162
163 -- echo ###################### TEST #6
164
165 ### ASSERTION: check that even if one is using a transactional table
166 ### and explicit transactions (no autocommit) if rotation
167 ### fails we get the error. Transaction is not rolledback
168 ### because rotation happens after the commit.
169
170 SET @@global.debug_dbug="d,error_unique_log_filename";
171 SET AUTOCOMMIT=0;
172 INSERT INTO t2 VALUES ('muse');
173 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
174 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t2
175 INSERT INTO t2 VALUES ('muse');
176 -- error ER_NO_UNIQUE_LOGFILE
177 COMMIT;
178
179 ### ACTION: Show the contents of the table after the test
180 -- echo # assert: must show three entries
181 SELECT count(*) FROM t2;
182
183 ### ACTION: clean up and move to the next test
184 SET AUTOCOMMIT= 1;
185 SET @@global.debug_dbug=@old_debug;
186 DELETE FROM t2;
187 RESET MASTER;
188
189 -- echo ###################### TEST #7
190
191 ### ASSERTION: check that on a non-transactional table, if rotation
192 ### fails then an error is reported and an incident event
193 ### is written to the current binary log.
194
195 SET @@global.debug_dbug="d,error_unique_log_filename";
196
197 # Disable logging Annotate_rows events to preserve events count.
198 let $binlog_annotate_row_events_saved= `SELECT @@binlog_annotate_row_events`;
199 SET @@binlog_annotate_row_events= 0;
200
201 SELECT count(*) FROM t4;
202 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
203 -- error ER_NO_UNIQUE_LOGFILE
204 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t4
205
206 -- echo # assert: must show 1 entry
207 SELECT count(*) FROM t4;
208
209 -- echo ### check that the incident event is written to the current log
210 SET @@global.debug_dbug=@old_debug;
211 if (!$binlog_limit)
212 {
213 -- let $binlog_limit= 4,1
214 }
215 -- source include/show_binlog_events.inc
216
217 # clean up and move to next test
218 DELETE FROM t4;
219
220 --disable_query_log
221 eval SET @@binlog_annotate_row_events= $binlog_annotate_row_events_saved;
222 --enable_query_log
223
224 RESET MASTER;
225
226 -- echo ###################### TEST #8
227
228 ### ASSERTION: check that statements end up in error but they succeed
229 ### on changing the data.
230
231 SET @@global.debug_dbug="d,error_unique_log_filename";
232 -- echo # must show 0 entries
233 SELECT count(*) FROM t4;
234 SELECT count(*) FROM t2;
235
236 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
237 -- error ER_NO_UNIQUE_LOGFILE
238 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t4
239 -- replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
240 -- error ER_NO_UNIQUE_LOGFILE
241 -- eval LOAD DATA INFILE '$load_file' INTO TABLE t2
242 -- error ER_NO_UNIQUE_LOGFILE
243 INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc');
244
245 -- echo # INFO: Count(*) Before Offending DELETEs
246 -- echo # assert: must show 1 entry
247 SELECT count(*) FROM t4;
248 -- echo # assert: must show 4 entries
249 SELECT count(*) FROM t2;
250
251 -- error ER_NO_UNIQUE_LOGFILE
252 DELETE FROM t4;
253 -- error ER_NO_UNIQUE_LOGFILE
254 DELETE FROM t2;
255
256 -- echo # INFO: Count(*) After Offending DELETEs
257 -- echo # assert: must show zero entries
258 SELECT count(*) FROM t4;
259 SELECT count(*) FROM t2;
260
261 # remove fault injection
262 SET @@global.debug_dbug=@old_debug;
263
264 -- echo ###################### TEST #9
265
266 ### ASSERTION: check that if we disable binlogging, then statements
267 ### succeed.
268 SET @@global.debug_dbug="d,error_unique_log_filename";
269 SET SQL_LOG_BIN=0;
270 INSERT INTO t2 VALUES ('aaa'), ('bbb'), ('ccc'), ('ddd');
271 INSERT INTO t4 VALUES ('eee'), ('fff'), ('ggg'), ('hhh');
272 -- echo # assert: must show four entries
273 SELECT count(*) FROM t2;
274 SELECT count(*) FROM t4;
275 DELETE FROM t2;
276 DELETE FROM t4;
277 -- echo # assert: must show zero entries
278 SELECT count(*) FROM t2;
279 SELECT count(*) FROM t4;
280 SET SQL_LOG_BIN=1;
281 SET @@global.debug_dbug=@old_debug;
282
283 -- echo ###################### TEST #10
284
285 ### ASSERTION: check that error is reported if there is a failure
286 ### while registering the index file and the binary log
287 ### file or failure to write the rotate event.
288
289 call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file.");
290 call mtr.add_suppression("Could not use .*");
291
292 RESET MASTER;
293 SHOW WARNINGS;
294
295 # +d,fault_injection_registering_index => injects fault on MYSQL_BIN_LOG::open
296 SET @@global.debug_dbug="d,fault_injection_registering_index";
297 -- replace_regex /\.[\\\/]master/master/
298 -- error ER_CANT_OPEN_FILE
299 FLUSH LOGS;
300 SET @@global.debug_dbug=@old_debug;
301
302 -- error ER_NO_BINARY_LOGGING
303 SHOW BINARY LOGS;
304
305 # issue some statements and check that they don't fail
306 CREATE TABLE t5 (a INT);
307 INSERT INTO t4 VALUES ('bbbbb');
308 INSERT INTO t2 VALUES ('aaaaa');
309 DELETE FROM t4;
310 DELETE FROM t2;
311 DROP TABLE t5;
312 flush tables;
313
314 -- echo ###################### TEST #11
315
316 ### ASSERTION: check that error is reported if there is a failure
317 ### while opening the index file and the binary log file or
318 ### failure to write the rotate event.
319
320 # restart the server so that we have binlog again
321 --let $rpl_server_number= 1
322 --source include/rpl_restart_server.inc
323
324 # +d,fault_injection_openning_index => injects fault on MYSQL_BIN_LOG::open_index_file
325 SET @@global.debug_dbug="d,fault_injection_openning_index";
326 -- replace_regex /\.[\\\/]master/master/
327 -- error ER_CANT_OPEN_FILE
328 FLUSH LOGS;
329 SET @@global.debug_dbug=@old_debug;
330
331 -- error ER_FLUSH_MASTER_BINLOG_CLOSED
332 RESET MASTER;
333
334 # issue some statements and check that they don't fail
335 CREATE TABLE t5 (a INT);
336 INSERT INTO t4 VALUES ('bbbbb');
337 INSERT INTO t2 VALUES ('aaaaa');
338 DELETE FROM t4;
339 DELETE FROM t2;
340 DROP TABLE t5;
341 flush tables;
342
343 # restart the server so that we have binlog again
344 --let $rpl_server_number= 1
345 --source include/rpl_restart_server.inc
346
347 -- echo ###################### TEST #12
348
349 ### ASSERTION: check that error is reported if there is a failure
350 ### while writing the rotate event when creating a new log
351 ### file.
352
353 # +d,fault_injection_new_file_rotate_event => injects fault on MYSQL_BIN_LOG::MYSQL_BIN_LOG::new_file_impl
354 SET @@global.debug_dbug="d,fault_injection_new_file_rotate_event";
355 -- error ER_ERROR_ON_WRITE
356 FLUSH LOGS;
357 SET @@global.debug_dbug=@old_debug;
358
359 -- error ER_FLUSH_MASTER_BINLOG_CLOSED
360 RESET MASTER;
361
362 # issue some statements and check that they don't fail
363 CREATE TABLE t5 (a INT);
364 INSERT INTO t4 VALUES ('bbbbb');
365 INSERT INTO t2 VALUES ('aaaaa');
366 DELETE FROM t4;
367 DELETE FROM t2;
368 DROP TABLE t5;
369 flush tables;
370
371 # restart the server so that we have binlog again
372 --let $rpl_server_number= 1
373 --source include/rpl_restart_server.inc
374
375 ## clean up
376 DROP TABLE t1, t2, t4;
377 RESET MASTER;
378
379 # restart slave again
380 -- connection slave
381 -- source include/start_slave.inc
382 -- connection master
383
384 -- echo #######################################################################
385 -- echo ####################### PART 2: SLAVE TESTS ###########################
386 -- echo #######################################################################
387
388 ### setup
389 --source include/rpl_reset.inc
390 -- connection slave
391
392 # Slave tests rely on logic of non-gtid mode
393 --source include/stop_slave.inc
394 CHANGE MASTER TO MASTER_USE_GTID=NO;
395 --source include/start_slave.inc
396
397 # slave suppressions
398
399 call mtr.add_suppression("Slave I/O: Relay log write failure: could not queue event from master.*");
400 call mtr.add_suppression("Error writing file .*");
401 call mtr.add_suppression("Could not use .*");
402 call mtr.add_suppression("MYSQL_BIN_LOG::open failed to sync the index file.");
403 call mtr.add_suppression("Can't generate a unique log-filename .*");
404 -- echo ###################### TEST #13
405
406 #### ASSERTION: check against unique log filename error
407 -- let $io_thd_injection_fault_flag= error_unique_log_filename
408 -- let $slave_io_errno= 1595
409 -- let $show_slave_io_error= 1
410 -- source include/io_thd_fault_injection.inc
411
412 -- echo ###################### TEST #14
413
414 #### ASSERTION: check against rotate failing
415 -- let $io_thd_injection_fault_flag= fault_injection_new_file_rotate_event
416 -- let $slave_io_errno= 1595
417 -- let $show_slave_io_error= 1
418 -- source include/io_thd_fault_injection.inc
419
420 -- echo ###################### TEST #15
421
422 #### ASSERTION: check against relay log open failure
423 -- let $io_thd_injection_fault_flag= fault_injection_registering_index
424 -- let $slave_io_errno= 1595
425 -- let $show_slave_io_error= 1
426 -- source include/io_thd_fault_injection.inc
427
428 -- echo ###################### TEST #16
429
430 #### ASSERTION: check against relay log index open failure
431 -- let $io_thd_injection_fault_flag= fault_injection_openning_index
432 -- let $slave_io_errno= 1595
433 -- let $show_slave_io_error= 1
434 -- source include/io_thd_fault_injection.inc
435
436 ### clean up
437 -- source include/stop_slave_sql.inc
438 RESET SLAVE;
439 RESET MASTER;
440 --remove_file $load_file
441 --remove_file $load_file2
442 --let $rpl_only_running_threads= 1
443 --source include/rpl_end.inc