mariadb/mysql-test/r/flush_block_commit.result
Konstantin Osipov e001a9f0d0 Backport of:
------------------------------------------------------------
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.
2009-12-09 18:56:34 +03:00

65 lines
1.5 KiB
Text

# Save the initial number of concurrent sessions
# Establish connection con1 (user=root)
# Establish connection con2 (user=root)
# Establish connection con3 (user=root)
# Switch to connection con1
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT) ENGINE=innodb;
BEGIN;
INSERT INTO t1 VALUES(1);
# Switch to connection con2
FLUSH TABLES WITH READ LOCK;
# Switch to connection con1
# Sending:
COMMIT;
# Switch to connection con2
# Wait until COMMIT gets blocked.
# Verify that 'con1' was blocked and data did not move.
SELECT * FROM t1;
a
UNLOCK TABLES;
# Switch to connection con1
# Reaping COMMIT
# Switch to connection con1
BEGIN;
SELECT * FROM t1 FOR UPDATE;
a
1
# Switch to connection con2
BEGIN;
SELECT * FROM t1 FOR UPDATE;
# Switch to connection con3
FLUSH TABLES WITH READ LOCK;
# Switch to connection con1
COMMIT;
# Switch to connection con2
a
1
COMMIT;
# Switch to connection con3
UNLOCK TABLES;
# Switch to connection con2
COMMIT;
# Switch to connection con1
BEGIN;
INSERT INTO t1 VALUES(10);
FLUSH TABLES WITH READ LOCK;
# Switch to connection con2
FLUSH TABLES WITH READ LOCK;
UNLOCK TABLES;
BEGIN;
SELECT * FROM t1;
a
1
10
SHOW CREATE DATABASE test;
Database Create Database
test CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */
COMMIT;
# Cleanup
# Switch to connection default and close connections con1, con2, con3
# We commit open transactions when we disconnect: only then we can
# drop the table.
DROP TABLE t1;
# End of 4.1 tests
# Wait till all disconnects are completed