| 1 |
# |
| 2 |
# Purpose: |
| 3 |
# This test ensures consistency in binlogging behavior for XA transactions |
| 4 |
# that have all statements error and rollback, effectively leaving an "empty" |
| 5 |
# transaction. In such cases, an empty XA transaction should be binlogged. The |
| 6 |
# bug reported by MDEV-25616 revealed that an "empty" XA transaction would |
| 7 |
# binlog an XA ROLLBACK or XA COMMIT event without a preceding setup, i.e. |
| 8 |
# XA START through XA PREPARE. The bug presented differently for XA |
| 9 |
# transactions consisting of transactional and non-transactional statements. |
| 10 |
# Therefore, this test validates that an entire XA transaction is binlogged |
| 11 |
# for different combinations of transactional or non-transactional statements. |
| 12 |
# Note that the behavior changes when binlogging empty XA transactions |
| 13 |
# depending on the binlog_row_format variables. That is, when the content of |
| 14 |
# the transaction consists of errored transactional statements, in row format, |
| 15 |
# an empty XA transaction will be binlogged; however, in mixed and statement |
| 16 |
# formats, nothing will be written into the binary log. |
| 17 |
# |
| 18 |
# Methodology: |
| 19 |
# Create XA transactions with various combinations of erroring transactional |
| 20 |
# or non-transactional statements. The binary log is examined to ensure all |
| 21 |
# XA components are written. Chain replication is used, i.e. |
| 22 |
# (primary->replica->replica), to ensure replica binlogging is consistent with |
| 23 |
# manual execution. The transactional and non-transactional tables use InnoDB |
| 24 |
# and MyISAM, respectively. |
| 25 |
# |
| 26 |
# Parameters |
| 27 |
# $expect_transactional_xa_binlog : Boolean indicating whether or not an |
| 28 |
# errored transactional statement should result in XA statements written |
| 29 |
# into the binary log. |
| 30 |
# |
| 31 |
# References: |
| 32 |
# MDEV-25616: Binlog event for XA COMMIT is generated without matching |
| 33 |
# XA START, replication aborts |
| 34 |
# |
| 35 |
# MDEV-33921: Replication fails when XA transactions are used where the slave |
| 36 |
# has replicate_do_db set and the client has touched a different |
| 37 |
# database when running DML such as inserts. |
| 38 |
# |
| 39 |
--source include/have_log_bin.inc |
| 40 |
|
| 41 |
--let $rpl_server_count= 3 |
| 42 |
--let $rpl_topology= 1->2->3 |
| 43 |
--source include/rpl_init.inc |
| 44 |
|
| 45 |
--connection server_1 |
| 46 |
-- source include/have_innodb.inc |
| 47 |
--connection server_2 |
| 48 |
-- source include/have_innodb.inc |
| 49 |
--connection server_3 |
| 50 |
-- source include/have_innodb.inc |
| 51 |
--connection server_1 |
| 52 |
|
| 53 |
--echo # |
| 54 |
--echo # Test Case 1: An XA transaction without any statements should not be |
| 55 |
--echo # binlogged |
| 56 |
--let $trx_statements= |
| 57 |
|
| 58 |
--let $xa_completion_action= COMMIT |
| 59 |
--source include/rpl_xa_empty_transaction.inc |
| 60 |
|
| 61 |
--let $xa_completion_action= ROLLBACK |
| 62 |
--source include/rpl_xa_empty_transaction.inc |
| 63 |
|
| 64 |
|
| 65 |
--echo # |
| 66 |
--echo # Test Case 2: An XA transaction consisting of a successfully rolled back |
| 67 |
--echo # statement should not be binlogged |
| 68 |
--let $trx_statements= T |
| 69 |
|
| 70 |
--let $xa_completion_action= COMMIT |
| 71 |
--source include/rpl_xa_empty_transaction.inc |
| 72 |
|
| 73 |
--let $xa_completion_action= ROLLBACK |
| 74 |
--source include/rpl_xa_empty_transaction.inc |
| 75 |
|
| 76 |
|
| 77 |
--echo # |
| 78 |
--echo # Test Case 3: An XA transaction with a statement that cannot be rolled |
| 79 |
--echo # back should be binlogged |
| 80 |
|
| 81 |
# TODO: remove work-around MDEV-24654 when fixed. |
| 82 |
--connection server_1 |
| 83 |
set @sav_binlog_format = @@binlog_format; |
| 84 |
set @@binlog_format = row; |
| 85 |
set @@global.binlog_format = row; |
| 86 |
--let $trx_statements= N |
| 87 |
|
| 88 |
--let $xa_completion_action= COMMIT |
| 89 |
--source include/rpl_xa_empty_transaction.inc |
| 90 |
|
| 91 |
--let $xa_completion_action= ROLLBACK |
| 92 |
--source include/rpl_xa_empty_transaction.inc |
| 93 |
|
| 94 |
--connection server_1 |
| 95 |
set @@binlog_format = @sav_binlog_format; |
| 96 |
set @@global.binlog_format = @sav_binlog_format; |
| 97 |
|
| 98 |
|
| 99 |
--echo # |
| 100 |
--echo # Test Case 4: An XA transaction with multiple statements that can all |
| 101 |
--echo # be rolled back should not be binlogged |
| 102 |
--let $trx_statements= T,T |
| 103 |
|
| 104 |
--let $xa_completion_action= COMMIT |
| 105 |
--source include/rpl_xa_empty_transaction.inc |
| 106 |
|
| 107 |
--let $xa_completion_action= ROLLBACK |
| 108 |
--source include/rpl_xa_empty_transaction.inc |
| 109 |
|
| 110 |
|
| 111 |
--echo # |
| 112 |
--echo # Test Case 5: A mixed XA transaction consisting of one statement that |
| 113 |
--echo # can successfully be rolled back (first statement), and another that |
| 114 |
--echo # can not (second statement) should be binlogged |
| 115 |
|
| 116 |
--connection server_1 |
| 117 |
set @sav_binlog_format = @@binlog_format; |
| 118 |
set @@binlog_format = row; |
| 119 |
set @@global.binlog_format = row; |
| 120 |
--let $trx_statements= T,N |
| 121 |
|
| 122 |
--let $xa_completion_action= COMMIT |
| 123 |
--source include/rpl_xa_empty_transaction.inc |
| 124 |
|
| 125 |
--let $xa_completion_action= ROLLBACK |
| 126 |
--source include/rpl_xa_empty_transaction.inc |
| 127 |
|
| 128 |
--connection server_1 |
| 129 |
set @@binlog_format = @sav_binlog_format; |
| 130 |
set @@global.binlog_format = @sav_binlog_format; |
| 131 |
|
| 132 |
|
| 133 |
--echo # |
| 134 |
--echo # Test Case 6: A mixed XA transaction consisting of one statement that |
| 135 |
--echo # cannot successfully be rolled back (first statement), and another that |
| 136 |
--echo # can (second statement) should be binlogged |
| 137 |
|
| 138 |
--connection server_1 |
| 139 |
set @sav_binlog_format = @@binlog_format; |
| 140 |
set @@binlog_format = row; |
| 141 |
set @@global.binlog_format = row; |
| 142 |
--let $trx_statements= N,T |
| 143 |
|
| 144 |
--let $xa_completion_action= COMMIT |
| 145 |
--source include/rpl_xa_empty_transaction.inc |
| 146 |
|
| 147 |
--let $xa_completion_action= ROLLBACK |
| 148 |
--source include/rpl_xa_empty_transaction.inc |
| 149 |
|
| 150 |
--connection server_1 |
| 151 |
set @@binlog_format = @sav_binlog_format; |
| 152 |
set @@global.binlog_format = @sav_binlog_format; |
| 153 |
|
| 154 |
--echo # |
| 155 |
--echo # Test Case 7: An XA transaction consisting of two failed |
| 156 |
--echo # non-transactional statements should be binlogged |
| 157 |
|
| 158 |
--connection server_1 |
| 159 |
set @sav_binlog_format = @@binlog_format; |
| 160 |
set @@binlog_format = row; |
| 161 |
set @@global.binlog_format = row; |
| 162 |
--let $trx_statements= N,N |
| 163 |
|
| 164 |
--let $xa_completion_action= COMMIT |
| 165 |
--source include/rpl_xa_empty_transaction.inc |
| 166 |
|
| 167 |
--let $xa_completion_action= ROLLBACK |
| 168 |
--source include/rpl_xa_empty_transaction.inc |
| 169 |
|
| 170 |
--connection server_1 |
| 171 |
set @@binlog_format = @sav_binlog_format; |
| 172 |
set @@global.binlog_format = @sav_binlog_format; |
| 173 |
|
| 174 |
|
| 175 |
--echo # |
| 176 |
--echo # MDEV-33921.1: If a slave's replication of an XA transaction results in |
| 177 |
--echo # an empty transaction, e.g. due to replication filters, the slave |
| 178 |
--echo # should not binlog any part of the XA transaction. |
| 179 |
# |
| 180 |
# Note that the MDEV-33921 report is actually about that XA END is filtered |
| 181 |
# out (not executed), and then its corresponding XA PREPARE errors because the |
| 182 |
# XA state of the transaction is incorrect. This test case inherently tests |
| 183 |
# both bugs. |
| 184 |
|
| 185 |
--connection server_1 |
| 186 |
create database db1; |
| 187 |
create database db2; |
| 188 |
create table db1.t1 (a int) engine=innodb; |
| 189 |
--source include/save_master_gtid.inc |
| 190 |
--connection server_3 |
| 191 |
--source include/sync_with_master_gtid.inc |
| 192 |
--source include/stop_slave.inc |
| 193 |
change master to master_use_gtid=slave_pos; |
| 194 |
|
| 195 |
--connection server_2 |
| 196 |
--source include/stop_slave.inc |
| 197 |
SET @@GLOBAL.replicate_ignore_db= ""; |
| 198 |
SET @@GLOBAL.replicate_do_db= "db2"; |
| 199 |
change master to master_use_gtid=slave_pos; |
| 200 |
--source include/start_slave.inc |
| 201 |
|
| 202 |
--connection server_1 |
| 203 |
--let $pre_xa_gtid= `SELECT @@global.gtid_binlog_pos` |
| 204 |
use db1; |
| 205 |
XA START "x1"; |
| 206 |
insert into db1.t1 values (1); |
| 207 |
XA END "x1"; |
| 208 |
XA PREPARE "x1"; |
| 209 |
XA COMMIT "x1"; |
| 210 |
--source include/save_master_gtid.inc |
| 211 |
|
| 212 |
--connection server_2 |
| 213 |
--source include/sync_with_master_gtid.inc |
| 214 |
--let $slave_binlogged_gtid= `SELECT @@global.gtid_binlog_pos` |
| 215 |
if (`SELECT strcmp("$slave_binlogged_gtid","$pre_xa_gtid")`) |
| 216 |
{ |
| 217 |
--die Slave binlogged an empty XA transaction yet should not have |
| 218 |
} |
| 219 |
|
| 220 |
--connection server_2 |
| 221 |
--source include/save_master_gtid.inc |
| 222 |
|
| 223 |
--connection server_3 |
| 224 |
--source include/start_slave.inc |
| 225 |
--source include/sync_with_master_gtid.inc |
| 226 |
|
| 227 |
--echo # |
| 228 |
--echo # 33921.2: If the slave shuts down after "preparing" a filtered-to-empty |
| 229 |
--echo # XA transaction (and not completing it), then when the respective |
| 230 |
--echo # XA completion (COMMIT in this test) command is replicated, the slave |
| 231 |
--echo # should not throw ER_XAER_NOTA. Note that internally, the error is |
| 232 |
--echo # thrown, but it is ignored because the target db is filtered. |
| 233 |
|
| 234 |
--connection server_3 |
| 235 |
--source include/stop_slave.inc |
| 236 |
|
| 237 |
--connection server_1 |
| 238 |
--let $pre_xa_gtid= `SELECT @@global.gtid_binlog_pos` |
| 239 |
|
| 240 |
# Used by mysqlbinlog in part 3 |
| 241 |
--let $pre_xa_pos = query_get_value(SHOW MASTER STATUS, Position, 1) |
| 242 |
|
| 243 |
use db1; |
| 244 |
XA START "x2"; |
| 245 |
insert into db1.t1 values (2); |
| 246 |
XA END "x2"; |
| 247 |
XA PREPARE "x2"; |
| 248 |
--source include/save_master_gtid.inc |
| 249 |
|
| 250 |
--connection server_2 |
| 251 |
--source include/sync_with_master_gtid.inc |
| 252 |
--let $rpl_server_number= 2 |
| 253 |
--echo # Connection named slave is needed for reconnection |
| 254 |
--connect(slave,localhost,root,,) |
| 255 |
--connect(slave1,localhost,root,,) |
| 256 |
--source include/rpl_restart_server.inc |
| 257 |
|
| 258 |
--connection server_2 |
| 259 |
--source include/stop_slave.inc |
| 260 |
SET @@GLOBAL.replicate_do_db= "db2"; |
| 261 |
change master to master_use_gtid=slave_pos; |
| 262 |
--source include/start_slave.inc |
| 263 |
|
| 264 |
--connection server_1 |
| 265 |
XA COMMIT "x2"; |
| 266 |
--source include/save_master_gtid.inc |
| 267 |
|
| 268 |
--connection server_2 |
| 269 |
--source include/sync_with_master_gtid.inc |
| 270 |
--source include/save_master_gtid.inc |
| 271 |
|
| 272 |
--connection server_3 |
| 273 |
--source include/start_slave.inc |
| 274 |
--source include/sync_with_master_gtid.inc |
| 275 |
|
| 276 |
--echo # |
| 277 |
--echo # 33921.3: Ensure XA commands are not considered by mysqlbinlog's |
| 278 |
--echo # --database filter |
| 279 |
--connection server_1 |
| 280 |
--let $datadir= `select @@datadir` |
| 281 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 282 |
--let assert_file= $MYSQLTEST_VARDIR/tmp/binlog_decoded.out |
| 283 |
--echo # MYSQL_BINLOG datadir/binlog_file --start-position=pre_xa_pos --database=db2 --result-file=assert_file |
| 284 |
--exec $MYSQL_BINLOG $datadir/$binlog_file --start-position=$pre_xa_pos --database=db2 --result-file=$assert_file |
| 285 |
|
| 286 |
--let assert_text= Mysqlbinlog should output all XA commands from the filtered transaction |
| 287 |
--let assert_count= 4 |
| 288 |
--let assert_select= XA START|XA END|XA PREPARE|XA COMMIT |
| 289 |
--source include/assert_grep.inc |
| 290 |
|
| 291 |
--connection server_2 |
| 292 |
--source include/stop_slave.inc |
| 293 |
SET @@GLOBAL.replicate_do_db=""; |
| 294 |
--source include/start_slave.inc |
| 295 |
|
| 296 |
--connection server_1 |
| 297 |
drop database db1; |
| 298 |
drop database db2; |
| 299 |
|
| 300 |
|
| 301 |
# |
| 302 |
# Cleanup |
| 303 |
--connection server_1 |
| 304 |
--source include/rpl_end.inc |
| 305 |
|
| 306 |
--echo # End of rpl_xa_empty_transaction.test |