• Sergey Vojtovich's avatar
    MDEV-8889 - Assertion `next_insert_id == 0' failed in handler::ha_external_lock · 994030c0
    Sergey Vojtovich authored
    There was a race condition between delayed insert thread and connection thread
    actually performing INSERT/REPLACE DELAYED. It was triggered by concurrent
    INSERT/REPLACE DELAYED and statements that flush the same table either
    explicitely or implicitely (like FLUSH TABLE, ALTER TABLE, ...).
    
    This race condition was caused by a gap in delayed thread shutdown logic,
    which allowed concurrent connection running INSERT/REPLACE DELAYED to change
    essential data consequently leaving table in semi-consistent state.
    
    Specifically query thread could decrease "tables_in_use" reference counter in
    this gap, causing delayed insert thread to shutdown without releasing auto
    increment and table lock.
    
    Fixed by extending condition so that delayed insert thread won't shutdown
    until there're locked tables.
    
    Also removed volatile qualifier from tables_in_use and stacked_inserts since
    they're supposed to be protected by mutexes.
    994030c0
sql_insert.cc 143 KB