| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Tests that an autocommitted XA transaction where the master crashes |
| 4 |
# just before writing the XID log event is executed correctly. The |
| 5 |
# master rolls back, so the slave should not execute statement. |
| 6 |
# |
| 7 |
# This test was previously part of rpl_ndb_transaction.test |
| 8 |
# |
| 9 |
# |
| 10 |
# ==== Method ==== |
| 11 |
# |
| 12 |
# We want master to be alive so that it can replicate the statement to |
| 13 |
# the slave. So in the test case, we must not crash the |
| 14 |
# master. Instead, we fake the crash by just not writing the XID event |
| 15 |
# to the binlog. This is done by the @@debug='d,do_not_write_xid' |
| 16 |
# flag. This, in turn, requires us to do 'source |
| 17 |
# include/have_debug.inc' |
| 18 |
# |
| 19 |
# So, unlike if the master had crashed, the master *will* execute the |
| 20 |
# statement. But the slave should not execute it. Hence, after the |
| 21 |
# test is executed, the expected result on master is a table with one |
| 22 |
# row, and on slave a table with no rows. |
| 23 |
# |
| 24 |
# To simulate the slave correctly, we wait until everything up to but |
| 25 |
# not including the XID is replicated. This has to be done with |
| 26 |
# include/sync_slave_io_with_master.inc, not sync_slave_with_master, |
| 27 |
# since the latter waits until the slave *SQL* thread has caught up |
| 28 |
# with the master's position, which it will never do. |
| 29 |
# |
| 30 |
# |
| 31 |
# ==== Related bugs ==== |
| 32 |
# |
| 33 |
# BUG#26395: if crash during autocommit update to transactional table on master, slave fails |
| 34 |
|
| 35 |
--source include/not_group_replication_plugin.inc |
| 36 |
|
| 37 |
# have_debug is needed since we use the @@debug variable on master |
| 38 |
--source include/have_debug.inc |
| 39 |
|
| 40 |
# test adapts simulation of incomplete transaction that MTS does not tolerate |
| 41 |
# when is stopped. So it reacts with an error whereas the single-threaded is fine. |
| 42 |
--source include/not_mts_replica_parallel_workers.inc |
| 43 |
|
| 44 |
--source include/master-slave.inc |
| 45 |
|
| 46 |
--echo ==== Initialize ==== |
| 47 |
|
| 48 |
--echo [on master] |
| 49 |
--connection master |
| 50 |
|
| 51 |
CREATE TABLE tinnodb (a INT) ENGINE = INNODB; |
| 52 |
SHOW CREATE TABLE tinnodb; |
| 53 |
|
| 54 |
# do_not_write_xid stops the master from writing an XID event. |
| 55 |
set @old_debug= @@debug; |
| 56 |
set @@debug= '+d,do_not_write_xid'; |
| 57 |
|
| 58 |
|
| 59 |
--echo ==== Test ==== |
| 60 |
|
| 61 |
# Save the position up to which the slave SQL thread should execute. |
| 62 |
save_master_pos; |
| 63 |
|
| 64 |
# Execute query and check that the row made it to the table. |
| 65 |
INSERT INTO tinnodb VALUES (1); |
| 66 |
SELECT * FROM tinnodb ORDER BY a; |
| 67 |
|
| 68 |
# Sync slave's IO thread. |
| 69 |
--echo [on slave] |
| 70 |
# After the implementation of the transaction boundary parser, |
| 71 |
# this sync cannot use GTIDs or else sync will timeout because only |
| 72 |
# GTIDs of fully replicated transactions are in the |
| 73 |
# Retrieved_Gtid_Set of the slave and, as the last event of the |
| 74 |
# transaction never arrives, syncing with GTIDs won't work. |
| 75 |
--let ignore_gtids_on_sync= 1 |
| 76 |
source include/sync_slave_io_with_master.inc; |
| 77 |
|
| 78 |
# Sync slave's SQL thread. |
| 79 |
sync_with_master 0; |
| 80 |
|
| 81 |
--echo ==== Verify results on slave ==== |
| 82 |
|
| 83 |
source include/stop_slave.inc; |
| 84 |
|
| 85 |
--let $status_items=Slave_IO_State,Last_SQL_Error,Last_IO_Error |
| 86 |
--source include/show_slave_status.inc |
| 87 |
|
| 88 |
--let $assert_text= Assert that the slave table has no rows |
| 89 |
--let $assert_cond= `SELECT COUNT(*) = 0 FROM tinnodb` |
| 90 |
--source include/assert.inc |
| 91 |
|
| 92 |
--echo ==== Clean up ==== |
| 93 |
|
| 94 |
# Easiest to clean up master and slave separately, without |
| 95 |
# replication, since master and slave are out of sync. |
| 96 |
|
| 97 |
--echo [on master] |
| 98 |
connection master; |
| 99 |
DROP TABLE tinnodb; |
| 100 |
set @@debug= @old_debug; |
| 101 |
|
| 102 |
--echo [on slave] |
| 103 |
connection slave; |
| 104 |
DROP TABLE tinnodb; |
| 105 |
|
| 106 |
# Warning: do not add more tests here. The binlog is in a bad state. |
| 107 |
--let $rpl_only_running_threads= 1 |
| 108 |
--source include/rpl_end.inc |