summaryrefslogtreecommitdiff
path: root/mysql-test/suite/rpl/t/rpl_mdev-11092.test
blob: 0c020386b9871bd1074a09ee70431701db426893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
--source include/have_debug.inc
--source include/have_innodb.inc
--source include/not_embedded.inc
--source include/not_windows.inc
--source include/have_binlog_format_row.inc
--source include/master-slave.inc

########################################################################################
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occured on the master. .*");
call mtr.add_suppression("Write to binary log failed: Multi-row statements required more than .max_binlog_stmt_cache_size.* ");
call mtr.add_suppression("Write to binary log failed: Multi-statement transaction required more than .max_binlog_cache_size.* ");
call mtr.add_suppression("Incident event write to the binary log file failed");
call mtr.add_suppression("handlerton rollback failed");

let $old_max_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_cache_size", Value, 1);
let $old_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_cache_size", Value, 1);
let $old_max_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_stmt_cache_size", Value, 1);
let $old_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_stmt_cache_size", Value, 1);

--echo "*********** Annotate Event write failure **************"

SET GLOBAL max_binlog_cache_size = 4096;
SET GLOBAL binlog_cache_size = 4096;
SET GLOBAL max_binlog_stmt_cache_size = 4096;
SET GLOBAL binlog_stmt_cache_size = 4096;
disconnect master;
connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);

CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM;

let $data = `select concat('"', repeat('a',2000), '"')`;

connection master;

# Insert a huge row into MyISAM table. The row will be inserted in engine and a
# request to write to binary log will be initiated. Since row annotations are
# enabled the size of the annotate event itself will exceed the
# "max_binlog_stmt_cache_size". This will result in ER_STMT_CACHE_FULL error
# and an incident event will be written to the binary log as row update in
# engine cannot be undone.

--echo "#######################################################################"
--echo "# Test Case1: Annotate event write failure for MyISAM                 #"
--echo "#######################################################################"

--disable_query_log
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--error ER_STMT_CACHE_FULL
eval INSERT INTO t1 (a, data) VALUES (2,
       CONCAT($data, $data, $data, $data, $data, $data));
--enable_query_log

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating that the inserted data was saved on the master..
if(`SELECT COUNT(*)!=1 FROM t1`)
{
  --die The insertion should have saved on a non-transactional table
}
--echo # ..success

--connection slave
# Incident event
# 1590=ER_SLAVE_INCIDENT
--let $slave_sql_errno= 1590
--source include/wait_for_slave_sql_error_and_skip.inc

--echo # Validating that the insert was not replicated to the slave..
if(`SELECT COUNT(*) FROM t1`)
{
  --die The insertion should not have replicated to the slave
}
--echo # ..success

# MDEV-21087
# Insert two huge rows in to transaction cache. Have data such that first row
# fits inside the binary log cache. While writing the annotate event for the
# second row the binary log cache size will exceed "max_binlog_cache_size".
# Hence this statement cannot be written to binary log. As DMLs in Innodb can
# be safely rolled back only an error will be reported. Slave will continue to
# work.

--echo "#######################################################################"
--echo "# Test Case2: Annotate event write failure for INNODB                 #"
--echo "#######################################################################"

--connection master
CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=INNODB;
--disable_query_log
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
BEGIN;
eval INSERT INTO t2 (a, data) VALUES (1, CONCAT($data, $data));
--error ER_TRANS_CACHE_FULL
eval INSERT INTO t2 (a, data) VALUES (2, CONCAT($data, $data));
COMMIT;
--enable_query_log

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating binlog GTID position progressed from first insert..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
{
  --die Binlog GTID position should have updated
}
--echo # ..success

--echo # Validating that only the first insert into t2 saved..
if(`SELECT COUNT(*)!=1 FROM t2`)
{
  --die Only one row should exist in t2 from the first insert, the second should have rolled back
}
--echo # ..success
--source include/save_master_gtid.inc

--connection slave
--source include/sync_with_master_gtid.inc
--echo # Validating the first insert into t2 replicated to slave..
--let $diff_tables= master:test.t2,slave:test.t2
--source include/diff_tables.inc
--echo # ..success

