| 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 |
# ==== Method ==== |
| 8 |
# |
| 9 |
# We want master to be alive so that it can replicate the statement to |
| 10 |
# the slave. So in the test case, we must not crash the |
| 11 |
# master. Instead, we fake the crash by just not writing the XID event |
| 12 |
# to the binlog. This is done by the @@debug_dbug='d,do_not_write_xid' |
| 13 |
# flag. This, in turn, requires us to do 'source |
| 14 |
# include/have_debug.inc' |
| 15 |
# |
| 16 |
# So, unlike if the master had crashed, the master *will* execute the |
| 17 |
# statement. But the slave should not execute it. Hence, after the |
| 18 |
# test is executed, the expected result on master is a table with one |
| 19 |
# row, and on slave a table with no rows. |
| 20 |
# |
| 21 |
# To simulate the slave correctly, we wait until everything up to but |
| 22 |
# not including the XID is replicated. This has to be done with |
| 23 |
# include/sync_slave_io_with_master.inc, not sync_slave_with_master, |
| 24 |
# since the latter waits until the slave *SQL* thread has caught up |
| 25 |
# with the master's position, which it will never do. |
| 26 |
# |
| 27 |
# |
| 28 |
# ==== Related bugs ==== |
| 29 |
# |
| 30 |
# BUG#26395: if crash during autocommit update to transactional table on master, slave fails |
| 31 |
|
| 32 |
source include/have_innodb.inc; |
| 33 |
# have_debug is needed since we use the @@debug_dbug variable on master |
| 34 |
source include/have_debug.inc; |
| 35 |
source include/master-slave.inc; |
| 36 |
|
| 37 |
|
| 38 |
--echo ==== Initialize ==== |
| 39 |
|
| 40 |
--connection master |
| 41 |
|
| 42 |
CREATE TABLE tinnodb (a INT) ENGINE = INNODB; |
| 43 |
SHOW CREATE TABLE tinnodb; |
| 44 |
|
| 45 |
# do_not_write_xid stops the master from writing an XID event. |
| 46 |
set @old_debug= @@debug_dbug; |
| 47 |
set @@debug_dbug= 'd,do_not_write_xid'; |
| 48 |
|
| 49 |
|
| 50 |
--echo ==== Test ==== |
| 51 |
|
| 52 |
# Save the position up to which the slave SQL thread should execute. |
| 53 |
save_master_pos; |
| 54 |
|
| 55 |
# Execute query and check that the row made it to the table. |
| 56 |
INSERT INTO tinnodb VALUES (1); |
| 57 |
SELECT * FROM tinnodb ORDER BY a; |
| 58 |
|
| 59 |
# Sync slave's IO thread. |
| 60 |
--echo [on slave] |
| 61 |
source include/sync_slave_io_with_master.inc; |
| 62 |
|
| 63 |
# Sync slave's SQL thread. |
| 64 |
sync_with_master 0; |
| 65 |
|
| 66 |
|
| 67 |
--echo ==== Verify results on slave ==== |
| 68 |
|
| 69 |
source include/stop_slave.inc; |
| 70 |
let $tmp= query_get_value("SHOW SLAVE STATUS", Slave_IO_State, 1); |
| 71 |
eval SELECT "$tmp" AS Slave_IO_State; |
| 72 |
let $tmp= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1); |
| 73 |
eval SELECT "$tmp" AS Last_SQL_Error; |
| 74 |
let $tmp= query_get_value("SHOW SLAVE STATUS", Last_IO_Error, 1); |
| 75 |
eval SELECT "$tmp" AS Last_IO_Error; |
| 76 |
SELECT * FROM tinnodb ORDER BY a; |
| 77 |
|
| 78 |
|
| 79 |
--echo ==== Clean up ==== |
| 80 |
|
| 81 |
# Easiest to clean up master and slave separately, without |
| 82 |
# replication, since master and slave are out of sync. |
| 83 |
|
| 84 |
connection master; |
| 85 |
DROP TABLE tinnodb; |
| 86 |
set @@debug_dbug= @old_debug; |
| 87 |
|
| 88 |
connection slave; |
| 89 |
DROP TABLE tinnodb; |
| 90 |
|
| 91 |
# Warning: do not add more tests here. The binlog is in a bad state. |
| 92 |
--let $rpl_only_running_threads= 1 |
| 93 |
--source include/rpl_end.inc |