polardbxengine/mysql-test/suite/innodb/t/innodb-import-partition-rpl...

108 lines
3.5 KiB
Plaintext

# Testcase for import/export partition table with replication for InnoDB
# Only hash partition table is used for sanity check
--source include/master-slave.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
# Set file per table on slave
--echo # On slave
connection slave;
let $slave_per_table = `select @@innodb_file_per_table`;
set global innodb_file_per_table = 1;
--echo # On master
# Set file per table on master
connection master;
LET $MYSQLD_DATA_DIR = `select @@datadir`;
let $master_per_table = `select @@innodb_file_per_table`;
set global innodb_file_per_table = 1;
LET $MYSQLD_MASTER_DATA_DIR = `select @@datadir`;
--echo # Create partitioned table on master
CREATE TABLE t1 ( i INT ) ENGINE = InnoDB PARTITION BY HASH(i) PARTITIONS 3;
CREATE TABLE t2 ( i INT ) ENGINE = InnoDB PARTITION BY KEY(i) PARTITIONS 3;
INSERT INTO t1 VALUES (1),(111),(321);
INSERT INTO t2 VALUES (0),(1),(2);
FLUSH TABLES t1,t2 FOR EXPORT;
--source include/sync_slave_sql_with_master.inc
--echo # set MYSQLD_DATADIR with master datadir to copy idb and cfg files
LET MYSQLD_DATADIR = $MYSQLD_MASTER_DATA_DIR;
perl;
require 'include/innodb-util.inc';
ib_backup_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_backup_tablespaces("test", "t2#P#p0", "t2#P#p1");
EOF
--echo # On slave
connection slave;
--echo # check table created on slave
SELECT * FROM t1;
SELECT * FROM t2;
--echo # On master
--echo # DISCARD TABLESPACE on master.It will be also discarded from slave.
connection master;
UNLOCK TABLES;
ALTER TABLE t1 DISCARD TABLESPACE;
#--source include/sync_slave_sql_with_master.inc
ALTER TABLE t2 DISCARD PARTITION p0,p1 TABLESPACE;
--source include/sync_slave_sql_with_master.inc
--echo # Copy back ibd and cfg files on master
LET MYSQLD_DATADIR = $MYSQLD_MASTER_DATA_DIR;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_restore_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_discard_tablespaces("test", "t2#P#p0", "t2#P#p1");
ib_restore_tablespaces("test", "t2#P#p0", "t2#P#p1");
EOF
--echo # Copy back ibd and cfg files on slave
connection slave;
LET $MYSQLD_SLAVE_DATA_DIR = `select @@datadir`;
LET MYSQLD_DATADIR = $MYSQLD_SLAVE_DATA_DIR;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_restore_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_discard_tablespaces("test", "t2#P#p0", "t2#P#p1");
ib_restore_tablespaces("test", "t2#P#p0", "t2#P#p1");
EOF
--echo # IMPORT TABLESPACE on master.It will be also imported on slave.
connection master;
ALTER TABLE t1 IMPORT TABLESPACE;
SELECT * FROM t1;
ALTER TABLE t2 IMPORT PARTITION p0,p1 TABLESPACE;
SELECT * FROM t2;
--source include/sync_slave_sql_with_master.inc
--echo # On slave
--echo # Verify table data on slave
connection slave;
SELECT * FROM t1;
SELECT * FROM t2;
# Cleanup
connection slave;
eval set global innodb_file_per_table = $slave_per_table;
connection master;
eval set global innodb_file_per_table = $master_per_table;
DROP TABLE t1;
DROP TABLE t2;
--source include/rpl_end.inc
call mtr.add_suppression("Got error -1 when reading table '.*'");
call mtr.add_suppression("Error: tablespace id and flags in file '.*'.*");
call mtr.add_suppression("The table .* doesn't have a corresponding tablespace, it was discarded");
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.ibd
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.cfg
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t2*.ibd
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t2*.cfg