# Testing mixed engine UPDATE statement scenario. In the following multi
# update query 'ha_update_row' will be invoked for t1 (myisam) table. This
# intern invokes binlog_write_table_map() function call. While writing a huge
# annotate event binary log cache size will exceed max_binlog_cache_size.
# Writing to binary log fails. Since non transactional changes cannot be
# rolled back incident event will be written to binary log.

--echo "#######################################################################"
--echo "# Test Case3: Annotate event write failure for mixed engine UPDATE    #"
--echo "#######################################################################"

--connection master
let $new_data = `select concat('"', repeat('b',2000), '"')`;
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--disable_query_log
--error ER_STMT_CACHE_FULL
eval UPDATE t1,t2 SET t1.data="Hello", t2.data=CONCAT($new_data,$new_data,$new_data,$new_data,$new_data);
--enable_query_log

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating non-transactional part of update saved..
if(`SELECT COUNT(*)!=1 from t1 where data="Hello"`)
{
  --die Non-transactional part of update should have saved
}
--echo # ..success

--echo # Validating transactional part of update was rolled back..
if(`SELECT COUNT(*) from t2 where data LIKE "b%"`)
{
  --die Transactional part of update should have been rolled back
}
--echo # ..success

--source include/save_master_gtid.inc

--connection slave

# Incident event
# 1590=ER_SLAVE_INCIDENT
--let $slave_sql_errno= 1590
--source include/wait_for_slave_sql_error_and_skip.inc

--echo # Validating the rolled-back multi-engine update did not replicate to slave at all..
if(`SELECT COUNT(*) from t1 where data="Hello"`)
{
  --die Non-transactional part of update should not have replicated
}
if(`SELECT COUNT(*) from t2 where data LIKE "b%"`)
{
  --die Transactional part of update should not have replicated
}
--echo # ..success

--connection master

--echo "****** Clean up *******"
--replace_result $old_max_binlog_cache_size ORIGINAL_VALUE
--eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size
--replace_result $old_binlog_cache_size ORIGINAL_VALUE
--eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size
--replace_result $old_max_binlog_stmt_cache_size ORIGINAL_VALUE
--eval SET GLOBAL max_binlog_stmt_cache_size= $old_max_binlog_stmt_cache_size
--replace_result $old_binlog_stmt_cache_size ORIGINAL_VALUE
--eval SET GLOBAL binlog_stmt_cache_size= $old_binlog_stmt_cache_size

DROP TABLE t1,t2;

--echo "*********** TABLE MAP Event write failure **************"

--let $debug_save= `SELECT @@GLOBAL.debug_dbug`
CREATE TABLE tm (f INT) ENGINE=MYISAM;
CREATE TABLE ti (f INT) ENGINE=INNODB;
INSERT INTO tm VALUES (10);
INSERT INTO ti VALUES (20);
--sync_slave_with_master

--echo "#######################################################################"
--echo "# Test Case4: Table_map event write failure for trans engine UPDATE   #"
--echo "#######################################################################"
--echo # Transaction should be rolled back without writing incident event
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
SET debug_dbug="+d,table_map_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=30;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating update was rolled back from storage engines..
if(`SELECT COUNT(*) FROM ti WHERE f=130`)
{
  --die Update for InnoDB table should not have saved
}
--echo # ..success

--source include/save_master_gtid.inc

--connection slave
--source include/sync_with_master_gtid.inc

--echo "#######################################################################"
--echo "# Test Case5: Table_map event write failure for mixed engine UPDATE   #"
--echo "#######################################################################"
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # In case of mixed engines if non trans table is updated write INCIDENT event
--error ER_TRANS_CACHE_FULL
UPDATE ti,tm SET tm.f=88, ti.f=120;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating that only the non-transactional update saved on master..
if(`SELECT COUNT(*)!=1 FROM tm WHERE f=88`)
{
  --die Update for MyISAM table should have saved
}
if(`SELECT COUNT(*) FROM ti WHERE f=120`)
{
  --die Update for InnoDB table should not have saved
}
--echo # ..success


