| 1 |
################################################################################ |
| 2 |
# InnoDB transparent tablespace data encryption for general shared tablespace. |
| 3 |
# This test case will test |
| 4 |
# - Progress monitoring of 'ALTER TABLESPACE ... ENCRYPTION=Y' |
| 5 |
# in performance_schema table. |
| 6 |
################################################################################ |
| 7 |
|
| 8 |
--source include/no_valgrind_without_big.inc |
| 9 |
--source include/have_debug.inc |
| 10 |
# Waiting time when (re)starting the server |
| 11 |
--let $explicit_default_wait_counter=10000 |
| 12 |
|
| 13 |
--disable_query_log |
| 14 |
call mtr.add_suppression("ibd can't be decrypted, please confirm that keyring is loaded."); |
| 15 |
call mtr.add_suppression("\\[Error\\] \\[[^]]*\\] \\[[^]]*\\] Encryption can't find master key, please check the keyring is loaded."); |
| 16 |
call mtr.add_suppression("\\[ERROR\\] \\[[^]]*\\] \\[[^]]*\\] Check keyring fail, please check the keyring is loaded."); |
| 17 |
--enable_query_log |
| 18 |
|
| 19 |
--echo ######################################################################### |
| 20 |
--echo # START : WITHOUT KEYRING PLUGIN |
| 21 |
--echo ######################################################################### |
| 22 |
--echo |
| 23 |
--echo ######### |
| 24 |
--echo # SETUP # |
| 25 |
--echo ######### |
| 26 |
|
| 27 |
# Create an Unencrypted tablespace |
| 28 |
CREATE TABLESPACE encrypt_ts ADD DATAFILE 'encrypt_ts.ibd' |
| 29 |
ENGINE=InnoDB ENCRYPTION="N"; |
| 30 |
# Create an unencrypted table in tablespace |
| 31 |
CREATE TABLE t1(c1 char(100)) ENGINE=InnoDB TABLESPACE encrypt_ts; |
| 32 |
# Insert few rows in table |
| 33 |
--disable_query_log |
| 34 |
INSERT INTO t1 VALUES ("SOME VALUES"); |
| 35 |
let $counter=5; |
| 36 |
while ($counter>0) |
| 37 |
{ |
| 38 |
INSERT INTO test.t1 SELECT * FROM test.t1; |
| 39 |
dec $counter; |
| 40 |
} |
| 41 |
--enable_query_log |
| 42 |
|
| 43 |
# Make sure ts file is updated with new records in table |
| 44 |
set global innodb_buf_flush_list_now = 1; |
| 45 |
|
| 46 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES |
| 47 |
WHERE NAME='encrypt_ts'; |
| 48 |
SELECT * FROM t1 LIMIT 10; |
| 49 |
|
| 50 |
# Try to alter tablespace to be encrypted. Should fail as keyring is not laoded. |
| 51 |
--error ER_CANNOT_FIND_KEY_IN_KEYRING |
| 52 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 53 |
|
| 54 |
--echo ######################################################################### |
| 55 |
--echo # RESTART 1 : WITH KEYRING PLUGIN |
| 56 |
--echo ######################################################################### |
| 57 |
let $restart_parameters = restart: |
| 58 |
--early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT --performance-schema-consumer-events-stages-current=ON --performance-schema-events-stages-history-size=1000; |
| 59 |
--source include/restart_mysqld_no_echo.inc |
| 60 |
|
| 61 |
--echo # Monitoring connection |
| 62 |
connect(con1, localhost, root,,); |
| 63 |
--connection con1 |
| 64 |
|
| 65 |
UPDATE performance_schema.setup_consumers SET ENABLED='YES'; |
| 66 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES |
| 67 |
WHERE NAME='encrypt_ts'; |
| 68 |
SELECT * FROM performance_schema.setup_consumers |
| 69 |
WHERE NAME LIKE "%stages%"; |
| 70 |
SELECT * FROM performance_schema.setup_instruments |
| 71 |
WHERE NAME LIKE "%encryption%"; |
| 72 |
|
| 73 |
select count(*) from performance_schema.events_stages_current |
| 74 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 75 |
|
| 76 |
--echo # Default connection |
| 77 |
--connection default |
| 78 |
--echo ############################################################ |
| 79 |
--echo # ALTER TABLESPACE 1 : Unencrypted => Encrypted # |
| 80 |
--echo ############################################################ |
| 81 |
--echo |
| 82 |
--echo # Set Encryption process to wait after page 5 so that we can monitor |
| 83 |
--echo # progress in performance_schema table |
| 84 |
SET DEBUG_SYNC = 'alter_encrypt_tablespace_wait_after_page5 SIGNAL s1 WAIT_FOR s2'; |
| 85 |
|
| 86 |
let $con_default_thread_id= `select THREAD_ID from performance_schema.threads |
| 87 |
where PROCESSLIST_ID = connection_id()`; |
| 88 |
|
| 89 |
--send |
| 90 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='Y'; |
| 91 |
|
| 92 |
--echo # Monitoring connection |
| 93 |
--connection con1 |
| 94 |
SET DEBUG_SYNC = 'now WAIT_FOR s1'; |
| 95 |
|
| 96 |
--echo # Wait for Encryption progress monitoring to appear in PFS table |
| 97 |
let $wait_condition = SELECT COUNT(*) = 1 |
| 98 |
FROM performance_schema.events_stages_current |
| 99 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 100 |
--source include/wait_condition.inc |
| 101 |
|
| 102 |
--echo # Wait for some progress to appear in PFS table |
| 103 |
let $wait_condition = SELECT WORK_COMPLETED > 0 |
| 104 |
FROM performance_schema.events_stages_current |
| 105 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 106 |
--source include/wait_condition.inc |
| 107 |
|
| 108 |
# Verify the expected progress seen in PFS table |
| 109 |
select WORK_ESTIMATED > WORK_COMPLETED, WORK_COMPLETED |
| 110 |
FROM performance_schema.events_stages_current |
| 111 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)'; |
| 112 |
|
| 113 |
# Let the encryption processing continue |
| 114 |
SET DEBUG_SYNC = 'now SIGNAL s2'; |
| 115 |
|
| 116 |
--echo # Default connection |
| 117 |
--connection default |
| 118 |
--reap |
| 119 |
|
| 120 |
--echo # Once done, select count from PFS tables |
| 121 |
SELECT COUNT(*) |
| 122 |
FROM performance_schema.events_stages_current |
| 123 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 124 |
|
| 125 |
SELECT COUNT(*) |
| 126 |
FROM performance_schema.events_stages_history |
| 127 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 128 |
|
| 129 |
SELECT COUNT(*) |
| 130 |
FROM performance_schema.events_stages_history_long |
| 131 |
WHERE EVENT_NAME='stage/innodb/alter tablespace (encryption)'; |
| 132 |
|
| 133 |
SELECT COUNT(*) |
| 134 |
FROM performance_schema.events_stages_summary_global_by_event_name |
| 135 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)' AND |
| 136 |
COUNT_STAR>0; |
| 137 |
|
| 138 |
--disable_query_log |
| 139 |
eval SELECT COUNT(*) |
| 140 |
FROM performance_schema.events_stages_summary_by_thread_by_event_name |
| 141 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)' AND |
| 142 |
THREAD_ID=$con_default_thread_id; |
| 143 |
--enable_query_log |
| 144 |
|
| 145 |
SELECT COUNT(*) |
| 146 |
FROM performance_schema.events_stages_summary_by_user_by_event_name |
| 147 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)' AND |
| 148 |
COUNT_STAR>0; |
| 149 |
|
| 150 |
SELECT COUNT(*) |
| 151 |
FROM performance_schema.events_stages_summary_by_host_by_event_name |
| 152 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)' AND |
| 153 |
COUNT_STAR>0; |
| 154 |
|
| 155 |
SELECT COUNT(*) |
| 156 |
FROM performance_schema.events_stages_summary_by_account_by_event_name |
| 157 |
WHERE EVENT_NAME = 'stage/innodb/alter tablespace (encryption)' AND |
| 158 |
COUNT_STAR>0; |
| 159 |
|
| 160 |
--echo # Check that Encryption done successfully. |
| 161 |
SELECT NAME, ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES |
| 162 |
WHERE NAME='encrypt_ts'; |
| 163 |
SELECT * FROM t1 LIMIT 10; |
| 164 |
|
| 165 |
--echo ######################################################################### |
| 166 |
--echo # RESTART 2 : WITHOUT KEYRING PLUGIN |
| 167 |
--echo ######################################################################### |
| 168 |
let $restart_parameters = restart:; |
| 169 |
--source include/restart_mysqld_no_echo.inc |
| 170 |
|
| 171 |
# We shouldn't be able to read t1 records as it is encrypted now and keyring |
| 172 |
# plugin is not loaded. |
| 173 |
--error ER_CANNOT_FIND_KEY_IN_KEYRING |
| 174 |
SELECT * FROM t1 LIMIT 10; |
| 175 |
|
| 176 |
--echo ######################################################################### |
| 177 |
--echo # RESTART 3 : WITH KEYRING PLUGIN |
| 178 |
--echo ######################################################################### |
| 179 |
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT; |
| 180 |
--source include/restart_mysqld_no_echo.inc |
| 181 |
|
| 182 |
# Disable all consumers |
| 183 |
UPDATE performance_schema.setup_consumers SET ENABLED='NO'; |
| 184 |
ALTER TABLESPACE encrypt_ts ENCRYPTION='N'; |
| 185 |
|
| 186 |
--echo ########### |
| 187 |
--echo # Cleanup # |
| 188 |
--echo ########### |
| 189 |
--disconnect con1 |
| 190 |
SELECT COUNT(*) FROM t1; |
| 191 |
DROP TABLE t1; |
| 192 |
DROP TABLESPACE encrypt_ts; |
| 193 |
remove_file $MYSQL_TMP_DIR/mysecret_keyring; |
| 194 |
|
| 195 |
--let $restart_parameters= restart: |
| 196 |
--source include/restart_mysqld.inc |