• Jon Olav Hauglid's avatar
    Bug #48724 Deadlock between INSERT DELAYED and FLUSH TABLES · 911550d5
    Jon Olav Hauglid authored
    If the handler (or delayed insert) thread failed to lock a table due
    to being killed, the "dead" flag was used to notify the connection thread
    of this failure. However, with the changes introduced by Bug#45949, 
    the handler thread will no longer try to lock the table if it was killed.
    This meant that the "dead" flag would not be set, and the connection
    thread would not notice that the handler thread had failed.
    
    This could happen with concurrent INSERT DELAYED and FLUSH TABLES.
    FLUSH TABLES would kill any active INSERT DELAYED that had opened any
    table(s) to be flushed. This could cause the INSERT DELAYED connection
    thread to be stuck waiting for the handler thread to lock its table,
    while the handler thread would be looping, trying to get the connection
    thread to notice the error.
    
    The root of the problem was that the handler thread had both the "dead"
    flag and "thd->killed" to indicate that it had been killed. Most places
    both were set, but some only set "thd->killed". And 
    Delayed_insert::get_local_table() only checked "dead" while waiting for
    the table to be locked.
    
    This patch removes the "dead" variable and replaces its usage with
    "thd->killed", thereby resolving the issue.
    911550d5
sql_insert.cc 130 KB