• Eugene Kosov's avatar
    MDEV-8069 DROP or rebuild of a large table may lock up InnoDB · 264a98ea
    Eugene Kosov authored
    Problematic mutex is dict_sys.mutex.
    Idea of the patch: unlink() fd under that mutex while
    it's still open. This way unlink() will be fast and
    actual file removal will happen on close().
    And close() will be called outside of dict_sys.mutex.
    This should be safe against crash which may happen between
    unlink() and close(): file will be removed by OS anyway.
    The same applies to both *nix and Windows.
    
    I created and removed a 4G file on some NVMe SSD on ext4:
    
    write(3, "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"..., 1048576) = 1048576 <0.000519>
    fdatasync(3)                            = 0 <3.533763>
    close(3)                                = 0 <0.000011>
    unlink("file")                          = 0 <0.411563>
    
    write(3, "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"..., 1048576) = 1048576 <0.000520>
    fdatasync(3)                            = 0 <3.544938>
    unlink("file")                          = 0 <0.000029>
    close(3)                                = 0 <0.407057>
    
    Such systems can benefit of this patch.
    
    fil_node_t::detach(): closes fil_node_t but not file handle,
      returns that file handle
    
    fil_node_t::prepare_to_close_or_deatch(): 'closes' fil_node_t
    
    fil_node_t:close_to_free(): new argument detach_handle
    
    fil_system_t::detach(): now can detach file handles
    
    fil_delete_tablespace(): now can detach file handles
    
    row_drop_table_for_mysql(): performs actual file removal
    264a98ea
row0mysql.cc 130 KB