| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This script tests server behavior when a crash occurs during the |
| 4 |
# execution of `XA COMMIT`, on a GR primary, after binary log has been |
| 5 |
# rotated (`XA 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 COMMIT` 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 COMMIT`. |
| 27 |
# 3. Take the `GTID_EXECUTED` state. |
| 28 |
# 4. Rotate and purge binary logs. |
| 29 |
# 5. Crash the primary during `XA COMMIT` 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 COMMIT` 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 COMMIT` isn't present in the binary |
| 41 |
# 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` is not found in the binary log. |
| 51 |
# b. There is one pending XA transaction listed in the output of `XA |
| 52 |
# RECOVER`. |
| 53 |
# 11. Commit the transaction on primary. |
| 54 |
# 12. Check table was 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 COMMIT`. |
| 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 COMMIT` execution, before commiting in the |
| 105 |
# TC. |
| 106 |
# |
| 107 |
--let $auxiliary_connection = server1 |
| 108 |
--let $statement_connection = con1 |
| 109 |
--let $statement = XA COMMIT $xid |
| 110 |
--let $sync_point = before_commit_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 COMMIT` 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 COMMIT` isn't present in the binary |
| 166 |
# 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 |
# |
| 176 |
--let $expected_prepared_xa_count = 1 |
| 177 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 178 |
|
| 179 |
# 7.c. There aren't changes to the table. |
| 180 |
# |
| 181 |
--let $expected_row_count = 1 |
| 182 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 183 |
|
| 184 |
# 8. Restart server 1 and check that the transaction is still in preared |
| 185 |
# state, meaning, the recovery process moved the transaction to |
| 186 |
# `PERSISTED_IN_TC` and that state was persisted. |
| 187 |
# |
| 188 |
--let $rpl_connection_name = server1 |
| 189 |
--source include/rpl_connection.inc |
| 190 |
|
| 191 |
--let $allow_rpl_inited = 1 |
| 192 |
--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 |
| 193 |
--source include/restart_mysqld.inc |
| 194 |
--let $rpl_server_number = 1 |
| 195 |
--source include/rpl_reconnect.inc |
| 196 |
|
| 197 |
--let $expected_prepared_xa_count = 1 |
| 198 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 199 |
|
| 200 |
# 9. Re-join server 1 (former primary) to the group. |
| 201 |
# |
| 202 |
--let $rpl_connection_name = server1 |
| 203 |
--source include/rpl_connection.inc |
| 204 |
--source include/save_binlog_position.inc |
| 205 |
--let $group_replication_group_name = $_group_replication_group_name |
| 206 |
--source include/start_group_replication.inc |
| 207 |
|
| 208 |
--let $rpl_connection_name = server2 |
| 209 |
--source include/rpl_connection.inc |
| 210 |
--let $group_replication_number_of_members = 3 |
| 211 |
--source include/gr_wait_for_number_of_members.inc |
| 212 |
|
| 213 |
# 10. On server 1, check state after distributed recovery: |
| 214 |
# |
| 215 |
--let $rpl_connection_name = server1 |
| 216 |
--source include/rpl_connection.inc |
| 217 |
|
| 218 |
# 10.a. The `XA PREPARE` is not found in the binary log. |
| 219 |
# |
| 220 |
--let $event_sequence = $view_change |
| 221 |
--source include/assert_binlog_events.inc |
| 222 |
|
| 223 |
# 10.b. There is one pending XA transaction listed in the output of `XA |
| 224 |
# RECOVER`. |
| 225 |
# |
| 226 |
--let $expected_prepared_xa_count = 1 |
| 227 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 228 |
|
| 229 |
# 11. Commit the transaction on primary. |
| 230 |
# |
| 231 |
--source include/gr_find_a_primary.inc |
| 232 |
--connection $group_replication_primary_connection_out_var |
| 233 |
--eval XA COMMIT $xid |
| 234 |
|
| 235 |
--source include/rpl_sync.inc |
| 236 |
|
| 237 |
--let $rpl_connection_name = server1 |
| 238 |
--source include/rpl_connection.inc |
| 239 |
|
| 240 |
# 12. Check table was updated on server 1. |
| 241 |
# |
| 242 |
--let $expected_row_count = 2 |
| 243 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 244 |
|
| 245 |
--connection $group_replication_primary_connection_out_var |
| 246 |
|
| 247 |
DROP TABLE t1; |
| 248 |
|
| 249 |
--let $rpl_connection_name = server2 |
| 250 |
--source include/rpl_connection.inc |
| 251 |
--source include/restore_sysvars.inc |
| 252 |
--let $rpl_connection_name = server3 |
| 253 |
--source include/rpl_connection.inc |
| 254 |
--source include/restore_sysvars.inc |
| 255 |
|
| 256 |
--source include/group_replication_end.inc |