Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # This script tests server behavior when a crash occurs during the
4 # execution of `XA COMMIT` and just before the transaction is broadcasted
5 # to GR.
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 COMMIT` statement shouldn't be logged to the binlog.
14 # R2. There shouldn't be any changes to GTID_EXECUTED.
15 # R3. There should be one pending XA transactions visible with `XA
16 # RECOVER`.
17 #
18 # ==== Implementation ====
19 #
20 # 1. Setup scenario: setup GR, create table and insert some records.
21 # 2. Start and execute an XA transaction containing an insert until before
22 # `XA COMMIT`.
23 # 3. Take the `GTID_EXECUTED` state, on the primary.
24 # 4. Crash the primary during `XA COMMIT` execution, after preparing in the
25 # storage engines and just before broadcasting to GR
26 # 5. Restart server 1 (former primary) and check:
27 # a. Error log for messages stating that recovery process found one
28 # transaction needing recovery.
29 # b. The `XA COMMIT` wasn't logged to the binary log.
30 # c. There aren't any changes to GTID_EXECUTED.
31 # d. There is one pending XA transaction listed in the output of `XA
32 # RECOVER`.
33 # e. There aren't changes to the table.
34 # 6. On server 2, check:
35 # a. The `XA COMMIT` wasn't logged to the binary log.
36 # b. There is one pending XA transaction listed in the output of `XA
37 # RECOVER`.
38 # c. There aren't changes to the table.
39 # 7. Re-join server 1 (former primary) to the group.
40 # 8. On server 1, check state after distributed recovery:
41 # a. The `XA COMMIT` wasn't logged to the binary log.
42 # b. There is one pending XA transaction listed in the output of `XA
43 # RECOVER`.
44 # 9. Commit the transaction on primary.
45 # 10. Check table was updated on server 1.
46 #
47 # ==== References ====
48 #
49 # WL#11300: Crash-safe XA + binary log
50 #
51 # Related tests:
52 # see extra/xa_crash_safe_tests/setup.inc
53 #
54 --source include/not_valgrind.inc
55 --source include/have_debug.inc
56 --source include/have_debug_sync.inc
57 --source include/have_group_replication_plugin.inc
58 --let $rpl_group_replication_single_primary_mode =1
59 --let $rpl_skip_group_replication_start = 1
60 --let $rpl_server_count = 3
61 --source include/group_replication.inc
62
63 # 1. Setup scenario: setup GR, create table and insert some records.
64 #
65 --let $rpl_connection_name = server1
66 --source include/rpl_connection.inc
67 --let $xid_data = xid1
68 --let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
69 --source extra/xa_crash_safe_tests/setup.inc
70
71 # 2. Start and execute an XA transaction containing an insert until before
72 # `XA COMMIT`.
73 #
74 --connect(con1, localhost, root,,)
75 --connection con1
76 --eval XA START $xid
77 INSERT INTO t1 VALUES (1);
78 --eval XA END $xid
79 --eval XA PREPARE $xid
80
81 # 3. Take the `GTID_EXECUTED` state, on the primary.
82 #
83 --let $rpl_connection_name = server1
84 --source include/rpl_connection.inc
85 --source include/rpl_sync.inc
86 --let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
87
88 # 4. Crash the primary during `XA COMMIT` execution, after preparing in the
89 # storage engines and just before broadcasting to GR
90 #
91 --let $auxiliary_connection = server1
92 --let $statement_connection = con1
93 --let $statement = XA COMMIT $xid
94 --let $sync_point = before_invoke_before_commit_hook
95 --source include/execute_to_conditional_timestamp_sync_point.inc
96 --source include/kill_mysqld.inc
97 --source extra/xa_crash_safe_tests/cleanup_connection.inc
98
99 --let $rpl_connection_name = server2
100 --source include/rpl_connection.inc
101 --let $group_replication_number_of_members = 2
102 --source include/gr_wait_for_number_of_members.inc
103
104 # 5. Restart server 1 (former primary) and check:
105 #
106 --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
107 --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
108 --source include/start_mysqld.inc
109 --let $rpl_server_number = 1
110 --source include/rpl_reconnect.inc
111
112 --let $rpl_connection_name = server1
113 --source include/rpl_connection.inc
114
115 # 5.a. Error log for messages stating that recovery process found one
116 # transaction needing recovery.
117 #
118 --let $assert_select = Successfully prepared 1 XA transaction
119 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
120
121 # 5.b. The `XA COMMIT` wasn't logged to the binary log.
122 #
123 --let $event_sequence = Gtid # $xa_start_end # XA_prepare/XA PREPARE $xid
124 --source include/assert_binlog_events.inc
125
126 # 5.c. There aren't any changes to GTID_EXECUTED.
127 #
128 --let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
129 --let $assert_text = GTID_EXECUTED has not been updated
130 --let $assert_cond = "$before_gtid_executed" = "$after_gtid_executed"
131 --source include/assert.inc
132
133 # 5.d. There is one pending XA transaction listed in the output of `XA
134 # RECOVER`.
135 #
136 --let $expected_prepared_xa_count = 1
137 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
138
139 # 5.e. There aren't changes to the table.
140 #
141 --let $expected_row_count = 1
142 --source extra/xa_crash_safe_tests/assert_row_count.inc
143
144 # 6. On server 2, check:
145 #
146 --let $rpl_connection_name = server2
147 --source include/rpl_connection.inc
148
149 # 6.a. The `XA COMMIT` wasn't logged to the binary log.
150 #
151 --let $binlog_file = `SELECT @binlog_file`
152 --let $binlog_position = `SELECT @binlog_position`
153 --let $event_sequence = $view_change # Gtid # $xa_start_end # XA_prepare/XA PREPARE $xid
154 --source include/assert_binlog_events.inc
155
156 # 6.b. There is one pending XA transaction listed in the output of `XA
157 # RECOVER`.
158 #
159 --let $expected_prepared_xa_count = 1
160 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
161
162 # 6.c. There aren't changes to the table.
163 #
164 --let $expected_row_count = 1
165 --source extra/xa_crash_safe_tests/assert_row_count.inc
166
167 # 7. Re-join server 1 (former primary) to the group.
168 #
169 --let $rpl_connection_name = server1
170 --source include/rpl_connection.inc
171 --source include/save_binlog_position.inc
172 --let $group_replication_group_name = $_group_replication_group_name
173 --source include/start_group_replication.inc
174
175 --let $rpl_connection_name = server2
176 --source include/rpl_connection.inc
177 --let $group_replication_number_of_members = 3
178 --source include/gr_wait_for_number_of_members.inc
179
180 # 8. On server 1, check state after distributed recovery:
181 #
182 --let $rpl_connection_name = server1
183 --source include/rpl_connection.inc
184
185 # 8.a. The `XA COMMIT` wasn't logged to the binary log.
186 #
187 --let $event_sequence = $view_change
188 --source include/assert_binlog_events.inc
189
190 # 8.b. There is one pending XA transaction listed in the output of `XA
191 # RECOVER`.
192 #
193 --let $expected_prepared_xa_count = 1
194 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
195
196 # 9. Commit the transaction on primary.
197 #
198 --source include/gr_find_a_primary.inc
199 --connection $group_replication_primary_connection_out_var
200 --eval XA COMMIT $xid
201
202 --source include/rpl_sync.inc
203
204 # 10. Check table was updated on server 1.
205 #
206 --let $rpl_connection_name = server1
207 --source include/rpl_connection.inc
208
209 --let $expected_row_count = 2
210 --source extra/xa_crash_safe_tests/assert_row_count.inc
211
212 --connection $group_replication_primary_connection_out_var
213
214 DROP TABLE t1;
215
216 --let $rpl_connection_name = server2
217 --source include/rpl_connection.inc
218 --source include/restore_sysvars.inc
219 --let $rpl_connection_name = server3
220 --source include/rpl_connection.inc
221 --source include/restore_sysvars.inc
222
223 --source include/group_replication_end.inc