1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Acquire global read lock (MDL_BACKUP_STMT) after share is acquired

Part of MDEV-5336 Implement LOCK FOR BACKUP

FLUSH TABLE table_names have changed slighty as we are now opening
tables before taking the MDL lock. The difference is that FLUSH TABLE
table_name will now be blocked by a table that is waiting for FTWRL.
There should not be any new deadlocks as part of this change.

The end result is still better in most cases as FTWRL is now only
waiting for write statements to end, not for read only statements and
it's not flushing tables in use from the table cache.

Share will be needed to be able to determine if table supports online
backup. Appropriate metadata lock type in BACKUP namespace will be
acquired basing on this information.

Also made pending global read lock request to be preferred victim of MDL
deadlock detector. This allows us to hide some non-fatal deadlocks and
make FTWRL less likely to break concurrent queries.
This commit is contained in:
Sergey Vojtovich
2018-10-30 02:00:46 +04:00
committed by Monty
parent 7a9dfdd8d9
commit f1867505a6
8 changed files with 278 additions and 69 deletions

View File

@ -4122,6 +4122,91 @@ DROP TABLE t1;
disconnect con1;
--echo #
--echo # MDEV-5336 - Implement LOCK FOR BACKUP
--echo #
--echo # Make sure deadlock detector prefers FTWRL connection as a victim
--echo # and FTWRL retries lock attempt. This deadlock was present before
--echo # MDEV-5336.
CREATE TABLE t1(a INT) ENGINE=InnoDB;
CREATE TABLE t2(a INT) ENGINE=InnoDB;
BEGIN;
SELECT * FROM t2;
--echo #
connect(con1,localhost,root,,);
SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL waiting';
send LOCK TABLES t2 WRITE;
--echo #
connect(con2,localhost,root,,);
SET DEBUG_SYNC='now WAIT_FOR waiting';
SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL waiting';
send FLUSH TABLES WITH READ LOCK;
--echo #
connection default;
SET DEBUG_SYNC='now WAIT_FOR waiting';
INSERT INTO t1 VALUES(1);
COMMIT;
connection con1;
reap;
UNLOCK TABLES;
connection con2;
reap;
UNLOCK TABLES;
connection default;
DROP TABLE t1, t2;
SET DEBUG_SYNC='RESET';
disconnect con1;
disconnect con2;
--echo # Make sure deadlock detector prefers FTWRL connection as a victim
--echo # and FTWRL retries lock attempt. This deadlock was found during
--echo # MDEV-5336 review.
CREATE TABLE t1(a INT) ENGINE=InnoDB;
CREATE TABLE t2(a INT) ENGINE=InnoDB;
BEGIN;
INSERT INTO t2 VALUES(1);
SET DEBUG_SYNC='after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR go';
send INSERT INTO t1 VALUES(1);
--echo #
connect(con1,localhost,root,,);
SET DEBUG_SYNC='now WAIT_FOR table_opened';
SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL waiting';
send LOCK TABLES t1 WRITE;
--echo #
connect(con2,localhost,root,,);
SET DEBUG_SYNC='now WAIT_FOR waiting';
SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL waiting';
send FLUSH TABLES WITH READ LOCK;
--echo #
connect(con3,localhost,root,,);
SET DEBUG_SYNC='now WAIT_FOR waiting';
SET DEBUG_SYNC='now SIGNAL go';
connection default;
reap;
COMMIT;
connection con1;
reap;
UNLOCK TABLES;
connection con2;
reap;
UNLOCK TABLES;
connection default;
DROP TABLE t1, t2;
SET DEBUG_SYNC='RESET';
disconnect con1;
disconnect con2;
disconnect con3;
# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc