@@ -70,6 +70,8 @@ NOT FOUND /foobar/ in t1.ibd
NOT FOUND /temp/ in t2.ibd
# t3 ... on expecting NOT FOUND
NOT FOUND /barfoo/ in t3.ibd
SET GLOBAL innodb_file_format = `Barracuda`;
SET GLOBAL innodb_file_per_table = ON;
ALTER TABLE t1 ENGINE InnoDB;
SHOW CREATE TABLE t1;
Table Create Table
@@ -37,10 +37,12 @@ set autocommit=1;

--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
--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

--sleep 5
# shutdown so that grep is safe
--source include/shutdown_mysqld.inc

--echo # tablespaces should be now encrypted
--let SEARCH_PATTERN=foobar
--echo # t1 yes on expecting NOT FOUND
@@ -55,6 +57,8 @@ set autocommit=1;
-- let SEARCH_FILE=$t3_IBD
-- source include/search_pattern_in_file.inc

--source include/start_mysqld.inc

--list_files $MYSQLD_DATADIR/test
FLUSH TABLES t1, t2, t3 FOR EXPORT;
perl;
@@ -81,7 +85,9 @@ SELECT COUNT(1) FROM t2;
ALTER TABLE t3 IMPORT TABLESPACE;
SELECT COUNT(1) FROM t3;

--sleep 5
# shutdown so that grep is safe
--source include/shutdown_mysqld.inc

--echo # tablespaces should remain encrypted after import
--let SEARCH_PATTERN=foobar
--echo # t1 yes on expecting NOT FOUND
@@ -96,6 +102,13 @@ SELECT COUNT(1) FROM t3;
-- let SEARCH_FILE=$t3_IBD
-- source include/search_pattern_in_file.inc

--source include/start_mysqld.inc

--disable_warnings
SET GLOBAL innodb_file_format = `Barracuda`;
SET GLOBAL innodb_file_per_table = ON;
--enable_warnings

ALTER TABLE t1 ENGINE InnoDB;
SHOW CREATE TABLE t1;
ALTER TABLE t2 ENGINE InnoDB;
@@ -112,7 +125,9 @@ SELECT COUNT(1) FROM t1;
SELECT COUNT(1) FROM t2;
SELECT COUNT(1) FROM t3;

--sleep 5
# shutdown so that grep is safe
--source include/shutdown_mysqld.inc

--echo # Tablespaces should be encrypted after restart
--let SEARCH_PATTERN=foobar
--echo # t1 yes on expecting NOT FOUND
@@ -127,9 +142,11 @@ SELECT COUNT(1) FROM t3;
-- let SEARCH_FILE=$t3_IBD
-- source include/search_pattern_in_file.inc

--source include/start_mysqld.inc

--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
--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

--echo # Success!
@@ -3349,12 +3349,12 @@ fil_iterate(
bool updated = false;
os_offset_t page_off = offset;
ulint n_pages_read = n_bytes / size;
bool decrypted = false;
block->page.id.set_page_no(ulint(page_off / size));

for (ulint i = 0; i < n_pages_read;
block->page.id.set_page_no(block->page.id.page_no() + 1),
++i, page_off += size, block->frame += size) {
bool decrypted = false;
err = DB_SUCCESS;
byte* src = readptr + i * size;
byte* dst = io_buffer + i * size;
@@ -3401,6 +3401,7 @@ fil_iterate(
block->frame = src;
frame_changed = true;
} else {
ut_ad(dst != src);
memcpy(dst, src, size);
}
}
@@ -3460,9 +3461,13 @@ fil_iterate(
ut_ad(encrypted ?
src != dst && dst != writeptr + (i * size):1);

if (encrypted) {
memcpy(writeptr + (i * size),
callback.get_frame(block), size);
/* When tablespace is encrypted or compressed its
first page (i.e. page 0) is not encrypted or
compressed and there is no need to copy frame. */
if (encrypted && i != 0) {
byte *local_frame = callback.get_frame(block);
ut_ad((writeptr + (i * size)) != local_frame);
memcpy((writeptr + (i * size)), local_frame, size);
}

if (frame_changed) {
@@ -3500,6 +3505,7 @@ fil_iterate(

if (tmp == src) {
/* TODO: remove unnecessary memcpy's */
ut_ad(dest != src);
memcpy(dest, src, size);
}