• Dmitry Lenev's avatar
    Fix for sporadical crashes of lock_multi_bug38499.test · 575c7b37
    Dmitry Lenev authored
    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.
    
    sql/mdl.cc:
      We must set MDL_ticket::m_lock member before adding ticket
      to the list of granted tickets, since such tickets can be
      accessed by other threads which might call methods using
      this member.
      Added assert which ensures that all MDL_tickets which are
      added to the granted/pending lists have properly set
      MDL_ticket::m_lock member.
    sql/mdl.h:
      Adjusted comment describing MDL_ticket::m_lock member to
      reflect current reality.
      Added accessor method for this member.
    575c7b37
mdl.cc 62 KB