Debian Codegraph @

mysql-test/suite/rpl_gtid/t/rpl_gtid_replica_skip_errors.test

raw
1 # ==== Purpose ====
2 #
3 # Verify that transactions skipped due to replica-skip-errors produce empty
4 # transactions in the replica's binary log when needed.
5 #
6 # ==== Requirements ====
7 #
8 # When one of the following errors occurs while the replica applies a
9 # transaction, and the error is skipped because of replica-skip-errors, the
10 # replica shall write the GTID to its binary log:
11 #
12 # R1.1. CREATE TABLE fails because the table exists
13 # R1.2. CREATE TABLE ... SELECT fails because the table exists, when
14 # binlog_format=STATEMENT
15 # R1.3. CREATE TABLE ... SELECT fails because the table exists, when
16 # binlog_format=ROW
17 # R2. ALTER TABLE fails because the table does not exist
18 # R3. OPTIMIZE TABLE fails because the table does not exist
19 # R4. CREATE TRIGGER fails because the table does not exist
20 # R5. DROP TABLE fails because the table does not exist
21 # R6. INSERT fails because the table does not exist
22 # R6.1. binlog_format=ROW
23 # R6.2. binlog_format=STATEMENT
24 # R7. INSERT fails because the row already exists
25 # R7.1. binlog_format=ROW
26 # R7.2. binlog_format=STATEMENT
27 # R8. A DDL statement fails with parse error
28 # R9. A DML statement fails with parse error
29 # R10. CREATE USER fails because the user exists
30 # R11. XA COMMIT fails because the XID does not exist
31 # R12. XA ROLLBACK fails becasue the XID does not exist
32 # R13. INSERT fails within XA START ... XA END ; XA PREPARE
33 # R14. CREATE DATABASE fails because the database exists
34 # R15. DROP DATABASE fails because the database is not empty
35 # R16. Incident event fails because that's what incident event do
36 #
37 # In all cases except R3, it shall write an empty transaction to the replica's
38 # binary log. In case R3, OPTIMIZE TABLE is written instead, because that is a
39 # special statement that is written even when it fails.
40 #
41 # Note: we can't test every possible error for every possible statement. These
42 # requirements are chosen with the intention to be representative for a variety
43 # of code paths.
44 #
45 # We do not test failures in XA START, because replica_skip_errors doesn't work
46 # with XA START: if we skip the error, there is no transaction for the next
47 # event to execute in, which results in other, non-skippable errors.
48 #
49 # ==== Implementation ====
50 #
51 # For each of the requirements except R3:
52 # - Execute the scenario
53 # - Check that it replicates. This verifies that the replica did not stop, and
54 # that the GTID was added to gtid_executed.
55 # - Check that the GTID was written to the replica's binary log as an empty
56 # transaction.
57 #
58 # For R3, the replica will write OPTIMIZE TABLE to its binary log, because
59 # OPTIMIZE TABLE is a special statement that gets written even when it fails.
60 # So instead of checking for an empty transaction, we check for OPTIMIZE TABLE.
61
62 --source include/have_binlog_format_row.inc
63 --source include/have_debug.inc
64 --source include/master-slave.inc
65
66 --echo #
67 --echo # Initialize
68 --echo #
69
70 --source include/rpl_connection_slave.inc
71 --let $messages = Replica SQL for channel .*: Worker 1 failed executing transaction.*
72 --let $suppress_on_current_connection = 1
73 --source include/suppress_messages.inc
74
75 --echo #
76 --echo # R1.1. CREATE TABLE fails because table exists on replica
77 --echo #
78
79 --source include/rpl_connection_slave.inc
80 CREATE TABLE t (a INT PRIMARY KEY);
81 --source include/save_binlog_position.inc
82
83 --source include/rpl_connection_master.inc
84 CREATE TABLE t (a INT PRIMARY KEY);
85
86 # Replica will observe and ignore error 1050 = ER_TABLE_EXISTS_ERROR
87 --source include/sync_slave_sql_with_master.inc
88 # Replica will write empty transaction.
89 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
90 --source include/assert_binlog_events.inc
91
92 # Clean up
93 --source include/rpl_connection_master.inc
94 DROP table t;
95 --source include/sync_slave_sql_with_master.inc
96
97 --echo #
98 --echo # R1.2. CREATE TABLE ... SELECT fails because table exists on replica
99 --echo # with binlog_format=STATEMENT
100 --echo #
101
102 --source include/rpl_connection_master.inc
103 CREATE TABLE t0 (a INT PRIMARY KEY);
104 INSERT INTO t0 VALUES (1), (2);
105 --source include/sync_slave_sql_with_master.inc
106
107 CREATE TABLE t (a TEXT);
108 --source include/save_binlog_position.inc
109
110 --source include/rpl_connection_master.inc
111 SET @@session.binlog_format = STATEMENT;
112 CREATE TABLE t (a INT PRIMARY KEY) SELECT * FROM t0;
113 SET @@session.binlog_format = ROW;
114
115 # Replica will observe and ignore error 1050 = ER_TABLE_EXISTS_ERROR
116 --source include/sync_slave_sql_with_master.inc
117 # Replica will write empty transaction.
118 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
119 --source include/assert_binlog_events.inc
120
121 # Clean up
122 --source include/rpl_connection_master.inc
123 DROP TABLE t;
124 --source include/sync_slave_sql_with_master.inc
125
126 # Reuse t0 in the next scenario
127
128 --echo #
129 --echo # R1.3. CREATE TABLE ... SELECT fails because table exists on replica
130 --echo # with binlog_format=ROW
131 --echo #
132
133 --source include/rpl_connection_slave.inc
134 CREATE TABLE t (a TEXT);
135 --source include/save_binlog_position.inc
136
137 --source include/rpl_connection_master.inc
138 CREATE TABLE t (a INT PRIMARY KEY) SELECT * FROM t0;
139
140 # Replica will:
141 # - when applying the CREATE, observe and ignore error 1050 =
142 # ER_TABLE_EXISTS_ERROR;
143 # - but it is ignoring that error, so it will proceed and try to apply the row
144 # insertion;
145 # - when applying the row insertion, the table exists but does not have the
146 # same data type in the first column as the event, so it will observe and
147 # ignore error 13146 = ER_SERVER_REPLICA_CONVERSION_FAILED.
148 --source include/sync_slave_sql_with_master.inc
149 # Replica will write empty transaction.
150 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
151 --source include/assert_binlog_events.inc
152
153 # Clean up
154 --source include/rpl_connection_master.inc
155 DROP TABLE t0;
156 --source include/sync_slave_sql_with_master.inc
157
158 # Reuse t in the next scenario
159
160 --echo #
161 --echo # R2. ALTER TABLE fails because table does not exist on replica
162 --echo #
163
164 --source include/rpl_connection_slave.inc
165 DROP TABLE t;
166 --source include/save_binlog_position.inc
167
168 --source include/rpl_connection_master.inc
169 ALTER TABLE t ADD COLUMN b INT;
170
171 # Replica will observe and ignore error 1146 = ER_NO_SUCH_TABLE
172 --source include/sync_slave_sql_with_master.inc
173 # Replica will write empty transaction.
174 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
175 --source include/assert_binlog_events.inc
176 --source include/save_binlog_position.inc
177
178 # Reuse t, which exists only on source, in the next scenario
179
180 --echo #
181 --echo # R3. OPTIMIZE TABLE fails because table does not exist on replica
182 --echo #
183
184 --source include/rpl_connection_master.inc
185 OPTIMIZE TABLE t;
186
187 # Replica will observe and ignore error 1050 = ER_TABLE_EXISTS_ERROR
188 --source include/sync_slave_sql_with_master.inc
189 # Because OPTIMIZE TABLE is special, it actually gets logged on errors.
190 # Verify that it got logged and that no empty transaction got logged.
191 --let $event_sequence = Gtid # Query/.*OPTIMIZE TABLE t
192 --source include/assert_binlog_events.inc
193 --source include/save_binlog_position.inc
194
195 # Reuse t, which exists only on source, in the next scenario
196
197 --echo #
198 --echo # R4. CREATE TRIGGER fails because table does not exist on replica
199 --echo #
200
201 --source include/rpl_connection_master.inc
202 CREATE TRIGGER trig BEFORE UPDATE ON t FOR EACH ROW SET @tmp := 1;
203
204 # Replica will observe and ignore error 1146 = ER_NO_SUCH_TABLE
205 --source include/sync_slave_sql_with_master.inc
206 # Replica will write empty transaction.
207 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
208 --source include/assert_binlog_events.inc
209 --source include/save_binlog_position.inc
210
211 # Reuse t, which exists only on source, in the next scenario
212
213 --echo #
214 --echo # R5. DROP TABLE fails because table does not exist on replica
215 --echo #
216
217 --source include/rpl_connection_master.inc
218 DROP TABLE t;
219
220 # Replica will observe and ignore error 1051 = ER_BAD_TABLE_ERROR
221 --source include/sync_slave_sql_with_master.inc
222 # Replica will write empty transaction.
223 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
224 --source include/assert_binlog_events.inc
225
226 #### R6, R7: use rpl_gtid_replica_skip_errors_dml.test ####
227
228 --let $engine = InnoDB
229 --source extra/rpl_tests/rpl_gtid_replica_skip_errors_dml.test
230
231 --echo #
232 --echo # R8. A DDL statement fails with parse error
233 --echo #
234
235 --source include/rpl_connection_slave.inc
236 --source include/save_binlog_position.inc
237 --source include/rpl_connection_master.inc
238
239 # This removes the first character from the query before writing to the binlog,
240 # so replica will see `REATE TABLE t (a INT)`
241 --let $debug_point = binlog_corrupt_query
242 --source include/add_debug_point.inc
243 CREATE TABLE t (a INT);
244 --let $debug_point = binlog_corrupt_query
245 --source include/remove_debug_point.inc
246
247 # Replica will observe and ignore error 1064 = ER_PARSE_ERROR
248 --source include/sync_slave_sql_with_master.inc
249 # Replica will write empty transaction.
250 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
251 --source include/assert_binlog_events.inc
252
253 # Clean up
254 --source include/rpl_connection_master.inc
255 DROP TABLE IF EXISTS t;
256 --source include/sync_slave_sql_with_master.inc
257
258 --echo #
259 --echo # R9. A DML statement fails with parse error
260 --echo #
261
262 --source include/rpl_connection_master.inc
263 CREATE TABLE t (a INT);
264 --source include/sync_slave_sql_with_master.inc
265 --source include/save_binlog_position.inc
266
267 --source include/rpl_connection_master.inc
268 # This removes the first character from the query before writing to the binlog,
269 # so replica will see `NSERT INTO t VALUES (1)`
270 SET @@session.binlog_format = STATEMENT;
271 --let $debug_point = binlog_corrupt_query
272 --source include/add_debug_point.inc
273 INSERT INTO t VALUES (1);
274 --let $debug_point = binlog_corrupt_query
275 --source include/remove_debug_point.inc
276 SET @@session.binlog_format = ROW;
277
278 # Replica will observe and ignore error 1064 = ER_PARSE_ERROR
279 --source include/sync_slave_sql_with_master.inc
280 # Replica will write empty transaction.
281 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
282 --source include/assert_binlog_events.inc
283
284 # Clean up
285 --source include/rpl_connection_master.inc
286 DROP TABLE t;
287 --source include/sync_slave_sql_with_master.inc
288
289 --echo #
290 --echo # R10. CREATE USER fails because the user exists
291 --echo #
292
293 --source include/rpl_connection_slave.inc
294 CREATE USER user1;
295
296 --source include/save_binlog_position.inc
297 --source include/rpl_connection_master.inc
298 CREATE USER user1;
299
300 # Replica will observe and ignore error 1396 = ER_CANNOT_USER
301 --source include/sync_slave_sql_with_master.inc
302 # Replica will write empty transaction.
303 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
304 --source include/assert_binlog_events.inc
305
306 # Clean up
307 --source include/rpl_connection_master.inc
308 DROP USER user1;
309 --source include/sync_slave_sql_with_master.inc
310
311 --echo #
312 --echo # R11. XA COMMIT fails because the XID does not exist
313 --echo #
314
315 --source include/rpl_connection_master.inc
316 CREATE TABLE t (a INT PRIMARY KEY);
317 XA START 'a';
318 INSERT INTO t VALUES (2);
319 XA END 'a';
320 XA PREPARE 'a';
321 --source include/sync_slave_sql_with_master.inc
322
323 --source include/rpl_connection_slave.inc
324 --let $xa_prepared_count = 1
325 --source include/wait_for_xa_prepared_count.inc
326 XA ROLLBACK 'a';
327 --source include/save_binlog_position.inc
328
329 --source include/rpl_connection_master.inc
330 XA COMMIT 'a';
331
332 # Replica will observe and ignore error 1397 = ER_XAER_NOTA
333 --source include/sync_slave_sql_with_master.inc
334 # Replica will write empty transaction.
335 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
336 --source include/assert_binlog_events.inc
337
338 # Reuse t in the next scenario
339
340 --echo #
341 --echo # R12. XA ROLLBACK fails because the XID does not exist
342 --echo #
343
344 --source include/rpl_connection_master.inc
345 XA START 'a';
346 INSERT INTO t VALUES (3);
347 XA END 'a';
348 XA PREPARE 'a';
349 --source include/sync_slave_sql_with_master.inc
350 --let $xa_prepared_count = 1
351 --source include/wait_for_xa_prepared_count.inc
352 XA ROLLBACK 'a';
353 --source include/save_binlog_position.inc
354
355 --source include/rpl_connection_master.inc
356 XA ROLLBACK 'a';
357
358 # Replica will observe and ignore error 1397 = ER_XAER_NOTA
359 --source include/sync_slave_sql_with_master.inc
360 # Replica will write empty transaction.
361 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
362 --source include/assert_binlog_events.inc
363
364 # Reuse t in the next scenario
365
366 --echo #
367 --echo # R13. INSERT fails within XA START ... XA END ; XA PREPARE
368 --echo #
369
370 --source include/rpl_connection_slave.inc
371 INSERT INTO t VALUES (4);
372 --source include/save_binlog_position.inc
373
374 --source include/rpl_connection_master.inc
375 XA START 'a';
376 INSERT INTO t VALUES (4);
377 XA END 'a';
378 XA PREPARE 'a';
379
380 # Replica will observe and ignore error 1146 = ER_NO_SUCH_TABLE
381 --source include/sync_slave_sql_with_master.inc
382 # Replica will write empty transaction.
383 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
384 --source include/assert_binlog_events.inc
385
386 # Clean up
387 --source include/rpl_connection_master.inc
388 XA ROLLBACK 'a';
389 DROP TABLE t;
390 --source include/sync_slave_sql_with_master.inc
391
392 --echo #
393 --echo # R14. CREATE DATABASE fails because the database exists
394 --echo #
395
396 --source include/rpl_connection_slave.inc
397 CREATE DATABASE db;
398 --source include/save_binlog_position.inc
399
400 --source include/rpl_connection_master.inc
401 CREATE DATABASE db;
402
403 # Replica will observe and ignore error 1007 = ER_DB_CREATE_EXISTS
404 --source include/sync_slave_sql_with_master.inc
405 # Replica will write empty transaction.
406 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
407 --source include/assert_binlog_events.inc
408
409 # Reuse db in the next scenario
410
411 --echo #
412 --echo # R15. DROP DATABASE fails because the database does not exist
413 --echo #
414
415 --source include/rpl_connection_slave.inc
416 DROP DATABASE db;
417 --source include/save_binlog_position.inc
418
419 --source include/rpl_connection_master.inc
420 DROP DATABASE db;
421
422 # Replica will observe and ignore error 1008 = ER_DB_DROP_EXISTS
423 --source include/sync_slave_sql_with_master.inc
424 # Replica will write empty transaction.
425 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
426 --source include/assert_binlog_events.inc
427
428 --echo #
429 --echo # R16. Incident fails
430 --echo #
431
432 --source include/rpl_connection_slave.inc
433 --source include/save_binlog_position.inc
434 --let $replica_binlog_file = $binlog_file
435 --let $replica_binlog_position = $binlog_position
436
437 --source include/rpl_connection_master.inc
438 --source include/save_binlog_position.inc
439 --source include/save_error_log_position.inc
440
441 --let $debug_point = binlog_inject_incident
442 --source include/add_debug_point.inc
443 CREATE TABLE t (a INT);
444 --let $debug_point = binlog_inject_incident
445 --source include/remove_debug_point.inc
446
447 --let $event_sequence = Gtid # Incident
448 --source include/assert_binlog_events.inc
449
450 --let $error_pattern = Non-transactional changes were not written to the binlog. An incident event has been written to the binary log which will stop the replicas.
451 --source include/assert_error_log.inc
452
453 # Replica will observe and ignore error 13119 = ER_REPLICA_INCIDENT
454 --source include/sync_slave_sql_with_master.inc
455 # Replica will write empty transaction.
456 --let $event_sequence = Gtid # Query/BEGIN # Query/COMMIT
457 --let $binlog_file = $replica_binlog_file
458 --let $binlog_position = $replica_binlog_position
459 --source include/assert_binlog_events.inc
460
461 # Clean up
462 --source include/rpl_connection_master.inc
463 DROP TABLE IF EXISTS t;
464 --source include/sync_slave_sql_with_master.inc
465
466 --echo #
467 --echo # Clean up
468 --echo #
469
470 --source include/rpl_end.inc