rpl_bug26395.test 3.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
# ==== Purpose ====
#
# Tests that an autocommitted XA transaction where the master crashes
# just before writing the XID log event is executed correctly.  The
# master rolls back, so the slave should not execute statement.
#
# This test was previously part of rpl_ndb_transaction.test
#
#
# ==== Method ====
#
# We want master to be alive so that it can replicate the statement to
# the slave. So in the test case, we must not crash the
# master. Instead, we fake the crash by just not writing the XID event
# to the binlog. This is done by the @@debug='d,do_not_write_xid'
# flag. This, in turn, requires us to do 'source
# include/have_debug.inc'
#
# So, unlike if the master had crashed, the master *will* execute the
# statement. But the slave should not execute it. Hence, after the
# test is executed, the expected result on master is a table with one
# row, and on slave a table with no rows.
#
# To simulate the slave correctly, we wait until everything up to but
# not including the XID is replicated. This has to be done with
# include/sync_slave_io_with_master.inc, not sync_slave_with_master,
# since the latter waits until the slave *SQL* thread has caught up
# with the master's position, which it will never do.
#
#
# ==== Related bugs ====
#
# BUG#26395: if crash during autocommit update to transactional table on master, slave fails

source include/have_innodb.inc;
# have_debug is needed since we use the @@debug variable on master
source include/have_debug.inc;
source include/master-slave.inc;

# test adapts simulation of incomplete transaction that MTS does not tolerate
# when is stopped. So it reacts with an error whereas the single-threaded is fine.
-- source include/not_mts_slave_parallel_workers.inc


--echo ==== Initialize ====

--echo [on master]
--connection master

CREATE TABLE tinnodb (a INT) ENGINE = INNODB;
SHOW CREATE TABLE tinnodb;

# do_not_write_xid stops the master from writing an XID event.
set @old_debug= @@debug;
set @@debug= 'd,do_not_write_xid';


--echo ==== Test ====

# Save the position up to which the slave SQL thread should execute.
save_master_pos;

# Execute query and check that the row made it to the table.
INSERT INTO tinnodb VALUES (1);
SELECT * FROM tinnodb ORDER BY a;

# Sync slave's IO thread.
--echo [on slave]
source include/sync_slave_io_with_master.inc;

# Sync slave's SQL thread.
sync_with_master 0;

--echo ==== Verify results on slave ====

source include/stop_slave.inc;

--let $status_items=Slave_IO_State,Last_SQL_Error,Last_IO_Error
--source include/show_slave_status.inc

--let $assert_text= Assert that the slave table has no rows
--let $assert_cond= `SELECT COUNT(*) = 0 FROM tinnodb`
--source include/assert.inc

--echo ==== Clean up ====

# Easiest to clean up master and slave separately, without
# replication, since master and slave are out of sync.

--echo [on master]
connection master;
DROP TABLE tinnodb;
set @@debug= @old_debug;

--echo [on slave]
connection slave;
DROP TABLE tinnodb;

# Warning: do not add more tests here. The binlog is in a bad state.
--let $rpl_only_running_threads= 1
--source include/rpl_end.inc