Debian Codegraph @

mysql-test/suite/binlog_gtid/t/binlog_xa_empty_rollback.test

raw
1 # ==== Requirements ====
2 #
3 # R1. When '@@SESSION.GTID_NEXT' is set to 'AUTOMATIC', an XA empty
4 # transaction, ended with 'XA ROLLBACK', should not log anything to the
5 # binlog and should not add to GTID_EXECUTED.
6 # R2. When '@@SESSION.GTID_NEXT' is set to a specific UUID, an XA empty
7 # transaction, ended with 'XA ROLLBACK', should not log anything to the
8 # binlog and should not add to GTID_EXECUTED.
9 # R3. Above requirements should hold at any time and with any XA related
10 # sequence of commands.
11 # R4. A non-empty XA transaction ended with XA ROLLBACK statement MUST
12 # both log to the binlog and add GTID_NEXT to GTID_EXECUTED.
13 #
14 # ==== Implementation ====
15 #
16 # USE-CASE 1 - rollback empty transaction as first statement and GTID_NEXT
17 # set to autotmatic:
18 # S1. Set GTID_NEXT to 'AUTOMATIC'.
19 # S2. Start and end an XA transaction.
20 # S3. Rollback the XA transaction.
21 # S4. Check binlog for related event (should not be found).
22 # S5. Check for an unchanged GTID_EXECUTED set.
23 #
24 # USE-CASE 2 - rollback empty transaction as first statement and GTID_NEXT
25 # set to specific UUID:
26 # S1. Set GTID_NEXT to a specific UUID.
27 # S2. Start and end an XA transaction.
28 # S3. Rollback the XA transaction.
29 # S4. Check binlog for related event (should not be found).
30 # S5. Check GTID_EXECUTED for the specific UUID (should not be found).
31 #
32 # USE-CASE 3 - start with GTID_NEXT set to a specific UUID and rollback empty
33 # transaction after XA COMMIT ... ONE PHASE and GTID_NEXT set to a specific
34 # UUID:
35 # S1. Set GTID_NEXT to a specific UUID.
36 # S2. Start and end an XA transaction.
37 # S3. Commit the XA transaction with 'XA COMMIT ... ONE PHASE'.
38 # S4. Set GTID_NEXT to a specific UUID.
39 # S5. Start and end an XA transaction.
40 # S6. Rollback the XA transaction.
41 # S7. Check binlog for related event (should not be found).
42 # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
43 #
44 # USE-CASE 4 - start with GTID_NEXT set to 'AUTOMATIC' and rollback empty
45 # transaction after XA COMMIT ... ONE PHASE and GTID_NEXT set to a specific
46 # UUID:
47 # S1. Set GTID_NEXT to 'AUTOMATIC'.
48 # S2. Start and end an XA transaction.
49 # S3. Commit the XA transaction with 'XA COMMIT ... ONE PHASE'.
50 # S4. Set GTID_NEXT to a specific UUID.
51 # S5. Start and end an XA transaction.
52 # S6. Rollback the XA transaction.
53 # S7. Check binlog for related event (should not be found).
54 # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
55 #
56 # USE-CASE 5 - rollback empty transaction after XA PREPARE and XA COMMIT and
57 # GTID_NEXT set to a specific UUID:
58 # S1. Set GTID_NEXT to a 'AUTOMATIC'.
59 # S2. Start and end an XA transaction.
60 # S3. Commit the XA transaction with 'XA PREPARE' and 'XA COMMIT'.
61 # S4. Set GTID_NEXT to a specific UUID.
62 # S5. Start and end an XA transaction.
63 # S6. Rollback the XA transaction.
64 # S7. Check binlog for related event (should not be found).
65 # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
66 #
67 # USE-CASE 6 - ensure that non-empty XA transactions are logged and
68 # GITD-executed even if they are rolled back with XA ROLLBACK:
69 # S1. Create a table
70 # S2. Set GTID_NEXT to a 'AUTOMATIC'.
71 # S3. Start an XA transaction.
72 # s4. Insert values into created table.
73 # S5. End the XA transaction.
74 # s6. Prepare the XA transaction.
75 # S7. Rollback the XA transaction.
76 # S8. Check binlog for related event (should be found).
77 # S9. Check GTID_EXECUTED for the executed UUID (should not be found).
78 #
79 # ==== References ====
80 #
81 # BUG#27041402: ASSERTION `NEW_VALUE >= 0' FAILED.
82 # BUG#27435974: XA ROLLBACK GETS BINLOGGED AFTER 'XA COMMIT ONE PHASE' GTID
83 # BUG#27407670: XA + GTID_NEXT: XA ROLLBACK IS COUNTED IN GTID_EXECUTED BUT WITHOUT BINLOG INFO
84 #
85
86 --source include/have_binlog_format_row.inc
87
88 RESET MASTER;
89
90 --echo #
91 --echo # USE-CASE 1 - rollback empty transaction as first statement and GTID_NEXT
92 --echo # set to autotmatic:
93 --echo #
94
95 --let $gtid_executed_count= `SELECT COUNT(*) FROM mysql.gtid_executed`
96
97 --source include/save_binlog_position.inc
98 --let $pre_commit_position= $binlog_position
99 --echo #
100 --echo # S1. Set GTID_NEXT to 'AUTOMATIC'.
101 --echo #
102 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
103 --echo #
104 --echo # S2. Start and end an XA transaction.
105 --echo #
106 XA START 'trx';
107 XA END 'trx';
108 --echo #
109 --echo # S3. Rollback the XA transaction.
110 --echo #
111 XA ROLLBACK 'trx';
112
113 --echo #
114 --echo # S4. Check binlog for related event (should not be found).
115 --echo #
116 --source include/save_binlog_position.inc
117 --let $assert_cond= $pre_commit_position = $binlog_position
118 --let $assert_text= Empty transaction, binlog position is the same
119 --source include/assert.inc
120
121 --echo #
122 --echo # S5. Check for an unchanged GTID_EXECUTED set.
123 --echo #
124 --let $assert_cond= [SELECT COUNT(*) FROM mysql.gtid_executed] = $gtid_executed_count
125 --let $assert_text= GTID_EXECUTED has not changed
126 --source include/assert.inc
127
128 --echo #
129 --echo # USE-CASE 2 - rollback empty transaction as first statement and GTID_NEXT
130 --echo # set to specific UUID:
131 --echo #
132
133 --source include/save_binlog_position.inc
134 --let $pre_commit_position= $binlog_position
135 --echo #
136 --echo # S1. Set GTID_NEXT to a specific UUID.
137 --echo #
138 SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1';
139 --echo #
140 --echo # S2. Start and end an XA transaction.
141 --echo #
142 XA START 'trx';
143 XA END 'trx';
144 --echo #
145 --echo # S3. Rollback the XA transaction.
146 --echo #
147 XA ROLLBACK 'trx';
148 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
149
150 --echo #
151 --echo # S4. Check binlog for related event (should not be found).
152 --echo #
153 --source include/save_binlog_position.inc
154 --let $assert_cond= $pre_commit_position = $binlog_position
155 --let $assert_text= Empty transaction, binlog position is the same
156 --source include/assert.inc
157
158 --echo #
159 --echo # S5. Check GTID_EXECUTED for the specific UUID (should not be found).
160 --echo #
161 --let $assert_cond= [SELECT GTID_SUBSET("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1", @@GLOBAL.GTID_EXECUTED)] = 0
162 --let $assert_text= Transaction is NOT present in GTID_EXECUTED
163 --source include/assert.inc
164
165 --echo #
166 --echo # USE-CASE 3 - start with GTID_NEXT set to a specific UUID and rollback empty
167 --echo # transaction after XA COMMIT ... ONE PHASE and GTID_NEXT set to a specific
168 --echo # UUID:
169 --echo #
170
171 --echo #
172 --echo # S1. Set GTID_NEXT to a specific UUID.
173 --echo #
174 SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2';
175 --echo #
176 --echo # S2. Start and end an XA transaction.
177 --echo #
178 XA START 'trx';
179 XA END 'trx';
180 --echo #
181 --echo # S3. Commit the XA transaction with 'XA COMMIT ... ONE PHASE'.
182 --echo #
183 XA COMMIT 'trx' ONE PHASE;
184
185 --source include/save_binlog_position.inc
186 --let $pre_commit_position= $binlog_position
187 --echo #
188 --echo # S4. Set GTID_NEXT to a specific UUID.
189 --echo #
190 SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3';
191 --echo #
192 --echo # S5. Start and end an XA transaction.
193 --echo #
194 XA START 'trx';
195 XA END 'trx';
196 --echo #
197 --echo # S6. Rollback the XA transaction.
198 --echo #
199 XA ROLLBACK 'trx';
200 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
201
202 --echo #
203 --echo # S7. Check binlog for related event (should not be found).
204 --echo #
205 --source include/save_binlog_position.inc
206 --let $assert_cond= $pre_commit_position = $binlog_position
207 --let $assert_text= Empty transaction, binlog position is the same
208 --source include/assert.inc
209
210 --echo #
211 --echo # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
212 --echo #
213 --let $assert_cond= [SELECT GTID_SUBSET("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3", @@GLOBAL.GTID_EXECUTED)] = 0
214 --let $assert_text= Transaction is NOT present in GTID_EXECUTED
215 --source include/assert.inc
216
217 --echo #
218 --echo # USE-CASE 4 - start with GTID_NEXT set to 'AUTOMATIC' and rollback empty
219 --echo # transaction after XA COMMIT ... ONE PHASE and GTID_NEXT set to a specific
220 --echo # UUID:
221 --echo #
222
223 --echo #
224 --echo # S1. Set GTID_NEXT to 'AUTOMATIC'.
225 --echo #
226 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
227 --echo #
228 --echo # S2. Start and end an XA transaction.
229 --echo #
230 XA START 'trx';
231 XA END 'trx';
232 --echo #
233 --echo # S3. Commit the XA transaction with 'XA COMMIT ... ONE PHASE'.
234 --echo #
235 XA COMMIT 'trx' ONE PHASE;
236
237 --source include/save_binlog_position.inc
238 --let $pre_commit_position= $binlog_position
239 --echo #
240 --echo # S4. Set GTID_NEXT to a specific UUID.
241 --echo #
242 SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4';
243 --echo #
244 --echo # S5. Start and end an XA transaction.
245 --echo #
246 XA START 'trx';
247 XA END 'trx';
248 --echo #
249 --echo # S6. Rollback the XA transaction.
250 --echo #
251 XA ROLLBACK 'trx';
252 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
253
254 --echo #
255 --echo # S7. Check binlog for related event (should not be found).
256 --echo #
257 --source include/save_binlog_position.inc
258 --let $assert_cond= $pre_commit_position = $binlog_position
259 --let $assert_text= Empty transaction, binlog position is the same
260 --source include/assert.inc
261
262 --echo #
263 --echo # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
264 --echo #
265 --let $assert_cond= [SELECT GTID_SUBSET("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4", @@GLOBAL.GTID_EXECUTED)] = 0
266 --let $assert_text= Transaction is NOT present in GTID_EXECUTED
267 --source include/assert.inc
268
269 --echo #
270 --echo # USE-CASE 5 - rollback empty transaction after XA PREPARE and XA COMMIT and
271 --echo # GTID_NEXT set to a specific UUID:
272 --echo #
273
274 --echo #
275 --echo # S1. Set GTID_NEXT to 'AUTOMATIC'.
276 --echo #
277 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
278 --echo #
279 --echo # S2. Start and end an XA transaction.
280 --echo #
281 XA START 'trx';
282 XA END 'trx';
283 --echo #
284 --echo # S3. Commit the XA transaction with 'XA PREPARE' and 'XA COMMIT'.
285 --echo #
286 XA PREPARE 'trx';
287 XA COMMIT 'trx';
288
289 --source include/save_binlog_position.inc
290 --let $pre_commit_position= $binlog_position
291 --echo #
292 --echo # S4. Set GTID_NEXT to a specific UUID.
293 --echo #
294 SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:5';
295 --echo #
296 --echo # S5. Start and end an XA transaction.
297 --echo #
298 XA START 'trx';
299 XA END 'trx';
300 --echo #
301 --echo # S6. Rollback the XA transaction.
302 --echo #
303 XA ROLLBACK 'trx';
304 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
305
306 --echo #
307 --echo # S7. Check binlog for related event (should not be found).
308 --echo #
309 --source include/save_binlog_position.inc
310 --let $assert_cond= $pre_commit_position = $binlog_position
311 --let $assert_text= Empty transaction, binlog position is the same
312 --source include/assert.inc
313
314 --echo #
315 --echo # S8. Check GTID_EXECUTED for the specific UUID (should not be found).
316 --echo #
317 --let $assert_cond= [SELECT GTID_SUBSET("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:5", @@GLOBAL.GTID_EXECUTED)] = 0
318 --let $assert_text= Transaction is NOT present in GTID_EXECUTED
319 --source include/assert.inc
320
321 --echo #
322 --echo # USE-CASE 6 - ensure that non-empty XA transactions are logged and
323 --echo # GITD-executed even if they are rolled back with XA ROLLBACK:
324 --echo #
325
326 --echo #
327 --echo # S1. Create a table
328 --echo #
329 CREATE TABLE t (a INT);
330
331 --echo #
332 --echo # S2. Set GTID_NEXT to a 'AUTOMATIC'.
333 --echo #
334 SET @@SESSION.GTID_NEXT= 'AUTOMATIC';
335
336 --echo #
337 --echo # S3. Start an XA transaction.
338 --echo #
339 XA START 'trx';
340
341 --echo #
342 --echo # s4. Insert values into created table.
343 --echo #
344 INSERT INTO t VALUES (1), (2), (3);
345
346 --echo #
347 --echo # S5. End the XA transaction.
348 --echo #
349 XA END 'trx';
350
351 --echo #
352 --echo # S6. Prepare the XA transaction.
353 --echo #
354 XA PREPARE 'trx';
355
356 --echo #
357 --echo # S7. Rollback the XA transaction.
358 --echo #
359 XA ROLLBACK 'trx';
360
361 --echo #
362 --echo # S8. Check binlog for related event (should be found).
363 --echo #
364
365 --let $event_sequence= Gtid/SET.* # Query/use.* # Gtid/SET.* # Query/XA START.* # Table_map/.* # Write_rows/.* # Query/XA END.* # XA_prepare/XA PREPARE.* # Gtid/SET.* # Query/XA ROLLBACK.*
366 --source include/assert_binlog_events.inc
367
368 --echo #
369 --echo # S9. Check GTID_EXECUTED for the executed UUID (should be found).
370 --echo #
371 --let $event_no = 13
372 if (`SELECT @@session.binlog_transaction_compression`)
373 {
374 --let $event_no = 14
375 }
376 --let $gtid_set= query_get_value("SHOW BINLOG EVENTS LIMIT $event_no,1", Info, 1)
377 --let $gtid_split= `SELECT SUBSTRING_INDEX("$gtid_set", "'", -2)`
378 --let $gtid= `SELECT SUBSTRING_INDEX("$gtid_split", "'", 1)`
379
380 --replace_result $gtid GTID
381 --let $assert_cond= [SELECT GTID_SUBSET("$gtid", @@GLOBAL.GTID_EXECUTED)] != 0
382 --let $assert_text= Transaction is present in GTID_EXECUTED
383 --source include/assert.inc
384
385 DROP TABLE t;