| 1 |
################################################################################ |
| 2 |
# InnoDB transparent tablespace data encryption for general shared tablespace. |
| 3 |
# This test case will test |
| 4 |
# - Crash during encrypting an unencrypted tablespace. |
| 5 |
# - And then restart without loading keyring plugin. Server should fail to |
| 6 |
# start. |
| 7 |
# - Restart with keyring pluing. Server should start and recover properly. |
| 8 |
################################################################################ |
| 9 |
|
| 10 |
--source include/have_debug.inc |
| 11 |
--source include/big_test.inc |
| 12 |
# --source include/no_valgrind_without_big.inc |
| 13 |
# Disable in valgrind because of timeout, cf. Bug#22760145 |
| 14 |
--source include/not_valgrind.inc |
| 15 |
# Waiting time when (re)starting the server |
| 16 |
--let $explicit_default_wait_counter=10000 |
| 17 |
|
| 18 |
--let $PLUGIN_DIR = `select @@plugin_dir` |
| 19 |
--disable_query_log |
| 20 |
call mtr.add_suppression("ibd can't be decrypted, please confirm the keyfile is match and keyring plugin is loaded."); |
| 21 |
call mtr.add_suppression("\\[Error\\] \\[[^]]*\\] \\[[^]]*\\] Encryption can't find master key, please check the keyring is loaded."); |
| 22 |
call mtr.add_suppression("\\[ERROR\\] \\[[^]]*\\] \\[[^]]*\\] Check keyring fail, please check the keyring is loaded."); |
| 23 |
call mtr.add_suppression(" Encryption information in datafile:"); |
| 24 |
--enable_query_log |
| 25 |
|
| 26 |
--echo ######################################################################### |
| 27 |
--echo # START : WITHOUT KEYRING PLUGIN |
| 28 |
--echo ######################################################################### |
| 29 |
--echo |
| 30 |
--echo ######### |
| 31 |
--echo # SETUP # |
| 32 |
--echo ######### |
| 33 |
|
| 34 |
# Create an Unencrypted tablespace |
| 35 |
CREATE TABLESPACE encrypt_ts ADD DATAFILE 'encrypt_ts.ibd' ENGINE=InnoDB ENCRYPTION="N"; |
| 36 |
# Create an unencrypted table in tablespace |
| 37 |
CREATE TABLE t1(c1 char(100)) ENGINE=InnoDB TABLESPACE encrypt_ts; |
| 38 |
# Insert few rows in table |
| 39 |
--disable_query_log |
| 40 |
INSERT INTO t1 VALUES ("SOME VALUES"); |
| 41 |
let $counter=12; |
| 42 |
while ($counter>0) |
| 43 |
{ |
| 44 |
INSERT INTO test.t1 SELECT * FROM test.t1; |
| 45 |
dec $counter; |
| 46 |
} |
| 47 |
--enable_query_log |
| 48 |
|
| 49 |
# Make sure ts file is updated with new records in table |
| 50 |
set global innodb_buf_flush_list_now = 1; |
| 51 |
|
| 52 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; |
| 53 |
SELECT * FROM t1 LIMIT 10; |
| 54 |
|
| 55 |
# Try to alter tablespace to be encrypted. Should fail as keyring is not laoded. |
| 56 |
--error ER_CANNOT_FIND_KEY_IN_KEYRING |
| 57 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 58 |
|
| 59 |
--echo ############################################################# |
| 60 |
--echo # TEST 1 : CRASH DURING ALTER ENCRYPT A TABLESPACE. |
| 61 |
--echo ############################################################# |
| 62 |
--echo |
| 63 |
--echo ######################################################################### |
| 64 |
--echo # RESTART 1 : WITH KEYRING PLUGIN |
| 65 |
--echo ######################################################################### |
| 66 |
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; |
| 67 |
--source include/restart_mysqld_no_echo.inc |
| 68 |
|
| 69 |
--echo ############################################################ |
| 70 |
--echo # ALTER TABLESPACE 1 : Unencrypted => Encrypted # |
| 71 |
--echo # (crash at page 10) # |
| 72 |
--echo ############################################################ |
| 73 |
--echo # Set Encryption process to crash at page 10 |
| 74 |
SET SESSION debug= '+d,alter_encrypt_tablespace_page_10'; |
| 75 |
SET GLOBAL innodb_log_checkpoint_now = ON; |
| 76 |
SET GLOBAL innodb_page_cleaner_disabled_debug = 1; |
| 77 |
SET GLOBAL innodb_dict_stats_disabled_debug = 1; |
| 78 |
SET GLOBAL innodb_master_thread_disabled_debug = 1; |
| 79 |
|
| 80 |
--echo # Encrypt the tablespace. It will cause crash. |
| 81 |
--source include/expect_crash.inc |
| 82 |
--error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR |
| 83 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 84 |
--echo # Restart after crash without Keyring plugin loaded |
| 85 |
--error 1,42 |
| 86 |
--exec $MYSQLD_CMD --plugin-dir=$PLUGIN_DIR --log-error=$MYSQLTEST_VARDIR/log/my_restart.err |
| 87 |
|
| 88 |
# Search the failure pattern in error log |
| 89 |
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/my_restart.err; |
| 90 |
let SEARCH_PATTERN=CORRUPT LOG RECORD FOUND; |
| 91 |
--source include/search_pattern.inc |
| 92 |
|
| 93 |
--echo # Server shouldn't have restarted, so query should fail. |
| 94 |
--error CR_SERVER_LOST |
| 95 |
SELECT * from test.t1 limit 10; |
| 96 |
|
| 97 |
--echo ######################################################################### |
| 98 |
--echo # RESTART 2 : WITH KEYRING PLUGIN |
| 99 |
--echo ######################################################################### |
| 100 |
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; |
| 101 |
--source include/start_mysqld_no_echo.inc |
| 102 |
|
| 103 |
--echo # Server should have restarted properly. |
| 104 |
SELECT * from test.t1 limit 10; |
| 105 |
|
| 106 |
--echo # |
| 107 |
--echo # Bug#30888919 : [INNODB] ASSERTION FAILURE:SPACE->ENCRYPTION_OP_IN_PROGRESS == NONE |
| 108 |
--echo # |
| 109 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='N'; |
| 110 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; |
| 111 |
SELECT * FROM t1 LIMIT 10; |
| 112 |
--echo ############################################################ |
| 113 |
--echo # ALTER TABLESPACE : Unencrypted => Encrypted # |
| 114 |
--echo # (crash at page 10) # |
| 115 |
--echo ############################################################ |
| 116 |
|
| 117 |
--echo # Connection con1: |
| 118 |
connect (con1,localhost,root,,); |
| 119 |
connection con1; |
| 120 |
let $SAVED_CON_ID = `SELECT connection_id();`; |
| 121 |
--echo # Set Encryption process to crash at page 10 |
| 122 |
SET SESSION debug= '+d,alter_encrypt_tablespace_page_10'; |
| 123 |
--echo # Encrypt the tablespace. It will cause crash. |
| 124 |
--source include/expect_crash.inc |
| 125 |
--error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR |
| 126 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 127 |
|
| 128 |
--echo # Restart after crash with sleep_resume_alter_encrypt to make resume |
| 129 |
--echo # thread to sleep. |
| 130 |
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT --debug=d,sleep_resume_alter_encrypt; |
| 131 |
--source include/start_mysqld_no_echo.inc |
| 132 |
|
| 133 |
--echo # Connection con2: |
| 134 |
connect (con2,localhost,root,,); |
| 135 |
connection con2; |
| 136 |
--echo # Check that this connection id is same as of the one which was trying |
| 137 |
--echo # to encrypt the tablespace before crash. |
| 138 |
let $CUR_CON_ID = `SELECT connection_id();`; |
| 139 |
if ($CUR_CON_ID == $SAVED_CON_ID) { |
| 140 |
--echo Connectin ids are same. |
| 141 |
} |
| 142 |
if ($CUR_CON_ID != $SAVED_CON_ID) { |
| 143 |
--echo Connectin ids are not same. |
| 144 |
} |
| 145 |
|
| 146 |
# Run a DDL with this connection. At post DDL it will remove DDL Log records. |
| 147 |
CREATE TABLESPACE temp_ts ADD DATAFILE 'temp_ts.ibd'; |
| 148 |
|
| 149 |
--echo # connection con3 |
| 150 |
connect (con3,localhost,root,,); |
| 151 |
connection con3; |
| 152 |
SELECT connection_id(); |
| 153 |
--echo # Run a DDL with this connection con3 |
| 154 |
ALTER TABLESPACE temp_ts ENCRYPTION='Y'; |
| 155 |
|
| 156 |
set global innodb_buf_flush_list_now = 1; |
| 157 |
|
| 158 |
--echo # Now restart without sleep_resume_alter_encrypt. |
| 159 |
# NOTE : resume processing for connection con1 wouldn't have finished yet and |
| 160 |
# should be tried again in next restart. |
| 161 |
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR $KEYRING_PLUGIN_OPT --plugin-dir=KEYRING_PLUGIN_PATH $KEYRING_PLUGIN keyring_file.so |
| 162 |
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; |
| 163 |
--source include/kill_and_restart_mysqld.inc |
| 164 |
|
| 165 |
--echo # Wait for Encryption processing to finish in background thread |
| 166 |
let $wait_condition = SELECT ENCRYPTION = 'Y' |
| 167 |
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES |
| 168 |
WHERE NAME='encrypt_ts'; |
| 169 |
--source include/wait_condition.inc |
| 170 |
|
| 171 |
--echo # After restart/recovery, check that Encryption was roll-forward |
| 172 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; |
| 173 |
SELECT * FROM t1 LIMIT 10; |
| 174 |
|
| 175 |
--echo # Now try to encrypt tablespace. Without patch, an assert will be hit. |
| 176 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 177 |
|
| 178 |
--echo ########### |
| 179 |
--echo # Cleanup # |
| 180 |
--echo ########### |
| 181 |
DROP TABLE t1; |
| 182 |
DROP TABLESPACE encrypt_ts; |
| 183 |
remove_file $MYSQL_TMP_DIR/mysecret_keyring; |
| 184 |
remove_file $SEARCH_FILE; |
| 185 |
|
| 186 |
--echo # Restarting server without keyring to restore server state |
| 187 |
let $restart_parameters = restart: ; |
| 188 |
--source include/restart_mysqld.inc |