Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-26137 Improve import tablespace workflow.
Allow ALTER TABLE ... IMPORT TABLESPACE without creating the table followed by discarding the tablespace. That is, assuming we want to import table t1 to t2, instead of CREATE TABLE t2 LIKE t1; ALTER TABLE t2 DISCARD TABLESPACE; FLUSH TABLES t1 FOR EXPORT; --copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg --copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd UNLOCK TABLES; ALTER TABLE t2 IMPORT TABLESPACE; We can simply do FLUSH TABLES t1 FOR EXPORT; --copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg --copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/t2.frm --copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd UNLOCK TABLES; ALTER TABLE t2 IMPORT TABLESPACE; We achieve this by creating a "stub" table in the second scenario while opening the table, where t2 does not exist but needs to import from t1. The "stub" table is similar to a table that is created but then instructed to discard its tablespace. We include tests with various row formats, encryption, with indexes and auto-increment.
- Loading branch information
1 parent
b7ee3c7
commit 9b431d7
Showing
23 changed files
with
852 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--source include/innodb_row_format.inc | ||
--source include/innodb_row_format_2.inc | ||
--source include/innodb_checksum_algorithm.inc | ||
|
||
--echo # | ||
--echo # MDEV-26137 ALTER TABLE IMPORT enhancement | ||
--echo # | ||
|
||
let $MYSQLD_DATADIR = `SELECT @@datadir`; | ||
|
||
--disable_query_log | ||
let $ROW_FORMAT_OPTION=; | ||
if($MTR_COMBINATION_R_REDUNDANT) { | ||
let $ROW_FORMAT_OPTION= ROW_FORMAT=REDUNDANT; | ||
} | ||
if($MTR_COMBINATION_R_COMPACT) { | ||
let $ROW_FORMAT_OPTION= ROW_FORMAT=COMPACT; | ||
} | ||
if($MTR_COMBINATION_R_DYNAMIC) { | ||
let $ROW_FORMAT_OPTION= ROW_FORMAT=DYNAMIC; | ||
} | ||
if($MTR_COMBINATION_R_COMPRESSED) { | ||
let $ROW_FORMAT_OPTION= ROW_FORMAT=COMPRESSED; | ||
} | ||
let $CREATE_OPTIONS_REGEX= /ENGINE=InnoDB.*$ROW_FORMAT_OPTION/CREATE_OPTIONS/; | ||
--enable_query_log | ||
|
||
--replace_regex $CREATE_OPTIONS_REGEX | ||
eval | ||
CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 42) ENGINE=InnoDB $ROW_FORMAT_OPTION; | ||
INSERT INTO t1() VALUES(); | ||
FLUSH TABLES t1 FOR EXPORT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/t2.frm | ||
--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
--replace_regex $CREATE_OPTIONS_REGEX | ||
SHOW CREATE TABLE t2; | ||
SELECT * FROM t2; | ||
DROP TABLE t1, t2; |
5 changes: 5 additions & 0 deletions
5
mysql-test/suite/innodb/include/innodb_row_format_2.combinations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[r_default] | ||
[r_redundant] | ||
[r_compact] | ||
[r_dynamic] | ||
[r_compressed] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# The goal of including this file is to add various row_format options | ||
# combinations (see include/innodb_row_format_2.combinations) | ||
|
||
--source include/have_innodb.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# MDEV-26137 ALTER TABLE IMPORT enhancement | ||
# | ||
CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 42) CREATE_OPTIONS; | ||
INSERT INTO t1() VALUES(); | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) NOT NULL DEFAULT 42, | ||
PRIMARY KEY (`a`) | ||
) CREATE_OPTIONS | ||
SELECT * FROM t2; | ||
a | ||
42 | ||
DROP TABLE t1, t2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# MDEV-26137 ALTER TABLE IMPORT enhancement | ||
# | ||
CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 42) CREATE_OPTIONS; | ||
INSERT INTO t1() VALUES(); | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
Warnings: | ||
Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification | ||
Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) NOT NULL DEFAULT 42, | ||
PRIMARY KEY (`a`) | ||
) CREATE_OPTIONS | ||
SELECT * FROM t2; | ||
a | ||
42 | ||
DROP TABLE t1, t2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# | ||
# MDEV-26137 ALTER TABLE IMPORT enhancement | ||
# | ||
call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t1` is set as discarded.'); | ||
call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t2` is set as discarded.'); | ||
call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t3` is set as discarded.'); | ||
call mtr.add_suppression('InnoDB: ./test/t3.ibd: Page 0 at offset 0 looks corrupted.'); | ||
call mtr.add_suppression("mariadbd.*: Index for table 't3' is corrupt; try to repair it"); | ||
call mtr.add_suppression("InnoDB: Expected tablespace id \\d+ but found \\d+ in the file ./test/t3.ibd"); | ||
call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t3.ibd' could not be found in the doublewrite buffer."); | ||
call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t4` is set as discarded.'); | ||
call mtr.add_suppression('InnoDB: ./test/t4.ibd: Page 0 at offset 0 looks corrupted.'); | ||
call mtr.add_suppression("mariadbd.*: Index for table 't4' is corrupt; try to repair it"); | ||
call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t4.ibd' could not be found in the doublewrite buffer."); | ||
# Recovery from crashes | ||
## t1: Creation of stub succeeds; server crashes; second import attempt succeeds | ||
## t2: Creation of stub succeeds; server crashes; drop table | ||
## t3: Creation of stub succeeds; server crashes; ibd corrupted; second import attempt fails; drop table | ||
## t4: Did not copy .cfg; creation of stub succeeds; server crashes; ibd corrupted; second import attempt fails; drop table | ||
CREATE TABLE t (a int) ENGINE=InnoDB; | ||
INSERT INTO t VALUES(42); | ||
FLUSH TABLES t FOR EXPORT; | ||
UNLOCK TABLES; | ||
SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; | ||
SET GLOBAL innodb_max_dirty_pages_pct=0.0; | ||
connect hang1,localhost,root; | ||
SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever'; | ||
ALTER TABLE t1 IMPORT TABLESPACE; | ||
connection default; | ||
SET DEBUG_SYNC='now WAIT_FOR hung'; | ||
connect hang2,localhost,root; | ||
SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever'; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
connection default; | ||
SET DEBUG_SYNC='now WAIT_FOR hung'; | ||
connect hang3,localhost,root; | ||
SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever'; | ||
ALTER TABLE t3 IMPORT TABLESPACE; | ||
connection default; | ||
SET DEBUG_SYNC='now WAIT_FOR hung'; | ||
connect hang4,localhost,root; | ||
SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever'; | ||
ALTER TABLE t4 IMPORT TABLESPACE; | ||
connection default; | ||
SET DEBUG_SYNC='now WAIT_FOR hung'; | ||
# corrupting the 0th page | ||
# Restart mysqld after the crash and reconnect. | ||
# restart | ||
ALTER TABLE t1 IMPORT TABLESPACE; | ||
SHOW CREATE TABLE t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`a` int(11) DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
SELECT * FROM t1; | ||
a | ||
42 | ||
ALTER TABLE t3 IMPORT TABLESPACE; | ||
ERROR HY000: Internal error: Error importing tablespace for table `test`.`t3` : Data structure corruption | ||
ALTER TABLE t4 IMPORT TABLESPACE; | ||
ERROR HY000: Schema mismatch (Expected FSP_SPACE_FLAGS=0x15, .ibd file contains 0x1010115.) | ||
DROP TABLE t, t1, t2, t3, t4; | ||
# Recovery from corruption only, no server restart | ||
## t5: Recovery from corruption, with cfg | ||
## t6: Recovery from corruption, without cfg | ||
call mtr.add_suppression('InnoDB: ./test/t5.ibd: Page 0 at offset 0 looks corrupted.'); | ||
call mtr.add_suppression("mariadbd.*: Index for table 't5' is corrupt; try to repair it"); | ||
call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t5.ibd' could not be found in the doublewrite buffer."); | ||
call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t6.ibd' could not be found in the doublewrite buffer."); | ||
call mtr.add_suppression("mariadbd.*: Index for table 't6' is corrupt; try to repair it"); | ||
CREATE TABLE t (a int) ENGINE=InnoDB; | ||
INSERT INTO t VALUES(42); | ||
FLUSH TABLES t FOR EXPORT; | ||
UNLOCK TABLES; | ||
# corrupting the 0th page | ||
ALTER TABLE t5 IMPORT TABLESPACE; | ||
ERROR HY000: Internal error: Error importing tablespace for table `test`.`t5` : Data structure corruption | ||
ALTER TABLE t6 IMPORT TABLESPACE; | ||
ERROR HY000: Schema mismatch (Expected FSP_SPACE_FLAGS=0x15, .ibd file contains 0x1010115.) | ||
DROP TABLE t, t5, t6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# | ||
# MDEV-26137 ALTER TABLE IMPORT enhancement | ||
# | ||
# drop t1 before importing t2 | ||
CREATE TABLE t1 (a int) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES(42); | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
DROP TABLE t1; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
SELECT * FROM t2; | ||
a | ||
42 | ||
DROP TABLE t2; | ||
# created t2 but did not discard tablespace | ||
CREATE TABLE t1 (a int) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES(42); | ||
CREATE TABLE t2 LIKE t1; | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
DROP TABLE t1; | ||
call mtr.add_suppression("InnoDB: Unable to import tablespace"); | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
ERROR HY000: Tablespace for table 'test/t2' exists. Please DISCARD the tablespace before IMPORT | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
SELECT * FROM t2; | ||
a | ||
DROP TABLE t2; | ||
# attempt to import when there's no tablespace | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
ERROR 42S02: Table 'test.t2' doesn't exist | ||
# with index | ||
CREATE TABLE t1 (a int, b varchar(50)) ENGINE=InnoDB; | ||
CREATE UNIQUE INDEX ai ON t1 (a); | ||
INSERT INTO t1 VALUES(42, "hello"); | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) DEFAULT NULL, | ||
`b` varchar(50) DEFAULT NULL, | ||
UNIQUE KEY `ai` (`a`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
SELECT * FROM t2; | ||
a b | ||
42 hello | ||
SHOW INDEX FROM t1; | ||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
t1 0 ai 1 a A 1 NULL NULL YES BTREE NO | ||
SHOW INDEX FROM t2; | ||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
t2 0 ai 1 a A 1 NULL NULL YES BTREE NO | ||
DROP TABLE t1, t2; | ||
# with virtual column index | ||
CREATE TABLE t1 (a int, b int as (a * a)) ENGINE=InnoDB; | ||
CREATE UNIQUE INDEX ai ON t1 (b); | ||
INSERT INTO t1 VALUES(42, default); | ||
FLUSH TABLES t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`a` int(11) DEFAULT NULL, | ||
`b` int(11) GENERATED ALWAYS AS (`a` * `a`) VIRTUAL, | ||
UNIQUE KEY `ai` (`b`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci | ||
SELECT * FROM t2; | ||
a b | ||
42 1764 | ||
SELECT b FROM t2 USE INDEX (ai); | ||
b | ||
1764 | ||
SHOW INDEX FROM t1; | ||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
t1 0 ai 1 b A 1 NULL NULL YES BTREE NO | ||
SHOW INDEX FROM t2; | ||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
t2 0 ai 1 b A 1 NULL NULL YES BTREE NO | ||
CHECK TABLE t2 EXTENDED; | ||
Table Op Msg_type Msg_text | ||
test.t2 check status OK | ||
DROP TABLE t1, t2; | ||
# with auto_increment | ||
CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i2 INT, i1 INT)ENGINE=INNODB; | ||
INSERT INTO t1 (i2) SELECT 4 FROM seq_1_to_1024; | ||
FLUSH TABLE t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE t2 IMPORT TABLESPACE; | ||
CHECK TABLE t2 EXTENDED; | ||
Table Op Msg_type Msg_text | ||
test.t2 check status OK | ||
DROP TABLE t2, t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--source include/import_begin.inc | ||
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg | ||
--source include/import_end.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# embedded server uses absolute path, causing result mismatch in warning messages | ||
--source include/not_embedded.inc | ||
--source include/import_begin.inc | ||
--source include/import_end.inc |
Oops, something went wrong.