mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 02:51:44 +01:00
1bd681c8b3
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.
218 lines
8.7 KiB
Text
218 lines
8.7 KiB
Text
# WL#7142 InnoDB: Simplify tablespace discovery during crash recovery
|
|
# Test the detection of duplicate tablespaces.
|
|
|
|
--source include/have_innodb.inc
|
|
--source include/not_valgrind.inc
|
|
|
|
# Embedded server does not support crashing
|
|
--source include/not_embedded.inc
|
|
|
|
SET GLOBAL innodb_file_per_table=ON;
|
|
FLUSH TABLES;
|
|
|
|
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
|
|
--source include/restart_mysqld.inc
|
|
--source include/no_checkpoint_start.inc
|
|
CREATE TABLE t3(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
|
|
BEGIN;
|
|
INSERT INTO t3 VALUES (33101),(347);
|
|
INSERT INTO t1 VALUES (42),(9),(101);
|
|
RENAME TABLE t1 TO t2;
|
|
UPDATE t2 SET a=347 where a=42;
|
|
COMMIT;
|
|
|
|
--let CLEANUP_IF_CHECKPOINT=DROP TABLE t2,t3;
|
|
--source include/no_checkpoint_end.inc
|
|
|
|
--echo # Fault 0 (no real fault): Orphan file with duplicate space_id.
|
|
--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t0.ibd
|
|
|
|
--echo # Fault 1: Two dirty files with the same space_id.
|
|
--copy_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t1.ibd
|
|
|
|
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
|
|
let $check_no_innodb=SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
|
|
# This could fail to refuse InnoDB startup, in case there was a log
|
|
# checkpoint after the INSERT. That is what we checked above.
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
let SEARCH_PATTERN= InnoDB: Ignoring data file '.*t2.ibd' with space ID \d+. Another data file called .*t1.ibd exists with the same space ID;
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
--remove_file $MYSQLD_DATADIR/test/t1.ibd
|
|
|
|
# This could fail to refuse InnoDB startup, in case there was a log
|
|
# checkpoint after the CREATE TABLE t3. That is what we checked above.
|
|
--echo # Fault 2: Wrong space_id in a dirty file, and a missing file.
|
|
--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t1.ibd
|
|
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
|
|
let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at.*t3.ibd;
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
--move_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t3.ibd
|
|
|
|
--echo # Fault 3: Wrong space_id in a dirty file, and no missing file.
|
|
# Swap t2.ibd and t3.ibd.
|
|
--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t.ibd
|
|
--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t3.ibd
|
|
--move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd
|
|
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
|
|
let SEARCH_PATTERN= InnoDB: Ignoring data file '.*t[23].ibd' with space ID;
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t1.ibd;
|
|
--source include/search_pattern_in_file.inc
|
|
let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t3.ibd;
|
|
--source include/search_pattern_in_file.inc
|
|
let SEARCH_PATTERN= InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace;
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
# Swap back t3.ibd, but hide t2.ibd (which the redo log also knows as t1.ibd).
|
|
--move_file $MYSQLD_DATADIR/test/t3.ibd $MYSQLD_DATADIR/test/t.ibd
|
|
--move_file $MYSQLD_DATADIR/test/t2.ibd $MYSQLD_DATADIR/test/t3.ibd
|
|
|
|
--echo # Fault 4: Missing data file
|
|
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t[12].ibd.
|
|
.*InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace;
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
--echo # Fault 5: Wrong type of data file
|
|
|
|
--mkdir $MYSQLD_DATADIR/test/t2.ibd
|
|
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
--source include/shutdown_mysqld.inc
|
|
# On Windows, this error message is not output when t2.ibd is a directory!
|
|
#let SEARCH_PATTERN= \[Note\] InnoDB: Cannot read first page of .*t2.ibd;
|
|
#--source include/search_pattern_in_file.inc
|
|
|
|
--rmdir $MYSQLD_DATADIR/test/t2.ibd
|
|
|
|
# Create a short file.
|
|
--write_file $MYSQLD_DATADIR/test/t2.ibd
|
|
EOF
|
|
|
|
--source include/start_mysqld.inc
|
|
eval $check_no_innodb;
|
|
--source include/shutdown_mysqld.inc
|
|
|
|
let SEARCH_PATTERN= \[Note\] InnoDB: Cannot read first page of .*t2.ibd;
|
|
--source include/search_pattern_in_file.inc
|
|
let SEARCH_PATTERN= .*\[ERROR\] InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd';
|
|
--source include/search_pattern_in_file.inc
|
|
|
|
# Restore t2.ibd
|
|
--remove_file $MYSQLD_DATADIR/test/t2.ibd
|
|
--move_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd
|
|
|
|
--source include/start_mysqld.inc
|
|
|
|
SELECT * FROM t2;
|
|
SELECT * FROM t3;
|
|
SHOW TABLES;
|
|
DROP TABLE t2,t3;
|
|
|
|
--error ER_CANT_CREATE_TABLE
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
--error ER_CANT_CREATE_TABLE
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
--remove_file $MYSQLD_DATADIR/test/t0.ibd
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
DROP TABLE t0;
|
|
|
|
--disable_query_log
|
|
# The following are for the orphan file t0.ibd or for the directory t2.ibd:
|
|
call mtr.add_suppression("InnoDB: Operating system error number [0-9]* in a file operation");
|
|
call mtr.add_suppression("InnoDB: Error number [0-9]* means '(File exists|Is a directory)'");
|
|
call mtr.add_suppression("InnoDB: Cannot create file '.*t0.ibd'");
|
|
call mtr.add_suppression("InnoDB: The file '.*t0\.ibd' already exists");
|
|
call mtr.add_suppression("InnoDB: Cannot open datafile for read-write: '.*t2\.ibd'");
|
|
# The following are for aborted startup without --innodb-force-recovery:
|
|
call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*test");
|
|
call mtr.add_suppression("InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace");
|
|
call mtr.add_suppression("InnoDB: Cannot read first page of '.*test.[tu]2.ibd': I/O error");
|
|
call mtr.add_suppression("InnoDB: Cannot apply log to \\[page id: space=[1-9][0-9]*, page number=3\\] of corrupted file './test/t2\\.ibd'");
|
|
call mtr.add_suppression("InnoDB: Datafile '.*test.*ibd' is corrupted");
|
|
call mtr.add_suppression("InnoDB: Cannot replay file rename. Remove either file and try again");
|
|
call mtr.add_suppression("InnoDB: Cannot rename.*because the target file exists");
|
|
call mtr.add_suppression("InnoDB: Log scan aborted at LSN");
|
|
# The following are for the --innodb-force-recovery=1 with broken u* tables:
|
|
call mtr.add_suppression("InnoDB: The size of the file .*u[12]\\.ibd is only [1-9][0-9]* bytes, should be at least 65536");
|
|
call mtr.add_suppression("InnoDB: The size of tablespace file '.*test/u[12].ibd' is only");
|
|
call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
|
|
call mtr.add_suppression("InnoDB: .*you must create directories");
|
|
call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: '.*u[1-5]\.ibd'");
|
|
call mtr.add_suppression("InnoDB: Could not find a valid tablespace file for `test/u[1-5]`");
|
|
call mtr.add_suppression("InnoDB: Ignoring tablespace for test/u[1-3] because it could not be opened\\.");
|
|
call mtr.add_suppression("InnoDB: Failed to find tablespace for table .* in the cache. Attempting to load the tablespace with space id");
|
|
call mtr.add_suppression("InnoDB: Plugin initialization aborted");
|
|
call mtr.add_suppression("Plugin 'InnoDB' \(init function returned error\|registration as a STORAGE ENGINE failed\)");
|
|
call mtr.add_suppression("InnoDB: Table test/u[123] in the InnoDB data dictionary has tablespace id [1-9][0-9]*, but tablespace with that id or name does not exist\\. Have you deleted or moved \\.ibd files\\?");
|
|
call mtr.add_suppression("InnoDB: Cannot replay rename of tablespace.*");
|
|
FLUSH TABLES;
|
|
--enable_query_log
|
|
|
|
--source include/no_checkpoint_start.inc
|
|
|
|
CREATE TABLE u1(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
CREATE TABLE u2(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
CREATE TABLE u3(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
CREATE TABLE u4(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
INSERT INTO u4 VALUES(1);
|
|
RENAME TABLE u4 TO u5;
|
|
RENAME TABLE u5 TO u6;
|
|
INSERT INTO u6 VALUES(2);
|
|
|
|
--let CLEANUP_IF_CHECKPOINT=DROP TABLE u1,u2,u3,u6;
|
|
--source include/no_checkpoint_end.inc
|
|
|
|
--echo # Fault 6: All-zero data file and innodb_force_recovery
|
|
|
|
--remove_file $MYSQLD_DATADIR/test/u1.ibd
|
|
--remove_file $MYSQLD_DATADIR/test/u2.ibd
|
|
--remove_file $MYSQLD_DATADIR/test/u3.ibd
|
|
|
|
# InnoDB: Header page consists of zero bytes
|
|
--perl
|
|
die unless open(FILE, ">$ENV{MYSQLD_DATADIR}/test/u1.ibd");
|
|
print FILE "\0" x 16384;
|
|
close(FILE);
|
|
EOF
|
|
|
|
--exec echo "" > $MYSQLD_DATADIR/test/u2.ibd
|
|
|
|
--copy_file $MYSQLD_DATADIR/test/u6.ibd $MYSQLD_DATADIR/test/u4.ibd
|
|
|
|
--let $restart_parameters= --innodb-force-recovery=1
|
|
--source include/start_mysqld.inc
|
|
DROP TABLE u1,u2,u3,u6;
|
|
|
|
--remove_file $MYSQLD_DATADIR/test/u4.ibd
|
|
|
|
--echo # List of files:
|
|
--list_files $MYSQLD_DATADIR/test
|
|
|
|
SHOW TABLES;
|