summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2019-06-05 23:46:21 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2019-06-05 23:46:21 +0530
commitc8e73f9e851d634d6a528fecfe0e946fe25a9b2f (patch)
treeb1e0fb72092d1ca23543db2280c89c707268ff2f
parentb4287ec3865d90920f0cc440c36f4873dcf51703 (diff)
downloadmariadb-git-c8e73f9e851d634d6a528fecfe0e946fe25a9b2f.tar.gz
MDEV-19695 Import tablespace doesn't work with compressed encrypted tablespacebb-10.2-MDEV-19695
Problem: ======= fil_iterate() writes imported tablespace page0 as it is to discarded tablespace. Space id wasn't even changed. While opening the tablespace, tablespace fails with space id mismatch error. Fix: ==== fil_iterate() copies the page0 with discarded space id to imported tablespace.
-rw-r--r--mysql-test/suite/encryption/r/compressed_import_tablespace.result37
-rw-r--r--mysql-test/suite/encryption/t/compressed_import_tablespace.opt3
-rw-r--r--mysql-test/suite/encryption/t/compressed_import_tablespace.test47
-rw-r--r--storage/innobase/row/row0import.cc14
4 files changed, 98 insertions, 3 deletions
diff --git a/mysql-test/suite/encryption/r/compressed_import_tablespace.result b/mysql-test/suite/encryption/r/compressed_import_tablespace.result
new file mode 100644
index 00000000000..aafe4447884
--- /dev/null
+++ b/mysql-test/suite/encryption/r/compressed_import_tablespace.result
@@ -0,0 +1,37 @@
+CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED ENCRYPTED=YES;
+INSERT INTO t1 VALUES(1, repeat('Nesamani', 10));
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+1
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `id` int(11) NOT NULL,
+ `a` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED `ENCRYPTED`=YES
+# Wait max 10 min for key encryption threads to encrypt all spaces
+t1.frm
+t1.ibd
+FLUSH TABLES t1 FOR EXPORT;
+backup: t1
+t1.cfg
+t1.frm
+t1.ibd
+UNLOCK TABLES;
+DROP TABLE t1;
+CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED ENCRYPTED=YES;
+ALTER TABLE t1 DISCARD TABLESPACE;
+restore: t1 .ibd and .cfg files
+ALTER TABLE t1 IMPORT TABLESPACE;
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+1
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `id` int(11) NOT NULL,
+ `a` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED `ENCRYPTED`=YES
+DROP TABLE t1;
diff --git a/mysql-test/suite/encryption/t/compressed_import_tablespace.opt b/mysql-test/suite/encryption/t/compressed_import_tablespace.opt
new file mode 100644
index 00000000000..a9893ed4b29
--- /dev/null
+++ b/mysql-test/suite/encryption/t/compressed_import_tablespace.opt
@@ -0,0 +1,3 @@
+--innodb-encrypt-tables=ON
+--innodb-encryption-threads=4
+--innodb-tablespaces-encryption
diff --git a/mysql-test/suite/encryption/t/compressed_import_tablespace.test b/mysql-test/suite/encryption/t/compressed_import_tablespace.test
new file mode 100644
index 00000000000..ca99d839ef3
--- /dev/null
+++ b/mysql-test/suite/encryption/t/compressed_import_tablespace.test
@@ -0,0 +1,47 @@
+-- source include/have_innodb.inc
+-- source include/have_example_key_management_plugin.inc
+-- source include/not_valgrind.inc
+-- source include/not_embedded.inc
+
+let MYSQLD_DATADIR = `SELECT @@datadir`;
+--let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd
+CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED ENCRYPTED=YES;
+INSERT INTO t1 VALUES(1, repeat('Nesamani', 10));
+
+SELECT COUNT(*) FROM t1;
+SHOW CREATE TABLE t1;
+
+--echo # Wait max 10 min for key encryption threads to encrypt all spaces
+--let $wait_timeout= 600
+--let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND ROTATING_OR_FLUSHING <> 0
+--source include/wait_condition.inc
+
+--source include/shutdown_mysqld.inc
+
+--source include/start_mysqld.inc
+let MYSQLD_DATADIR =`SELECT @@datadir`;
+
+--list_files $MYSQLD_DATADIR/test
+FLUSH TABLES t1 FOR EXPORT;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_backup_tablespaces("test", "t1");
+EOF
+--list_files $MYSQLD_DATADIR/test
+UNLOCK TABLES;
+DROP TABLE t1;
+
+CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=COMPRESSED ENCRYPTED=YES;
+ALTER TABLE t1 DISCARD TABLESPACE;
+perl;
+do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
+ib_discard_tablespaces("test", "t1");
+ib_restore_tablespaces("test", "t1");
+EOF
+
+ALTER TABLE t1 IMPORT TABLESPACE;
+
+SELECT COUNT(*) FROM t1;
+SHOW CREATE TABLE t1;
+--source include/restart_mysqld.inc
+DROP TABLE t1;
diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc
index 036b657e36c..abadeafba9c 100644
--- a/storage/innobase/row/row0import.cc
+++ b/storage/innobase/row/row0import.cc
@@ -3421,8 +3421,12 @@ page_corrupted:
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
+ src)) {
not_encrypted:
- if (!page_compressed
- && !block->page.zip.data) {
+ if (block->page.id.page_no() == 0
+ && block->page.zip.data) {
+ block->page.zip.data = src;
+ frame_changed = true;
+ } else if (!page_compressed
+ && !block->page.zip.data) {
block->frame = src;
frame_changed = true;
} else {
@@ -3513,7 +3517,11 @@ not_encrypted:
}
if (frame_changed) {
- block->frame = dst;
+ if (block->page.zip.data) {
+ block->page.zip.data = dst;
+ } else {
+ block->frame = dst;
+ }
}
src = io_buffer + (i * size);