--connection slave
# Incident event
# 1590=ER_SLAVE_INCIDENT
--let $slave_sql_errno= 1590
--source include/wait_for_slave_sql_error_and_skip.inc

--echo # Validating that neither of the updates replicated to slave..
if(`SELECT COUNT(*) FROM tm WHERE f=88`)
{
  --die Update for MyISAM table should not have replicated to slave
}
if(`SELECT COUNT(*) FROM ti WHERE f=120`)
{
  --die Update for InnoDB table should not have replicated to slave
}
--echo # ..success

--echo "#######################################################################"
--echo "# Test Case6: Committing a transaction consisting of two updates:
--echo "#   S1) Update transactional table
--echo "#   S2) Update transactional table
--echo "# with a table_map event write failure on the second event should
--echo "# roll-back only the second update without incident
--echo "#######################################################################"
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)

SET debug_dbug="";
BEGIN;
# successful update
UPDATE ti, tm set ti.f=40;
SET debug_dbug="+d,table_map_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=50;
COMMIT;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating binlog GTID position progressed from first update..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
{
  --die Binlog GTID position should have updated
}
--echo # ..success

--echo # Validating the first update saved..
if(`SELECT COUNT(*)!=1 FROM ti WHERE f=40`)
{
  --die The first update should have saved because it was transactional
}
--echo # ..and that the second update did not save..
if(`SELECT COUNT(*) FROM ti WHERE f=50`)
{
  --die The second update should have rolled back because it failed
}
--echo # ..success

--echo # Validating that only the first update replicated to slave without incident
--connection master
--source include/save_master_gtid.inc
--connection slave
--source include/sync_with_master_gtid.inc
--let $diff_tables= master:test.ti,slave:test.ti
--source include/diff_tables.inc


--echo "#######################################################################"
--echo "# Test Case7: Rolling back a transaction consisting of two updates:
--echo "#   S1) Update transactional table
--echo "#   S2) Update transactional table
--echo "# with a table_map event write failure on the second event should
--echo "# roll-back both updates without incident
--echo "#######################################################################"
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)

SET debug_dbug="";
BEGIN;
# successful update
UPDATE ti, tm set ti.f=60;
SET debug_dbug="+d,table_map_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=70;
ROLLBACK;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating that neither update saved on master..
if(`SELECT COUNT(*) FROM ti WHERE f=60`)
{
  --die The first update should not have saved
}
if(`SELECT COUNT(*) FROM ti WHERE f=70`)
{
  --die The second update should not have saved
}
--echo # ..success

--echo # Validating the transaction did not replicate to the slave
--connection master
--source include/save_master_gtid.inc

--connection slave
--source include/sync_with_master_gtid.inc
--let $diff_tables= master:test.ti,slave:test.ti
--source include/diff_tables.inc


--echo "#######################################################################"
--echo "# Test Case8: Committing a transaction consisting of two updates:
--echo "#   S1) Update transactional table
--echo "#   S2) Update mixed trans/non-trans tables
--echo "# with a table_map event write failure on the second event should
--echo "# roll-back only the second update with incident
--echo "#######################################################################"
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)

BEGIN;
# successful update
SET debug_dbug="";
UPDATE ti, tm set ti.f=80;
SET debug_dbug="+d,table_map_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=90,tm.f=99;
COMMIT;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating binlog GTID position progressed from first update..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") = 0`)
{
  --die Binlog GTID position should have updated
}
--echo # ..success

--echo # Validating the first update saved..
if(`SELECT COUNT(*)!=1 FROM ti WHERE f=80`)
{
  --die The first update should have saved because it was transactional
}
--echo # ..and the transactional part of the second update did not save..
if(`SELECT COUNT(*) FROM ti WHERE f=90`)
{
  --die The transactional part of the second update should have rolled back because it failed
}
--echo # ..whereas the non-trans part of the second update did save..
if(`SELECT COUNT(*)!=1 FROM tm WHERE f=99`)
{
  --die The non-trans part from the second update should have saved
}
--echo # ..success

