mariadb/mysql-test/include/check-testcase.test
Marko Mäkelä 1bd681c8b3 MDEV-25506 (3 of 3): Do not delete .ibd files before commit
This is a complete rewrite of DROP TABLE, also as part of other DDL,
such as ALTER TABLE, CREATE TABLE...SELECT, TRUNCATE TABLE.

The background DROP TABLE queue hack is removed.
If a transaction needs to drop and create a table by the same name
(like TRUNCATE TABLE does), it must first rename the table to an
internal #sql-ib name. No committed version of the data dictionary
will include any #sql-ib tables, because whenever a transaction
renames a table to a #sql-ib name, it will also drop that table.
Either the rename will be rolled back, or the drop will be committed.

Data files will be unlinked after the transaction has been committed
and a FILE_RENAME record has been durably written. The file will
actually be deleted when the detached file handle returned by
fil_delete_tablespace() will be closed, after the latches have been
released. It is possible that a purge of the delete of the SYS_INDEXES
record for the clustered index will execute fil_delete_tablespace()
concurrently with the DDL transaction. In that case, the thread that
arrives later will wait for the other thread to finish.

HTON_TRUNCATE_REQUIRES_EXCLUSIVE_USE: A new handler flag.
ha_innobase::truncate() now requires that all other references to
the table be released in advance. This was implemented by Monty.

ha_innobase::delete_table(): If CREATE TABLE..SELECT is detected,
we will "hijack" the current transaction, drop the table in
the current transaction and commit the current transaction.
This essentially fixes MDEV-21602. There is a FIXME comment about
making the check less failure-prone.

ha_innobase::truncate(), ha_innobase::delete_table():
Implement a fast path for temporary tables. We will no longer allow
temporary tables to use the adaptive hash index.

dict_table_t::mdl_name: The original table name for the purpose of
acquiring MDL in purge, to prevent a race condition between a
DDL transaction that is dropping a table, and purge processing
undo log records of DML that had executed before the DDL operation.
For #sql-backup- tables during ALTER TABLE...ALGORITHM=COPY, the
dict_table_t::mdl_name will differ from dict_table_t::name.

dict_table_t::parse_name(): Use mdl_name instead of name.

dict_table_rename_in_cache(): Update mdl_name.

For the internal FTS_ tables of FULLTEXT INDEX, purge would
acquire MDL on the FTS_ table name, but not on the main table,
and therefore it would be able to run concurrently with a
DDL transaction that is dropping the table. Previously, the
DROP TABLE queue hack prevented a race between purge and DDL.
For now, we introduce purge_sys.stop_FTS() to prevent purge from
opening any table, while a DDL transaction that may drop FTS_
tables is in progress. The function fts_lock_table(), which will
be invoked before the dictionary is locked, will wait for
purge to release any table handles.

trx_t::drop_table_statistics(): Drop statistics for the table.
This replaces dict_stats_drop_index(). We will drop or rename
persistent statistics atomically as part of DDL transactions.
On lock conflict for dropping statistics, we will fail instantly
with DB_LOCK_WAIT_TIMEOUT, because we will be holding the
exclusive data dictionary latch.

trx_t::commit_cleanup(): Separated from trx_t::commit_in_memory().
Relax an assertion around fts_commit() and allow DB_LOCK_WAIT_TIMEOUT
in addition to DB_DUPLICATE_KEY. The call to fts_commit() is
entirely misplaced here and may obviously break the consistency
of transactions that affect FULLTEXT INDEX. It needs to be fixed
separately.

dict_table_t::n_foreign_key_checks_running: Remove (MDEV-21175).
The counter was a work-around for missing meta-data locking (MDL)
on the SQL layer, and not really needed in MariaDB.

ER_TABLE_IN_FK_CHECK: Replaced with ER_UNUSED_28.

HA_ERR_TABLE_IN_FK_CHECK: Remove.

row_ins_check_foreign_constraints(): Do not acquire
dict_sys.latch either. The SQL-layer MDL will protect us.

This was reviewed by Thirunarayanan Balathandayuthapani
and tested by Matthias Leich.
2021-06-09 17:06:07 +03:00

155 lines
4.7 KiB
Text

