Debian Codegraph @

mysql-test/suite/binlog_gtid/t/binlog_gtid_xa_commit_failure_after_rotate.test

raw
1 # ==== Purpose ====
2 #
3 # This script tests server behavior when a crash occurs during the
4 # execution of `XA COMMIT`, 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 COMMIT` 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 COMMIT`.
23 # 3. Take the `GTID_EXECUTED` state.
24 # 4. Rotate and purge binary logs.
25 # 5. Crash the server during `XA COMMIT` execution, before commiting in the
26 # 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 COMMIT` 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. Commit the transaction.
39 # 9. Check the table has 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 COMMIT`.
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 COMMIT` execution, before commiting in the
82 # TC.
83 #
84 --let $auxiliary_connection = default
85 --let $statement_connection = con1
86 --let $statement = XA COMMIT $xid
87 --let $sync_point = before_commit_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 #
94 --source include/start_mysqld.inc
95
96 # 6.a. Error log for messages stating that recovery process found one
97 # transaction needing recovery.
98 #
99 --let $assert_select = Successfully prepared 1 XA transaction
100 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
101
102 # 6.b. The `XA PREPARE` and `XA COMMIT` aren't found in the binary log.
103 #
104 --let $event_sequence = $empty_event_sequence
105 --source include/assert_binlog_events.inc
106
107 # 6.c. The GTID_EXECUTED variable wasn't updated.
108 #
109 --let $after_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
110 --let $assert_text = GTID_EXECUTED has not been updated
111 --let $assert_cond = "$before_gtid_executed" = "$after_gtid_executed"
112 --source include/assert.inc
113
114 # 6.d. There is one pending XA transaction listed in the output of `XA
115 # RECOVER`.
116 #
117 --let $expected_prepared_xa_count = 1
118 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
119
120 # 6.e. There aren't changes to the table.
121 #
122 --let $expected_row_count = 1
123 --source extra/xa_crash_safe_tests/assert_row_count.inc
124
125 # 7. Restart the server and check that the transaction is still in preared
126 # state, meaning, the recovery process moved the transaction to
127 # `PERSISTED_IN_TC` and that state was persisted.
128 #
129 --source include/restart_mysqld.inc
130 --let $expected_prepared_xa_count = 1
131 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
132
133 # 8. Commit the transaction.
134 #
135 --eval XA COMMIT $xid
136
137 # 9. Check the table has changed.
138 #
139 --let $expected_row_count = 2
140 --source extra/xa_crash_safe_tests/assert_row_count.inc
141
142 DROP TABLE t1;