Debian Codegraph @

mysql-test/suite/group_replication/t/gr_xa_rollback_failure_after_rotate.test

raw
1 # ==== Purpose ====
2 #
3 # This script tests server behavior when a crash occurs during the
4 # execution of `XA ROLLBACK`, after binary log has been rotated (`XA
5 # PREPARED` is no longer in the latest binary log file).
6 #
7 # ==== Requirements ====
8 #
9 # Pre-conditions:
10 # PC1. GR single-primary topology with 3 servers.
11 #
12 # After server restart:
13 # R1. The `XA PREPARE` statement shouldn't be found in the binlog.
14 # R2. The `XA ROLLBACK` statement shouldn't be found in the binlog.
15 # R3. There shouldn't be any changes to GTID_EXECUTED.
16 # R4. There should be one pending XA transactions visible with `XA
17 # RECOVER`.
18 # R5. There should still be one pending XA transaction visible with `XA
19 # RECOVER`, on crashed server, if server is restarted after the
20 # crash-recovery.
21 #
22 # ==== Implementation ====
23 #
24 # 1. Setup scenario: setup GR, create table and insert some records.
25 # 2. Start and execute an XA transaction containing an insert until before
26 # `XA ROLLBACK`.
27 # 3. Take the `GTID_EXECUTED` state.
28 # 4. Rotate and purge binary logs.
29 # 5. Crash the primary during `XA ROLLBACK` execution, before commiting in the
30 # TC.
31 # 6. Restart server 1 (former primary) and check:
32 # a. Error log for messages stating that recovery process found one
33 # transaction needing recovery.
34 # b. The `XA PREPARE` and `XA ROLLBACK` aren't found in the binary log.
35 # c. The GTID_EXECUTED variable wasn't updated.
36 # d. There is one pending XA transaction listed in the output of `XA
37 # RECOVER`.
38 # e. There aren't changes to the table.
39 # 7. On server 2, check:
40 # a. The `XA PREPARE` is and the `XA ROLLBACK` isn't present in the
41 # binary log.
42 # b. There is one pending XA transaction listed in the output of `XA
43 # RECOVER`.
44 # c. There aren't changes to the table.
45 # 8. Restart server 1 and check that the transaction is still in preared
46 # state, meaning, the recovery process moved the transaction to
47 # `PERSISTED_IN_TC` and that state was persisted.
48 # 9. Re-join server 1 (former primary) to the group.
49 # 10. On server 1, check state after distributed recovery:
50 # a. The `XA PREPARE` isn't found in the binary log.
51 # b. There is one pending XA transaction listed in the output of `XA
52 # RECOVER`.
53 # 11. Rollback the transaction on primary.
54 # 12. Check table wasn't updated on server 1.
55 #
56 # ==== References ====
57 #
58 # WL#11300: Crash-safe XA + binary log
59 #
60 # Related tests:
61 # see extra/xa_crash_safe_tests/setup.inc
62 #
63 --source include/not_valgrind.inc
64 --source include/have_debug.inc
65 --source include/have_debug_sync.inc
66 --source include/have_group_replication_plugin.inc
67 --let $rpl_group_replication_single_primary_mode =1
68 --let $rpl_skip_group_replication_start = 1
69 --let $rpl_server_count = 3
70 --source include/group_replication.inc
71
72 # 1. Setup scenario: setup GR, create table and insert some records.
73 #
74 --let $rpl_connection_name = server1
75 --source include/rpl_connection.inc
76 --let $xid_data = xid1
77 --let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
78 --source extra/xa_crash_safe_tests/setup.inc
79
80 # 2. Start and execute an XA transaction containing an insert until before
81 # `XA ROLLBACK`.
82 #
83 --connect(con1, localhost, root,,)
84 --connection con1
85 --eval XA START $xid
86 INSERT INTO t1 VALUES (1);
87 --eval XA END $xid
88 --eval XA PREPARE $xid
89
90 # 3. Take the `GTID_EXECUTED` state.
91 #
92 --let $rpl_connection_name = server1
93 --source include/rpl_connection.inc
94 --source include/rpl_sync.inc
95 --let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
96
97 # 4. Rotate and purge binary logs.
98 #
99 FLUSH LOGS;
100 --replace_result $binlog_file BINLOG_FILE
101 --eval PURGE BINARY LOGS TO '$binlog_file'
102 --source include/save_binlog_position.inc
103
104 # 5. Crash the primary during `XA ROLLBACK` execution, before commiting in the
105 # TC.
106 #
107 --let $auxiliary_connection = server1
108 --let $statement_connection = con1
109 --let $statement = XA ROLLBACK $xid
110 --let $sync_point = before_rollback_xa_trx
111 --source include/execute_to_conditional_timestamp_sync_point.inc
112 --source include/kill_mysqld.inc
113 --source extra/xa_crash_safe_tests/cleanup_connection.inc
114
115 --let $rpl_connection_name = server2
116 --source include/rpl_connection.inc
117 --let $group_replication_number_of_members = 2
118 --source include/gr_wait_for_number_of_members.inc
119
120 # 6. Restart server 1 (former primary) and check:
121 #
122 --let $restart_parameters = restart:--group_replication_local_address=$_group_replication_local_address --group_replication_group_seeds=$_group_replication_group_seeds --group_replication_group_name=$_group_replication_group_name --group_replication_start_on_boot=OFF --group_replication_single_primary_mode=TRUE --group_replication_enforce_update_everywhere_checks=FALSE
123 --replace_result $_group_replication_local_address GROUP_REPLICATION_LOCAL_ADDRESS $_group_replication_group_seeds GROUP_REPLICATION_GROUP_SEEDS $_group_replication_group_name GROUP_REPLICATION_GROUP_NAME
124 --source include/start_mysqld.inc
125 --let $rpl_server_number = 1
126 --source include/rpl_reconnect.inc
127
128 --let $rpl_connection_name = server1
129 --source include/rpl_connection.inc
130
131 # 6.a. Error log for messages stating that recovery process found one
132 # transaction needing recovery.
133 #
134 --let $assert_select = Successfully prepared 1 XA transaction
135 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
136
137 # 6.b. The `XA PREPARE` and `XA ROLLBACK` aren't found in the binary log.
138 #
139 --let $event_sequence = $empty_event_sequence
140 --source include/assert_binlog_events.inc
141
142 # 6.c. The GTID_EXECUTED variable wasn't updated.
143 #
144 --let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
145 --let $assert_text = GTID_EXECUTED has not been updated
146 --let $assert_cond = "$before_gtid_executed" = "$after_gtid_executed"
147 --source include/assert.inc
148
149 # 6.d. There is one pending XA transaction listed in the output of `XA
150 # RECOVER`.
151 #
152 --let $expected_prepared_xa_count = 1
153 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
154
155 # 6.e. There aren't changes to the table.
156 #
157 --let $expected_row_count = 1
158 --source extra/xa_crash_safe_tests/assert_row_count.inc
159
160 # 7. On server 2, check:
161 #
162 --let $rpl_connection_name = server2
163 --source include/rpl_connection.inc
164
165 # 7.a. The `XA PREPARE` is and the `XA ROLLBACK` isn't present in the
166 # binary log.
167 #
168 --let $binlog_file = `SELECT @binlog_file`
169 --let $binlog_position = `SELECT @binlog_position`
170 --let $event_sequence = $view_change # Gtid # $xa_start_end # XA_prepare/XA PREPARE $xid
171 --source include/assert_binlog_events.inc
172
173 # 7.b. There is one pending XA transaction listed in the output of `XA
174 # RECOVER`.
175 --let $expected_prepared_xa_count = 1
176 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
177
178 # 7.c. There aren't changes to the table.
179 #
180 --let $expected_row_count = 1
181 --source extra/xa_crash_safe_tests/assert_row_count.inc
182
183 # 8. Restart server 1 and check that the transaction is still in preared
184 # state, meaning, the recovery process moved the transaction to
185 # `PERSISTED_IN_TC` and that state was persisted.
186 #
187 --let $rpl_connection_name = server1
188 --source include/rpl_connection.inc
189
190 --let $allow_rpl_inited = 1
191 --replace_result $_group_replication_local_address GROUP_REPLICATION_LOCAL_ADDRESS $_group_replication_group_seeds GROUP_REPLICATION_GROUP_SEEDS $_group_replication_group_name GROUP_REPLICATION_GROUP_NAME
192 --source include/restart_mysqld.inc
193 --let $rpl_server_number = 1
194 --source include/rpl_reconnect.inc
195
196 --let $expected_prepared_xa_count = 1
197 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
198
199 # 9. Re-join server 1 (former primary) to the group.
200 #
201 --let $rpl_connection_name = server1
202 --source include/rpl_connection.inc
203 --source include/save_binlog_position.inc
204 --let $group_replication_group_name = $_group_replication_group_name
205 --source include/start_group_replication.inc
206
207 --let $rpl_connection_name = server2
208 --source include/rpl_connection.inc
209 --let $group_replication_number_of_members = 3
210 --source include/gr_wait_for_number_of_members.inc
211
212 # 10. On server 1, check state after distributed recovery:
213 #
214 --let $rpl_connection_name = server1
215 --source include/rpl_connection.inc
216
217 # 10.a. The `XA PREPARE` is not found in the binary log.
218 #
219 --let $event_sequence = $view_change
220 --source include/assert_binlog_events.inc
221
222 # 10.b. There is one pending XA transaction listed in the output of `XA
223 # RECOVER`.
224 #
225 --let $expected_prepared_xa_count = 1
226 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
227
228 # 11. Rollback the transaction on primary.
229 #
230 --source include/gr_find_a_primary.inc
231 --connection $group_replication_primary_connection_out_var
232 --eval XA ROLLBACK $xid
233
234 --source include/rpl_sync.inc
235
236 --let $rpl_connection_name = server1
237 --source include/rpl_connection.inc
238
239 # 12. Check table wasn't updated on server 1.
240 #
241 --let $expected_row_count = 1
242 --source extra/xa_crash_safe_tests/assert_row_count.inc
243
244 --connection $group_replication_primary_connection_out_var
245
246 DROP TABLE t1;
247
248 --let $rpl_connection_name = server2
249 --source include/rpl_connection.inc
250 --source include/restore_sysvars.inc
251 --let $rpl_connection_name = server3
252 --source include/rpl_connection.inc
253 --source include/restore_sysvars.inc
254
255 --source include/group_replication_end.inc