-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-33853 Async rollback prepared transactions during binlog crash recovery #3030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
mysql-test/suite/binlog/r/binlog_recover_async_rollback_trx.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| CREATE TABLE t1 (id int primary key, data int) ENGINE = InnoDB; | ||
| INSERT INTO t1 VALUES (0, 1); | ||
| # | ||
| # 1. Check DML in prepared state can rollback correctly. | ||
| # | ||
| connect con1, localhost, root,,; | ||
| SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared1 WAIT_FOR continue"; | ||
| INSERT INTO t1 VALUES(1, 1);; | ||
| connect con2, localhost, root,,; | ||
| SET debug_sync = "now WAIT_FOR prepared1"; | ||
| SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared2 WAIT_FOR continue"; | ||
| UPDATE t1 SET data = data + 1 WHERE id = 0; | ||
| connection default; | ||
| SET debug_sync = "now WAIT_FOR prepared2"; | ||
| # Kill the server | ||
| disconnect con1; | ||
| disconnect con2; | ||
| # restart | ||
| # Expect (0, 1) | ||
| SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | ||
| SELECT * FROM t1; | ||
| id data | ||
| 0 1 | ||
| INSERT INTO t1 VALUES(1, 1); | ||
| UPDATE t1 SET data = data + 1 WHERE id = 0; | ||
| # Expect (0, 2), (1, 1) | ||
| SELECT * FROM t1; | ||
| id data | ||
| 0 2 | ||
| 1 1 | ||
| # | ||
| # 2. Test that innodb shutdown as expected if any error happens before | ||
| # normal rollback task is started. In the situation, rollback task | ||
| # should be started at preshutdown accordingly to rollback or | ||
| # deregister all recovered active transactions. | ||
| # | ||
| INSERT INTO t1 SELECT seq + 2, 1 FROM seq_1_to_1024; | ||
| BEGIN; | ||
| UPDATE t1 SET data = 10; | ||
| SET GLOBAL innodb_log_checkpoint_now = 1; | ||
| # Kill the server | ||
| # restart: --innodb-read-only | ||
| SELECT count(*) FROM information_schema.innodb_trx; | ||
| count(*) | ||
| 1 | ||
| # Kill the server | ||
| # restart: --innodb-read-only | ||
| SELECT count(*) FROM information_schema.innodb_trx; | ||
| count(*) | ||
| 1 | ||
| # restart | ||
| DROP TABLE t1; |
117 changes: 117 additions & 0 deletions
117
mysql-test/suite/binlog/t/binlog_recover_async_rollback_trx.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| ################################################################################ | ||
| # Async rollback prepared transactions during binlog crash recovery | ||
| # | ||
| # It verifies that binlog recovery just set the prepared transactions to | ||
| # active and the background recovery rollback thread will rollback the | ||
| # transactions asynchronously. | ||
| ################################################################################ | ||
| --source include/have_debug.inc | ||
| --source include/have_debug_sync.inc | ||
| --source include/have_innodb.inc | ||
| --source include/have_binlog_format_row.inc | ||
| --source include/have_sequence.inc | ||
|
|
||
| CREATE TABLE t1 (id int primary key, data int) ENGINE = InnoDB; | ||
| INSERT INTO t1 VALUES (0, 1); | ||
|
|
||
| --echo # | ||
| --echo # 1. Check DML in prepared state can rollback correctly. | ||
| --echo # | ||
|
|
||
| --connect(con1, localhost, root,,) | ||
| SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared1 WAIT_FOR continue"; | ||
| --send INSERT INTO t1 VALUES(1, 1); | ||
|
|
||
| --connect(con2, localhost, root,,) | ||
| SET debug_sync = "now WAIT_FOR prepared1"; | ||
| SET debug_sync = "ha_commit_trans_after_prepare SIGNAL prepared2 WAIT_FOR continue"; | ||
| --send UPDATE t1 SET data = data + 1 WHERE id = 0 | ||
|
|
||
| --connection default | ||
| SET debug_sync = "now WAIT_FOR prepared2"; | ||
| --source include/kill_mysqld.inc | ||
|
|
||
| --disconnect con1 | ||
| --disconnect con2 | ||
|
|
||
| # With the debug option, recovery rollback thread just rolls back the | ||
| # first prepared transaction and then goes to sleep. | ||
| --source include/start_mysqld.inc | ||
| --let $wait_condition= SELECT count(*) = 0 FROM information_schema.innodb_trx | ||
| --source include/wait_condition.inc | ||
|
|
||
| --echo # Expect (0, 1) | ||
| SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | ||
| SELECT * FROM t1; | ||
|
|
||
| # The previous INSERT is rolled back, so this INSERT will succeed. | ||
| INSERT INTO t1 VALUES(1, 1); | ||
|
|
||
| # The previous UPDATE is rolled back, so this UPDATE will succeed. | ||
| UPDATE t1 SET data = data + 1 WHERE id = 0; | ||
|
|
||
| --echo # Expect (0, 2), (1, 1) | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # 2. Test that innodb shutdown as expected if any error happens before | ||
| --echo # normal rollback task is started. In the situation, rollback task | ||
| --echo # should be started at preshutdown accordingly to rollback or | ||
| --echo # deregister all recovered active transactions. | ||
| --echo # | ||
| # Generate an large active transaction | ||
| INSERT INTO t1 SELECT seq + 2, 1 FROM seq_1_to_1024; | ||
|
|
||
| BEGIN; | ||
| UPDATE t1 SET data = 10; | ||
|
|
||
| # Make sure above update is persisted. | ||
| SET GLOBAL innodb_log_checkpoint_now = 1; | ||
| --source include/kill_mysqld.inc | ||
|
|
||
| # tc-heuristic-recover triggers an error before innodb rollback task start | ||
| # Rollback task will not be started at preshutdown of read only mode. Active | ||
| # transactions are not expected to rollback. | ||
| --error 1 | ||
| --exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-read-only --log-error=$MYSQLTEST_VARDIR/tmp/log.err | ||
|
|
||
| # Rollback task will not be started at preshutdown if recovery mode is greater | ||
| # to 2. Active transactions are not expected to rollback. | ||
| --error 1 | ||
| --exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-force-recovery=3 --log-error=$MYSQLTEST_VARDIR/tmp/log.err | ||
|
|
||
| # Rollback task will be started at preshutdown of fast shutdown if force | ||
| # recovery is 2. But the transaction is deregistered instead of rollback. | ||
| --error 1 | ||
| --exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-fast-shutdown=1 --innodb-force-recovery=2 --log-error=$MYSQLTEST_VARDIR/tmp/log.err | ||
|
|
||
| --let $restart_parameters= --innodb-read-only | ||
| --source include/start_mysqld.inc | ||
|
|
||
| # Verify that the transaction is still there. | ||
| SELECT count(*) FROM information_schema.innodb_trx; | ||
|
|
||
| --source include/kill_mysqld.inc | ||
|
|
||
| # Rollback task will be started at preshutdown of fast shutdown. The | ||
| # active transaction is rolled back. | ||
| --error 1 | ||
| --exec $MYSQLD_LAST_CMD --tc-heuristic-recover=ROLLBACK --innodb-fast-shutdown=1 --log-error=$MYSQLTEST_VARDIR/tmp/log.err | ||
|
|
||
| --let $restart_parameters= --innodb-read-only | ||
| --source include/start_mysqld.inc | ||
| # Verify that the transaction is still there. | ||
| SELECT count(*) FROM information_schema.innodb_trx; | ||
|
|
||
| --remove_file $MYSQLTEST_VARDIR/tmp/log.err | ||
|
|
||
| --let $restart_parameters= | ||
| --source include/restart_mysqld.inc | ||
|
|
||
| # There should be no any transaction | ||
| --let $wait_condition= SELECT count(*) = 0 FROM information_schema.innodb_trx | ||
| --source include/wait_condition.inc | ||
|
|
||
| # Cleanup. | ||
| DROP TABLE t1; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.