Debian Codegraph @

mysql-test/suite/ndb_rpl/t/log_transaction_dependency.test

raw
1 # ==== Purpose ====
2 #
3 # This tests the transaction dependency functionality of ndb_binlog thread,
4 # it's based on the rpl_binlog_transaction_dependency_tracking.test
5 # with adaption to how binlogging works for tables in NDB.
6 #
7 # - NOTE! Since NDB transactions are handled asynchronously, it does not matter
8 # whether a transaction is started before or after the writeset history is
9 # reset by a serial synchronization point (like DDL, log rotation etx).
10 # Rather the conflict occurs when transaction is received by the ndb_binlog
11 # thread and committed in the binlog, this differs from local engines where
12 # transaction started before serial synchronization point is not
13 # conflicting - this primarily affects TRX5.
14 #
15 # - NOTE2! All NDB transactions are handled and committed by the single
16 # ndb_binlog thread and thus there will always be a conflict with previous
17 # transaction using binlog-transaction-dependency-tracking=WRITESET_SESSION
18 # as well as binlog-transaction-dependency-tracking=COMMIT_ORDER
19 #
20 # Test timestamps generated by binlog-transaction-dependency-tracking
21 # modes WRITESET, WRITESET_SESSION and COMMIT_ORDER.
22 #
23 # The following properties are tested:
24 # - With binlog-transaction-dependency-tracking=WRITESET, the logical timestamps
25 # are generated as expected, marking each transaction as conflicting with
26 # transactions having intersecting writesets.
27 # (type = 0)
28 # - With binlog-transaction-dependency-tracking=WRITESET_SESSION, transactions
29 # are additionally marked as conflicting with all previous transactions in the
30 # same session.
31 # (type = 1)
32 # - Additionally, transactions are marked as conflicting with any DDL.
33 # (step = 2)
34 # - Additionally, transactions are marked as conflicting if one appears before
35 # and the other after a binlog rotation.
36 # (step = 3)
37 # - Additionally, transactions are marked as conflicting if the writeset history
38 # was cleared between the transactions.
39 # (step = 4)
40 #
41 # - It tests this for INSERT, UPDATE and DELETE statements.
42 #
43 # ==== Implementation ====
44 #
45 # 1. Apply 8 transactions with different data dependencies and check the binary
46 # log generated (step 1). Do the same with DDL in the middle (step 2), with
47 # rotation (step 3) and when writeset history becomes full (step 4).
48 #
49 # 2. Test Bug#2561672: POST RESET MASTER/FLUSH LOGS SETTING BTDT=WRITESET
50 # BEHAVES LIKE COMMIT_ORDER
51 #
52 # ==== References ====
53 #
54 # WL#9556: Writeset-based MTS dependency tracking on master
55 # WL#15145: ndb binlog writeset trans dependencies
56 #
57
58 --source include/have_ndb.inc
59 --source include/have_binlog_format_row.inc
60 --source suite/ndb/include/ndb_log_transaction_dependency_enabled.inc
61 --source include/master-slave.inc
62
63 --echo #### INITIALIZE ####
64
65 --connection slave
66 call mtr.add_suppression("Transaction is tagged with inconsistent logical timestamps");
67 call mtr.add_suppression("Cannot execute the current event group in the parallel mode.");
68
69 --source include/stop_slave.inc
70
71 SET @save_replica_parallel_type = @@GLOBAL.replica_parallel_type;
72 SET @save_replica_parallel_workers = @@GLOBAL.replica_parallel_workers;
73 SET @save_replica_transaction_retries = @@GLOBAL.replica_transaction_retries;
74
75 SET GLOBAL replica_parallel_type = LOGICAL_CLOCK;
76 SET GLOBAL replica_parallel_workers = 3;
77 SET GLOBAL replica_transaction_retries = 0;
78
79 --connection master
80
81 SET @save_binlog_transaction_dependency_tracking = @@GLOBAL.binlog_transaction_dependency_tracking;
82 SET @save_binlog_transaction_dependency_history_size = @@GLOBAL.binlog_transaction_dependency_history_size;
83
84 # for step 4
85 SET GLOBAL binlog_transaction_dependency_tracking = COMMIT_ORDER;
86
87
88 CREATE TABLE tests (`id` INT NOT NULL, `description` VARCHAR(50), `results` VARCHAR(100), PRIMARY KEY(`id`));
89 INSERT INTO `tests` (`id`, `description`, `results`) VALUES
90 (1, 'Writeset', '0 1;1 2;1 3;1 4;3 5;3 6;4 7;7 8;6 9;9 10'),
91 (2, 'Writeset+DDL', '0 1;1 2;1 3;1 4;4 5;5 6;6 7;7 8;7 9;7 10;10 11;9 12;12 13'),
92 (3, 'Writeset+rotation', '0 1;1 2;1 3;3 4;2 5;5 6'),
93 (4, 'Writeset+history', '0 1;1 2;1 3;1 4;4 5;4 6;4 7;7 8;7 9;9 10'),
94 (5, 'Writeset_session', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10'),
95 (6, 'Writeset_session+DDL', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10;10 11;11 12;12 13'),
96 (7, 'Writeset_session+rotation', '0 1;1 2;2 3;3 4;4 5;5 6'),
97 (8, 'Writeset_session+history', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10'),
98 (9, 'Commit_order', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10'),
99 (10, 'Commit_order+DDL', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10;10 11;11 12;12 13'),
100 (11, 'Commit_order+rotation', '0 1;1 2;2 3;3 4;4 5;5 6'),
101 (12, 'Commit_order+history', '0 1;1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10');
102
103 # flush logs to clear previous transactions
104 FLUSH LOGS;
105
106 --let $idx= 0
107
108 --echo #### TEST ####
109
110 # loop between WRITESET and WRITESET_SESSION
111 --let $type= 0
112 while ($type < 3)
113 {
114 --inc $type
115
116 --connection master
117 if ($type == 1)
118 {
119 SET GLOBAL binlog_transaction_dependency_tracking = WRITESET;
120 --echo ######## 1. WRITESET ########
121 }
122 if ($type == 2)
123 {
124 SET GLOBAL binlog_transaction_dependency_tracking = WRITESET_SESSION;
125 --echo ######## 2. WRITESET_SESSION ########
126 }
127 if ($type == 3)
128 {
129 SET GLOBAL binlog_transaction_dependency_tracking = COMMIT_ORDER;
130 --echo ######## 3. COMMIT_ORDER ########
131 }
132
133 # loop between steps
134 --let $step= 0
135 while ($step < 4)
136 {
137 --inc $step
138 --inc $idx
139
140 --let $testname=`SELECT description FROM tests WHERE id=$idx`
141 --echo #### STEP $type.$step TEST $testname ####
142
143 SET GLOBAL binlog_transaction_dependency_history_size=25000;
144 if ($step == 4)
145 {
146 --echo History size reduced to 5 to test when it becomes full
147 SET GLOBAL binlog_transaction_dependency_history_size=5;
148 }
149
150 SELECT @@binlog_transaction_dependency_tracking,
151 @@binlog_transaction_dependency_history_size;
152
153 CREATE TABLE `t1` (`id` int NOT NULL, `val` int NOT NULL,
154 PRIMARY KEY (`id`)) ENGINE=NDB; #// seq 1
155
156 --connection master
157 --echo #TRX2 (session A, independent)
158 BEGIN;
159 INSERT INTO t1(id, val) VALUES (1, 0),(2, 0),(3, 0);
160
161 --connection master1
162 --echo #TRX1 (session B, independent)
163 BEGIN;
164 INSERT INTO t1(id, val) VALUES (4, 0),(5, 0);
165 COMMIT;
166 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
167
168 --connection master
169 --echo finish TRX2 after TRX1
170 COMMIT;
171 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
172
173 --connection master1
174 --echo #TRX3 (session B, no data dependency, depends on TRX1 (session))
175 BEGIN;
176 INSERT INTO t1(id, val) VALUES (6, 0),(7, 0);
177 COMMIT;
178 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
179
180 --connection master
181 --echo #TRX5 (session A, depends on TRX2 (session and data) and TRX1(data))
182 BEGIN;
183 INSERT INTO t1(id, val) VALUES (8, 1);
184 UPDATE t1 SET val=val+1 WHERE id=1;
185 UPDATE t1 SET val=val+1 WHERE id=4;
186
187 if ($step == 2)
188 {
189 --connection master1
190 --echo Inserted a DDL after TRX5 and check that they run in parallel due to commit_order
191 CREATE TABLE `t2` (`id` int NOT NULL, `val` int NOT NULL) ENGINE=NDB;
192 ALTER TABLE t2 ADD COLUMN b INT;
193 DROP TABLE `t2`;
194 }
195
196 # flush logs in the middle
197 if ($step == 3)
198 {
199 --connection master1
200 --echo Flushing logs in the middle of the set
201 FLUSH LOGS;
202 }
203
204 --connection server_1
205 --echo #TRX4 (session C, depends on TRX2 (data))
206 BEGIN;
207 UPDATE t1 SET val=val+1 WHERE id=3;
208 INSERT INTO t1(id, val) VALUES (9, 1);
209 COMMIT;
210 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
211
212 --connection master
213 --echo finish TRX5 after TRX4
214 COMMIT;
215 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
216
217 --connection server_1
218 --echo #TRX6 (session C, depends on TRX4 (session) and TRX3(data))
219 BEGIN;
220 DELETE FROM t1 WHERE id=6;
221 COMMIT;
222 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
223
224 --connection server_1
225 --echo #TRX8 (session C, depends on TRX5 (data) and TRX6 (session))
226 BEGIN;
227 UPDATE t1 SET val=val+1 WHERE id=4;
228
229 --connection master1
230 --echo #TRX7 (session B, depends on TRX1 and TRX6 (data) and TRX3 (session))
231 BEGIN;
232 UPDATE t1 SET val=val+1 WHERE id=5;
233 INSERT INTO t1(id, val) VALUES (6, 0);
234 COMMIT;
235 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
236
237 --connection server_1
238 --echo finish TRX8 after TRX7
239 COMMIT;
240 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
241
242 --connection master
243 --echo Drop table and flush logs to force binlog to rotate
244 DROP TABLE t1;
245
246 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
247 --echo Processing binlog $binlog_file
248 FLUSH LOGS;
249
250 --let $source_file= $server_1_datadir/$binlog_file
251 --let $logical_timestamps=`SELECT results FROM tests WHERE id=$idx`
252 --source include/assert_logical_timestamps.inc
253 }
254 }
255
256 --echo
257 --echo #### Verify that replication was correct ####
258
259 --connection slave
260 --source include/start_slave.inc
261
262 --connection master
263 --source include/sync_slave_sql_with_master.inc
264
265 --let $diff_tables= master:test.tests, slave:test.tests
266 --source include/diff_tables.inc
267
268 --connection master
269 DROP TABLE `tests`;
270 --source include/sync_slave_sql_with_master.inc
271
272 --connection master
273 SET GLOBAL binlog_transaction_dependency_tracking= WRITESET;
274 SET GLOBAL binlog_transaction_dependency_history_size= DEFAULT;
275 FLUSH LOGS;
276
277 --echo
278 --echo #### Bug#25616372, PART1 ####
279 CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT) ENGINE=NDB; # 0 1
280 INSERT INTO t1 VALUES (null); # 1 2
281 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
282 INSERT INTO t1 VALUES (null); # 1 3
283 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
284 set global binlog_transaction_dependency_tracking=WRITESET;
285 INSERT INTO t1 VALUES (null); # 3 4
286 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
287 INSERT INTO t1 VALUES (null); # 3 5
288 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
289
290 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
291 -- echo Processing binlog $binlog_file
292 --let $source_file= $server_1_datadir/$binlog_file
293 --let $logical_timestamps=0 1;1 2;1 3;3 4;3 5
294 --source include/assert_logical_timestamps.inc
295 FLUSH LOGS;
296
297 --echo
298 --echo #### Bug#25616372, PART2 ####
299 INSERT INTO t1 VALUES (null); # 0 1
300 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
301 INSERT INTO t1 VALUES (null); # 0 2
302 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
303 set global binlog_transaction_dependency_tracking=WRITESET;
304 INSERT INTO t1 VALUES (null); # 2 3
305 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
306 INSERT INTO t1 VALUES (null); # 3 4. # It should be 2 4
307 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
308 INSERT INTO t1 VALUES (null); # 4 5. # It should be 2 5
309 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
310
311 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
312 -- echo Processing binlog $binlog_file
313 --let $source_file= $server_1_datadir/$binlog_file
314 --let $logical_timestamps=0 1;1 2;2 3;2 4;2 5
315 --source include/assert_logical_timestamps.inc
316 DROP TABLE t1;
317 FLUSH LOGS;
318
319
320 --echo
321 --echo #### Bug#26277771, PART1 ####
322 # Bug#26277771 original issue due to missing collation in generating hashes
323 CREATE TABLE t1 (c1 int NOT NULL, c2 varchar(20) NOT NULL, PRIMARY KEY (c1),
324 UNIQUE KEY (c1, c2)) ENGINE=NDB DEFAULT CHARSET=latin1; # 0 1
325 INSERT INTO t1 VALUES (1, 'a'); # 1 2
326 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
327 DELETE FROM t1 WHERE c1=1 AND c2='a'; # 2 3
328 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
329 INSERT INTO t1 VALUES (1, 'A'); # 3 4
330 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
331
332 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
333 -- echo Processing binlog $binlog_file
334 --let $source_file= $server_1_datadir/$binlog_file
335 --let $logical_timestamps=0 1;1 2;2 3;3 4
336 --source include/assert_logical_timestamps.inc
337 DROP TABLE t1;
338 FLUSH LOGS;
339
340 --echo
341 --echo #### Bug#26277771, PART2 ####
342 # Bug#26277771 issue due to wrong string length calculation
343 CREATE TABLE t1 (c1 VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL PRIMARY KEY) ENGINE=NDB; # 0 1
344 INSERT INTO t1 VALUES ('a'); # 1 2
345 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
346 INSERT INTO t1 VALUES ('A'); # 1 3
347 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
348 INSERT INTO t1 VALUES ('b'); # 1 4
349 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
350 INSERT INTO t1 VALUES ('B'); # 1 5
351 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
352
353 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
354 -- echo Processing binlog $binlog_file
355 --let $source_file= $server_1_datadir/$binlog_file
356 --let $logical_timestamps=0 1;1 2;1 3;1 4;1 5
357 --source include/assert_logical_timestamps.inc
358 DROP TABLE t1;
359 FLUSH LOGS;
360
361 --echo
362 --echo #### Bug#26277771, PART3 ####
363 # test for unset charset, padding and null terminaton
364 CREATE TABLE t1 (c1 VARCHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; # 0 1
365 INSERT INTO t1 VALUES ('a'); # 1 2
366 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
367 INSERT INTO t1 VALUES ('b'); # 1 3
368 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
369
370 CREATE TABLE t2 (c1 BINARY(3) NOT NULL PRIMARY KEY) ENGINE=NDB; # 3 4
371 INSERT INTO t2 VALUES ('a'); # 4 5
372 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
373 # copy using strmake will generate same hash for '\0a' and '\0'
374 # as it was copying till null termination character and binary
375 # doesn't consider null as temination character.
376 INSERT INTO t2 VALUES ('\0a'); # 4 6
377 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
378 INSERT INTO t2 VALUES ('\0'); # 4 7
379 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
380 INSERT INTO t2 VALUES ('a '); # 4 8
381 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
382
383 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
384 -- echo Processing binlog $binlog_file
385 --let $source_file= $server_1_datadir/$binlog_file
386 --let $logical_timestamps=0 1;1 2;1 3;3 4;4 5;4 6;4 7;4 8
387 --source include/assert_logical_timestamps.inc
388 DROP TABLE t1;
389 DROP TABLE t2;
390 FLUSH LOGS;
391
392 --echo
393 --echo #### Bug#26277771, PART4 ####
394 CREATE TABLE t1 (c1 varchar(20) NOT NULL PRIMARY KEY)
395 ENGINE=NDB CHARACTER SET utf8 COLLATE utf8_bin; # 0 1
396 INSERT INTO t1 VALUES ('a'); # 1 2
397 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
398 INSERT INTO t1 VALUES ('รก'); # 1 3
399 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
400
401 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
402 --echo Processing binlog $binlog_file
403 --let $source_file= $server_1_datadir/$binlog_file
404 --let $logical_timestamps=0 1;1 2;1 3
405 --source include/assert_logical_timestamps.inc
406 DROP TABLE t1;
407 FLUSH LOGS;
408
409 #
410 # Cleanup
411 #
412 --echo
413 --echo #### CLEANUP ####
414
415 --source include/sync_slave_sql_with_master.inc
416 --source include/stop_slave.inc
417
418 SET @@GLOBAL.replica_parallel_type= @save_replica_parallel_type;
419 --disable_warnings
420 SET @@GLOBAL.replica_parallel_workers= @save_replica_parallel_workers;
421 --enable_warnings
422 SET @@GLOBAL.replica_transaction_retries= @save_replica_transaction_retries;
423
424 --source include/start_slave.inc
425
426 --connection master
427 SET GLOBAL binlog_transaction_dependency_tracking = COMMIT_ORDER;
428 SET @@GLOBAL.binlog_transaction_dependency_tracking= @save_binlog_transaction_dependency_tracking;
429 SET @@GLOBAL.binlog_transaction_dependency_history_size= @save_binlog_transaction_dependency_history_size;
430
431 --source include/rpl_end.inc
432