• Michael Widenius's avatar
    Fixed bug MPDEV-628 / LP:989055 - Querying myisam table metadata may corrupt the table. · 8ed283d8
    Michael Widenius authored
    The issue was that there was that SHOW commands could open the table in the store engine, even in cases
    where it should not be allowed to do that (ie, the storage engines meta data for that table was under big changes).
    
    The cases where this should not be allowed are:
    - ALTER TABLE DISABLE KEYS
    - ALTER TABLE ENABLE KEYS
    - REPAIR TABLE
    - OPTIMIZE TABLE
    - DROP TABLE
    
    This patch adds a new mode, protected_against_usage(). If this is used then the SHOW command will wait until the table
    is accessable. This is implemented by re-using the already exising 'version' flag for TABLE_SHARE.
    It also added functions to be used to change TABLE_SHARE->version instead of changing it directly.
    	
    
    
    mysql-test/r/myisam-metadata.result:
      Added test case
    mysql-test/t/myisam-metadata.test:
      Added test case
    sql/mysqld.cc:
      Start from refresh_version 2 as 0 and 1 are reserved.
    sql/sql_admin.cc:
      Added MYSQL_OPEN_FOR_REPAIR
      Updated call to wait_while_table_is_used()
    sql/sql_base.cc:
      Updated call to wait_while_table_is_used()
      - Allow one to specify how the table should be removed (for all commands except show or for all commands).
      - Don't allow one to reopen the table if one has called share->protect_against_usage()
    sql/sql_base.h:
      Added TDC_RT_REMOVE_NOT_OWN_AND_MARK_NOT_USABLE, which is used to mark that no one can reopen this table, except with MYSQL_OPEN_FOR_REPAIR .
      - Added MYSQL_OPEN_FOR_REPAIR
      - Updated prototype for wait_while_table_is_used()
    sql/sql_table.cc:
      Updated call to wait_while_table_is_used()
      Use MYSQL_OPEN_FOR_REPAIR for open tables that where repaired.
    sql/sql_truncate.cc:
      Updated call to wait_while_table_is_used()
    sql/table.cc:
      Use set_refresh_version()
    sql/table.h:
      Added functions to be used to change TABLE_SHARE->version instead of changing it directly
    8ed283d8
sql_table.cc 251 KB