Commit c01f008c authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

Bug #50912 Assertion `ticket->m_type >= mdl_request->type'

           failed on HANDLER + I_S

This assert was triggered when an I_S query tried to acquire a
metadata lock on a table which was already locked by a HANDLER
statement in the same connection.

First the HANDLER took a MDL_SHARED lock. Afterwards, the I_S query
requested a MDL_SHARED_HIGH_PRIO lock. The existing MDL_SHARED ticket
is found in find_ticket() since it satisfies 
ticket->has_stronger_or_equal_type(mdl_request->type) as MDL_SHARED
and MDL_SHARED_HIGH_PRIO have equal strengths, just different priority.

However, two asserts later check lock type strengths using relational
operators (>= and <=) rather than MDL_ticket::has_stronger_or_equal_type().
These asserts are triggered since MDL_SHARED >= MDL_SHARED_HIGH_PRIORITY
is false (mapped to 1 and 2 respectively).

This patch updates the asserts to use MDL_ticket::has_stronger_or_equal_type()
rather than relational operators to check lock type strength.

Test case added to include/handler.inc.
parent f95f3506
......@@ -1522,3 +1522,23 @@ HANDLER t2 READ FIRST;
HANDLER t2 CLOSE;
DROP TABLE t1, t2;
--echo #
--echo # Bug#50912 Assertion `ticket->m_type >= mdl_request->type'
--echo # failed on HANDLER + I_S
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (id INT);
HANDLER t1 OPEN;
# This used to trigger the assert.
SELECT table_name, table_comment FROM information_schema.tables
WHERE table_schema= 'test' AND table_name= 't1';
HANDLER t1 CLOSE;
DROP TABLE t1;
......@@ -1476,3 +1476,16 @@ HANDLER t2 READ FIRST;
i
HANDLER t2 CLOSE;
DROP TABLE t1, t2;
#
# Bug#50912 Assertion `ticket->m_type >= mdl_request->type'
# failed on HANDLER + I_S
#
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT);
HANDLER t1 OPEN;
SELECT table_name, table_comment FROM information_schema.tables
WHERE table_schema= 'test' AND table_name= 't1';
table_name table_comment
t1
HANDLER t1 CLOSE;
DROP TABLE t1;
......@@ -1474,6 +1474,19 @@ i
HANDLER t2 CLOSE;
DROP TABLE t1, t2;
#
# Bug#50912 Assertion `ticket->m_type >= mdl_request->type'
# failed on HANDLER + I_S
#
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT);
HANDLER t1 OPEN;
SELECT table_name, table_comment FROM information_schema.tables
WHERE table_schema= 'test' AND table_name= 't1';
table_name table_comment
t1
HANDLER t1 CLOSE;
DROP TABLE t1;
#
# BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
#
CREATE TABLE t1 AS SELECT 1 AS f1;
......
......@@ -1261,7 +1261,7 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request)
if ((ticket= find_ticket(mdl_request, &is_transactional)))
{
DBUG_ASSERT(ticket->m_lock);
DBUG_ASSERT(ticket->m_type >= mdl_request->type);
DBUG_ASSERT(ticket->has_stronger_or_equal_type(mdl_request->type));
/*
If the request is for a transactional lock, and we found
a transactional lock, just reuse the found ticket.
......@@ -1349,7 +1349,7 @@ MDL_context::clone_ticket(MDL_request *mdl_request)
return TRUE;
/* clone() is not supposed to be used to get a stronger lock. */
DBUG_ASSERT(ticket->m_type <= mdl_request->ticket->m_type);
DBUG_ASSERT(mdl_request->ticket->has_stronger_or_equal_type(ticket->m_type));
ticket->m_lock= mdl_request->ticket->m_lock;
mdl_request->ticket= ticket;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment