| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This script tests server behavior when a crash occurs while applying an |
| 4 |
# of `XA COMMIT`, on the replica, and 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. Asynchronous replication topology with 2 servers (source -> replica). |
| 11 |
# PC2. GTID is enabled. |
| 12 |
# |
| 13 |
# After server restart: |
| 14 |
# R1. The `XA PREPARE` statement shouldn't be found in the replca's binlog. |
| 15 |
# R2. The `XA COMMIT` statement shouldn't be found in the replca's binlog. |
| 16 |
# R3. There shouldn't be any changes to GTID_EXECUTED, on the replica. |
| 17 |
# R4. There should be one pending XA transactions visible with `XA |
| 18 |
# RECOVER`, on the replica. |
| 19 |
# R5. There should still be one pending XA transaction visible with `XA |
| 20 |
# RECOVER`, on the replica, if server is restarted after the |
| 21 |
# crash-recovery. |
| 22 |
# |
| 23 |
# ==== Implementation ==== |
| 24 |
# |
| 25 |
# 1. Setup scenario: create table and insert some records on the source. |
| 26 |
# 2. Start and execute, on the source, an XA transaction containing an |
| 27 |
# insert until before `XA COMMIT`. |
| 28 |
# 3. Take the `GTID_EXECUTED` state on the replica. |
| 29 |
# 4. Rotate and purge the replica's binary logs. |
| 30 |
# 5. Crash the replica during `XA COMMIT` execution, before commiting in the |
| 31 |
# TC. |
| 32 |
# 6. Restart the replica server and check it for: |
| 33 |
# a. Error log for messages stating that recovery process found one |
| 34 |
# transaction needing recovery. |
| 35 |
# b. The `XA PREPARE` and `XA COMMIT` aren't found in the replica's |
| 36 |
# binary log. |
| 37 |
# c. The GTID_EXECUTED variable wasn't updated. |
| 38 |
# d. There is one pending XA transaction listed in the output of `XA |
| 39 |
# RECOVER`. |
| 40 |
# e. There aren't changes to the table. |
| 41 |
# 7. Restart the replica and check that the transaction is still in preared |
| 42 |
# state, meaning, the recovery process moved the transaction to |
| 43 |
# `PERSISTED_IN_TC` and that state was persisted. |
| 44 |
# 8. Start replica. |
| 45 |
# 9. Check the table has changed. |
| 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/have_binlog_format_row.inc |
| 55 |
--source include/not_valgrind.inc |
| 56 |
--source include/have_debug.inc |
| 57 |
--source include/have_debug_sync.inc |
| 58 |
--source include/master-slave.inc |
| 59 |
|
| 60 |
# 1. Setup scenario: create table and insert some records on the source. |
| 61 |
# |
| 62 |
--source include/rpl_connection_master.inc |
| 63 |
--let $xid_data = xid1 |
| 64 |
--let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")` |
| 65 |
--source extra/xa_crash_safe_tests/setup.inc |
| 66 |
|
| 67 |
--source include/sync_slave_sql_with_master.inc |
| 68 |
|
| 69 |
# 2. Start and execute, on the source, an XA transaction containing an |
| 70 |
# insert until before `XA COMMIT`. |
| 71 |
# |
| 72 |
--source include/rpl_connection_master1.inc |
| 73 |
--eval XA START $xid |
| 74 |
INSERT INTO t1 VALUES (1); |
| 75 |
--eval XA END $xid |
| 76 |
--eval XA PREPARE $xid |
| 77 |
|
| 78 |
# 3. Take the `GTID_EXECUTED` state on the replica. |
| 79 |
# |
| 80 |
--source include/rpl_connection_master.inc |
| 81 |
--source include/sync_slave_sql_with_master.inc |
| 82 |
--let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed` |
| 83 |
|
| 84 |
# 4. Rotate and purge the replica's binary logs. |
| 85 |
# |
| 86 |
FLUSH LOGS; |
| 87 |
--replace_result $binlog_file BINLOG_FILE |
| 88 |
--eval PURGE BINARY LOGS TO '$binlog_file' |
| 89 |
--source include/save_binlog_position.inc |
| 90 |
|
| 91 |
# 5. Crash the replica during `XA COMMIT` execution, before commiting in the |
| 92 |
# TC. |
| 93 |
# |
| 94 |
--let $auxiliary_connection = slave |
| 95 |
--let $statement_connection = master1 |
| 96 |
--let $statement = XA COMMIT $xid |
| 97 |
--let $sync_point = before_commit_xa_trx |
| 98 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 99 |
|
| 100 |
--source include/rpl_connection_slave.inc |
| 101 |
--source include/kill_mysqld.inc |
| 102 |
|
| 103 |
# 6. Restart the replica server and check it for: |
| 104 |
# |
| 105 |
--let $restart_parameters=restart:--skip-replica-start |
| 106 |
--source include/start_mysqld.inc |
| 107 |
--source include/rpl_reconnect.inc |
| 108 |
|
| 109 |
# 6.a. Error log for messages stating that recovery process found one |
| 110 |
# transaction needing recovery. |
| 111 |
# |
| 112 |
--let $assert_select = Successfully prepared 1 XA transaction |
| 113 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 114 |
|
| 115 |
# 6.b. The `XA PREPARE` and `XA COMMIT` aren't found in the replica's |
| 116 |
# binary log. |
| 117 |
# |
| 118 |
--source include/rpl_connection_slave.inc |
| 119 |
--let $event_sequence = $empty_event_sequence |
| 120 |
--source include/assert_binlog_events.inc |
| 121 |
|
| 122 |
# 6.c. The GTID_EXECUTED variable wasn't updated. |
| 123 |
# |
| 124 |
--let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed` |
| 125 |
--let $assert_text = GTID_EXECUTED has not been updated |
| 126 |
--let $assert_cond = "$before_gtid_executed" = "$after_gtid_executed" |
| 127 |
--source include/assert.inc |
| 128 |
|
| 129 |
# 6.d. There is one pending XA transaction listed in the output of `XA |
| 130 |
# RECOVER`. |
| 131 |
# |
| 132 |
--let $expected_prepared_xa_count = 1 |
| 133 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 134 |
|
| 135 |
# 6.e. There aren't changes to the table. |
| 136 |
# |
| 137 |
--let $expected_row_count = 1 |
| 138 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 139 |
|
| 140 |
# 7. Restart the replica and check that the transaction is still in preared |
| 141 |
# state, meaning, the recovery process moved the transaction to |
| 142 |
# `PERSISTED_IN_TC` and that state was persisted. |
| 143 |
# |
| 144 |
--let $allow_rpl_inited = 1 |
| 145 |
--source include/restart_mysqld.inc |
| 146 |
--source include/rpl_reconnect.inc |
| 147 |
|
| 148 |
--let $expected_prepared_xa_count = 1 |
| 149 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 150 |
|
| 151 |
# 8. Start replica. |
| 152 |
# |
| 153 |
--source include/start_slave.inc |
| 154 |
|
| 155 |
# 9. Check the table has changed. |
| 156 |
# |
| 157 |
--source include/rpl_connection_master.inc |
| 158 |
--source include/sync_slave_sql_with_master.inc |
| 159 |
--let $expected_row_count = 2 |
| 160 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 161 |
|
| 162 |
--source include/rpl_connection_master.inc |
| 163 |
DROP TABLE t1; |
| 164 |
--source include/rpl_end.inc |