# ==== Purpose ====
#
# This test is executed twice for each test case. Before every
# testcase it is run with mysqltest in record mode and will thus
# produce an output file that can be compared to output from after the
# tescase. In that way, it is possible to check that a testcase does
# not have any unwanted side affects.
--disable_query_log
# We want to ensure all slave configuration is restored. But SHOW
# SLAVE STATUS returns nothing for servers not configured as slaves,
# and (after BUG#28796 was fixed) there is no way to de-configure a
# slave. Hence, it's impossible to clean up the replication state at
# the end. But we want to check that the slave is stopped, there is
# no error, and a few other invariants. So we issue SHOW SLAVE
# STATUS, and if it returns no rows we fake the result.
--let $tmp= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1)
--let $tmp= `SELECT '$tmp' = 'No such row'`
if ($tmp)
{
# Note: after WL#5177, fields 13-18 shall not be filtered-out.
--echo Slave_IO_State
--echo Master_Host 127.0.0.1
--echo Master_User root
--echo Master_Port #
--echo Connect_Retry #
--echo Master_Log_File #
--echo Read_Master_Log_Pos #
--echo Relay_Log_File #
--echo Relay_Log_Pos #
--echo Relay_Master_Log_File #
--echo Slave_IO_Running No
--echo Slave_SQL_Running No
--echo Replicate_Do_DB #
--echo Replicate_Ignore_DB #
--echo Replicate_Do_Table #
--echo Replicate_Ignore_Table #
--echo Replicate_Wild_Do_Table #
--echo Replicate_Wild_Ignore_Table #
--echo Last_Errno 0
--echo Last_Error
--echo Skip_Counter 0
--echo Exec_Master_Log_Pos #
--echo Relay_Log_Space #
--echo Until_Condition #
--echo Until_Log_File #
--echo Until_Log_Pos #
--echo Master_SSL_Allowed No
--echo Master_SSL_CA_File
--echo Master_SSL_CA_Path
--echo Master_SSL_Cert
--echo Master_SSL_Cipher
--echo Master_SSL_Key
--echo Seconds_Behind_Master NULL
--echo Master_SSL_Verify_Server_Cert No
--echo Last_IO_Errno 0
--echo Last_IO_Error
--echo Last_SQL_Errno 0
--echo Last_SQL_Error
--echo Replicate_Ignore_Server_Ids
--echo Master_Server_Id #
--echo Master_SSL_Crl #
--echo Master_SSL_Crlpath #
--echo Using_Gtid No
--echo Gtid_IO_Pos #
--echo Replicate_Do_Domain_Ids
--echo Replicate_Ignore_Domain_Ids
--echo Parallel_Mode optimistic
--echo SQL_Delay 0
--echo SQL_Remaining_Delay NULL
--echo Slave_SQL_Running_State
--echo Slave_DDL_Groups #
--echo Slave_Non_Transactional_Groups #
--echo Slave_Transactional_Groups #
}
if (!$tmp) {
# Note: after WL#5177, fields 13-18 shall not be filtered-out.
--replace_column 4 # 5 # 6 # 7 # 8 # 9 # 10 # 13 # 14 # 15 # 16 # 17 # 18 # 22 # 23 # 24 # 25 # 26 # 40 # 41 # 42 # 44 # 51 # 52 # 53 #
query_vertical
SHOW SLAVE STATUS;
}
#
# Ensure that we don't get warnings from mysql.proc (used by check_mysqld)
#
--disable_query_log
--disable_warnings
--disable_result_log
select count(*) from mysql.proc;
--enable_result_log
--enable_warnings
--enable_query_log
call mtr.check_testcase();
let $datadir=`select @@datadir`;
list_files $datadir mysql_upgrade_info;
list_files $datadir/test #sql*;
list_files $datadir/mysql #sql*;
#
# Check that SHOW ENGINE INNODB STATUS does not show any active transactions
# We do this only if wsrep provider is loaded, to avoid disturbing any non-Galera MTR tests
#
if (`SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'wsrep' AND PLUGIN_STATUS='ACTIVE'`) {
if (`SELECT @@wsrep_on`) {
if (`SELECT COUNT(*) FROM information_schema.innodb_trx WHERE trx_mysql_thread_id != 0`) {
if ($before) {
--echo Before test start.
}
if (!$before) {
--echo After test end.
}
--echo There is one or more active InnoDB transaction(s) when there should be none. Dumping some diagnostics.
--let $status_locks = `SELECT @@innodb_status_output_locks`
--let $status_output = `SELECT @@innodb_status_output`
--enable_query_log
SET GLOBAL innodb_status_output_locks=ON;
SHOW ENGINE INNODB STATUS;
--disable_query_log
--eval SET GLOBAL innodb_status_output_locks=$status_locks;
--eval SET GLOBAL innodb_status_output=$status_output;
--enable_query_log
--vertical_results
if ($before) {
--replace_regex /$/ /
}
SELECT * FROM information_schema.processlist;
if ($before) {
--replace_regex /$/ /
}
SELECT * FROM information_schema.innodb_trx;
if ($before) {
--replace_regex /$/ /
}
SELECT * FROM information_schema.innodb_locks;
if ($before) {
--replace_regex /$/ /
}
SELECT * FROM information_schema.innodb_lock_waits;
--horizontal_results
--disable_query_log
}
}
}
--enable_query_log