• Sergey Vojtovich's avatar
    BUG#11763712 - 56458: KILLING A FLUSH TABLE FOR A MERGE/CHILD · ef84b24d
    Sergey Vojtovich authored
                          CRASHES SERVER
    
    Flushing of MERGE table or one of its child tables, which was
    locked by flushing thread using LOCK TABLES, might have caused
    crashes or assertion failures if the thread failed to reopen
    child or parent table.
    Particularly, this might have happened when another connection
    killed this FLUSH TABLE statement/connection.
    Also this problem might have occurred when we failed to reopen
    MERGE table or one of its children when executing DDL statement
    under LOCK TABLES.
    
    The problem was caused by the fact that reopen_tables() might
    have failed to reopen child table but still tried to reopen,
    reattach children for and re-lock its parent. Vice versa it
    might have failed to reopen parent but kept references from
    children to parent around. Since reopen_tables() closes table
    it has failed to reopen and therefore frees all associated
    memory such dangling references led to crashes when followed.
    
    This patch solves this problem by ensuring that we always close
    parent table and all its children if we fail to reopen this
    table or one of its children. Same happens if we fail to reattach
    children to parent.
    
    Affects 5.1 only.
    
    mysql-test/r/merge.result:
      A test case for BUG#11763712.
    mysql-test/t/merge.test:
      A test case for BUG#11763712.
    sql/sql_base.cc:
      When flushing tables under LOCK TABLES, all locked
      and flushed tables are released and then reopened.
      It may happen that we failed to reopen some tables,
      in this case we reopen as much tables as possible.
      
      If it was not possible to reopen MERGE child, MERGE
      parent is unusable and must be removed from thread
      open tables list.
      
      If it was not possible to reopen MERGE parent, all
      MERGE child table objects are unusable as well, at
      least because their locks are handled by MERGE parent.
      They must also be removed from thread open tables
      list.
      
      In other words if it was impossible to reopen any
      object of a MERGE table or reattach child tables,
      all objects of this MERGE table must be considered
      unusable and closed.
    ef84b24d
merge.test 54.8 KB