Debian Codegraph @

mysql-test/suite/rpl/t/rpl_mdev-11092.test

raw
1 --source include/have_debug.inc
2 --source include/have_innodb.inc
3 --source include/not_embedded.inc
4 --source include/not_windows.inc
5 --source include/have_binlog_format_row.inc
6 --source include/master-slave.inc
7
8 ########################################################################################
9 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
10 call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occurred on the master. .*");
11 call mtr.add_suppression("Write to binary log failed: Multi-row statements required more than .max_binlog_stmt_cache_size.* ");
12 call mtr.add_suppression("Write to binary log failed: Multi-statement transaction required more than .max_binlog_cache_size.* ");
13 call mtr.add_suppression("Incident event write to the binary log file failed");
14 call mtr.add_suppression("handlerton rollback failed");
15
16 let $old_max_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_cache_size", Value, 1);
17 let $old_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_cache_size", Value, 1);
18 let $old_max_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_stmt_cache_size", Value, 1);
19 let $old_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_stmt_cache_size", Value, 1);
20
21 --source include/test_db_charset_latin1.inc
22
23 --echo "*********** Annotate Event write failure **************"
24
25 SET GLOBAL max_binlog_cache_size = 4096;
26 SET GLOBAL binlog_cache_size = 4096;
27 SET GLOBAL max_binlog_stmt_cache_size = 4096;
28 SET GLOBAL binlog_stmt_cache_size = 4096;
29 disconnect master;
30 connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
31
32 CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM;
33
34 let $data = `select concat('"', repeat('a',2000), '"')`;
35
36 connection master;
37
38 # Insert a huge row into MyISAM table. The row will be inserted in engine and a
39 # request to write to binary log will be initiated. Since row annotations are
40 # enabled the size of the annotate event itself will exceed the
41 # "max_binlog_stmt_cache_size". This will result in ER_STMT_CACHE_FULL error
42 # and an incident event will be written to the binary log as row update in
43 # engine cannot be undone.
44
45 --echo "#######################################################################"
46 --echo "# Test Case1: Annotate event write failure for MyISAM #"
47 --echo "#######################################################################"
48
49 --disable_query_log
50 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
51 --error ER_STMT_CACHE_FULL
52 eval INSERT INTO t1 (a, data) VALUES (2,
53 CONCAT($data, $data, $data, $data, $data, $data));
54 --enable_query_log
55
56 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
57 --echo # Validating update was not binlogged..
58 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
59 {
60 --die Binlog GTID position should have been unchanged after failed update
61 }
62 --echo # ..success
63
64 --echo # Validating that the inserted data was saved on the master..
65 if(`SELECT COUNT(*)!=1 FROM t1`)
66 {
67 --die The insertion should have saved on a non-transactional table
68 }
69 --echo # ..success
70
71 --connection slave
72 # Incident event
73 # 1590=ER_SLAVE_INCIDENT
74 --let $slave_sql_errno= 1590
75 --source include/wait_for_slave_sql_error_and_skip.inc
76
77 --echo # Validating that the insert was not replicated to the slave..
78 if(`SELECT COUNT(*) FROM t1`)
79 {
80 --die The insertion should not have replicated to the slave
81 }
82 --echo # ..success
83
84 # MDEV-21087
85 # Insert two huge rows in to transaction cache. Have data such that first row
86 # fits inside the binary log cache. While writing the annotate event for the
87 # second row the binary log cache size will exceed "max_binlog_cache_size".
88 # Hence this statement cannot be written to binary log. As DMLs in Innodb can
89 # be safely rolled back only an error will be reported. Slave will continue to
90 # work.
91
92 --echo "#######################################################################"
93 --echo "# Test Case2: Annotate event write failure for INNODB #"
94 --echo "#######################################################################"
95
96 --connection master
97 CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=INNODB;
98 --disable_query_log
99 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
100 BEGIN;
101 eval INSERT INTO t2 (a, data) VALUES (1, CONCAT($data, $data));
102 --error ER_TRANS_CACHE_FULL
103 eval INSERT INTO t2 (a, data) VALUES (2, CONCAT($data, $data));
104 COMMIT;
105 --enable_query_log
106
107 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
108 --echo # Validating binlog GTID position progressed from first insert..
109 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
110 {
111 --die Binlog GTID position should have updated
112 }
113 --echo # ..success
114
115 --echo # Validating that only the first insert into t2 saved..
116 if(`SELECT COUNT(*)!=1 FROM t2`)
117 {
118 --die Only one row should exist in t2 from the first insert, the second should have rolled back
119 }
120 --echo # ..success
121 --source include/save_master_gtid.inc
122
123 --connection slave
124 --source include/sync_with_master_gtid.inc
125 --echo # Validating the first insert into t2 replicated to slave..
126 --let $diff_tables= master:test.t2,slave:test.t2
127 --source include/diff_tables.inc
128 --echo # ..success
129
130 # Testing mixed engine UPDATE statement scenario. In the following multi
131 # update query 'ha_update_row' will be invoked for t1 (myisam) table. This
132 # intern invokes binlog_write_table_map() function call. While writing a huge
133 # annotate event binary log cache size will exceed max_binlog_cache_size.
134 # Writing to binary log fails. Since non transactional changes cannot be
135 # rolled back incident event will be written to binary log.
136
137 --echo "#######################################################################"
138 --echo "# Test Case3: Annotate event write failure for mixed engine UPDATE #"
139 --echo "#######################################################################"
140
141 --connection master
142 let $new_data = `select concat('"', repeat('b',2000), '"')`;
143 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
144 --disable_query_log
145 --error ER_STMT_CACHE_FULL
146 eval UPDATE t1,t2 SET t1.data="Hello", t2.data=CONCAT($new_data,$new_data,$new_data,$new_data,$new_data);
147 --enable_query_log
148
149 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
150 --echo # Validating update was not binlogged..
151 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
152 {
153 --die Binlog GTID position should have been unchanged after failed update
154 }
155 --echo # ..success
156
157 --echo # Validating non-transactional part of update saved..
158 if(`SELECT COUNT(*)!=1 from t1 where data="Hello"`)
159 {
160 --die Non-transactional part of update should have saved
161 }
162 --echo # ..success
163
164 --echo # Validating transactional part of update was rolled back..
165 if(`SELECT COUNT(*) from t2 where data LIKE "b%"`)
166 {
167 --die Transactional part of update should have been rolled back
168 }
169 --echo # ..success
170
171 --source include/save_master_gtid.inc
172
173 --connection slave
174
175 # Incident event
176 # 1590=ER_SLAVE_INCIDENT
177 --let $slave_sql_errno= 1590
178 --source include/wait_for_slave_sql_error_and_skip.inc
179
180 --echo # Validating the rolled-back multi-engine update did not replicate to slave at all..
181 if(`SELECT COUNT(*) from t1 where data="Hello"`)
182 {
183 --die Non-transactional part of update should not have replicated
184 }
185 if(`SELECT COUNT(*) from t2 where data LIKE "b%"`)
186 {
187 --die Transactional part of update should not have replicated
188 }
189 --echo # ..success
190
191 --connection master
192
193 --echo "****** Clean up *******"
194 --replace_result $old_max_binlog_cache_size ORIGINAL_VALUE
195 --eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size
196 --replace_result $old_binlog_cache_size ORIGINAL_VALUE
197 --eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size
198 --replace_result $old_max_binlog_stmt_cache_size ORIGINAL_VALUE
199 --eval SET GLOBAL max_binlog_stmt_cache_size= $old_max_binlog_stmt_cache_size
200 --replace_result $old_binlog_stmt_cache_size ORIGINAL_VALUE
201 --eval SET GLOBAL binlog_stmt_cache_size= $old_binlog_stmt_cache_size
202
203 DROP TABLE t1,t2;
204
205 --echo "*********** TABLE MAP Event write failure **************"
206
207 --let $debug_save= `SELECT @@GLOBAL.debug_dbug`
208 CREATE TABLE tm (f INT) ENGINE=MYISAM;
209 CREATE TABLE ti (f INT) ENGINE=INNODB;
210 INSERT INTO tm VALUES (10);
211 INSERT INTO ti VALUES (20);
212 --sync_slave_with_master
213
214 --echo "#######################################################################"
215 --echo "# Test Case4: Table_map event write failure for trans engine UPDATE #"
216 --echo "#######################################################################"
217 --echo # Transaction should be rolled back without writing incident event
218 --connection master
219 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
220 SET debug_dbug="+d,table_map_write_error";
221 --error ER_TRANS_CACHE_FULL
222 UPDATE ti, tm set ti.f=30;
223
224 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
225 --echo # Validating update was not binlogged..
226 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
227 {
228 --die Binlog GTID position should have been unchanged after failed update
229 }
230 --echo # ..success
231
232 --echo # Validating update was rolled back from storage engines..
233 if(`SELECT COUNT(*) FROM ti WHERE f=130`)
234 {
235 --die Update for InnoDB table should not have saved
236 }
237 --echo # ..success
238
239 --source include/save_master_gtid.inc
240
241 --connection slave
242 --source include/sync_with_master_gtid.inc
243
244 --echo "#######################################################################"
245 --echo "# Test Case5: Table_map event write failure for mixed engine UPDATE #"
246 --echo "#######################################################################"
247 --connection master
248 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
249 --echo # In case of mixed engines if non trans table is updated write INCIDENT event
250 --error ER_TRANS_CACHE_FULL
251 UPDATE ti,tm SET tm.f=88, ti.f=120;
252
253 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
254 --echo # Validating update was not binlogged..
255 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
256 {
257 --die Binlog GTID position should have been unchanged after failed update
258 }
259 --echo # ..success
260
261 --echo # Validating that only the non-transactional update saved on master..
262 if(`SELECT COUNT(*)!=1 FROM tm WHERE f=88`)
263 {
264 --die Update for MyISAM table should have saved
265 }
266 if(`SELECT COUNT(*) FROM ti WHERE f=120`)
267 {
268 --die Update for InnoDB table should not have saved
269 }
270 --echo # ..success
271
272
273 --connection slave
274 # Incident event
275 # 1590=ER_SLAVE_INCIDENT
276 --let $slave_sql_errno= 1590
277 --source include/wait_for_slave_sql_error_and_skip.inc
278
279 --echo # Validating that neither of the updates replicated to slave..
280 if(`SELECT COUNT(*) FROM tm WHERE f=88`)
281 {
282 --die Update for MyISAM table should not have replicated to slave
283 }
284 if(`SELECT COUNT(*) FROM ti WHERE f=120`)
285 {
286 --die Update for InnoDB table should not have replicated to slave
287 }
288 --echo # ..success
289
290 --echo "#######################################################################"
291 --echo "# Test Case6: Committing a transaction consisting of two updates:
292 --echo "# S1) Update transactional table
293 --echo "# S2) Update transactional table
294 --echo "# with a table_map event write failure on the second event should
295 --echo "# roll-back only the second update without incident
296 --echo "#######################################################################"
297 --connection master
298 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
299
300 SET debug_dbug="";
301 BEGIN;
302 # successful update
303 UPDATE ti, tm set ti.f=40;
304 SET debug_dbug="+d,table_map_write_error";
305 --error ER_TRANS_CACHE_FULL
306 UPDATE ti, tm set ti.f=50;
307 COMMIT;
308
309 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
310 --echo # Validating binlog GTID position progressed from first update..
311 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
312 {
313 --die Binlog GTID position should have updated
314 }
315 --echo # ..success
316
317 --echo # Validating the first update saved..
318 if(`SELECT COUNT(*)!=1 FROM ti WHERE f=40`)
319 {
320 --die The first update should have saved because it was transactional
321 }
322 --echo # ..and that the second update did not save..
323 if(`SELECT COUNT(*) FROM ti WHERE f=50`)
324 {
325 --die The second update should have rolled back because it failed
326 }
327 --echo # ..success
328
329 --echo # Validating that only the first update replicated to slave without incident
330 --connection master
331 --source include/save_master_gtid.inc
332 --connection slave
333 --source include/sync_with_master_gtid.inc
334 --let $diff_tables= master:test.ti,slave:test.ti
335 --source include/diff_tables.inc
336
337
338 --echo "#######################################################################"
339 --echo "# Test Case7: Rolling back a transaction consisting of two updates:
340 --echo "# S1) Update transactional table
341 --echo "# S2) Update transactional table
342 --echo "# with a table_map event write failure on the second event should
343 --echo "# roll-back both updates without incident
344 --echo "#######################################################################"
345 --connection master
346 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
347
348 SET debug_dbug="";
349 BEGIN;
350 # successful update
351 UPDATE ti, tm set ti.f=60;
352 SET debug_dbug="+d,table_map_write_error";
353 --error ER_TRANS_CACHE_FULL
354 UPDATE ti, tm set ti.f=70;
355 ROLLBACK;
356
357 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
358 --echo # Validating update was not binlogged..
359 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
360 {
361 --die Binlog GTID position should have been unchanged after failed update
362 }
363 --echo # ..success
364
365 --echo # Validating that neither update saved on master..
366 if(`SELECT COUNT(*) FROM ti WHERE f=60`)
367 {
368 --die The first update should not have saved
369 }
370 if(`SELECT COUNT(*) FROM ti WHERE f=70`)
371 {
372 --die The second update should not have saved
373 }
374 --echo # ..success
375
376 --echo # Validating the transaction did not replicate to the slave
377 --connection master
378 --source include/save_master_gtid.inc
379
380 --connection slave
381 --source include/sync_with_master_gtid.inc
382 --let $diff_tables= master:test.ti,slave:test.ti
383 --source include/diff_tables.inc
384
385
386 --echo "#######################################################################"
387 --echo "# Test Case8: Committing a transaction consisting of two updates:
388 --echo "# S1) Update transactional table
389 --echo "# S2) Update mixed trans/non-trans tables
390 --echo "# with a table_map event write failure on the second event should
391 --echo "# roll-back only the second update with incident
392 --echo "#######################################################################"
393 --connection master
394 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
395
396 BEGIN;
397 # successful update
398 SET debug_dbug="";
399 UPDATE ti, tm set ti.f=80;
400 SET debug_dbug="+d,table_map_write_error";
401 --error ER_TRANS_CACHE_FULL
402 UPDATE ti, tm set ti.f=90,tm.f=99;
403 COMMIT;
404
405 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
406 --echo # Validating binlog GTID position progressed from first update..
407 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
408 {
409 --die Binlog GTID position should have updated
410 }
411 --echo # ..success
412
413 --echo # Validating the first update saved..
414 if(`SELECT COUNT(*)!=1 FROM ti WHERE f=80`)
415 {
416 --die The first update should have saved because it was transactional
417 }
418 --echo # ..and the transactional part of the second update did not save..
419 if(`SELECT COUNT(*) FROM ti WHERE f=90`)
420 {
421 --die The transactional part of the second update should have rolled back because it failed
422 }
423 --echo # ..whereas the non-trans part of the second update did save..
424 if(`SELECT COUNT(*)!=1 FROM tm WHERE f=99`)
425 {
426 --die The non-trans part from the second update should have saved
427 }
428 --echo # ..success
429
430 --echo # Validating that the incident propagated to the slave
431 --connection slave
432 # Incident event
433 # 1590=ER_SLAVE_INCIDENT
434 --let $slave_sql_errno= 1590
435 --source include/wait_for_slave_sql_error_and_skip.inc
436
437 --echo # Validating that the first update replicated to the slave..
438 if(`SELECT COUNT(*)!=1 FROM ti WHERE f=80`)
439 {
440 --die The first update should have replicated because it was transactional
441 }
442 --echo # ..and neither part of the second update replicated..
443 if(`SELECT COUNT(*) FROM ti WHERE f=90`)
444 {
445 --die The trans part from the second update should not have replicated because it was rolled back
446 }
447 if(`SELECT COUNT(*) FROM tm WHERE f=99`)
448 {
449 --die The non-trans part from the second update should not have replicated because it was not binlogged
450 }
451 --echo # ..success
452
453
454 --echo "#######################################################################"
455 --echo "# Test Case9: Rolling back a transaction consisting of two updates:
456 --echo "# S1) Update transactional table
457 --echo "# S2) Update mixed trans/non-trans tables
458 --echo "# with a table_map event write failure on the second event should
459 --echo "# roll-back both transactional updates, preserve the non-transactional
460 --echo "# update on the master (only), and write an incident event
461 --echo "#######################################################################"
462 --connection master
463 --let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
464
465 SET debug_dbug="";
466 BEGIN;
467 # successful update
468 UPDATE ti, tm set ti.f=100;
469 SET debug_dbug="+d,table_map_write_error";
470 --error ER_TRANS_CACHE_FULL
471 UPDATE ti, tm set ti.f=110,tm.f=111;
472 ROLLBACK;
473
474 --let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
475 --echo # Validating update was not binlogged..
476 if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
477 {
478 --die Binlog GTID position should have been unchanged after failed update
479 }
480 --echo # ..success
481
482 --echo # Validating trans updates rollback, but the non-trans update stays..
483 if(`SELECT COUNT(*) FROM ti WHERE f=100`)
484 {
485 --die The first update should not have saved
486 }
487 if(`SELECT COUNT(*) FROM ti WHERE f=110`)
488 {
489 --die The transactional part of the second update should not have saved
490 }
491 if(`SELECT COUNT(*)!=1 FROM tm WHERE f=111`)
492 {
493 --die The non-trans part of the second update should have saved
494 }
495 --echo # ..success
496
497 --echo # Validating that the incident propagated to the slave
498 --connection slave
499 # Incident event
500 # 1590=ER_SLAVE_INCIDENT
501 --let $slave_sql_errno= 1590
502 --source include/wait_for_slave_sql_error_and_skip.inc
503
504 --echo # Validating that none of the updates replicated to the slave
505 --let $diff_tables= master:test.ti,slave:test.ti
506 --source include/diff_tables.inc
507 if(`SELECT COUNT(*) FROM tm WHERE f=111`)
508 {
509 --die The non-trans part from the second update should not have replicated because it was not binlogged
510 }
511 --echo # ..success
512
513
514 --echo "#######################################################################"
515 --echo "# Test Case10: If an incident event fails to write, a specific error
516 --echo "# should be logged
517 --echo "#
518 --echo "# Note: This test case is the same as test case 5, with the caveat of
519 --echo "# the incident event failing to write.
520 --echo "#######################################################################"
521
522 --connection master
523 SET debug_dbug="d,table_map_write_error,incident_event_write_error";
524 --error ER_TRANS_CACHE_FULL
525 UPDATE ti, tm set ti.f=120, tm.f=122;
526
527 --echo # Validate error message indicating incident event failed to write
528 let $log_error_= `SELECT @@GLOBAL.log_error`;
529 if(!$log_error_)
530 {
531 # MySQL Server on windows is started with --console and thus
532 # does not know the location of its .err log, use default location
533 let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err;
534 }
535 --let SEARCH_PATTERN= Incident event write to the binary log file failed
536 --let SEARCH_FILE= $log_error_
537 --source include/search_pattern_in_file.inc
538
539
540 --connection master
541 --echo "******** Clean Up **********"
542 --eval SET GLOBAL debug_dbug = '$debug_save'
543 DROP TABLE tm,ti;
544
545 --source include/test_db_charset_restore.inc
546 --source include/rpl_end.inc