#At file:///export/home/z/mysql-6.0-codebase-bugfixing-bug47249/ based on revid:tor.didriksen@stripped
2824 Jon Olav Hauglid 2009-09-18
Bug #47249 assert in MDL_global_lock::is_lock_type_compatible
This assert could be triggered if LOCK TABLES were used to lock
both a table and a view that used the same table. The table would have
to be first WRITE locked and then READ locked. So "LOCK TABLES v1
WRITE, t1 READ" would eventually trigger the assert, "LOCK TABLES
v1 READ, t1 WRITE" would not. The reason is that the ordering of locks
in the interal representation made a difference when executing
FLUSH TABLE on the table.
During FLUSH TABLE, a lock was upgraded to exclusive. If this lock
is of type MDL_SHARED and not MDL_SHARED_UPGRADABLE, an internal
counter in the MDL subsystem would get out of sync. This would happen
if the *last* mention of the table in LOCK TABLES was a READ lock.
The counter in question is the number exclusive locks (active or intention).
This is used to make sure a global metadata lock is only taken when the
counter is zero (= no conflicts). The counter was increased when a
MDL_EXCLUSIVE or MDL_SHARED_UPGRADABLE lock is taken, but not when
upgrade_shared_lock_to_exclusive() was used to upgrade directly
from MDL_SHARED to MDL_EXCLUSIVE. This patch fixed the problem by increasing
the counter if a MDL_SHARED lock is upgraded to MDL_EXCLUSIVE.
Test case added to mdl_sync.test.
modified:
mysql-test/r/mdl_sync.result
mysql-test/t/mdl_sync.test
sql/mdl.cc
=== modified file 'mysql-test/r/mdl_sync.result'
--- a/mysql-test/r/mdl_sync.result 2009-09-01 15:57:05 +0000
+++ b/mysql-test/r/mdl_sync.result 2009-09-18 11:31:47 +0000
@@ -254,3 +254,34 @@ commit;
# Switching to connection 'default'.
# Clean-up
drop table t1;
+#
+# Bug#47249 assert in MDL_global_lock::is_lock_type_compatible
+#
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+#
+# Test 1: LOCK TABLES v1 WRITE, t1 READ;
+#
+CREATE TABLE t1 ( f1 integer );
+CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+# Connection 2
+LOCK TABLES v1 WRITE, t1 READ;
+FLUSH TABLE t1;
+# Connection 1
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1;
+DROP TABLE t1;
+DROP VIEW v1;
+#
+# Test 2: LOCK TABLES t1 WRITE, v1 READ;
+#
+CREATE TABLE t1 ( f1 integer );
+CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+# Connection 2
+LOCK TABLES t1 WRITE, v1 READ;
+FLUSH TABLE t1;
+# Connection 1
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1;
+DROP TABLE t1;
+DROP VIEW v1;
=== modified file 'mysql-test/t/mdl_sync.test'
--- a/mysql-test/t/mdl_sync.test 2009-09-01 15:57:05 +0000
+++ b/mysql-test/t/mdl_sync.test 2009-09-18 11:31:47 +0000
@@ -475,6 +475,62 @@ disconnect con46673;
drop table t1;
+--echo #
+--echo # Bug#47249 assert in MDL_global_lock::is_lock_type_compatible
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+--enable_warnings
+
+--echo #
+--echo # Test 1: LOCK TABLES v1 WRITE, t1 READ;
+--echo #
+
+CREATE TABLE t1 ( f1 integer );
+CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+
+--echo # Connection 2
+connect (con2,localhost,root);
+LOCK TABLES v1 WRITE, t1 READ;
+FLUSH TABLE t1;
+disconnect con2;
+--source include/wait_until_disconnected.inc
+
+--echo # Connection 1
+connection default;
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1; # Assertion happened here
+
+# Cleanup
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #
+--echo # Test 2: LOCK TABLES t1 WRITE, v1 READ;
+--echo #
+
+CREATE TABLE t1 ( f1 integer );
+CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+
+--echo # Connection 2
+connect (con2,localhost,root);
+LOCK TABLES t1 WRITE, v1 READ;
+FLUSH TABLE t1;
+disconnect con2;
+--source include/wait_until_disconnected.inc
+
+--echo # Connection 1
+connection default;
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1; # Assertion happened here
+
+# Cleanup
+DROP TABLE t1;
+DROP VIEW v1;
+
+
# 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
=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc 2009-09-16 14:26:50 +0000
+++ b/sql/mdl.cc 2009-09-18 11:31:47 +0000
@@ -1075,6 +1075,13 @@ MDL_ticket::upgrade_shared_lock_to_exclu
}
}
+ /*
+ Counter already updated for MDL_SHARED_UPGRADABLE, but
+ needs to be adjusted if we upgrade from MDL_SHARED.
+ */
+ if (m_type == MDL_SHARED)
+ global_lock.active_intention_exclusive++;
+
m_lock->type= MDL_lock::MDL_LOCK_EXCLUSIVE;
/* Set the new type of lock in the ticket. */
m_type= MDL_EXCLUSIVE;
Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20090918113147-0fi2o3iowusv6hlr.bundle