mirror of
https://github.com/MariaDB/server.git
synced 2025-04-23 07:05:53 +03:00
Problem: ======== - After the commit ada1074bb10359342ee00e220fe9c172574265fb (MDEV-14398) fil_crypt_set_encrypt_tables() iterates through all tablespaces to fill the default_encrypt tables list. This was a trigger to encrypt or decrypt when key rotation age is set to 0. But import tablespace does call fil_crypt_set_encrypt_tables() unnecessarily. The motivation for the call is to signal the encryption threads. Fix: ==== ha_innobase::discard_or_import_tablespace: Remove the fil_crypt_set_encrypt_tables() and add the import tablespace to the default encrypt list if necessary
181 lines
6.2 KiB
Plaintext
181 lines
6.2 KiB
Plaintext
-- source include/have_innodb.inc
|
|
-- source include/have_example_key_management_plugin.inc
|
|
-- source include/not_valgrind.inc
|
|
-- source include/not_embedded.inc
|
|
SET @start_encr_threads = @@global.innodb_encryption_threads;
|
|
SET @start_encrypt_tables = @@global.innodb_encrypt_tables;
|
|
let MYSQLD_DATADIR = `SELECT @@datadir`;
|
|
|
|
--let SEARCH_RANGE = 10000000
|
|
--let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd
|
|
--let t2_IBD = $MYSQLD_DATADIR/test/t2.ibd
|
|
--let t3_IBD = $MYSQLD_DATADIR/test/t3.ibd
|
|
|
|
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB encrypted=yes;
|
|
CREATE TABLE t2 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB;
|
|
CREATE TABLE t3 (id INT NOT NULL PRIMARY KEY, a VARCHAR(255)) ENGINE=InnoDB row_format=compressed encrypted=yes;
|
|
|
|
delimiter //;
|
|
create procedure innodb_insert_proc (repeat_count int)
|
|
begin
|
|
declare current_num int;
|
|
set current_num = 0;
|
|
while current_num < repeat_count do
|
|
insert into t1 values (current_num,repeat('foobar',42));
|
|
insert into t2 values (current_num,repeat('temp', 42));
|
|
insert into t3 values (current_num,repeat('barfoo',42));
|
|
set current_num = current_num + 1;
|
|
end while;
|
|
end//
|
|
delimiter ;//
|
|
commit;
|
|
|
|
begin;
|
|
set statement unique_checks=0, foreign_key_checks=0 for
|
|
call innodb_insert_proc(100);
|
|
commit;
|
|
DROP PROCEDURE innodb_insert_proc;
|
|
|
|
--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
|
|
|
|
FLUSH TABLES t1, t2, t3 FOR EXPORT;
|
|
--echo # tablespaces should be now encrypted
|
|
--let SEARCH_PATTERN=foobar
|
|
--echo # t1 yes on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t1_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--let SEARCH_PATTERN=temp
|
|
--echo # t2 ... on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t2_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--let SEARCH_PATTERN=barfoo
|
|
--echo # t3 ... on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t3_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
|
|
let MYSQLD_DATADIR =`SELECT @@datadir`;
|
|
--list_files $MYSQLD_DATADIR/test
|
|
perl;
|
|
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
|
|
ib_backup_tablespaces("test", "t1","t2","t3");
|
|
EOF
|
|
--list_files $MYSQLD_DATADIR/test
|
|
UNLOCK TABLES;
|
|
|
|
ALTER TABLE t1 DISCARD TABLESPACE;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
ALTER TABLE t3 DISCARD TABLESPACE;
|
|
|
|
perl;
|
|
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
|
|
ib_discard_tablespaces("test", "t1","t2","t3");
|
|
ib_restore_tablespaces("test", "t1","t2","t3");
|
|
EOF
|
|
|
|
ALTER TABLE t1 IMPORT TABLESPACE;
|
|
SELECT COUNT(*) FROM t1;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
SELECT COUNT(*) FROM t2;
|
|
ALTER TABLE t3 IMPORT TABLESPACE;
|
|
SELECT COUNT(*) FROM t3;
|
|
|
|
FLUSH TABLES t1, t2, t3 FOR EXPORT;
|
|
|
|
--echo # tablespaces should remain encrypted after import
|
|
--let SEARCH_PATTERN=foobar
|
|
--echo # t1 yes on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t1_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--let SEARCH_PATTERN=temp
|
|
--echo # t2 ... on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t2_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--echo # t3 ... on expecting NOT FOUND
|
|
--let SEARCH_PATTERN=barfoo
|
|
-- let SEARCH_FILE=$t3_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t1 FORCE;
|
|
SHOW CREATE TABLE t1;
|
|
ALTER TABLE t2 FORCE;
|
|
SHOW CREATE TABLE t2;
|
|
ALTER TABLE t3 FORCE;
|
|
SHOW CREATE TABLE t3;
|
|
|
|
--echo # Verify that tables are still usable
|
|
CHECK TABLE t1, t2, t3 EXTENDED;
|
|
FLUSH TABLES t1, t2, t3 FOR EXPORT;
|
|
|
|
--let SEARCH_PATTERN=foobar
|
|
--echo # t1 yes on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t1_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--let SEARCH_PATTERN=temp
|
|
--echo # t2 ... on expecting NOT FOUND
|
|
-- let SEARCH_FILE=$t2_IBD
|
|
-- source include/search_pattern_in_file.inc
|
|
--echo # t3 ... on expecting NOT FOUND
|
|
--let SEARCH_PATTERN=barfoo
|
|
-- let SEARCH_FILE=$t3_IBD
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1, t2, t3;
|
|
|
|
--echo #
|
|
--echo # MDEV-34670 IMPORT TABLESPACE unnecessary traverses
|
|
--echo # tablespace list
|
|
--echo #
|
|
SET GLOBAL innodb_encrypt_tables= OFF;
|
|
SET GLOBAL innodb_encryption_threads= 0;
|
|
|
|
CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES(1, "InnoDB");
|
|
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;
|
|
|
|
SET GLOBAL innodb_encryption_threads=2;
|
|
SET GLOBAL innodb_encrypt_tables = ON;
|
|
|
|
--let $tables_count= `select count(*) + @@global.innodb_undo_tablespaces + 1 from information_schema.tables where engine = 'InnoDB'`
|
|
|
|
--echo # Wait max 10 min for key encryption threads to encrypt all spaces
|
|
--let $wait_timeout= 600
|
|
--let $wait_condition=SELECT COUNT(*) >= $tables_count FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0;
|
|
--source include/wait_condition.inc
|
|
|
|
--sorted_result
|
|
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0
|
|
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry';
|
|
--sorted_result
|
|
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0
|
|
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry';
|
|
|
|
SET GLOBAL innodb_encrypt_tables = OFF;
|
|
|
|
--echo # Wait max 10 min for key encryption threads to decrypt all spaces
|
|
--let $wait_timeout= 600
|
|
--let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0;
|
|
--source include/wait_condition.inc
|
|
|
|
--sorted_result
|
|
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0
|
|
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry';
|
|
|
|
--sorted_result
|
|
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0
|
|
AND NAME NOT LIKE 'innodb_undo%' AND NAME NOT LIKE 'mysql/innodb_%_stats' AND NAME NOT LIKE 'mysql/transaction_registry';
|
|
|
|
DROP TABLE t1, t2;
|
|
SET GLOBAL innodb_encryption_threads=@start_encr_threads;
|
|
SET GLOBAL innodb_encrypt_tables=@start_encrypt_tables;
|