Skip to content

Commit cf23a80

Browse files
author
Dmitry Lenev
committed
Fix for sporadical crashes of lock_multi_bug38499.test
caused by patch which implemented new type-of-operation-aware metadata locks and added a wait-for graph based deadlock detector to the MDL subsystem (this patch fixed bug #46272 "MySQL 5.4.4, new MDL: unnecessary deadlock" and bug #37346 "innodb does not detect deadlock between update and alter table"). Crashes were caused by a race in MDL_context::try_acquire_lock(). This method added MDL_ticket to the list of granted tickets and released lock protecting list before setting MDL_ticket::m_lock. Thus some other thread was able to see ticket without properly set m_lock member for some short period of time. If this thread called method involving this member during this period crash happened. This fix ensures that MDL_ticket::m_lock is set in all cases when ticket is added to granted/pending lists in MDL_lock. --BZR-- revision-id: [email protected] property-branch-nick: mysql-next-4284-nl-push property-file-info: ld7:file_id40:mdl.cc-20080523121737-j62pi0m62eaw1hq6-17:message324:We must set MDL_ticket::m_lock member before adding ticket property-file-info: to the list of granted tickets, since such tickets can be property-file-info: accessed by other threads which might call methods using property-file-info: this member. property-file-info: Added assert which ensures that all MDL_tickets which are property-file-info: added to the granted/pending lists have properly set property-file-info: MDL_ticket::m_lock member.4:path10:sql/mdl.cced7:file_id39:mdl.h-20080523121748-o4y2wcq3maotb9do-17:message120:Adjusted comment describing MDL_ticket::m_lock member to property-file-info: reflect current reality. property-file-info: Added accessor method for this member.4:path9:sql/mdl.hee testament3-sha1: c51a82262c714dad4615811908b8ef1f87b5c276
1 parent d75921b commit cf23a80

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sql/mdl.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,12 @@ void MDL_lock::Ticket_list::clear_bit_if_not_in_list(enum_mdl_type type)
838838

839839
void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
840840
{
841+
/*
842+
Ticket being added to the list must have MDL_ticket::m_lock set,
843+
since for such tickets methods accessing this member might be
844+
called by other threads.
845+
*/
846+
DBUG_ASSERT(ticket->get_lock());
841847
m_list.push_front(ticket);
842848
m_bitmap|= MDL_BIT(ticket->get_type());
843849
}
@@ -1317,11 +1323,10 @@ MDL_context::try_acquire_lock(MDL_request *mdl_request)
13171323

13181324
if (lock->can_grant_lock(mdl_request->type, this))
13191325
{
1326+
ticket->m_lock= lock;
13201327
lock->m_granted.add_ticket(ticket);
13211328
rw_unlock(&lock->m_rwlock);
13221329

1323-
ticket->m_lock= lock;
1324-
13251330
m_tickets.push_front(ticket);
13261331

13271332
mdl_request->ticket= ticket;

sql/mdl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class MDL_ticket
397397
m_type == MDL_EXCLUSIVE;
398398
}
399399
enum_mdl_type get_type() const { return m_type; }
400+
MDL_lock *get_lock() const { return m_lock; }
400401
void downgrade_exclusive_lock(enum_mdl_type type);
401402

402403
bool has_stronger_or_equal_type(enum_mdl_type type) const;
@@ -423,7 +424,9 @@ class MDL_ticket
423424
*/
424425
MDL_context *m_ctx;
425426

426-
/** Pointer to the lock object for this lock ticket. Context private. */
427+
/**
428+
Pointer to the lock object for this lock ticket. Externally accessible.
429+
*/
427430
MDL_lock *m_lock;
428431

429432
private:

0 commit comments

Comments
 (0)