[Commits] 9c1ecbe: MDEV-12882 - Assertion failed in MDL_context::upgrade_shared_lock

Sergey Vojtovich svoj at mariadb.org
Fri Jun 23 09:12:55 EEST 2017


revision-id: 9c1ecbec33cbbeacdffa25c41499a5945ce20fa7 (mariadb-10.2.6-58-g9c1ecbe)
parent(s): 62021f391a42c5577190aa43cb8ad91e56235b46
committer: Sergey Vojtovich
timestamp: 2017-06-23 10:12:49 +0400
message:

MDEV-12882 - Assertion failed in MDL_context::upgrade_shared_lock

Relaxed assertion (in MySQL it was removed).
For "LOCK TABLES t1 WRITE CONCURRENT, t1 READ" upgrade lock to weakest
existing suitable lock, which is MDL_SHARED_NO_READ_WRITE.

---
 mysql-test/r/mdl.result | 22 ++++++++++++++++++++++
 mysql-test/t/mdl.test   | 19 +++++++++++++++++++
 sql/mdl.cc              |  5 +++--
 sql/sql_parse.cc        |  6 +++++-
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/mdl.result b/mysql-test/r/mdl.result
new file mode 100644
index 0000000..1a7291d
--- /dev/null
+++ b/mysql-test/r/mdl.result
@@ -0,0 +1,22 @@
+#
+# MDEV-12882 - Assertion `mdl_ticket->m_type == MDL_SHARED_UPGRADABLE ||
+#                         mdl_ticket->m_type == MDL_SHARED_NO_WRITE ||
+#                         mdl_ticket->m_type == MDL_SHARED_NO_READ_WRITE ||
+#                         mdl_ticket->m_type == MDL_SHARED_READ'
+#                         failed in MDL_context::upgrade_shared_lock
+#
+CREATE TABLE t1(a INT) ENGINE=InnoDB;
+LOCK TABLES t1 WRITE CONCURRENT, t1 AS t2 READ;
+SELECT * FROM information_schema.metadata_lock_info;
+THREAD_ID	LOCK_MODE	LOCK_DURATION	LOCK_TYPE	TABLE_SCHEMA	TABLE_NAME
+9	MDL_INTENTION_EXCLUSIVE	NULL	Global read lock		
+9	MDL_SHARED_NO_READ_WRITE	NULL	Table metadata lock	test	t1
+UNLOCK TABLES;
+LOCK TABLES t1 AS t2 READ, t1 WRITE CONCURRENT;
+SELECT * FROM information_schema.metadata_lock_info;
+THREAD_ID	LOCK_MODE	LOCK_DURATION	LOCK_TYPE	TABLE_SCHEMA	TABLE_NAME
+9	MDL_INTENTION_EXCLUSIVE	NULL	Global read lock		
+9	MDL_SHARED_WRITE	NULL	Table metadata lock	test	t1
+9	MDL_SHARED_READ_ONLY	NULL	Table metadata lock	test	t1
+UNLOCK TABLES;
+DROP TABLE t1;
diff --git a/mysql-test/t/mdl.test b/mysql-test/t/mdl.test
new file mode 100644
index 0000000..1770e53b
--- /dev/null
+++ b/mysql-test/t/mdl.test
@@ -0,0 +1,19 @@
+--source include/have_metadata_lock_info.inc
+--source include/have_innodb.inc
+
+--echo #
+--echo # MDEV-12882 - Assertion `mdl_ticket->m_type == MDL_SHARED_UPGRADABLE ||
+--echo #                         mdl_ticket->m_type == MDL_SHARED_NO_WRITE ||
+--echo #                         mdl_ticket->m_type == MDL_SHARED_NO_READ_WRITE ||
+--echo #                         mdl_ticket->m_type == MDL_SHARED_READ'
+--echo #                         failed in MDL_context::upgrade_shared_lock
+--echo #
+
+CREATE TABLE t1(a INT) ENGINE=InnoDB;
+LOCK TABLES t1 WRITE CONCURRENT, t1 AS t2 READ;
+SELECT * FROM information_schema.metadata_lock_info;
+UNLOCK TABLES;
+LOCK TABLES t1 AS t2 READ, t1 WRITE CONCURRENT;
+SELECT * FROM information_schema.metadata_lock_info;
+UNLOCK TABLES;
+DROP TABLE t1;
diff --git a/sql/mdl.cc b/sql/mdl.cc
index f1a505f..25809c3 100644
--- a/sql/mdl.cc
+++ b/sql/mdl.cc
@@ -2320,11 +2320,12 @@ MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket,
   if (mdl_ticket->has_stronger_or_equal_type(new_type))
     DBUG_RETURN(FALSE);
 
-  /* Only allow upgrades from SHARED_UPGRADABLE/NO_WRITE/NO_READ_WRITE/READ */
+  /* Only allow upgrades from UPGRADABLE/NO_WRITE/NO_READ_WRITE/READ/WRITE */
   DBUG_ASSERT(mdl_ticket->m_type == MDL_SHARED_UPGRADABLE ||
               mdl_ticket->m_type == MDL_SHARED_NO_WRITE ||
               mdl_ticket->m_type == MDL_SHARED_NO_READ_WRITE ||
-              mdl_ticket->m_type == MDL_SHARED_READ);
+              mdl_ticket->m_type == MDL_SHARED_READ ||
+              mdl_ticket->m_type == MDL_SHARED_WRITE);
 
   mdl_xlock_request.init(&mdl_ticket->m_lock->key, new_type,
                          MDL_TRANSACTION);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 412cd1d..7c910e8 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2787,6 +2787,7 @@ static bool lock_tables_open_and_lock_tables(THD *thd, TABLE_LIST *tables)
                ! table->prelocking_placeholder &&
                table->table->file->lock_count() == 0)
       {
+        enum enum_mdl_type lock_type;
         /*
           In case when LOCK TABLE ... READ LOCAL was issued for table with
           storage engine which doesn't support READ LOCAL option and doesn't
@@ -2799,9 +2800,12 @@ static bool lock_tables_open_and_lock_tables(THD *thd, TABLE_LIST *tables)
         deadlock_handler.init();
         thd->push_internal_handler(&deadlock_handler);
 
+        lock_type= table->table->mdl_ticket->get_type() == MDL_SHARED_WRITE ?
+                   MDL_SHARED_NO_READ_WRITE : MDL_SHARED_READ_ONLY;
+
         bool result= thd->mdl_context.upgrade_shared_lock(
                                         table->table->mdl_ticket,
-                                        MDL_SHARED_READ_ONLY,
+                                        lock_type,
                                         thd->variables.lock_wait_timeout);
 
         thd->pop_internal_handler();


More information about the commits mailing list