mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug #54332 Deadlock with two connections doing LOCK TABLE+INSERT DELAYED
The problem was that deadlocks involving INSERT DELAYED were not detected. The reason for this is that two threads are involved in INSERT DELAYED: the connection thread and the handler thread. The connection thread would wait while the handler thread acquired locks and opened the table. In essence, this adds an edge to the wait-for-graph between the connection thread and the handler thread that the deadlock detector is unaware of. Therefore many deadlocks involving INSERT DELAYED were not detected. This patch fixes the problem by having the connection thread acquire the metadata lock the table before starting the handler thread. This allows the deadlock detector to detect any possible deadlocks resulting from trying to acquire a metadata lock the table. If a metadata lock is successfully acquired, the handler thread is started and given a copy of the ticket representing the metadata lock. When the handler thread then tries to lock and open the table, it will find that it already has the metadata lock and therefore not acquire any new metadata locks. Test cases added to delayed.test.
This commit is contained in:
@ -345,3 +345,78 @@ CREATE TABLE t1 LIKE t2;
|
||||
ERROR 42S01: Table 't1' already exists
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug#54332 Deadlock with two connections doing LOCK TABLE+INSERT DELAYED
|
||||
#
|
||||
DROP TABLE IF EXISTS t1, t2;
|
||||
CREATE TABLE t1 (a INT);
|
||||
CREATE TABLE t2 (a INT);
|
||||
CREATE TABLE t3 (a INT);
|
||||
# Test 1: Using LOCK TABLE
|
||||
# Connection con1
|
||||
LOCK TABLE t1 WRITE;
|
||||
# Connection default
|
||||
LOCK TABLE t2 WRITE;
|
||||
# Sending:
|
||||
INSERT DELAYED INTO t1 VALUES (1);
|
||||
# Connection con1
|
||||
# Wait until INSERT DELAYED is blocked on table 't1'.
|
||||
INSERT DELAYED INTO t2 VALUES (1);
|
||||
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
||||
UNLOCK TABLES;
|
||||
# Connection default
|
||||
# Reaping: INSERT DELAYED INTO t1 VALUES (1)
|
||||
UNLOCK TABLES;
|
||||
# Test 2: Using ALTER TABLE
|
||||
START TRANSACTION;
|
||||
SELECT * FROM t1 WHERE a=0;
|
||||
a
|
||||
# Connection con1
|
||||
# Sending:
|
||||
ALTER TABLE t1 COMMENT 'test';
|
||||
# Connection default
|
||||
# Wait until ALTER TABLE is blocked on table 't1'.
|
||||
INSERT DELAYED INTO t1 VALUES (3);
|
||||
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
||||
COMMIT;
|
||||
# Connection con1
|
||||
# Reaping: ALTER TABLE t1 COMMENT 'test'
|
||||
# Test 3: Using RENAME TABLE
|
||||
# Connection default
|
||||
START TRANSACTION;
|
||||
INSERT INTO t2 VALUES (1);
|
||||
# Connection con1
|
||||
# Sending:
|
||||
RENAME TABLE t1 to t5, t2 to t4;
|
||||
# Connection default
|
||||
# Wait until RENAME TABLE is blocked on table 't1'.
|
||||
INSERT DELAYED INTO t1 VALUES (4);
|
||||
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
||||
COMMIT;
|
||||
# Connection con1
|
||||
# Reaping: RENAME TABLE t1 to t5, t2 to t4
|
||||
# Connection default
|
||||
# Reverting the renames
|
||||
RENAME TABLE t5 to t1, t4 to t2;
|
||||
# Test 4: Two INSERT DELAYED on the same table
|
||||
START TRANSACTION;
|
||||
INSERT INTO t2 VALUES (1);
|
||||
# Connection con2
|
||||
LOCK TABLE t1 WRITE, t2 WRITE;
|
||||
# Connection con1
|
||||
# Wait until LOCK TABLE is blocked on table 't2'.
|
||||
INSERT DELAYED INTO t1 VALUES (5);
|
||||
# Connection default
|
||||
# Wait until INSERT DELAYED is blocked on table 't1'.
|
||||
INSERT DELAYED INTO t1 VALUES (6);
|
||||
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
||||
COMMIT;
|
||||
# Connection con2
|
||||
# Reaping: LOCK TABLE t1 WRITE, t2 WRITE
|
||||
UNLOCK TABLES;
|
||||
# Connection con1
|
||||
# Reaping: INSERT DELAYED INTO t1 VALUES (5)
|
||||
# Connection con2
|
||||
# Connection con1
|
||||
# Connection default
|
||||
DROP TABLE t1, t2, t3;
|
||||
|
Reference in New Issue
Block a user