--echo # Validating that the incident propagated to the slave
--connection slave
# Incident event
# 1590=ER_SLAVE_INCIDENT
--let $slave_sql_errno= 1590
--source include/wait_for_slave_sql_error_and_skip.inc

--echo # Validating that the first update replicated to the slave..
if(`SELECT COUNT(*)!=1 FROM ti WHERE f=80`)
{
  --die The first update should have replicated because it was transactional
}
--echo # ..and neither part of the second update replicated..
if(`SELECT COUNT(*) FROM ti WHERE f=90`)
{
  --die The trans part from the second update should not have replicated because it was rolled back
}
if(`SELECT COUNT(*) FROM tm WHERE f=99`)
{
  --die The non-trans part from the second update should not have replicated because it was not binlogged
}
--echo # ..success


--echo "#######################################################################"
--echo "# Test Case9: Rolling back a transaction consisting of two updates:
--echo "#   S1) Update transactional table
--echo "#   S2) Update mixed trans/non-trans tables
--echo "# with a table_map event write failure on the second event should
--echo "# roll-back both transactional updates, preserve the non-transactional
--echo "# update on the master (only), and write an incident event
--echo "#######################################################################"
--connection master
--let $old_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)

SET debug_dbug="";
BEGIN;
# successful update
UPDATE ti, tm set ti.f=100;
SET debug_dbug="+d,table_map_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=110,tm.f=111;
ROLLBACK;

--let $new_gtid_binlog_pos= query_get_value(SHOW VARIABLES LIKE 'gtid_binlog_pos', Value, 1)
--echo # Validating update was not binlogged..
if(`SELECT strcmp("$old_gtid_binlog_pos","$new_gtid_binlog_pos") != 0`)
{
  --die Binlog GTID position should have been unchanged after failed update
}
--echo # ..success

--echo # Validating trans updates rollback, but the non-trans update stays..
if(`SELECT COUNT(*) FROM ti WHERE f=100`)
{
  --die The first update should not have saved
}
if(`SELECT COUNT(*) FROM ti WHERE f=110`)
{
  --die The transactional part of the second update should not have saved
}
if(`SELECT COUNT(*)!=1 FROM tm WHERE f=111`)
{
  --die The non-trans part of the second update should have saved
}
--echo # ..success

--echo # Validating that the incident propagated to the slave
--connection slave
# Incident event
# 1590=ER_SLAVE_INCIDENT
--let $slave_sql_errno= 1590
--source include/wait_for_slave_sql_error_and_skip.inc

--echo # Validating that none of the updates replicated to the slave
--let $diff_tables= master:test.ti,slave:test.ti
--source include/diff_tables.inc
if(`SELECT COUNT(*) FROM tm WHERE f=111`)
{
  --die The non-trans part from the second update should not have replicated because it was not binlogged
}
--echo # ..success


--echo "#######################################################################"
--echo "# Test Case10: If an incident event fails to write, a specific error
--echo "# should be logged
--echo "#
--echo "# Note: This test case is the same as test case 5, with the caveat of
--echo "# the incident event failing to write.
--echo "#######################################################################"

--connection master
SET debug_dbug="d,table_map_write_error,incident_event_write_error";
--error ER_TRANS_CACHE_FULL
UPDATE ti, tm set ti.f=120, tm.f=122;

--echo # Validate error message indicating incident event failed to write
let $log_error_= `SELECT @@GLOBAL.log_error`;
if(!$log_error_)
{
    # MySQL Server on windows is started with --console and thus
    # does not know the location of its .err log, use default location
    let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err;
}
--let SEARCH_PATTERN= Incident event write to the binary log file failed
--let SEARCH_FILE= $log_error_
--source include/search_pattern_in_file.inc


--connection master
--echo "******** Clean Up **********"
--eval SET GLOBAL debug_dbug = '$debug_save'
DROP TABLE tm,ti;

--source include/rpl_end.inc