################################################################################ # InnoDB transparent tablespace data encryption for general shared tablespace. # This test case will test # - Crash during encrypting an unencrypted tablespace. # - And then restart without loading keyring plugin. Server should fail to # start. # - Restart with keyring pluing. Server should start and recover properly. ################################################################################ --source include/have_debug.inc --source include/big_test.inc # --source include/no_valgrind_without_big.inc # Disable in valgrind because of timeout, cf. Bug#22760145 --source include/not_valgrind.inc # Waiting time when (re)starting the server --let $explicit_default_wait_counter=10000 --let $PLUGIN_DIR = `select @@plugin_dir` --disable_query_log call mtr.add_suppression("ibd can't be decrypted, please confirm the keyfile is match and keyring plugin is loaded."); call mtr.add_suppression("\\[Error\\] \\[[^]]*\\] \\[[^]]*\\] Encryption can't find master key, please check the keyring is loaded."); call mtr.add_suppression("\\[ERROR\\] \\[[^]]*\\] \\[[^]]*\\] Check keyring fail, please check the keyring is loaded."); call mtr.add_suppression(" Encryption information in datafile:"); --enable_query_log --echo ######################################################################### --echo # START : WITHOUT KEYRING PLUGIN --echo ######################################################################### --echo --echo ######### --echo # SETUP # --echo ######### # Create an Unencrypted tablespace CREATE TABLESPACE encrypt_ts ADD DATAFILE 'encrypt_ts.ibd' ENGINE=InnoDB ENCRYPTION="N"; # Create an unencrypted table in tablespace CREATE TABLE t1(c1 char(100)) ENGINE=InnoDB TABLESPACE encrypt_ts; # Insert few rows in table --disable_query_log INSERT INTO t1 VALUES ("SOME VALUES"); let $counter=12; while ($counter>0) { INSERT INTO test.t1 SELECT * FROM test.t1; dec $counter; } --enable_query_log # Make sure ts file is updated with new records in table set global innodb_buf_flush_list_now = 1; SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; SELECT * FROM t1 LIMIT 10; # Try to alter tablespace to be encrypted. Should fail as keyring is not laoded. --error ER_CANNOT_FIND_KEY_IN_KEYRING ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; --echo ############################################################# --echo # TEST 1 : CRASH DURING ALTER ENCRYPT A TABLESPACE. --echo ############################################################# --echo --echo ######################################################################### --echo # RESTART 1 : WITH KEYRING PLUGIN --echo ######################################################################### let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; --source include/restart_mysqld_no_echo.inc --echo ############################################################ --echo # ALTER TABLESPACE 1 : Unencrypted => Encrypted # --echo # (crash at page 10) # --echo ############################################################ --echo # Set Encryption process to crash at page 10 SET SESSION debug= '+d,alter_encrypt_tablespace_page_10'; SET GLOBAL innodb_log_checkpoint_now = ON; SET GLOBAL innodb_page_cleaner_disabled_debug = 1; SET GLOBAL innodb_dict_stats_disabled_debug = 1; SET GLOBAL innodb_master_thread_disabled_debug = 1; --echo # Encrypt the tablespace. It will cause crash. --source include/expect_crash.inc --error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; --echo # Restart after crash without Keyring plugin loaded --error 1,42 --exec $MYSQLD_CMD --plugin-dir=$PLUGIN_DIR --log-error=$MYSQLTEST_VARDIR/log/my_restart.err # Search the failure pattern in error log let SEARCH_FILE= $MYSQLTEST_VARDIR/log/my_restart.err; let SEARCH_PATTERN=CORRUPT LOG RECORD FOUND; --source include/search_pattern.inc --echo # Server shouldn't have restarted, so query should fail. --error CR_SERVER_LOST SELECT * from test.t1 limit 10; --echo ######################################################################### --echo # RESTART 2 : WITH KEYRING PLUGIN --echo ######################################################################### let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; --source include/start_mysqld_no_echo.inc --echo # Server should have restarted properly. SELECT * from test.t1 limit 10; --echo # --echo # Bug#30888919 : [INNODB] ASSERTION FAILURE:SPACE->ENCRYPTION_OP_IN_PROGRESS == NONE --echo # ALTER TABLESPACE encrypt_ts ENCRYPTION='N'; SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; SELECT * FROM t1 LIMIT 10; --echo ############################################################ --echo # ALTER TABLESPACE : Unencrypted => Encrypted # --echo # (crash at page 10) # --echo ############################################################ --echo # Connection con1: connect (con1,localhost,root,,); connection con1; let $SAVED_CON_ID = `SELECT connection_id();`; --echo # Set Encryption process to crash at page 10 SET SESSION debug= '+d,alter_encrypt_tablespace_page_10'; --echo # Encrypt the tablespace. It will cause crash. --source include/expect_crash.inc --error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; --echo # Restart after crash with sleep_resume_alter_encrypt to make resume --echo # thread to sleep. 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; --source include/start_mysqld_no_echo.inc --echo # Connection con2: connect (con2,localhost,root,,); connection con2; --echo # Check that this connection id is same as of the one which was trying --echo # to encrypt the tablespace before crash. let $CUR_CON_ID = `SELECT connection_id();`; if ($CUR_CON_ID == $SAVED_CON_ID) { --echo Connectin ids are same. } if ($CUR_CON_ID != $SAVED_CON_ID) { --echo Connectin ids are not same. } # Run a DDL with this connection. At post DDL it will remove DDL Log records. CREATE TABLESPACE temp_ts ADD DATAFILE 'temp_ts.ibd'; --echo # connection con3 connect (con3,localhost,root,,); connection con3; SELECT connection_id(); --echo # Run a DDL with this connection con3 ALTER TABLESPACE temp_ts ENCRYPTION='Y'; set global innodb_buf_flush_list_now = 1; --echo # Now restart without sleep_resume_alter_encrypt. # NOTE : resume processing for connection con1 wouldn't have finished yet and # should be tried again in next restart. --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR $KEYRING_PLUGIN_OPT --plugin-dir=KEYRING_PLUGIN_PATH $KEYRING_PLUGIN keyring_file.so let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; --source include/kill_and_restart_mysqld.inc --echo # Wait for Encryption processing to finish in background thread let $wait_condition = SELECT ENCRYPTION = 'Y' FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; --source include/wait_condition.inc --echo # After restart/recovery, check that Encryption was roll-forward SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='encrypt_ts'; SELECT * FROM t1 LIMIT 10; --echo # Now try to encrypt tablespace. Without patch, an assert will be hit. ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; --echo ########### --echo # Cleanup # --echo ########### DROP TABLE t1; DROP TABLESPACE encrypt_ts; remove_file $MYSQL_TMP_DIR/mysecret_keyring; remove_file $SEARCH_FILE; --echo # Restarting server without keyring to restore server state let $restart_parameters = restart: ; --source include/restart_mysqld.inc