Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # The purpose of this test is to check that crashing the server while there
4 # are several XA transactions executing up until several points of `XA
5 # PREPARE/COMMIT/ROLLBACK` statements, will result in consistency between
6 # SE and TC after recovery is finished.
7 #
8 # ==== Requirements ====
9 #
10 # R1. When crashing in the middle of an XA transaction and after recovery,
11 # storage engine and transaction coordinator MUST be in sync.
12 #
13 # For a more detailed list of requirements for the expected state for each
14 # of the sync points, check the `Requirements` section for the tests listed
15 # in `Related tests` section of `extra/xa_crash_safe_tests/setup.inc`.
16 #
17 # ==== Implementation ====
18 #
19 # 1) Execute several `XA PREPARE` statements up until:
20 # a) Before preparing in the SEs.
21 # b) Before preparing in the TC.
22 # c) Before setting the transaction as prepared in TC.
23 # d) After writing to the TC log.
24 # 2) Kill the server and restart it.
25 # 3) Check that:
26 # a) SE recovery rolled back the transaction executed in 1.a)
27 # b) XA recovery rolled back the transaction executed in 1.b)
28 # c) XA recovery left in prepared state transaction executed in 1.b) and
29 # 1.c)
30 # 4) Clean up pending transactions
31 # 5) Execute several `XA COMMIT` statements up until:
32 # a) Before starting the commit process.
33 # b) Before invoking the before commit hook.
34 # c) Before committing in SEs.
35 # 6) Kill the server and restart it.
36 # 7) Check that:
37 # a) XA recovery left in prepared state transaction executed in 5.a) and
38 # 5.b)
39 # b) XA recovery committed the transaction executed in 5.c)
40 # 8) Clean up pending transactions
41 # 9) Execute several `XA ROLLBACK` statements up until:
42 # a) Before starting the rollback process.
43 # b) Before invoking the before commit hook.
44 # c) Before rolling back in SEs.
45 # 10) Kill the server and restart it.
46 # 11) Check that:
47 # a) XA recovery left in prepared state transaction executed in 9.a) and
48 # 9.b)
49 # b) XA recovery rlled back the transaction executed in 9.c)
50 # 12) Clean up pending transactions
51 # 13) Execute several `XA COMMIT ... ONE PHASE` statements up until:
52 # a) Before preparing in SEs.
53 # b) Before invoking the before commit hook.
54 # c) Before committing in SEs.
55 # 14) Kill the server and restart it.
56 # 15) Check that:
57 # a) SE recovery rolled back the transaction executed in 13.a)
58 # b) XA recovery rolled back the transaction executed in 13.b)
59 # c) XA recovery committed transaction executed in 13.c)
60 #
61 # ==== References ====
62 #
63 # WL#11300: Crash-safe XA + binary log
64 #
65 # Related tests;
66 # see extra/xa_crash_safe_tests/setup.inc
67 #
68 --source include/have_binlog_format_row.inc
69 --source include/not_valgrind.inc
70 --source include/have_debug.inc
71 --source include/have_debug_sync.inc
72 # Sync point `after_writing_to_tc_log` only exercised when BCG is enabled
73 --let $option_name = binlog_order_commits
74 --let $option_value = 1
75 --source include/only_with_option.inc
76
77 --let $xid = 'xid0'
78 --source extra/xa_crash_safe_tests/setup.inc
79 # Include $exec_xa_transaction_body and $clean_up_xa_transactions
80 --source extra/xa_crash_safe_tests/utility_functions.inc
81
82 # 1) Execute several `XA PREPARE` statements up until:
83 --let $iteration = 1
84 while ($iteration != 5) {
85 --source $exec_xa_transaction_body
86 --let $timestamp = $iteration
87 --let $auxiliary_connection = default
88 --let $statement_connection = con$iteration
89 --let $statement = XA PREPARE $xid
90 # 1.a) Before preparing in the SEs.
91 if ($iteration == 1) {
92 --let $sync_point = before_prepare_in_engines
93 }
94 # 1.b) Before preparing in the TC.
95 if ($iteration == 2) {
96 --let $sync_point = after_ha_prepare_low
97 }
98 # 1.c) Before setting the transaction as prepared in TC.
99
100 if ($iteration == 3) {
101 --let $sync_point = before_set_prepared_in_tc
102 }
103 # 1.d) After writing to the TC log.
104 #
105 if ($iteration == 4) {
106 --let $sync_point = after_writing_to_tc_log
107 }
108 --source include/execute_to_conditional_timestamp_sync_point.inc
109 --disconnect con$iteration
110 --inc $iteration
111 }
112
113 # 2) Kill the server and restart it.
114 --connection default
115 --source include/kill_mysqld.inc
116 --source include/start_mysqld.inc
117
118 # 3) Check that:
119 # 3.a) SE recovery rolled back the transaction executed in 1.a)
120 #
121 --let $assert_select = Rolling back trx with id %, 1 rows to undo
122 --source extra/xa_crash_safe_tests/assert_se_recovery_message.inc
123
124 # 3.b) XA recovery rolled back the transaction executed in 1.b)
125 # 3.c) XA recovery left in prepared state transaction executed in 1.b) and
126 # 1.c)
127 --let $assert_select = Successfully rolled back 1, prepared 2 XA transaction
128 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
129
130 --let $expected_prepared_xa_count = 2
131 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
132
133 # 4) Clean up pending transactions
134 #
135 --let $start = 3
136 --let $stop = 5
137 --source $clean_up_xa_transactions
138
139 # 5) Execute several `XA COMMIT` statements up until:
140 #
141 while ($iteration != 8) {
142 --source $exec_xa_transaction_body
143 --eval XA PREPARE $xid
144 --let $timestamp = $iteration
145 --let $auxiliary_connection = default
146 --let $statement_connection = con$iteration
147 --let $statement = XA COMMIT $xid
148
149 # 5.a) Before starting the commit process.
150 #
151 if ($iteration == 5) {
152 --let $sync_point = before_commit_xa_trx
153 }
154 # 5.b) Before invoking the before commit hook.
155 #
156 if ($iteration == 6) {
157 --let $sync_point = before_invoke_before_commit_hook
158 }
159 # 5.c) Before committing in SEs.
160 #
161 if ($iteration == 7) {
162 --let $sync_point = before_commit_in_engines
163 }
164 --source include/execute_to_conditional_timestamp_sync_point.inc
165 --disconnect con$iteration
166 --inc $iteration
167 }
168
169 # 6) Kill the server and restart it.
170 #
171 --connection default
172 --source include/kill_mysqld.inc
173 --source include/start_mysqld.inc
174
175 # 7) Check that:
176 # 7.a) XA recovery left in prepared state transaction executed in 5.a) and
177 # 5.b)
178 # 7.b) XA recovery committed the transaction executed in 5.c)
179 #
180 --let $assert_select = Successfully committed 1, prepared 2 XA transaction
181 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
182 --let $expected_prepared_xa_count = 2
183 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
184
185 # 8) Clean up pending transactions
186 #
187 --let $start = 5
188 --let $stop = 7
189 --source $clean_up_xa_transactions
190
191 # 9) Execute several `XA ROLLBACK` statements up until:
192 #
193 while ($iteration != 11) {
194 --source $exec_xa_transaction_body
195 --eval XA PREPARE $xid
196 --let $timestamp = $iteration
197 --let $auxiliary_connection = default
198 --let $statement_connection = con$iteration
199 --let $statement = XA ROLLBACK $xid
200
201 # 9.a) Before starting the rollback process.
202 #
203 if ($iteration == 8) {
204 --let $sync_point = before_rollback_xa_trx
205 }
206 # 9.b) Before invoking the before commit hook.
207 #
208 if ($iteration == 9) {
209 --let $sync_point = before_invoke_before_commit_hook
210 }
211 # 9.c) Before rolling back in SEs.
212 #
213 if ($iteration == 10) {
214 --let $sync_point = before_rollback_in_engines
215 }
216 --source include/execute_to_conditional_timestamp_sync_point.inc
217 --disconnect con$iteration
218 --inc $iteration
219 }
220
221 # 10) Kill the server and restart it.
222 #
223 --connection default
224 --source include/kill_mysqld.inc
225 --source include/start_mysqld.inc
226
227 # 11) Check that:
228 # 11.a) XA recovery left in prepared state transaction executed in 9.a) and
229 # 9.b)
230 # 11.b) XA recovery rlled back the transaction executed in 9.c)
231 #
232 --let $assert_select = Successfully rolled back 1, prepared 2 XA transaction
233 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
234 --let $expected_prepared_xa_count = 2
235 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
236
237 # 12) Clean up pending transactions
238 #
239 --let $start = 8
240 --let $stop = 10
241 --source $clean_up_xa_transactions
242
243 # 13) Execute several `XA COMMIT ... ONE PHASE` statements up until:
244 #
245 while ($iteration != 14) {
246 --source $exec_xa_transaction_body
247 --let $timestamp = $iteration
248 --let $auxiliary_connection = default
249 --let $statement_connection = con$iteration
250 --let $statement = XA COMMIT $xid ONE PHASE
251
252 # 13.a) Before preparing in SEs.
253 #
254 if ($iteration == 11) {
255 --let $sync_point = before_prepare_in_engines
256 }
257 # 13.b) Before invoking the before commit hook.
258 #
259 if ($iteration == 12) {
260 --let $sync_point = before_invoke_before_commit_hook
261 }
262 # 13.c) Before committing in SEs.
263 #
264 if ($iteration == 13) {
265 --let $sync_point = before_commit_in_engines
266 }
267 --source include/execute_to_conditional_timestamp_sync_point.inc
268 --disconnect con$iteration
269 --inc $iteration
270 }
271
272 # 14) Kill the server and restart it.
273 #
274 --connection default
275 --source include/kill_mysqld.inc
276 --source include/start_mysqld.inc
277
278 # 15) Check that:
279 #
280 # 15.a) SE recovery rolled back the transaction executed in 13.a)
281 #
282 --let $assert_select = Rolling back trx with id %, 1 rows to undo
283 --source extra/xa_crash_safe_tests/assert_se_recovery_message.inc
284
285 # 15.b) XA recovery rolled back the transaction executed in 13.b)
286 # 15.c) XA recovery committed transaction executed in 13.c)
287 #
288 --let $assert_select = Successfully committed 1, rolled back 1 XA transaction
289 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
290 --let $expected_prepared_xa_count = 0
291 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
292
293 --connection default
294 DROP TABLE t1;
295 --source extra/xa_crash_safe_tests/end_utility_functions.inc