forked from MariaDB/server
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-29293 Refactor MDL BF abort logic
In this commit, the BF abort logic is refactored to eliminate the need to call back to server from InnoDB wsrep_abort_transaction(). This is to simplify the MDL BF abort codepath so that the direction is always only server -> InnoDB. The main change is in wsrep_abort_thd(), which first does the BF abort through wsrep-lib, and then continues to ha_abort_transaction() if the wsrep-lib BF abort was successful and no background rollback was started for victim. KILL command handling for wsrep threads was changed so that the thread to be killed is flagged first with wsrep_abort_by_kill to avoid calling storage engine ha_kill_query() from awake_no_mutex(). KILL for wsrep thread is executed by awake_no_mutex() combined with call to ha_abort_transaction(). The locking order for wsrep BF aborts is now: lock_sys.mutex trx.mutex LOCK_thd_kill LOCK_thd_data With this, BF aborts which originate from InnoDB lock manager don't have to release lock_sys.mutex and trx.mutex in between, which reduces chance for race conditions. In order to make the above locking order work for wsrep_abort_transaction(), the function records InnoDB transaction ID and releases victim LOCK_thd_kill and LOCK_thd_data. InnoDB lock_sys.mutex is then grabbed and the victim InnoDB trx object is looked up by InnoDB transaction ID. Locking/unlocking LOCK_thd_kill and LOCK_thd_data was reorganized so that it happens in the visible scope as much as possible. Remove LOCK_thd_kill from wsrep_thd_LOCK/UNLOCK to allow more fine grained locking for SR BF abort which may require locking of victim LOCK_thd_kill. Added explicit call for wsrep_thd_kill_LOCK/UNLOCK where appropriate. Wsrep-lib was updated to version which allows external locking for BF abort calls. Changes to MTR tests: - Disable galera_bf_abort_group_commit. This test is going to be removed (MDEV-30855). - Make galera_var_retry_autocommit result more readable by echoing cases and expectations into result. Only one expected result for reap to verify that server returns expected status for query. - Record galera_gcache_recover_manytrx as result file was incomplete. Trivial change. - Make galera_create_table_as_select more deterministic: Wait until CTAS execution has reached MDL wait for multi-master conflict case. Expected error from multi-master conflict is ER_QUERY_INTERRUPTED. This is because CTAS does not yet have open wsrep transaction when it is waiting for MDL, query gets interrupted instead of BF aborted. This should be addressed in separate task. - Test galera_bf_abort_registering to check that registering trx gets BF aborted through MDL. Co-authored-by: Jan Lindström <[email protected]>
- Loading branch information
1 parent
0b23494
commit 50ac97f
Showing
19 changed files
with
280 additions
and
199 deletions.
There are no files selected for viewing
This file contains 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
20 changes: 20 additions & 0 deletions
20
mysql-test/suite/galera/r/galera_bf_abort_registering.result
This file contains 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,20 @@ | ||
connection node_2; | ||
connection node_1; | ||
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; | ||
connection node_1; | ||
SET SESSION wsrep_retry_autocommit = 0; | ||
SET SESSION DEBUG_SYNC = "wsrep_after_trans_register_ha SIGNAL reached WAIT_FOR continue"; | ||
INSERT INTO t1 VALUES (1); | ||
connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1; | ||
SET DEBUG_SYNC = "now WAIT_FOR reached"; | ||
SET GLOBAL DEBUG_DBUG = "+d,sync.wsrep_abort_transaction_read_only"; | ||
connection node_2; | ||
ALTER TABLE t1 ADD COLUMN f2 INT; | ||
connection node_1_ctrl; | ||
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_abort_transaction_read_only_reached"; | ||
SET DEBUG_SYNC = "now SIGNAL continue"; | ||
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_abort_transaction_read_only"; | ||
connection node_1; | ||
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction | ||
SET DEBUG_SYNC = "RESET"; | ||
DROP TABLE t1; |
This file contains 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 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 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
45 changes: 45 additions & 0 deletions
45
mysql-test/suite/galera/t/galera_bf_abort_registering.test
This file contains 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,45 @@ | ||
# | ||
# Test that BF abort through MDL aborts InnoDB transaction which | ||
# is registering. | ||
# | ||
|
||
--source include/galera_cluster.inc | ||
--source include/have_innodb.inc | ||
--source include/have_debug_sync.inc | ||
|
||
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; | ||
|
||
--let $debug_dbug_orig = `SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = 'debug_dbug'` | ||
|
||
--connection node_1 | ||
SET SESSION wsrep_retry_autocommit = 0; | ||
# Stop execution in trans_register_ha() | ||
SET SESSION DEBUG_SYNC = "wsrep_after_trans_register_ha SIGNAL reached WAIT_FOR continue"; | ||
--send INSERT INTO t1 VALUES (1) | ||
|
||
--connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1 | ||
SET DEBUG_SYNC = "now WAIT_FOR reached"; | ||
|
||
# Stop APPLIER execution in wsrep_abort_transaction_read_only after | ||
# finding that victim is read only. | ||
SET GLOBAL DEBUG_DBUG = "+d,sync.wsrep_abort_transaction_read_only"; | ||
|
||
--connection node_2 | ||
ALTER TABLE t1 ADD COLUMN f2 INT; | ||
|
||
--connection node_1_ctrl | ||
# Wait for BF thread to arrive in sync point | ||
SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_abort_transaction_read_only_reached"; | ||
# Let the local INSERT continue | ||
SET DEBUG_SYNC = "now SIGNAL continue"; | ||
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_abort_transaction_read_only"; | ||
--connection node_1 | ||
--error ER_LOCK_DEADLOCK | ||
--reap | ||
|
||
SET DEBUG_SYNC = "RESET"; | ||
--disable_query_log | ||
--eval SET GLOBAL DEBUG_DBUG = "$debug_dbug_orig" | ||
--enable_query_log | ||
|
||
DROP TABLE t1; |
This file contains 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 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 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 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 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.