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