Debian Codegraph @

mysql-test/suite/rpl_gtid/t/rpl_gtid_xa_rollback_failure_after_rotate.test

raw
1 # ==== Purpose ====
2 #
3 # This script tests server behavior when a crash occurs while applying an
4 # `XA ROLLBACK`, on the replica, 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 replica's binlog.
15 # R2. The `XA ROLLBACK` statement shouldn't be found in the replica'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 ROLLBACK`.
28 # 3. Take the `GTID_EXECUTED` state, on the replica.
29 # 4. Rotate and purge binary logs, on the replica.
30 # 5. Crash the replica during `XA ROLLBACK` 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 ROLLBACK`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 hasn't changed and that there aren't any pending XA
46 # transactions.
47 #
48 # ==== References ====
49 #
50 # WL#11300: Crash-safe XA + binary log
51 #
52 # Related tests:
53 # see extra/xa_crash_safe_tests/setup.inc
54 #
55 --source include/have_binlog_format_row.inc
56 --source include/not_valgrind.inc
57 --source include/have_debug.inc
58 --source include/have_debug_sync.inc
59 --source include/master-slave.inc
60
61 # 1. Setup scenario: create table and insert some records on the source.
62 #
63 --source include/rpl_connection_master.inc
64 --let $xid_data = xid1
65 --let $xid = `SELECT CONCAT("X'", LOWER(HEX('$xid_data')), "',X'',1")`
66 --source extra/xa_crash_safe_tests/setup.inc
67
68 --source include/sync_slave_sql_with_master.inc
69
70 # 2. Start and execute, on the source, an XA transaction containing an
71 # insert until before `XA ROLLBACK`.
72 #
73 --source include/rpl_connection_master1.inc
74 --eval XA START $xid
75 INSERT INTO t1 VALUES (1);
76 --eval XA END $xid
77 --eval XA PREPARE $xid
78
79 # 3. Take the `GTID_EXECUTED` state, on the replica.
80 #
81 --source include/rpl_connection_master.inc
82 --source include/sync_slave_sql_with_master.inc
83 --let $before_gtid_executed = `SELECT @@GLOBAL.gtid_executed`
84
85 # 4. Rotate and purge binary logs, on the replica.
86 #
87 FLUSH LOGS;
88 --replace_result $binlog_file BINLOG_FILE
89 --eval PURGE BINARY LOGS TO '$binlog_file'
90 --source include/save_binlog_position.inc
91
92 # 5. Crash the replica during `XA ROLLBACK` execution, before commiting in the
93 # TC.
94 #
95 --let $auxiliary_connection = slave
96 --let $statement_connection = master1
97 --let $statement = XA ROLLBACK $xid
98 --let $sync_point = before_rollback_xa_trx
99 --source include/execute_to_conditional_timestamp_sync_point.inc
100
101 --source include/rpl_connection_slave.inc
102 --source include/kill_mysqld.inc
103
104 # 6. Restart the replica server and check it for:
105 #
106 --let $restart_parameters=restart:--skip-replica-start
107 --source include/start_mysqld.inc
108 --source include/rpl_reconnect.inc
109
110 # 6.a. Error log for messages stating that recovery process found one
111 # transaction needing recovery.
112 #
113 --let $assert_select = Successfully prepared 1 XA transaction
114 --source extra/xa_crash_safe_tests/assert_recovery_message.inc
115
116 # 6.b. The `XA PREPARE` and `XA ROLLBACK`aren't found in the replica's
117 # binary log.
118 #
119 --source include/rpl_connection_slave.inc
120 --let $event_sequence = $empty_event_sequence
121 --source include/assert_binlog_events.inc
122
123 # 6.c. The GTID_EXECUTED variable wasn't updated.
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 # 6.d. There is one pending XA transaction listed in the output of `XA
131 # RECOVER`.
132 #
133 --let $expected_prepared_xa_count = 1
134 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
135
136 # 6.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 # 7. Restart the replica and check that the transaction is still in preared
142 # state, meaning, the recovery process moved the transaction to
143 # `PERSISTED_IN_TC` and that state was persisted.
144 #
145 --let $allow_rpl_inited = 1
146 --source include/restart_mysqld.inc
147 --source include/rpl_reconnect.inc
148
149 --let $expected_prepared_xa_count = 1
150 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
151
152 # 8. Start replica.
153 #
154 --source include/start_slave.inc
155
156 # 9. Check the table hasn't changed and that there aren't any pending XA
157 # transactions.
158 #
159 --source include/rpl_connection_master.inc
160 --source include/sync_slave_sql_with_master.inc
161 --let $expected_row_count = 1
162 --source extra/xa_crash_safe_tests/assert_row_count.inc
163
164 --let $expected_prepared_xa_count = 0
165 --source extra/xa_crash_safe_tests/assert_xa_recover.inc
166
167 --source include/rpl_connection_master.inc
168 DROP TABLE t1;
169 --source include/rpl_end.inc