• Vlad Lesin's avatar
    MDEV-31049 fil_delete_tablespace() returns wrong file handle if tablespace was... · 71f16c83
    Vlad Lesin authored
    MDEV-31049 fil_delete_tablespace() returns wrong file handle if tablespace was closed by parallel thread
    
    fil_delete_tablespace() stores file handle in local variable and calls
    mtr_t::commit_file()=>fil_system_t::detach(..., detach_handle=true), which
    sets space->chain.start->handle = OS_FILE_CLOSED. fil_system_t::detach()
    is invoked under fil_system.mutex.
    
    But before the mutex is acquired some parallel thread can change
    space->chain.start->handle. fil_delete_tablespace() returns value, stored
    in local variable, i.e. wrong value.
    
    File handle can be closed, for example, from buf_flush_space() when the
    limit of innodb_open_files exceded and fil_space_t::get() causes
    fil_space_t::try_to_close() call.
    
    fil_space_t::try_to_close() is executed under fil_system.mutex. And
    mtr_t::commit_file() locks it for fil_system_t::detach() call.
    fil_system_t::detach() returns detached file handle if its argument
    detach_handle is true. The fix is to let mtr_t::commit_file() to pass
    that detached file handle to fil_delete_tablespace().
    71f16c83
mtr0mtr.cc 36.2 KB