mirror of
https://github.com/MariaDB/server.git
synced 2025-08-27 13:04:36 +03:00
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.
96 lines
3.5 KiB
Plaintext
96 lines
3.5 KiB
Plaintext
SET GLOBAL innodb_file_per_table=ON;
|
|
FLUSH TABLES;
|
|
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
# restart
|
|
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;
|
|
# Kill the server
|
|
# Fault 0 (no real fault): Orphan file with duplicate space_id.
|
|
# Fault 1: Two dirty files with the same space_id.
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
FOUND 1 /InnoDB: Ignoring data file '.*t2.ibd' with space ID \d+. Another data file called .*t1.ibd exists with the same space ID/ in mysqld.1.err
|
|
# Fault 2: Wrong space_id in a dirty file, and a missing file.
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
FOUND 1 /InnoDB: Tablespace \d+ was not found at.*t3.ibd/ in mysqld.1.err
|
|
# Fault 3: Wrong space_id in a dirty file, and no missing file.
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
FOUND 1 /InnoDB: Ignoring data file '.*t[23].ibd' with space ID/ in mysqld.1.err
|
|
NOT FOUND /InnoDB: Tablespace \d+ was not found at .*t1.ibd/ in mysqld.1.err
|
|
FOUND 1 /InnoDB: Tablespace \d+ was not found at .*t3.ibd/ in mysqld.1.err
|
|
FOUND 2 /InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace/ in mysqld.1.err
|
|
# Fault 4: Missing data file
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
FOUND 1 /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/ in mysqld.1.err
|
|
# Fault 5: Wrong type of data file
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
# restart
|
|
SELECT * FROM INFORMATION_SCHEMA.ENGINES
|
|
WHERE engine = 'innodb'
|
|
AND support IN ('YES', 'DEFAULT', 'ENABLED');
|
|
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
|
|
NOT FOUND /\[Note\] InnoDB: Cannot read first page of .*t2.ibd/ in mysqld.1.err
|
|
FOUND 1 /.*\[ERROR\] InnoDB: Cannot apply log to \[page id: space=[1-9][0-9]*, page number=3\] of corrupted file './test/t2\.ibd'/ in mysqld.1.err
|
|
# restart
|
|
SELECT * FROM t2;
|
|
a
|
|
9
|
|
101
|
|
347
|
|
SELECT * FROM t3;
|
|
a
|
|
347
|
|
33101
|
|
SHOW TABLES;
|
|
Tables_in_test
|
|
t2
|
|
t3
|
|
DROP TABLE t2,t3;
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
ERROR HY000: Can't create table `test`.`t0` (errno: 184 "Tablespace already exists")
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
ERROR HY000: Can't create table `test`.`t0` (errno: 184 "Tablespace already exists")
|
|
CREATE TABLE t0(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
DROP TABLE t0;
|
|
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);
|
|
# Kill the server
|
|
# Fault 6: All-zero data file and innodb_force_recovery
|
|
# restart: --innodb-force-recovery=1
|
|
DROP TABLE u1,u2,u3,u6;
|
|
# List of files:
|
|
db.opt
|
|
SHOW TABLES;
|
|
Tables_in_test
|