Debian Codegraph @

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

raw
1 ################################################################################
2 # ==== Purpose ====
3 #
4 # This tests the transaction dependency functionality of ndb_binlog thread,
5 # it's based on the rpl_binlog_transaction_dependency_tracking_with_fk.test
6 # with adaption to how binlogging works for tables in NDB.
7 #
8 # Test referential actions of the foreign keys with different
9 # binlog_transaction_dependency_tracking modes.
10 # Referential actions:
11 # RESTRICT | NO ACTION | CASCADE | SET NULL | SET DEFAULT
12 # Note* Table definition containing SET DEFAULT gets rejected thus not tested.
13 # Modes:
14 # COMMIT_ORDER | WRITESET | WRITESET_SESSION
15 # Note* COMMIT_ORDER is purposefully not tested with this test.
16 #
17 # - NOTE! Since NDB transactions are handled asynchronously, it does not matter
18 # whether a transaction is started before or after the writeset history is
19 # reset by a serial synchronization point (like DDL, log rotation etx).
20 # Rather the conflict occurs when transaction is received by the ndb_binlog
21 # thread and committed in the binlog, this differs from local engines where
22 # transaction started before serial synchronization point is not
23 # conflicting - this primarily affects 10, 11, 12 and subsequent transactions.
24 #
25 # - NOTE2! All NDB transactions are handled and committed by the single
26 # ndb_binlog thread and thus there will always be a conflict with previous
27 # transaction using binlog-transaction-dependency-tracking=WRITESET_SESSION
28 # as well as binlog-transaction-dependency-tracking=COMMIT_ORDER
29 #
30 # ==== Implementation ====
31 # 1. FK parent table:
32 # 1.1. Marked as conflicting with previous transactions.
33 # 1.2. Clears history.
34 # 1.3. Marked as conflicting with later transactions.
35 # 1.4. Falls back to COMMIT_ORDER, so *not* marked as conflicting with previous transactions
36 # committing in parallel.
37 # 1.5. Later transactions fall back to COMMIT_ORDER, so they are *not* marked as conflicting with
38 # this transaction if executing in parallel with it.
39 #
40 # 2. FK child table:
41 # 2.1. Can run in parallel with previous transactions.
42 # 2.2. Does not clear history.
43 # 2.3. Can run in parallel with subsequent transactions.
44 #
45 # 3. All the above is tested with INSERT, UPDATE, and DELETEs.
46 #
47 # 4. All the above is tested with RESTRICT, NO ACTION, CASCADE, SET NULL.
48 #
49 # 5. All the above is tested with ON UPDATE and ON DELETE.
50 #
51 # 6. All the above is tested with WRITESET_SESSION and WRITESET.
52 #
53 # ==== References ====
54 # WL#9556: Writeset-based MTS dependency tracking on master
55 # WL#15145: ndb binlog writeset trans dependencies
56 #
57
58 ################################################################################
59
60 --source include/have_ndb.inc
61 --source include/have_binlog_format_row.inc
62 --source suite/ndb/include/ndb_log_transaction_dependency_enabled.inc
63
64 --let $rpl_extra_connections_per_server= 8
65 --source include/master-slave.inc
66
67 --connection master
68 SET @save_binlog_transaction_dependency_tracking = @@GLOBAL.binlog_transaction_dependency_tracking;
69
70 --let $row_count= 1
71 --let $referential_action= 0
72 # RESTRICT, NO ACTION, CASCADE, SET NULL
73 while ($referential_action < 4)
74 {
75 # WRITESET, WRITESET_SESSION
76 --let $dependency_tracking= 0
77 while ($dependency_tracking < 2)
78 {
79 --connection master
80 if ($referential_action == 0)
81 {
82 --let $ref_action= RESTRICT
83 --let $error_success= ER_ROW_IS_REFERENCED_2
84 }
85 if ($referential_action == 1)
86 {
87 --let $ref_action= NO ACTION
88 --let $error_success= ER_ROW_IS_REFERENCED_2
89 }
90 if ($referential_action == 2)
91 {
92 # Since NDB does not support ON UPDATE CASCADE on primary key parent, the
93 # parent1 table has been extended with a UNIQUE column c
94 --let $ref_action= CASCADE
95 --let $error_success= 0
96 }
97 if ($referential_action == 3)
98 {
99 --let $ref_action= SET NULL
100 --let $error_success= 0
101 }
102
103 --echo
104 if ($dependency_tracking == 0)
105 {
106 SET GLOBAL binlog_transaction_dependency_tracking = WRITESET;
107 --let $text= $row_count. Test referential action $ref_action with WRITESET.
108 }
109 if ($dependency_tracking == 1)
110 {
111 SET GLOBAL binlog_transaction_dependency_tracking = WRITESET_SESSION;
112 --let $text= $row_count. Test referential action $ref_action with WRITESET_SESSION.
113 }
114
115 # Header according to all the parameters.
116 --echo ######## $text ########
117 SELECT @@binlog_transaction_dependency_tracking;
118
119 # In all these 8 cases, behavior should be identical.
120 CREATE TABLE parent1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(50), c INT, UNIQUE(c)) engine = NDB;
121 CREATE TABLE parent2 (a INT NOT NULL PRIMARY KEY, b VARCHAR(50)) engine = NDB;
122 CREATE TABLE t1 (a INT PRIMARY KEY) engine = NDB;
123 eval CREATE TABLE child1 (
124 a INT PRIMARY KEY,
125 b INT,
126 FOREIGN KEY(b) REFERENCES parent1 (c) ON UPDATE $ref_action
127 ) engine = NDB;
128 eval CREATE TABLE child2 (
129 a INT PRIMARY KEY,
130 b INT,
131 FOREIGN KEY(b) REFERENCES parent2 (a) ON DELETE $ref_action
132 ) engine = NDB;
133 INSERT INTO parent1 VALUES (1, 1, 1), (2, 2, 2);
134 INSERT INTO parent2 VALUES (1, 1), (2, 2);
135 FLUSH LOGS;
136
137 --echo # Case 2.1, 2.2, 2.3
138 # [0 1]
139 --connection server_1_1
140 INSERT INTO child1 VALUES (1, 1);
141 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
142
143 # [1 2]
144 --connection server_1_2
145 INSERT INTO child2 VALUES (1, 1);
146 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
147
148 # [1 3]
149 --connection server_1_1
150 UPDATE child1 SET a = 2;
151 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
152
153 # [2 4]
154 --connection server_1_2
155 UPDATE child2 SET a = 2;
156 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
157
158 # [3 5]
159 --connection server_1_1
160 DELETE FROM child1;
161 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
162
163 # [4 6]
164 --connection server_1_2
165 DELETE FROM child2;
166 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
167
168 --echo # Case 1.1, 1.2, 1.3
169 # [1 7]
170 --connection server_1_3
171 INSERT INTO t1 VALUES (1);
172 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
173
174 # [7 8]
175 --connection server_1_4
176 INSERT INTO parent1 VALUES (3, 3, 3);
177 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
178
179 # [8 9]
180 --connection server_1_5
181 INSERT INTO t1 VALUES (2);
182 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
183
184 --echo # Case 1.4, 1.5
185 # [8 10]
186 --connection server_1_6
187 BEGIN;
188 INSERT INTO t1 VALUES (3);
189 INSERT INTO child1 VALUES (1, 1);
190 # [9 11]
191 --connection server_1_7
192 BEGIN;
193 INSERT INTO parent1 VALUEs (4, 4, 4);
194 INSERT INTO child2 VALUES (1, 1);
195 # [9 12]
196 --connection server_1_8
197 BEGIN;
198 INSERT INTO t1 VALUES (4);
199 # Commit the above.
200 --connection server_1_6
201 COMMIT;
202 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
203 --connection server_1_7
204 COMMIT;
205 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
206 --connection server_1_8
207 COMMIT;
208 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
209
210 # [11 13] Verify again that history is cleared
211 --connection server_1_1
212 INSERT INTO t1 VALUES (5);
213 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
214
215 # [13 14] With CASCADE and SET NULL
216 --connection server_1_2
217 --error $error_success
218 UPDATE parent1 SET c=5 WHERE a=1;
219 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
220
221 # [14 15] With CASCADE and SET NULL
222 --connection server_1_3
223 --error $error_success
224 DELETE FROM parent2 WHERE a=1;
225 --source suite/ndb/include/ndb_binlog_wait_own_changes.inc
226
227 --echo # Drop table and flush logs to force binlog to rotate
228 --connection master
229 DROP TABLE child2, parent2, child1, parent1, t1;
230
231 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
232 FLUSH LOGS;
233
234 --echo # Processing binlog...
235 # For RESTRICT and NO ACTION
236 --let $logical_timestamps=0 1;1 2;1 3;2 4;3 5;4 6;1 7;7 8;8 9;8 10;10 11;11 12;11 13;13 14
237 if ($dependency_tracking == 1)
238 {
239 # WRITESET_SESSION -> always depend on previous
240 --let $logical_timestamps=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;13 14
241 }
242 if ($referential_action >= 2)
243 {
244 # For CASCADE and SET NULL
245 --let $logical_timestamps=0 1;1 2;1 3;2 4;3 5;4 6;1 7;7 8;8 9;8 10;10 11;11 12;11 13;13 14;14 15;15 16
246 if ($dependency_tracking == 1)
247 {
248 # WRITESET_SESSION -> always depend on previous
249 --let $logical_timestamps=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;13 14;14 15;15 16
250 }
251 }
252 --source include/assert_logical_timestamps.inc
253
254 --echo # Verify that replication is correct
255 --source include/sync_slave_sql_with_master.inc
256
257 --inc $dependency_tracking
258 --inc $row_count
259 }
260 --inc $referential_action
261 }
262
263 --echo
264 --echo # Clean up
265 --connection master
266 SET @@GLOBAL.binlog_transaction_dependency_tracking= @save_binlog_transaction_dependency_tracking;
267
268 --source include/rpl_end.inc