| 1 |
################################################################################ |
| 2 |
# Async rollback prepared transactions during binlog crash recovery |
| 3 |
# |
| 4 |
# It verifies that binlog recovery just set the prepared transactions to |
| 5 |
# active and the background recovery rollback thread will rollback the |
| 6 |
# transactions asynchronously. |
| 7 |
################################################################################ |
| 8 |
--source include/have_debug.inc |
| 9 |
--source include/have_debug_sync.inc |
| 10 |
--source include/have_innodb.inc |
| 11 |
--source include/have_binlog_format_row.inc |
| 12 |
--source include/have_sequence.inc |
| 13 |
|
| 14 |
CREATE TABLE t1 (id int primary key, data int) ENGINE = InnoDB; |
| 15 |
INSERT INTO t1 VALUES (0, 1); |
| 16 |
|
| 17 |
--echo # |
| 18 |
--echo # 1. Check DML in prepared state can rollback correctly. |
| 19 |
--echo # |
| 20 |
|
| 21 |
--connect(con1, localhost, root,,) |
| 22 |
SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared1 WAIT_FOR continue"; |
| 23 |
--send INSERT INTO t1 VALUES(1, 1); |
| 24 |
|
| 25 |
--connect(con2, localhost, root,,) |
| 26 |
SET debug_sync = "now WAIT_FOR prepared1"; |
| 27 |
SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared2 WAIT_FOR continue"; |
| 28 |
--send UPDATE t1 SET data = data + 1 WHERE id = 0 |
| 29 |
|
| 30 |
--connection default |
| 31 |
SET debug_sync = "now WAIT_FOR prepared2"; |
| 32 |
--source include/kill_mysqld.inc |
| 33 |
|
| 34 |
--disconnect con1 |
| 35 |
--disconnect con2 |
| 36 |
|
| 37 |
# With the debug option, recovery rollback thread just rolls back the |
| 38 |
# first prepared transaction and then goes to sleep. |
| 39 |
--source include/start_mysqld.inc |
| 40 |
--let $wait_condition= SELECT count(*) = 0 FROM information_schema.innodb_trx |
| 41 |
--source include/wait_condition.inc |
| 42 |
|
| 43 |
--echo # Expect (0, 1) |
| 44 |
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; |
| 45 |
SELECT * FROM t1; |
| 46 |
|
| 47 |
# The previous INSERT is rolled back, so this INSERT will succeed. |
| 48 |
INSERT INTO t1 VALUES(1, 1); |
| 49 |
|
| 50 |
# The previous UPDATE is rolled back, so this UPDATE will succeed. |
| 51 |
UPDATE t1 SET data = data + 1 WHERE id = 0; |
| 52 |
|
| 53 |
--echo # Expect (0, 2), (1, 1) |
| 54 |
SELECT * FROM t1; |
| 55 |
|
| 56 |
--echo # |
| 57 |
--echo # 2. Test that innodb shutdown as expected if any error happens before |
| 58 |
--echo # normal rollback task is started. In the situation, rollback task |
| 59 |
--echo # should be started at preshutdown accordingly to rollback or |
| 60 |
--echo # deregister all recovered active transactions. |
| 61 |
--echo # |
| 62 |
# Generate an large active transaction |
| 63 |
INSERT INTO t1 SELECT seq + 2, 1 FROM seq_1_to_1024; |
| 64 |
|
| 65 |
BEGIN; |
| 66 |
UPDATE t1 SET data = 10; |
| 67 |
|
| 68 |
# Make sure above update is persisted. |
| 69 |
SET GLOBAL innodb_log_checkpoint_now = 1; |
| 70 |
--source include/kill_mysqld.inc |
| 71 |
|
| 72 |
# tc-heuristic-recover triggers an error before innodb rollback task start |
| 73 |
# Rollback task will not be started at preshutdown of read only mode. Active |
| 74 |
# transactions are not expected to rollback. |
| 75 |
--error 1 |
| 76 |
--exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-read-only --log-error=$MYSQLTEST_VARDIR/tmp/log.err |
| 77 |
|
| 78 |
# Rollback task will not be started at preshutdown if recovery mode is greater |
| 79 |
# to 2. Active transactions are not expected to rollback. |
| 80 |
--error 1 |
| 81 |
--exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-force-recovery=3 --log-error=$MYSQLTEST_VARDIR/tmp/log.err |
| 82 |
|
| 83 |
# Rollback task will be started at preshutdown of fast shutdown if force |
| 84 |
# recovery is 2. But the transaction is deregistered instead of rollback. |
| 85 |
--error 1 |
| 86 |
--exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-fast-shutdown=1 --innodb-force-recovery=2 --log-error=$MYSQLTEST_VARDIR/tmp/log.err |
| 87 |
|
| 88 |
--let $restart_parameters= --innodb-read-only |
| 89 |
--source include/start_mysqld.inc |
| 90 |
|
| 91 |
# Verify that the transaction is still there. |
| 92 |
SELECT count(*) FROM information_schema.innodb_trx; |
| 93 |
|
| 94 |
--source include/kill_mysqld.inc |
| 95 |
|
| 96 |
# Rollback task will be started at preshutdown of fast shutdown. The |
| 97 |
# active transaction is rolled back. |
| 98 |
--error 1 |
| 99 |
--exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-fast-shutdown=1 --log-error=$MYSQLTEST_VARDIR/tmp/log.err |
| 100 |
|
| 101 |
--let $restart_parameters= --innodb-read-only |
| 102 |
--source include/start_mysqld.inc |
| 103 |
# Verify that the transaction is still there. |
| 104 |
SELECT count(*) FROM information_schema.innodb_trx; |
| 105 |
|
| 106 |
--remove_file $MYSQLTEST_VARDIR/tmp/log.err |
| 107 |
|
| 108 |
--let $restart_parameters= |
| 109 |
--source include/restart_mysqld.inc |
| 110 |
|
| 111 |
# There should be no any transaction |
| 112 |
--let $wait_condition= SELECT count(*) = 0 FROM information_schema.innodb_trx |
| 113 |
--source include/wait_condition.inc |
| 114 |
|
| 115 |
# Cleanup. |
| 116 |
DROP TABLE t1; |
| 117 |
|