Debian Codegraph @

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

raw
1 #------------------------------------------------------------------------------
2 ## InnoDB transparent tablespace data encryption
3 ## This test case will test basic recovery from known DBUG_SUICIDE point .
4 ## - ib_crash_during_rotation_for_encryption (assert during key rotation)
5 ## - ib_crash_during_create_for_encryption (assert during create)
6 ## - ib_crash_during_decrypt_page (assert during page decryption)
7 ##------------------------------------------------------------------------------
8
9 # Disable in valgrind because of timeout, cf. Bug#22760145
10 --source include/not_valgrind.inc
11
12 # Avoid CrashReporter popup on Mac
13 --source include/not_crashrep.inc
14
15 # innodb-force-recovery-crash needs debug
16 --source include/have_debug.inc
17
18 let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
19 let $MYSQLD_DATADIR = `SELECT @@datadir`;
20 let $innodb_file_per_table = `SELECT @@innodb_file_per_table`;
21
22 SET GLOBAL innodb_file_per_table = 1;
23 SELECT @@innodb_file_per_table;
24
25 --disable_warnings
26 DROP DATABASE IF EXISTS tde_db;
27 CREATE DATABASE tde_db;
28 USE tde_db;
29 --enable_warnings
30
31 --echo #
32 --echo # Set encryption ON for table `mysql`
33 --echo #
34 ALTER TABLESPACE mysql ENCRYPTION='Y';
35 SET debug='+d,skip_dd_table_access_check';
36 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
37 SET debug='-d,skip_dd_table_access_check';
38
39 --echo #
40 --echo # Test crash point `ib_crash_during_rotation_for_encryption`
41 --echo #
42 SET SESSION DEBUG="+d,ib_encryption_rotate_crash";
43
44 CREATE TABLE tde_db.t1(c1 INT, c2 char(20)) ENCRYPTION="Y" ENGINE = InnoDB;
45 SET debug='+d,skip_dd_table_access_check';
46 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
47 SET debug='-d,skip_dd_table_access_check';
48 SHOW CREATE TABLE tde_db.t1;
49 INSERT INTO tde_db.t1 VALUES(0, "aaaaa");
50 INSERT INTO tde_db.t1 VALUES(1, "bbbbb");
51 INSERT INTO tde_db.t1 VALUES(2, "ccccc");
52 INSERT INTO tde_db.t1 VALUES(3, "ddddd");
53
54 --echo # Execute the statement that causes the crash
55 # Write file to make mysql-test-run.pl start up the server again
56 --exec echo "restart:--early-plugin-load="keyring_file=$KEYRING_PLUGIN" --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
57 --error 2013
58 ALTER INSTANCE ROTATE INNODB MASTER KEY;
59 --enable_reconnect
60 --source include/wait_until_connected_again.inc
61 --disable_reconnect
62 SET SESSION DEBUG="-d,ib_encryption_rotate_crash";
63 let SEARCH_PATTERN = ib_encryption_rotate_crash;
64 --source include/search_pattern.inc
65
66 --echo # Show that encryption is OK
67 SET debug='+d,skip_dd_table_access_check';
68 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
69 SET debug='-d,skip_dd_table_access_check';
70 INSERT INTO tde_db.t1 VALUES(4, "eeeee");
71 SELECT * FROM tde_db.t1 ORDER BY c1;
72
73 --echo # Create a second table with encryption
74 CREATE TABLE tde_db.t2(c1 INT, c2 char(20)) ENCRYPTION="Y" ENGINE = InnoDB;
75 SHOW CREATE TABLE tde_db.t2;
76 SET debug='+d,skip_dd_table_access_check';
77 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
78 SET debug='-d,skip_dd_table_access_check';
79 INSERT INTO tde_db.t2 VALUES(0, "aaaaa");
80 INSERT INTO tde_db.t2 VALUES(1, "bbbbb");
81
82 --echo # Remove the current auto.cnf file to make sure a new server uuid is
83 --echo # generated at restart.
84 --remove_file $MYSQLD_DATADIR/auto.cnf
85
86 --echo # Execute the statement that causes the crash
87 # Write file to make mysql-test-run.pl start up the server again
88 --exec echo "restart:--early-plugin-load="keyring_file=$KEYRING_PLUGIN" --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
89 SET SESSION DEBUG="+d,ib_encryption_rotate_crash";
90 --error 2013
91 ALTER INSTANCE ROTATE INNODB MASTER KEY;
92 --enable_reconnect
93 --source include/wait_until_connected_again.inc
94 --disable_reconnect
95 SET SESSION DEBUG="-d,ib_encryption_rotate_crash";
96 let SEARCH_PATTERN = ib_encryption_rotate_crash;
97 --source include/search_pattern.inc
98
99 --echo # Show that encryption is OK
100 SET debug='+d,skip_dd_table_access_check';
101 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
102 SET debug='-d,skip_dd_table_access_check';
103 INSERT INTO tde_db.t1 VALUES(5, "fffff");
104 SELECT * FROM tde_db.t1 ORDER BY c1;
105 SELECT * FROM tde_db.t2 ORDER BY c1;
106
107 --echo # Rotate Encryption again without the Crash
108 ALTER INSTANCE ROTATE INNODB MASTER KEY;
109 SELECT * FROM tde_db.t1 ORDER BY c1 ;
110
111 --echo # Show that encryption is OK
112 SET debug='+d,skip_dd_table_access_check';
113 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
114 SET debug='-d,skip_dd_table_access_check';
115 SELECT * FROM tde_db.t1 ORDER BY c1 ;
116 SELECT * FROM tde_db.t2 ORDER BY c1 ;
117
118 DROP TABLE tde_db.t2;
119 ALTER TABLESPACE mysql ENCRYPTION='N';
120 SET debug='+d,skip_dd_table_access_check';
121 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
122 SET debug='-d,skip_dd_table_access_check';
123
124 --echo #
125 --echo # Test crash point `ib_crash_during_create_for_encryption` during a CREATE TABLE
126 --echo #
127 # Write file to make mysql-test-run.pl start up the server again
128 --exec echo "restart:--early-plugin-load="keyring_file=$KEYRING_PLUGIN" --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
129 SET SESSION DEBUG="+d,ib_crash_during_create_for_encryption";
130
131 --echo # Execute the statement that causes the crash
132 --error 2013
133 CREATE TABLE tde_db.t2(c1 INT, c2 char(20)) ENCRYPTION="Y" ENGINE = InnoDB;
134 --enable_reconnect
135 --source include/wait_until_connected_again.inc
136 --disable_reconnect
137 SET SESSION DEBUG="-d,ib_crash_during_create_for_encryption";
138
139 --echo # Show encrypted tables.
140 SET debug='+d,skip_dd_table_access_check';
141 SELECT NAME,OPTIONS FROM mysql.tablespaces WHERE OPTIONS LIKE '%encryption=Y%';
142 SET debug='-d,skip_dd_table_access_check';
143 SELECT * FROM tde_db.t1 ORDER BY c1 LIMIT 5;
144 INSERT INTO tde_db.t1 VALUES(6, "ggggg");
145 SELECT * FROM tde_db.t1 ORDER BY c1 ;
146 --error 1146
147 SELECT * FROM tde_db.t2;
148
149 --echo #
150 --echo # Test crash point `ib_crash_during_decrypt_page` during an IMPORT TABLESPACE
151 --echo #
152 # Write file to make mysql-test-run.pl start up the server again
153 --exec echo "restart:--early-plugin-load="keyring_file=$KEYRING_PLUGIN" --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
154
155 FLUSH TABLE tde_db.t1 FOR EXPORT;
156 --copy_file $MYSQLD_DATADIR/tde_db/t1.cfg $MYSQLD_DATADIR/t1.cfg_back
157 --copy_file $MYSQLD_DATADIR/tde_db/t1.cfp $MYSQLD_DATADIR/t1.cfp_back
158 --copy_file $MYSQLD_DATADIR/tde_db/t1.ibd $MYSQLD_DATADIR/t1.ibd_back
159 UNLOCK TABLES;
160 ALTER TABLE tde_db.t1 DISCARD TABLESPACE;
161 --copy_file $MYSQLD_DATADIR/t1.cfg_back $MYSQLD_DATADIR/tde_db/t1.cfg
162 --copy_file $MYSQLD_DATADIR/t1.cfp_back $MYSQLD_DATADIR/tde_db/t1.cfp
163 --copy_file $MYSQLD_DATADIR/t1.ibd_back $MYSQLD_DATADIR/tde_db/t1.ibd
164
165 SET SESSION DEBUG="+d,ib_crash_during_decrypt_page";
166
167 --echo # Execute the statement that causes the crash
168 --error 2013
169 eval ALTER TABLE tde_db.t1 IMPORT TABLESPACE;
170 --enable_reconnect
171 --source include/wait_until_connected_again.inc
172 --disable_reconnect
173 SET SESSION DEBUG="-d,ib_crash_during_decrypt_page";
174
175 --error ER_TABLESPACE_DISCARDED
176 INSERT INTO tde_db.t1 VALUES(7, "hhhhh");
177 --error ER_TABLESPACE_DISCARDED
178 SELECT * FROM tde_db.t1 ORDER BY c1 ;
179 DROP TABLE tde_db.t1;
180
181 --exec echo "restart: " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
182 --enable_reconnect
183 --source include/wait_until_connected_again.inc
184 --disable_reconnect
185
186 --remove_files_wildcard $MYSQLD_DATADIR/tde_db/ t1.*
187 DROP DATABASE tde_db;
188
189 --echo #
190 --echo # Bug #27307740 [ERROR] [MY-011066] INNODB: CORRUPT LOG RECORD FOUND
191 --echo # DURING CRASH RECOVERY
192 --echo #
193
194 CREATE DATABASE tde_db;
195
196 # Write file to make mysql-test-run.pl start up the server again
197 --exec echo "restart:--early-plugin-load="keyring_file=$KEYRING_PLUGIN" --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
198
199 CREATE TABLE tde_db.test_tbl(c1 int) ENCRYPTION="Y" ENGINE=InnoDB;
200
201 # Crash the server while executing ALTER INSTANCE ROTATE
202 SET SESSION DEBUG="+d,keyring_file_backup_fail";
203 --error 2013
204 ALTER INSTANCE ROTATE INNODB MASTER KEY;
205 --enable_reconnect
206 --source include/wait_until_connected_again.inc
207 --disable_reconnect
208 SET SESSION DEBUG="-d,keyring_file_backup_fail";
209
210 SELECT COUNT(*) FROM tde_db.test_tbl;
211
212 DROP TABLE tde_db.test_tbl;
213
214 # Cleanup
215 DROP DATABASE tde_db;
216 eval SET GLOBAL innodb_file_per_table=$innodb_file_per_table;
217
218 # Clean up
219 --source include/shutdown_mysqld.inc
220 --remove_file $MYSQLD_DATADIR/t1.cfg_back
221 --remove_file $MYSQLD_DATADIR/t1.cfp_back
222 --remove_file $MYSQLD_DATADIR/t1.ibd_back
223
224 # Tests above might leave this in bad state
225 --remove_file $MYSQL_TMP_DIR/mysecret_keyring
226 --source include/start_mysqld.inc
227
228 # Verify normal operation
229 CREATE TABLE test.t1(c1 INT, c2 char(20)) ENCRYPTION="Y" ENGINE = InnoDB;
230 DROP TABLE test.t1;
231
232 --disable_query_log
233 call mtr.add_suppression("\\[Warning\\].* Can't generate new master key for tablespace encryption, please check the keyring plugin is loaded.");
234 call mtr.add_suppression("\\[Warning\\].* Cannot calculate statistics for table .* because the \.ibd file is missing");
235 call mtr.add_suppression("\\[Warning\\].* Database page corruption or a failed file read of page");
236 call mtr.add_suppression("\\[Warning\\].* does not exist in the InnoDB internal data dictionary though MySQL is trying to drop it");
237 call mtr.add_suppression("\\[Warning\\].* Plugin keyring_file reported: 'Error while restoring keyring from backup file cannot overwrite keyring with backup'");
238 call mtr.add_suppression("\\[Warning\\].* Tablespace .*, name '.*', file '.*' is missing");
239 call mtr.add_suppression("\\[Warning\\].* Tablespace for table `tde_db`.`t1` is set as discarded");
240 call mtr.add_suppression("\\[ERROR\\].* Encryption algorithm support missing:");
241 call mtr.add_suppression("\\[ERROR\\].* Encryption can't find master key, please check the keyring plugin is loaded.");
242 call mtr.add_suppression("\\[ERROR\\].* The table .* doesn't have a corresponding tablespace, it was discarded.");
243 call mtr.add_suppression("\\[Warning\\].* Encryption key missing: space_id=");
244 call mtr.add_suppression("\\[Warning\\].* Decrypting a page in doublewrite file failed: space_id=");
245 --enable_query_log