File: binlog_rotate_binlog_master_key_crash_recovery.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (295 lines) | stat: -rw-r--r-- 12,416 bytes parent folder | download
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# ==== Purpose ====
#
# To verify that rotating master key are recovered correctly after crashes at
# different points when executing the command 'ALTER INSTANCE ROTATE BINLOG
# MASTER KEY' on enabling binlog_encryption.
#
# ==== Implementation ====
#
# 1. Set a debug point.
# 2. Verify that an expected crash happened at the debug point when executing
#    the command 'ALTER INSTANCE ROTATE BINLOG MASTER KEY'.
# 3. Recover the server with disabling the binlog_encryption.
# 4. Verify that 'binlog_encryption' is off after above crash recovery
# 5. Verify that an error is emitted to the client side if needed when
#    executing the command 'SET @@GLOBAL.binlog_encryption=ON' if there
#    is an error.
# 6. Verify that 'binlog_encryption' can be enabled and rotating master key
#    is recovered after above crash recovery on enabling binlog_encryption.
# 7. Verify that 'ALTER INSTANCE ROTATE BINLOG MASTER KEY' works after
#    above crash recovery.
#
# ==== References ====
#
# Wl#12080 Add support to binary log encryption key rotation and cleanup

--source include/have_binlog_format_row.inc
--source include/not_valgrind.inc
--source include/have_log_bin.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc

--let $MASTER_DATADIR= `select @@datadir`
--let $default_binlog_encryption = `SELECT @@GLOBAL.binlog_encryption`

SET @@GLOBAL.binlog_encryption=ON;

--let $first_encrypted_binary_log=query_get_value(SHOW MASTER STATUS, File, 1)
--let $rpl_log_file=$MASTER_DATADIR$first_encrypted_binary_log
--source include/rpl_get_log_encryption_key_id.inc
--let $assert_text=the first encrypted binary log is encrypted using first master key
--let $assert_cond= RIGHT("$rpl_encryption_key_id", 2) = "_1"
--source include/assert.inc

CREATE TABLE t1 (a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1);

ALTER INSTANCE ROTATE BINLOG MASTER KEY;
INSERT INTO t1 VALUES(2);


--echo # Part 1: crash_before_set_old_master_key_seqno_on_keyring
--let $debug_point=crash_before_set_old_master_key_seqno_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

--echo #
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error
--echo # when fetching master key seqno from keyring.
--echo #
--let $debug_point=fail_to_fetch_master_key_seqno_from_keyring
--source include/add_debug_point.inc
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

--echo #
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error
--echo # when fetching old master key seqno from keyring.
--echo #
--let $debug_point=fail_to_fetch_old_master_key_seqno_from_keyring
--source include/add_debug_point.inc
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=2
--let $current_comparison_digit=2
--let $rotated_master_key_id=3
--let $rotated_comparison_digit=2
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 2: crash_after_set_old_master_key_seqno_on_keyring
--let $debug_point=crash_after_set_old_master_key_seqno_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

--echo #
--echo # Verify that an error 'ER_binlog_MASTER_KEY_RECOVERY_OUT_OF_COMBINATION'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if the combination of
--echo # values of new_master_key_seqno, master_key_seqno and
--echo # old_master_key_seqno are wrong when recovering binlog master key.
--echo #
--let $debug_point=simulate_master_key_recovery_out_of_combination
--source include/add_debug_point.inc
--error ER_BINLOG_MASTER_KEY_RECOVERY_OUT_OF_COMBINATION
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=4
--let $rotated_master_key_id=5
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 3: crash_after_set_new_master_key_seqno_on_keyring
--let $debug_point=crash_after_set_new_master_key_seqno_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

--echo #
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error
--echo # when fetching new master key from keyring.
--echo #
--let $debug_point=fail_to_fetch_new_master_key_from_keyring
--source include/add_debug_point.inc
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=6
--let $rotated_master_key_id=7
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 4: crash_after_generate_new_master_key_on_keyring
--let $debug_point=crash_after_generate_new_master_key_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

--echo #
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error
--echo # when fetching new master key seqno from keyring.
--echo #
--let $debug_point=fail_to_fetch_new_master_key_seqno_from_keyring
--source include/add_debug_point.inc
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=8
--let $rotated_master_key_id=9
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 5: crash_after_remove_master_key_seqno_from_keyring 
--let $debug_point=crash_after_remove_master_key_seqno_from_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=10
--let $current_comparison_digit=3
--let $rotated_master_key_id=11
--let $rotated_comparison_digit=3
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 6: crash_after_set_master_key_seqno_on_keyring
--let $debug_point=crash_after_set_master_key_seqno_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=12
--let $rotated_master_key_id=13
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 7: crash_after_remove_old_master_key_seqno_from_keyring
--let $debug_point=crash_after_remove_old_master_key_seqno_from_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=14
--let $rotated_master_key_id=15
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 8: crash_after_remove_new_master_key_seqno_from_keyring
--let $debug_point=crash_after_remove_new_master_key_seqno_from_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=16
--let $rotated_master_key_id=17
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

--echo # Part 9: crash_after_set_old_master_key_seqno_on_keyring
--let $debug_point=crash_after_set_old_master_key_seqno_on_keyring
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY
--source suite/binlog/include/binlog_server_crash_recovery.inc

--let $assert_text= 'binlog_encryption' is off after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0"
--source include/assert.inc

--echo #
--echo # Verify that an error 'ER_RPL_ENCRYPTION_FAILED_TO_STORE_KEY'
--echo # is emitted to the client side when executing the command
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error
--echo # on setting new master key seqno on keyring when recovering
--echo # binlog master key.
--echo #
--let $debug_point=fail_to_set_new_master_key_seqno_on_keyring
--source include/add_debug_point.inc
--error ER_RPL_ENCRYPTION_FAILED_TO_STORE_KEY
SET @@GLOBAL.binlog_encryption=ON;
--source include/remove_debug_point.inc

SET @@GLOBAL.binlog_encryption=ON;
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery.
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1"
--source include/assert.inc

--let $current_master_key_id=18
--let $rotated_master_key_id=19
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc

# Cleanup
DROP TABLE t1;
--replace_result $default_binlog_encryption DEFAULT_BINLOG_ENCRYPTION
--eval SET @@GLOBAL.binlog_encryption=$default_binlog_encryption