• Praveenkumar.Hulakund's avatar
    Bug#19786309 - CRASH IN UNLOCK TABLES AFTER LOCKING AND TRUNCATING TEMPORARY TABLE. · 23321f62
    Praveenkumar.Hulakund authored
    Attempt to truncate temporary table using Blackhole storage and
    locked by LOCK TABLES caused assertion failure and crashes.
    
    Blackhole is a transaction-aware engine. While creating the temporary
    table in transaction-aware engine, temporary table of type
    "TRANSACTIONAL_TMP_TABLE" is created. For such temporary tables
    a THR_LOCK lock is acquired by the LOCK TABLE operation. References
    to them are also added into MYSQL_LOCK::table[] array. Also for
    Blackhole engine, flag HTON_CAN_RECREATE is set.
    
    While truncating temporary tables, no locks are taken and
    recreate_temporary_table() is called for engines having
    "HTON_CAN_RECREATE" in flag.
    
    Function closefrm() is called from the recreate_temporary_table(),
    to close the current temporary table. In closefrm(), the lock on
    table expected is "F_UNLCK". In debug builds, assert condition on
    this fails when lock of type "F_WRLCK" is acquired by LOCK TABLE
    operation on temporary tables using Blackhole engine.
    
    In non-debug builds closefrm() simply freed TABLE object leaving
    dangling pointer to this object in MYSQL_LOCK::table[] array which
    might lead to crashes later.
    
    Fix:
    ---------
    To fix this issue, we now unlock and remove table from MYSQL_LOCK::table[]
    array before calling close_temporary_table() in recreate_temporary_table().
    This is achieved by calling mysql_lock_remove() function for this table.
    23321f62
sql_truncate.cc 17.5 KB