summaryrefslogtreecommitdiff
path: root/mysql-test/suite/encryption/t/innodb_encryption.test
blob: 6e9f80aac0cf631189115c0fa0260f47a76e11c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
#
#
-- source include/have_innodb.inc
-- source include/have_example_key_management_plugin.inc
-- source include/innodb_undo_tablespaces.inc

# embedded does not support restart
-- source include/not_embedded.inc

call mtr.add_suppression("InnoDB: New log files created");
call mtr.add_suppression("InnoDB: Creating foreign key constraint system tables.");

SET @start_global_value = @@global.innodb_encryption_threads;

SHOW VARIABLES LIKE 'innodb_encrypt%';

DESCRIBE INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;

--echo # Wait max 5 min for key encryption threads to encrypt one space
let $cnt=300;
while ($cnt)
{
    let $success=`SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION > 0`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 1;
        dec $cnt;
    }
}
if (!$success)
{
    SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;
    SHOW STATUS LIKE 'innodb_encryption%';
    -- die Timeout waiting for encryption threads
}
--echo # Success!

--echo # Wait max 10 min for key encryption threads to encrypt all space
let $cnt=600;
while ($cnt)
{
    let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 1;
        dec $cnt;
    }
}
if (!$success)
{
    SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;
    SHOW STATUS LIKE 'innodb_encryption%';
    -- die Timeout waiting for encryption threads
}
--echo # Success!

--echo # Now turn off encryption and wait for threads to decrypt everything
SET GLOBAL innodb_encrypt_tables = off;

--echo # Wait max 10 min for key encryption threads to decrypt all space
let $cnt=600;
while ($cnt)
{
    let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 1;
        dec $cnt;
    }
}
if (!$success)
{
    SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;
    SHOW STATUS LIKE 'innodb_encryption%';
    -- die Timeout waiting for encryption threads
}
--echo # Success!

--echo # Shutdown innodb_encryption_threads
SET GLOBAL innodb_encryption_threads=0;

--echo # Turn on encryption
--echo # since threads are off tables should remain unencrypted
SET GLOBAL innodb_encrypt_tables = on;

--echo # Wait 15s to check that nothing gets encrypted
let $cnt=15;
while ($cnt)
{
    let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0`;
    if ($success)
    {
        real_sleep 1;
        dec $cnt;
    }
    if (!$success)
    {
        SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0;
        -- die Failure, tablespace getting encrypted even if innodb_encryption_threads=0
    }
}
--echo # Success!

--echo # Startup innodb_encryption_threads
SET GLOBAL innodb_encryption_threads=@start_global_value;

--echo # Wait 1 min to check that it start encrypting again
let $cnt=60;
while ($cnt)
{
    let $success=`SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 OR KEY_ROTATION_PAGE_NUMBER IS NOT NULL`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 1;
        dec $cnt;
    }
}
if (!$success)
{
    SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;
    SHOW STATUS LIKE 'innodb_encryption%';
    -- die Timeout waiting for encryption threads
}
--echo # Success!

--echo #
--echo # Check that restart with encryption turned off works
--echo # even if spaces are encrypted
--echo #
--echo # First wait max 10 min for key encryption threads to encrypt all spaces
let $cnt=600;
while ($cnt)
{
    let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0`;
    if ($success)
    {
        let $cnt=0;
    }
    if (!$success)
    {
        real_sleep 1;
        dec $cnt;
    }
}
if (!$success)
{
    SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION;
    SHOW STATUS LIKE 'innodb_encryption%';
    -- die Timeout waiting for encryption threads
}
--echo # Success!
--echo # Restart mysqld --innodb_encrypt_tables=0 --innodb_encryption_threads=0
-- let $restart_parameters=--innodb_encrypt_tables=0 --innodb_encryption_threads=0
-- source include/restart_mysqld.inc

SHOW VARIABLES LIKE 'innodb_encrypt%';
SELECT COUNT(*) > 0 as should_be_1
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
WHERE MIN_KEY_VERSION <> 0;

--echo # Restart mysqld again...with default options
-- let $restart_parameters=
-- source include/restart_mysqld.inc