| 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 |
# After server restart: |
| 10 |
# R1. The `XA PREPARE` statement shouldn't be found in the binlog. |
| 11 |
# R2. The `XA ROLLBACK` statement shouldn't be found in the binlog. |
| 12 |
# R3. There shouldn't be any changes to GTID_EXECUTED. |
| 13 |
# R4. There should be one pending XA transactions visible with `XA |
| 14 |
# RECOVER`. |
| 15 |
# R5. There should still be one pending XA transaction visible with `XA |
| 16 |
# RECOVER` if server is restarted after the crash-recovery. |
| 17 |
# |
| 18 |
# ==== Implementation ==== |
| 19 |
# |
| 20 |
# 1. Setup scenario: create table and insert some records. |
| 21 |
# 2. Start and execute an XA transaction containing an insert until before |
| 22 |
# `XA ROLLBACK`. |
| 23 |
# 3. Take the `GTID_EXECUTED` state. |
| 24 |
# 4. Rotate and purge binary logs. |
| 25 |
# 5. Crash the server during `XA ROLLBACK` execution, before rolling back |
| 26 |
# in the TC. |
| 27 |
# 6. Restart server and check: |
| 28 |
# a. Error log for messages stating that recovery process found one |
| 29 |
# transaction needing recovery. |
| 30 |
# b. The `XA PREPARE` and `XA ROLLBACK` aren't found in the binary log. |
| 31 |
# c. The GTID_EXECUTED variable wasn't updated. |
| 32 |
# d. There is one pending XA transaction listed in the output of `XA |
| 33 |
# RECOVER`. |
| 34 |
# e. There aren't changes to the table. |
| 35 |
# 7. Restart the server and check that the transaction is still in preared |
| 36 |
# state, meaning, the recovery process moved the transaction to |
| 37 |
# `PERSISTED_IN_TC` and that state was persisted. |
| 38 |
# 8. Rollback the transaction. |
| 39 |
# 9. Check the table hasn't changed. |
| 40 |
# |
| 41 |
# ==== References ==== |
| 42 |
# |
| 43 |
# WL#11300: Crash-safe XA + binary log |
| 44 |
# |
| 45 |
# Related tests; |
| 46 |
# see extra/xa_crash_safe_tests/setup.inc |
| 47 |
# |
| 48 |
--source include/not_valgrind.inc |
| 49 |
--source include/have_debug.inc |
| 50 |
--source include/have_debug_sync.inc |
| 51 |
--source include/have_binlog_format_row.inc |
| 52 |
|
| 53 |
# 1. Setup scenario: create table and insert some records. |
| 54 |
# |
| 55 |
--let $xid_data = xid1 |
| 56 |
--let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")` |
| 57 |
--source extra/xa_crash_safe_tests/setup.inc |
| 58 |
|
| 59 |
# 2. Start and execute an XA transaction containing an insert until before |
| 60 |
# `XA ROLLBACK`. |
| 61 |
# |
| 62 |
--connect(con1, localhost, root,,) |
| 63 |
--connection con1 |
| 64 |
--eval XA START $xid |
| 65 |
INSERT INTO t1 VALUES (1); |
| 66 |
--eval XA END $xid |
| 67 |
--eval XA PREPARE $xid |
| 68 |
|
| 69 |
# 3. Take the `GTID_EXECUTED` state. |
| 70 |
# |
| 71 |
--connection default |
| 72 |
--let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed` |
| 73 |
|
| 74 |
# 4. Rotate and purge binary logs. |
| 75 |
# |
| 76 |
FLUSH LOGS; |
| 77 |
--replace_result $binlog_file BINLOG_FILE |
| 78 |
--eval PURGE BINARY LOGS TO '$binlog_file' |
| 79 |
--source include/save_binlog_position.inc |
| 80 |
|
| 81 |
# 5. Crash the server during `XA ROLLBACK` execution, before rolling back |
| 82 |
# in the TC. |
| 83 |
# |
| 84 |
--let $auxiliary_connection = default |
| 85 |
--let $statement_connection = con1 |
| 86 |
--let $statement = XA ROLLBACK $xid |
| 87 |
--let $sync_point = before_rollback_xa_trx |
| 88 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 89 |
--source include/kill_mysqld.inc |
| 90 |
--source extra/xa_crash_safe_tests/cleanup_connection.inc |
| 91 |
|
| 92 |
# 6. Restart server and check: |
| 93 |
--source include/start_mysqld.inc |
| 94 |
|
| 95 |
# 6.a. Error log for messages stating that recovery process found one |
| 96 |
# transaction needing recovery. |
| 97 |
--let $assert_select = Successfully prepared 1 XA transaction |
| 98 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 99 |
|
| 100 |
# 6.b. The `XA PREPARE` and `XA ROLLBACK` aren't found in the binary log. |
| 101 |
# |
| 102 |
--let $event_sequence = $empty_event_sequence |
| 103 |
--source include/assert_binlog_events.inc |
| 104 |
|
| 105 |
# 6.c. The GTID_EXECUTED variable wasn't updated. |
| 106 |
# |
| 107 |
--let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed` |
| 108 |
--let $assert_text = GTID_EXECUTED has not been updated |
| 109 |
--let $assert_cond = "$before_gtid_executed" = "$after_gtid_executed" |
| 110 |
--source include/assert.inc |
| 111 |
|
| 112 |
# 6.d. There is one pending XA transaction listed in the output of `XA |
| 113 |
# RECOVER`. |
| 114 |
# |
| 115 |
--let $expected_prepared_xa_count = 1 |
| 116 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 117 |
|
| 118 |
# 6.e. There aren't changes to the table. |
| 119 |
# |
| 120 |
--let $expected_row_count = 1 |
| 121 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 122 |
|
| 123 |
# 7. Restart the server and check that the transaction is still in preared |
| 124 |
# state, meaning, the recovery process moved the transaction to |
| 125 |
# `PERSISTED_IN_TC` and that state was persisted. |
| 126 |
# |
| 127 |
--source include/restart_mysqld.inc |
| 128 |
--let $expected_prepared_xa_count = 1 |
| 129 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 130 |
|
| 131 |
# 8. Rollback the transaction. |
| 132 |
# |
| 133 |
--eval XA ROLLBACK $xid |
| 134 |
|
| 135 |
# 9. Check the table hasn't changed. |
| 136 |
# |
| 137 |
--let $expected_row_count = 1 |
| 138 |
--source extra/xa_crash_safe_tests/assert_row_count.inc |
| 139 |
|
| 140 |
DROP TABLE t1; |