Bug #121924 Server crash on next open from another connection after IMPORT TABLESPACE fails without .cfg
Description:
After ALTER TABLE ... IMPORT TABLESPACE is refused with ER_TABLE_SCHEMA_MISMATCH (1808)
because the .cfg file is missing and the .ibd has one column more than the target table,
the next open of that table from a different connection aborts mysqld:
[Warning] [MY-011989] [InnoDB] Index root in InnoDB is 4294967295 while index root in global DD is 4
[ERROR] [MY-013183] [InnoDB] Assertion failure: dict0dict.cc:<line>:table->get_ref_count() == 0
Stack (from the error log):
dict_table_remove_from_cache_low storage/innobase/dict/dict0dict.cc
dict_table_remove_from_cache storage/innobase/dict/dict0dict.cc
ha_innobase::open storage/innobase/handler/ha_innodb.cc
handler::ha_open
open_table_from_share
open_table / open_tables
mysqld_show_create
The same statement in the session that ran the IMPORT does not crash. Release and
debug builds both crash (the assertion is ut_a). The IMPORT itself also logs
"Apparent corruption in space N page M index PRIMARY" for each page.
ha_innobase::open finds the dict_table_t left in the cache by the failed IMPORT, finds
it does not match the DD (index root FIL_NULL vs 4), and calls
dict_table_remove_from_cache() without checking the reference count, unlike the
corrupted-table branch just above it ("if (ib_table->get_ref_count() == 0)").
Also: after the failed IMPORT, DROP TABLE leaves the copied .ibd on disk; while the
source table still exists the next restart can fail with "Multiple files found for the
same tablespace ID" until the file is removed by hand.
Expected: the IMPORT is refused and the table stays usable and droppable from any
connection; no crash.
Found while testing Percona Server; reproduced on MySQL Community 26.10.0.1, 9.7.4.1, 8.4.13.1.
How to repeat:
The attached MTR test crashes at SHOW CREATE TABLE t_dst. By hand:
CREATE TABLE test.t_src (id BIGINT UNSIGNED PRIMARY KEY, v VARBINARY(16) NOT NULL, c INT,
extra BIGINT UNSIGNED NOT NULL DEFAULT 7);
SET SESSION cte_max_recursion_depth = 10000;
INSERT INTO test.t_src (id, v, c)
WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 2000)
SELECT i, RANDOM_BYTES(16), i FROM n;
CREATE TABLE test.t_dst (id BIGINT UNSIGNED PRIMARY KEY, v VARBINARY(16) NOT NULL, c INT);
ALTER TABLE test.t_dst DISCARD TABLESPACE;
FLUSH TABLES test.t_src FOR EXPORT;
-- copy <datadir>/test/t_src.ibd to <datadir>/test/t_dst.ibd (do NOT copy the .cfg)
UNLOCK TABLES;
-- connection 1
ALTER TABLE test.t_dst IMPORT TABLESPACE; -- ERROR 1808 Schema mismatch (.cfg missing)
-- disconnect
-- connection 2
SHOW CREATE TABLE test.t_dst; -- ERROR 2013, mysqld aborted
Suggested fix:
In ha_innobase::open(), do not call dict_table_remove_from_cache() on a table that is
still referenced after a failed IMPORT; mark it and let the last reference release it,
as the corrupted-table branch already does.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: After ALTER TABLE ... IMPORT TABLESPACE is refused with ER_TABLE_SCHEMA_MISMATCH (1808) because the .cfg file is missing and the .ibd has one column more than the target table, the next open of that table from a different connection aborts mysqld: [Warning] [MY-011989] [InnoDB] Index root in InnoDB is 4294967295 while index root in global DD is 4 [ERROR] [MY-013183] [InnoDB] Assertion failure: dict0dict.cc:<line>:table->get_ref_count() == 0 Stack (from the error log): dict_table_remove_from_cache_low storage/innobase/dict/dict0dict.cc dict_table_remove_from_cache storage/innobase/dict/dict0dict.cc ha_innobase::open storage/innobase/handler/ha_innodb.cc handler::ha_open open_table_from_share open_table / open_tables mysqld_show_create The same statement in the session that ran the IMPORT does not crash. Release and debug builds both crash (the assertion is ut_a). The IMPORT itself also logs "Apparent corruption in space N page M index PRIMARY" for each page. ha_innobase::open finds the dict_table_t left in the cache by the failed IMPORT, finds it does not match the DD (index root FIL_NULL vs 4), and calls dict_table_remove_from_cache() without checking the reference count, unlike the corrupted-table branch just above it ("if (ib_table->get_ref_count() == 0)"). Also: after the failed IMPORT, DROP TABLE leaves the copied .ibd on disk; while the source table still exists the next restart can fail with "Multiple files found for the same tablespace ID" until the file is removed by hand. Expected: the IMPORT is refused and the table stays usable and droppable from any connection; no crash. Found while testing Percona Server; reproduced on MySQL Community 26.10.0.1, 9.7.4.1, 8.4.13.1. How to repeat: The attached MTR test crashes at SHOW CREATE TABLE t_dst. By hand: CREATE TABLE test.t_src (id BIGINT UNSIGNED PRIMARY KEY, v VARBINARY(16) NOT NULL, c INT, extra BIGINT UNSIGNED NOT NULL DEFAULT 7); SET SESSION cte_max_recursion_depth = 10000; INSERT INTO test.t_src (id, v, c) WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 2000) SELECT i, RANDOM_BYTES(16), i FROM n; CREATE TABLE test.t_dst (id BIGINT UNSIGNED PRIMARY KEY, v VARBINARY(16) NOT NULL, c INT); ALTER TABLE test.t_dst DISCARD TABLESPACE; FLUSH TABLES test.t_src FOR EXPORT; -- copy <datadir>/test/t_src.ibd to <datadir>/test/t_dst.ibd (do NOT copy the .cfg) UNLOCK TABLES; -- connection 1 ALTER TABLE test.t_dst IMPORT TABLESPACE; -- ERROR 1808 Schema mismatch (.cfg missing) -- disconnect -- connection 2 SHOW CREATE TABLE test.t_dst; -- ERROR 2013, mysqld aborted Suggested fix: In ha_innobase::open(), do not call dict_table_remove_from_cache() on a table that is still referenced after a failed IMPORT; mark it and let the last reference release it, as the corrupted-table branch already does.