• Dmitry Lenev's avatar
    Patch that changes approach to how we acquire metadata · 571acc87
    Dmitry Lenev authored
    locks for DML statements and changes the way MDL locks
    are acquired/granted in contended case.
    
    Instead of backing-off when a lock conflict is encountered
    and waiting for it to go away before restarting open_tables()
    process we now wait for lock to be released without releasing
    any previously acquired locks. If conflicting lock goes away
    we resume opening tables. If waiting leads to a deadlock we
    try to resolve it by backing-off and restarting open_tables()
    immediately.
    
    As result both waiting for possibility to acquire and
    acquiring of a metadata lock now always happen within the
    same MDL API call. This has allowed to make release of a lock
    and granting it to the most appropriate pending request an
    atomic operation.
    Thanks to this it became possible to wake up during release
    of lock only those waiters which requests can be satisfied
    at the moment as well as wake up only one waiter in case
    when granting its request would prevent all other requests
    from being satisfied. This solves thundering herd problem
    which occured in cases when we were releasing some lock and
    woke up many waiters for SNRW or X locks (this was the issue
    in bug#52289 "performance regression for MyISAM in sysbench
    OLTP_RW test".
    This also allowed to implement more fair (FIFO) scheduling
    among waiters with the same priority.
    It also opens the door for introducing new types of requests
    for metadata locks such as low-prio SNRW lock which is
    necessary in order to support LOCK TABLES LOW_PRIORITY WRITE.
    
    Notice that after this sometimes can report ER_LOCK_DEADLOCK
    error in cases in which it has not happened before.
    Particularly we will always report this error if waiting for
    conflicting lock has happened in the middle of transaction
    and resulted in a deadlock. Before this patch the error was
    not reported if deadlock could have been resolved by backing
    off all metadata locks acquired by the current statement.
    571acc87
sql_plist.h 6.63 KB