mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
e001a9f0d0
------------------------------------------------------------ revno: 2617.68.10 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-next-bg46673 timestamp: Tue 2009-09-01 19:57:05 +0400 message: Fix for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". Deadlocks occured when one concurrently executed transactions with several statements modifying data and FLUSH TABLES WITH READ LOCK statement or SET READ_ONLY=1 statement. These deadlocks were introduced by the patch for WL 4284: "Transactional DDL locking"/Bug 989: "If DROP TABLE while there's an active transaction, wrong binlog order" which has changed FLUSH TABLES WITH READ LOCK/SET READ_ONLY=1 to wait for pending transactions. What happened was that FLUSH TABLES WITH READ LOCK blocked all further statements changing tables by setting global_read_lock global variable and has started waiting for all pending transactions to complete. Then one of those transactions tried to executed DML, detected that global_read_lock non-zero and tried to wait until global read lock will be released (i.e. global_read_lock becomes 0), indeed, this led to a deadlock. Proper solution for this problem should probably involve full integration of global read lock with metadata locking subsystem (which will allow to implement waiting for pending transactions without blocking DML in them). But since it requires significant changes another, short-term solution for the problem is implemented in this patch. Basically, this patch restores behavior of FLUSH TABLES WITH READ LOCK/ SET READ_ONLY=1 before the patch for WL 4284/bug 989. By ensuring that extra references to TABLE_SHARE are not stored for active metadata locks it changes these statements not to wait for pending transactions. As result deadlock is eliminated. Note that this does not change the fact that active FLUSH TABLES WITH READ LOCK lock or SET READ_ONLY=1 prevent modifications to tables as they also block transaction commits. mysql-test/r/flush_block_commit.result: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/r/mdl_sync.result: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/r/read_only_innodb.result: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. mysql-test/t/flush_block_commit.test: Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior - it is no longer blocked by a pending transaction. mysql-test/t/mdl_sync.test: Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML". mysql-test/t/read_only_innodb.test: Adjusted test case after change in SET READ_ONLY behavior - it is no longer blocked by a pending transaction. sql/sql_base.cc: Disable caching of pointers to TABLE_SHARE objects in MDL subsystem. This means that transactions holding metadata lock on the table will no longer have extra reference to the TABLE_SHARE (due to this lock) and will no longer block concurrent FLUSH TABLES/FLUSH TABLES WITH READ LOCK. Note that this does not change the fact that FLUSH TABLES WITH READ LOCK prevents concurrent transactions from modifying data as it also blocks all commits.
116 lines
2.9 KiB
Text
116 lines
2.9 KiB
Text
# Let's see if FLUSH TABLES WITH READ LOCK blocks COMMIT of existing
|
|
# transactions.
|
|
# We verify that we did not introduce a deadlock.
|
|
# This is intended to mimick how mysqldump and innobackup work.
|
|
|
|
# And it requires InnoDB
|
|
--source include/have_innodb.inc
|
|
|
|
--echo # Save the initial number of concurrent sessions
|
|
--source include/count_sessions.inc
|
|
|
|
--echo # Establish connection con1 (user=root)
|
|
connect (con1,localhost,root,,);
|
|
--echo # Establish connection con2 (user=root)
|
|
connect (con2,localhost,root,,);
|
|
--echo # Establish connection con3 (user=root)
|
|
connect (con3,localhost,root,,);
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
|
|
--disable_warnings
|
|
DROP TABLE IF EXISTS t1;
|
|
--enable_warnings
|
|
CREATE TABLE t1 (a INT) ENGINE=innodb;
|
|
|
|
# blocks COMMIT ?
|
|
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES(1);
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
FLUSH TABLES WITH READ LOCK;
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
--echo # Sending:
|
|
--send COMMIT
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
--echo # Wait until COMMIT gets blocked.
|
|
let $wait_condition=
|
|
select count(*) = 1 from information_schema.processlist
|
|
where state = "Waiting for release of readlock" and info = "COMMIT";
|
|
--source include/wait_condition.inc
|
|
--echo # Verify that 'con1' was blocked and data did not move.
|
|
SELECT * FROM t1;
|
|
UNLOCK TABLES;
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
--echo # Reaping COMMIT
|
|
--reap
|
|
|
|
# No deadlock ?
|
|
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
BEGIN;
|
|
SELECT * FROM t1 FOR UPDATE;
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
BEGIN;
|
|
send SELECT * FROM t1 FOR UPDATE; # blocked by con1
|
|
sleep 1;
|
|
--echo # Switch to connection con3
|
|
connection con3;
|
|
send FLUSH TABLES WITH READ LOCK; # blocked by con2
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
COMMIT; # should not be blocked by con3
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
reap;
|
|
COMMIT;
|
|
--echo # Switch to connection con3
|
|
connection con3;
|
|
reap;
|
|
UNLOCK TABLES;
|
|
|
|
# Bug#6732 FLUSH TABLES WITH READ LOCK + COMMIT hangs later FLUSH TABLES
|
|
# WITH READ LOCK
|
|
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
COMMIT; # unlock InnoDB row locks to allow insertions
|
|
--echo # Switch to connection con1
|
|
connection con1;
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES(10);
|
|
FLUSH TABLES WITH READ LOCK;
|
|
--echo # Switch to connection con2
|
|
connection con2;
|
|
FLUSH TABLES WITH READ LOCK; # bug caused hang here
|
|
UNLOCK TABLES;
|
|
|
|
# Bug#7358 SHOW CREATE DATABASE fails if open transaction
|
|
|
|
BEGIN;
|
|
SELECT * FROM t1;
|
|
SHOW CREATE DATABASE test;
|
|
COMMIT;
|
|
|
|
|
|
--echo # Cleanup
|
|
--echo # Switch to connection default and close connections con1, con2, con3
|
|
connection default;
|
|
disconnect con1;
|
|
disconnect con2;
|
|
disconnect con3;
|
|
|
|
--echo # We commit open transactions when we disconnect: only then we can
|
|
--echo # drop the table.
|
|
DROP TABLE t1;
|
|
--echo # End of 4.1 tests
|
|
|
|
--echo # Wait till all disconnects are completed
|
|
--source include/wait_until_count_sessions.inc
|
|
|