Debian Codegraph @

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

raw
1 ###############################################################################
2 # Bug#25041920 GTID AUTO SKIP DOES NOT WORK ON XA TRANSACTION ON SQL THREAD
3 #
4 # Problem: Server has a mechanism to skip (silently) a GTID transaction if
5 # it is already executed that particular transaction in the past.
6 # This GTID transaction skipping mechanism is not working properly
7 # for XA transaction.
8 #
9 # Steps to reproduce:
10 # 1: Execute a XA transaction on Master.
11 # 2: While Slave is downloading the XA transaction, rotate the relaylog in
12 # between the transaction (exactly before XA_PREPARE event which is
13 # needed to test step 3.1.
14 # 3: Test the XA transaction on Slave that can go through four
15 # different execution paths
16 # 3.1> gtid_pre_statement_post_implicit_commit_checks returns
17 # GTID_STATEMENT_CANCEL
18 # 3.2> gtid_pre_statement_checks returns GTID_STATEMENT_CANCEL
19 # 3.3> XA transaction is succesfully applied
20 # 3.4> gtid_pre_statement_checks returns GTID_STATEMENT_SKIP
21 ###############################################################################
22
23 # This test should run only on debug build
24 # (rpl_receive_count.inc's restriction)
25
26 # The test cannot run in Valgrind since it generates an assert on the slave
27 --source include/not_valgrind.inc
28 --source include/not_rpl_gtid_only.inc
29 --source include/have_debug.inc
30 --source include/have_debug_sync.inc
31
32 # this test case requires that certain events appear in the
33 # relay log, therefore they cannot be enclosed in a Transaction_payload
34 # event.
35 --source include/not_binlog_transaction_compression_on.inc
36
37 --source include/have_myisam.inc
38 # This test script changes SQL thread coordinates in between
39 # which is not possible if AUTO_POSITION is active. So disable
40 # it for the testing purpose.
41 --let $use_gtids=0
42
43 # Start Master-slave replication
44 --source include/master-slave.inc
45
46 # Initial setup
47 CREATE TABLE t1 (c1 INT);
48 CREATE TABLE t2 (c1 INT);
49 --source include/sync_slave_sql_with_master.inc
50 FLUSH RELAY LOGS;
51 CALL mtr.add_suppression("@@SESSION.GTID_NEXT cannot be set to ANONYMOUS when @@GLOBAL.GTID_MODE = ON");
52 CALL mtr.add_suppression("When @@SESSION.GTID_NEXT is set to a GTID, you must explicitly set it to a different value after a COMMIT or ROLLBACK");
53 CALL mtr.add_suppression("Cannot execute the current event group");
54 CALL mtr.add_suppression("The replica coordinator and worker threads are stopped");
55
56 --source include/stop_slave.inc
57
58 ###################################################
59 # Step-1: Execute a XA transaction on Master.
60 ###################################################
61
62 --source include/rpl_connection_master.inc
63 XA START 'trx1';
64 --disable_warnings
65 INSERT INTO t1 VALUES (1);
66 INSERT INTO t2 VALUES (1);
67 --enable_warnings
68 XA END 'trx1';
69 XA PREPARE 'trx1';
70 XA COMMIT 'trx1';
71
72 ###############################################################################
73 # Step-2: While Slave is downloading the XA transaction, rotate the relaylog in
74 # between the transaction (exactly before XA_PREPARE event which is
75 # needed to test step 3.1.
76 ###############################################################################
77 --source include/rpl_connection_slave.inc
78 --let $rpl_after_received_events_action= flush
79 --let $rpl_skip_event_count_print_in_result_log= 1
80 if (`SELECT @@BINLOG_FORMAT != 'STATEMENT'`)
81 {
82 --let $rpl_event_count= 7
83 }
84 if (`SELECT @@BINLOG_FORMAT = 'STATEMENT'`)
85 {
86 --let $rpl_event_count= 5
87 }
88 --source include/rpl_receive_event_count.inc
89
90 # Assert that the XA_PREPARE is in the expected relay log file
91 --let $binlog_limit= 2, 3
92 --let $binlog_file=slave-relay-bin.000005
93 --source include/show_relaylog_events.inc
94
95 --source include/rpl_connection_master.inc
96 --source include/sync_slave_io_with_master.inc
97
98 ###############################################################################
99 # Step-3: Test the XA transaction on Slave that can go through four
100 # different execution paths
101 # 3.1> gtid_pre_statement_post_implicit_commit_checks returns
102 # GTID_STATEMENT_CANCEL
103 # 3.2> gtid_pre_statement_checks returns GTID_STATEMENT_CANCEL
104 # 3.3> XA transaction is succesfully applied
105 # 3.4> gtid_pre_statement_checks returns GTID_STATEMENT_SKIP
106 ###############################################################################
107 # Stop IO thread which is not needed for the rest of this step.
108 --source include/stop_slave_io.inc
109
110 ###############################################################################
111 # Step 3.1: Make gtid_pre_statement_post_implicit_commit_checks to return
112 # GTID_STATEMENT_CANCEL. If a transaction is started without
113 # executing it's GTID_NEXT, it will complain with error
114 # ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON
115 # or ER_MTA_CANT_PARALLEL (incase of MTS enabled server).
116 ###############################################################################
117 CHANGE REPLICATION SOURCE TO RELAY_LOG_FILE='slave-relay-bin.000005', RELAY_LOG_POS=4;
118 START REPLICA SQL_THREAD;
119 --let $sts_error= convert_error(ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON)
120 --let $mts_error= convert_error(ER_MTA_CANT_PARALLEL)
121 --let $slave_sql_errno= $sts_error, $mts_error
122 --source include/wait_for_slave_sql_error.inc
123
124 ###############################################################################
125 # Step 3.2: Make gtid_pre_statement_checks to return GTID_STATEMENT_CANCEL.
126 # If a transaction is involved with non-transactional DML followed
127 # by transactional DML, gtid_pre_statement_checks will complain that
128 # GTID_NEXT is set to UNDEFINED_GTID while it is executing
129 # transactional DML as GTID that came from Master is utilized by
130 # non-transaction DML alone.
131 ###############################################################################
132 # Change table t1's engine to MyISAM.
133 ALTER TABLE t1 engine=MyISAM;
134
135 # Start SQL thread from the begining of the XA transaction.
136 START REPLICA SQL_THREAD UNTIL SQL_AFTER_MTS_GAPS;
137 --source include/wait_for_slave_sql_to_stop.inc
138 CHANGE REPLICATION SOURCE TO RELAY_LOG_FILE='slave-relay-bin.000004', RELAY_LOG_POS=4;
139 START REPLICA SQL_THREAD;
140
141 # SQL thread should fail with ER_GTID_NEXT_TYPE_UNDEFINED_GTID
142 --let $slave_sql_errno= convert_error(ER_GTID_NEXT_TYPE_UNDEFINED_GTID)
143 --source include/wait_for_slave_sql_error.inc
144
145 # Cleanup the mess created by this testcase
146 ALTER TABLE t1 engine=Innodb;
147 DELETE FROM t1;
148 RESET MASTER;
149
150 ###############################################################################
151 # Step-3.3: Start SQL thread from the begining of the XA transaction.
152 # This time SQL thread should succesfully apply full XA transaction
153 # without any issues.
154 ###############################################################################
155 CHANGE REPLICATION SOURCE TO RELAY_LOG_FILE='slave-relay-bin.000004', RELAY_LOG_POS=4;
156 --source include/start_slave_sql.inc
157 --source include/rpl_connection_master.inc
158 --source include/sync_slave_sql_with_master.inc
159
160 # Assert that the data was inserted into slave's tables.
161 # (i.e., the GTID transaction wasn't skipped)
162 --let diff_tables=master:t1, slave:t1
163 --source include/diff_tables.inc
164
165 --let diff_tables=master:t2, slave:t2
166 --source include/diff_tables.inc
167
168 ###############################################################################
169 # Step-3.4: Again start SQL thread from the begining of the XA transaction.
170 # This time SQL thread should skip these gtid transactions
171 # without any issues (as the gtid transactions are already
172 # executed once).
173 ###############################################################################
174 --source include/stop_slave_sql.inc
175 CHANGE REPLICATION SOURCE TO RELAY_LOG_FILE='slave-relay-bin.000004', RELAY_LOG_POS=4;
176 --source include/start_slave_sql.inc
177
178 # Check that SQL thread reached end point.
179 --source include/sync_slave_sql_with_io.inc
180
181 # Assert that no new data was inserted into slave's tables.
182 # (i.e., the GTID transaction was skipped)
183 --let diff_tables=master:t1, slave:t1
184 --source include/diff_tables.inc
185
186 --let diff_tables=master:t2, slave:t2
187 --source include/diff_tables.inc
188
189 ###########
190 # Cleanup
191 ###########
192 --source include/start_slave_io.inc
193 --source include/rpl_connection_master.inc
194 DROP TABLE t1, t2;
195 CALL mtr.add_suppression("Statement is unsafe because it is being used inside a XA transaction");
196 --source include/rpl_end.inc