Debian Codegraph @

mysql-test/suite/binlog_encryption/encrypted_master_switch_to_unencrypted_gtid.test

raw
1 #
2 # The test starts with unencrypted master.
3 # It stops replication, generates a few statement and row events
4 # on the master, then restarts the server with encrypted binlog,
5 # generates some more events and restarts it back without encryption
6 # (no encryption plugin).
7 # Then it resumes replication and should error with
8 # ER_MASTER_FATAL_ERROR_READING_BINLOG because the encrypted binlog is
9 # sent and unable to be decrypted.
10 #
11 # Note this variation of encrypted_master_switch_to_unencrypted tests
12 # using MASTER_USE_GTID=SLAVE_POS. encrypted_master_switch_to_unencrypted
13 # was the original test which only used binlog coordinates. When tested
14 # using MASTER_USE_GTID=Slave_Pos, the master optimizes the detection of
15 # an undecryptable binlog. I.e, the master will initially look for a
16 # Gtid_list_log_event, but fail to decrypt it and fail immediately in
17 # part 3.
18 #
19
20 --source include/have_binlog_format_mixed.inc
21
22 --echo #################
23 --echo # Initialization
24 --echo #################
25
26 --let $rpl_topology= 1->2
27 --source include/rpl_init.inc
28
29 --enable_connect_log
30
31 # We stop replication because we want it to happen after the switch
32
33 --connection server_2
34 --disable_connect_log
35 --source include/stop_slave.inc
36 CHANGE MASTER TO MASTER_USE_GTID=SLAVE_POS;
37 --enable_connect_log
38 call mtr.add_suppression(" Got fatal error 1236 from master when reading data from binary log: 'Could not set up decryption for binlog.'");
39 call mtr.add_suppression(" Got fatal error 1236 from master when reading data from binary log: 'Could not decrypt binlog: encryption key error");
40
41 --echo #####################################################
42 --echo # Part 1: unencrypted master
43 --echo #####################################################
44
45 --connection server_1
46
47 CREATE TABLE table1_no_encryption (
48 pk INT AUTO_INCREMENT PRIMARY KEY,
49 ts TIMESTAMP NULL,
50 b BLOB
51 ) ENGINE=MyISAM;
52
53 INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
54 INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
55 FLUSH BINARY LOGS;
56 SET binlog_format=ROW;
57 INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
58 INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption;
59 --let $last_unencrypted_gtid= `SELECT @@gtid_binlog_pos`
60
61 # Make sure that binary logs are not encrypted
62
63 --let SEARCH_RANGE = 500000
64 --let SEARCH_FILE= master-bin.0*
65 --let SEARCH_PATTERN= table1_no_encryption
66 --source include/search_pattern_in_file.inc
67
68 --echo #####################################################
69 --echo # Part 2: restart master, now with binlog encryption
70 --echo #####################################################
71
72 --let $rpl_server_parameters= --encrypt-binlog=1 --plugin-load-add=$FILE_KEY_MANAGEMENT_SO --file-key-management --loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt
73
74 --let $rpl_server_number= 1
75 --source restart_server.inc
76
77 CREATE TABLE table2_to_encrypt (
78 pk INT AUTO_INCREMENT PRIMARY KEY,
79 ts TIMESTAMP NULL,
80 b BLOB
81 ) ENGINE=MyISAM;
82
83 INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt');
84 INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
85 FLUSH BINARY LOGS;
86 SET binlog_format=ROW;
87 INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
88 INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt;
89
90 # Make sure that binary logs are encrypted
91
92 --let SEARCH_FILE= master-bin.0*
93 --let SEARCH_PATTERN= table2_to_encrypt
94 --source include/search_pattern_in_file.inc
95
96 --echo #####################################################
97 --echo # Part 3: restart master again without encryption
98 --echo #####################################################
99
100 --let $rpl_server_parameters= --encrypt-binlog=0
101 --let $rpl_server_number= 1
102 --source restart_server.inc
103
104 CREATE TABLE table3_no_encryption (
105 pk INT AUTO_INCREMENT PRIMARY KEY,
106 ts TIMESTAMP NULL,
107 b BLOB
108 ) ENGINE=MyISAM;
109
110 INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption');
111 INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
112 INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption;
113
114 --echo #####################################################
115 --echo # Check: resume replication and check how it goes
116 --echo #####################################################
117
118 --connection server_2
119 start slave;
120 # Make slave to try to synchronize. It shouldn't work, the slave IO thread is
121 # expected to abort with an error
122 --let $slave_io_errno= 1236
123 --source include/wait_for_slave_io_error.inc
124
125 # Wait for the SQL thread to have replicated to the expected point. Otherwise
126 # there is a race where the IO thread can stop with error and the test case
127 # check the @@GLOBAL.gtid_slave_pos before the SQL thread has had time to
128 # replicate the events queued by the IO thread (MDEV-36424).
129 --replace_result "$last_unencrypted_gtid" "LAST_UNENCRYPTED_GTID"
130 eval SELECT MASTER_GTID_WAIT("$last_unencrypted_gtid", 60);
131
132 --echo # Ensuring slave was unable to replicate any encrypted transactions..
133 --let $gsp= `SELECT @@global.gtid_slave_pos`
134 if (`SELECT strcmp("$gsp","$last_unencrypted_gtid")`)
135 {
136 die Slave without encryption configured should fail to read encrypted binlog (expected $last_unencrypted_gtid but got $gsp);
137 }
138 --echo # ..success
139
140 --sorted_result
141 SHOW TABLES;
142
143 --disable_connect_log
144 # IO thread is stopped, wait for SQL thread to be stopped
145 --source include/stop_slave_sql.inc
146 --enable_connect_log
147 reset slave;
148
149 --echo ##########
150 --echo # Cleanup
151 --echo ##########
152
153 --connection server_1
154 reset master;
155
156 SELECT COUNT(*) FROM table1_no_encryption;
157 SELECT COUNT(*) FROM table2_to_encrypt;
158 SELECT COUNT(*) FROM table3_no_encryption;
159 DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption;
160
161 --connection server_2
162 --disable_connect_log
163 RESET MASTER;
164 SET GLOBAL gtid_slave_pos= '';
165 --source include/start_slave.inc
166 --source include/rpl_end.inc