Debian Codegraph @

mysql-test/suite/innodb/t/tablespace_encrypt_5.test

raw
1 ################################################################################
2 # InnoDB transparent tablespace data encryption for general shared tablespace.
3 # This test case will test
4 # - Crash during altering an encrypted tablespace
5 # - encryption='y' to encryption='n'
6 # - encryption='n' to encryption='y'
7 # This test checks physical ibd file to see if unencrypted string is present
8 # in any of the pages in tablespace file.
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 --disable_query_log
19 call mtr.add_suppression("\\[Warning\\] \\[MY-013674\\] \\[Innodb\\] Decrypting a page in doublewrite file failed");
20 call mtr.add_suppression("\\[Warning\\] \\[MY-013675\\] \\[Innodb\\] Encryption key missing");
21 --enable_query_log
22
23 --echo #########
24 --echo # SETUP #
25 --echo #########
26 --echo
27 let datadir=`SELECT @@datadir`;
28 let search_pattern=samplerecord;
29 let ts_name=encrypt_ts.ibd;
30
31 --echo #########################################################################
32 --echo # RESTART 1 : WITH KEYRING PLUGIN
33 --echo #########################################################################
34 let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT;
35 --source include/restart_mysqld_no_echo.inc
36
37 --echo # Create a new 'unencrypted' tablespace 'encrypt_ts'
38 SELECT NAME, FLAG, SPACE_TYPE FROM information_schema.INNODB_TABLESPACES
39 where NAME="encrypt_ts";
40 create tablespace encrypt_ts add datafile 'encrypt_ts.ibd'
41 engine=INNODB encryption='N';
42 SELECT NAME, FLAG, SPACE_TYPE FROM information_schema.INNODB_TABLESPACES
43 where NAME="encrypt_ts";
44
45 --echo # Create a table test.t1 in 'encrypt_ts' tablespace and insert some records.
46 create table test.t1 (c char(20)) tablespace encrypt_ts;
47 insert into test.t1 values ("samplerecord");
48
49 # Make sure ts file is updated
50 set global innodb_buf_flush_list_now = 1;
51
52 --echo #############################################################
53 --echo # INITIAL SETUP : Tablespace is created as unencrypted #
54 --echo # A table is created and rows are inserted #
55 --echo #############################################################
56
57 --echo # Check that tablespace file is not encrypted yet
58 --source include/if_encrypted.inc
59
60 --echo ############################################################
61 --echo # ALTER TABLESPACE 1 : Unencrypted => Encrypted #
62 --echo ############################################################
63 ALTER TABLESPACE encrypt_ts ENCRYPTION='Y';
64
65 # Make sure all pages are flushed
66 set global innodb_buf_flush_list_now = 1;
67
68 --echo # Check that tablespace file is encrypted now
69 --source include/if_encrypted.inc
70
71 --echo ############################################################
72 --echo # ALTER TABLESPACE 2 : Encrypted => Unencrypted #
73 --echo ############################################################
74 ALTER TABLESPACE encrypt_ts ENCRYPTION='N';
75
76 # Make sure all pages are flushed
77 set global innodb_buf_flush_list_now = 1;
78
79 --echo # Check that tablespace file is not encrypted now
80 --source include/if_encrypted.inc
81
82 --echo
83 --echo ################# CRASH/RECOVERY TESTING ###################
84 --echo
85
86 --echo ############################################################
87 --echo # ALTER TABLESPACE 3 : Unencrypted => Encrypted #
88 --echo # (crash at page 10) #
89 --echo ############################################################
90 # Insert few records in table
91 --disable_query_log
92 let $counter=12;
93 while ($counter>0)
94 {
95 INSERT INTO test.t1 SELECT * FROM test.t1;
96 dec $counter;
97 }
98 --enable_query_log
99
100 SELECT COUNT(*) FROM test.t1;
101
102 # Make sure ts file is updated with new records in table
103 set global innodb_buf_flush_list_now = 1;
104
105 --echo # Check that tablespace file is still unencrypted
106 --source include/if_encrypted.inc
107
108 --echo # Set Encryption process to crash at page 10
109 SET SESSION debug= '+d,alter_encrypt_tablespace_page_10';
110
111 --source include/expect_crash.inc
112 --error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR
113 ALTER TABLESPACE encrypt_ts ENCRYPTION='Y';
114 --source include/start_mysqld_no_echo.inc
115
116 --echo # Wait for Encryption processing to finish in background thread
117 let $wait_condition = select count(*) = 0
118 from performance_schema.events_stages_current
119 where EVENT_NAME='stage/innodb/alter tablespace (encryption)';
120 --source include/wait_condition.inc
121
122 --echo # After restart/recovery, check that Encryption was roll-forward and
123 --echo # tablespace file is encrypted now
124 --source include/if_encrypted.inc
125
126 --echo ############################################################
127 --echo # ALTER TABLESPACE 4 : Encrypted => Unencrypted #
128 --echo # (crash at page 10) #
129 --echo ############################################################
130
131 SELECT COUNT(*) FROM test.t1;
132
133 --echo # Check that tablespace file is Encrypted
134 --source include/if_encrypted.inc
135
136 --echo # Set Encryption process to crash after page 10
137 SET SESSION debug= '+d,alter_encrypt_tablespace_page_10';
138
139 --source include/expect_crash.inc
140 --error 0,CR_SERVER_LOST,ER_INTERNAL_ERROR
141 ALTER TABLESPACE encrypt_ts ENCRYPTION='N';
142 --source include/start_mysqld_no_echo.inc
143
144 --echo # Wait for Unencryption processing to finish in background thread
145 let $wait_condition = select count(*) = 0
146 from performance_schema.events_stages_current
147 where EVENT_NAME='stage/innodb/alter tablespace (encryption)';
148 --source include/wait_condition.inc
149
150 --echo # After restart/recovery, check that Unencryption was roll-forward and
151 --echo # tablespace file is Unencrypted now
152 --source include/if_encrypted.inc
153
154 --echo ###########
155 --echo # CLEANUP #
156 --echo ###########
157 DROP TABLE test.t1;
158 DROP TABLESPACE encrypt_ts;
159 remove_file $MYSQLTEST_VARDIR/tmpfile.txt;
160 remove_file $MYSQL_TMP_DIR/mysecret_keyring;
161
162 --echo # Restarting server without keyring to restore server state
163 let $restart_parameters = restart: ;
164 --source include/restart_mysqld.inc