Debian Codegraph @

mysql-test/suite/rpl/t/rpl_using_gtid_default.test

raw
1 #
2 # Purpose:
3 # This test ensures that a replica's default value for Using_Gtid is set
4 # correctly. Specifically, it should default to 'Slave_Pos' unless the primary
5 # server does not support GTIDs (if its version is less than 10), in which case
6 # the replica should fall back to 'No'.
7 #
8 # Methodology:
9 # Validate the value of Using_Gtid on replica initialization and after
10 # RESET SLAVE commands. Specifically, we validate the following use cases:
11 #
12 # Case 1) A replica will initialize with Slave_Pos if the primary supports
13 # GTIDs
14 # Case 2) A replica configured with the Using_Gtid=Slave_Pos issued
15 # RESET SLAVE will preserve Using_Gtid without any informational
16 # messages.
17 # Case 3) A replica configured with Using_Gtid=No against a master which
18 # supports GTIDs will revert to Using_Gtid=Slave_Pos after issued
19 # RESET SLAVE and provide an informational note
20 # Case 4) A fresh replica targeting a primary which does not support GTIDs
21 # will fall back to Using_Gtid=No when starting. An informational
22 # message should be logged.
23 # Case 5) A replica connected to a primary which does not support GTIDs
24 # should preserve Using_Gtid=No when issued RESET SLAVE. No message
25 # should be provided to the user.
26 # Case 6) A replica configured with Using_Gtid=Current_Pos should revert
27 # to Slave_Pos when issued RESET SLAVE. An informational message
28 # should be provided to the user.
29 # Case 7) The MTR include file rpl_change_topology.inc should implicitly
30 # set MASTER_USE_GTID=NO when provided with $rpl_master_log_file
31 # Case 8) The MTR include file reset_slave.inc should keep/delete GTID state
32 # when reset_slave_keep_gtid_state is set, respectively.
33 # Case 9) A replica issued CHANGE MASTER TO specified with log coordinates
34 # but not master_use_gtid=No should warn the user that Using_Gtid is
35 # being changed to No.
36 # Case 10) A replica issued CHANGE MASTER TO specified with log coordinates
37 # and master_use_gtid=Slave_Pos should warn the user that the log
38 # coordinates will be ignored.
39 #
40 # References:
41 # MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based
42 # replication is used by default if master supports it
43 #
44 --source include/have_debug.inc
45 # Format independent test so just use one
46 --source include/have_binlog_format_mixed.inc
47 --source include/master-slave.inc
48
49 --echo #
50 --echo # Slave default configuration should be Slave_Pos
51 --let $expected_default_using_gtid= Slave_Pos
52 --connection slave
53 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
54 if ($using_gtid != $expected_default_using_gtid)
55 {
56 --die Using_Gtid had wrong default value of '$using_gtid' when it should have been '$expected_default_using_gtid'
57 }
58
59 --echo #
60 --echo # Ensure that a slave configured with Using_Gtid=Slave_Pos will remain
61 --echo # as Slave_Pos after RESET SLAVE
62 --source include/stop_slave.inc
63 RESET SLAVE;
64 --echo # No warning should be given because Slave_Pos never changed
65 SHOW WARNINGS;
66 --source include/start_slave.inc
67 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
68 if ($using_gtid != $expected_default_using_gtid)
69 {
70 --die Using_Gtid has wrong value of '$using_gtid' when it should be '$expected_default_using_gtid'
71 }
72
73
74 --echo #
75 --echo # Ensure that a slave configured with Using_Gtid=No will revert to its
76 --echo # default of Slave_Pos after RESET SLAVE for a master which supports
77 --echo # GTIDs
78
79 --source include/stop_slave.inc
80 CHANGE MASTER TO MASTER_USE_GTID=NO;
81 --source include/start_slave.inc
82 --source include/stop_slave.inc
83 RESET SLAVE;
84 --echo # A notification that Using_Gtid was reverted should exist
85 SHOW WARNINGS;
86 --source include/start_slave.inc
87 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
88 if ($using_gtid != $expected_default_using_gtid)
89 {
90 --die Using_Gtid has wrong value of '$using_gtid' when it should be '$expected_default_using_gtid'
91 }
92
93 --echo # Clear SHOW WARNINGS
94 --disable_query_log
95 set SQL_LOG_BIN=0;
96 CREATE TABLE t1 (a int);
97 DROP TABLE t1;
98 set SQL_LOG_BIN=1;
99 --enable_query_log
100
101
102 --echo #
103 --echo # If the primary does not support GTIDs (version < 10), the replica
104 --echo # should fall back to Using_Gtid=No on slave start, and should not
105 --echo # revert Using_Gtid to Slave_Pos after RESET SLAVE
106
107 --source include/stop_slave.inc
108 RESET SLAVE ALL;
109
110 --replace_result $MASTER_MYPORT MASTER_MYPORT
111 --eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=1
112 SET @saved_dbug= @@GLOBAL.debug_dbug;
113 set @@global.debug_dbug= "d,mock_mariadb_primary_v5_in_get_master_version";
114 --source include/start_slave.inc
115
116 --echo # Replica should detect at start that the primary does not support GTIDs
117 --echo # and fall-back to Using_Gtid=No
118 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
119 if ($using_gtid != 'No')
120 {
121 --die Using_Gtid has wrong value of '$using_gtid' when it should be 'No'
122 }
123
124 --echo # Replica should have an informational message stating it is falling
125 --echo # back to Using_Gtid=No
126 let $log_error_= `SELECT @@GLOBAL.log_error`;
127 if(!$log_error_)
128 {
129 # MySQL Server on windows is started with --console and thus
130 # does not know the location of its .err log, use default location
131 let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.2.err;
132 }
133 --let SEARCH_FILE=$log_error_
134 --let SEARCH_PATTERN=Falling back to Using_Gtid=No because master does not support GTIDs
135 --source include/search_pattern_in_file.inc
136
137 --source include/stop_slave.inc
138 RESET SLAVE;
139
140 --echo # Replica should know that the primary does not support GTIDs and
141 --echo # preserve Using_Gtid=No
142 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
143 if ($using_gtid != 'No')
144 {
145 --die Using_Gtid has wrong value of '$using_gtid' when it should be 'No'
146 }
147 --echo # 'No' was not reverted and therefore no note should be added
148 SHOW WARNINGS;
149 set @@global.debug_dbug= @saved_dbug;
150 --source include/start_slave.inc
151
152
153 --echo #
154 --echo # Ensure that a slave configured with Using_Gtid=Current_Pos will revert
155 --echo # to its default of Slave_Pos after RESET SLAVE.
156
157 --source include/stop_slave.inc
158 CHANGE MASTER TO MASTER_USE_GTID=Current_Pos;
159 --source include/start_slave.inc
160 --source include/stop_slave.inc
161 RESET SLAVE;
162 --echo # A notification that Using_Gtid was reverted should exist
163 SHOW WARNINGS;
164 --source include/start_slave.inc
165 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
166 if ($using_gtid != $expected_default_using_gtid)
167 {
168 --die Using_Gtid has wrong value of '$using_gtid' when it should be '$expected_default_using_gtid'
169 }
170
171 --echo # Clear SHOW WARNINGS
172 --disable_query_log
173 set SQL_LOG_BIN=0;
174 CREATE TABLE t1 (a int);
175 DROP TABLE t1;
176 set SQL_LOG_BIN=1;
177 --enable_query_log
178
179 --echo # The MTR include file rpl_change_topology.inc should implicitly set
180 --echo # MASTER_USE_GTID=NO when provided with \$rpl_master_log_file. Note that
181 --echo # this will switch master and slave roles.
182 --connection slave
183 --source include/stop_slave.inc
184 --let $pos_c= query_get_value(SHOW SLAVE STATUS, Exec_Master_Log_Pos, 1)
185 --let $file_c= query_get_value(SHOW SLAVE STATUS, Master_Log_File, 1)
186 --let $rpl_master_log_file= 2:$file_c
187 --let $rpl_master_log_pos= 2:$pos_c
188 --let $rpl_topology= 2->1
189 --source include/rpl_change_topology.inc
190
191 --echo # connection 'master' is the slave in this comparison
192 --connection master
193 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
194 --echo # Validating Using_Gtid=No..
195 if (`SELECT strcmp("$using_gtid","No") != 0`)
196 {
197 --die Using_Gtid should be No when calling rpl_change_topology with \$rpl_master_log_file set
198 }
199 --echo # ..success
200
201 --let $rpl_master_log_file=
202 --let $rpl_topology= 1->2
203 --source include/rpl_change_topology.inc
204
205 --echo # connection 'slave' is back to slave role
206 --connection slave
207 --let $using_gtid= query_get_value(SHOW SLAVE STATUS, Using_Gtid, 1)
208 --echo # Validating Using_Gtid=$expected_default_using_gtid..
209 if (`SELECT strcmp("$using_gtid","$expected_default_using_gtid")!= 0`)
210 {
211 --die Using_Gtid should be back to $expected_default_using_gtid with empty \$rpl_master_log_file
212 }
213 --echo # ..success
214 --source include/start_slave.inc
215
216 --echo #
217 --echo # The MTR include file reset_slave.inc should keep/delete GTID state
218 --echo # when reset_slave_keep_gtid_state is set, respectively.
219 --echo #
220 --connection master
221 CREATE TABLE t1 (a INT);
222 INSERT INTO t1 VALUES (1);
223 DROP TABLE t1;
224 --source include/save_master_gtid.inc
225
226 --connection slave
227 --source include/sync_with_master_gtid.inc
228 --source include/stop_slave.inc
229
230 --echo # Tagging gtid_slave_pos before reset_slave.inc as old_slave_pos
231 --let $old_slave_pos= `SELECT @@gtid_slave_pos`
232 if (`SELECT strcmp("$old_slave_pos","") = 0`)
233 {
234 die gtid_slave_pos is empty but should not be;
235 }
236
237 --echo # Using reset_slave_keep_gtid_state=1 should preserve GTID state
238 --let $master_use_gtid_option=Slave_Pos
239 --let $reset_slave_keep_gtid_state=1
240 --source include/reset_slave.inc
241
242 --echo # Tagging gtid_slave_pos after reset_slave.inc as new_slave_pos
243 --let $new_slave_pos= `SELECT @@gtid_slave_pos`
244 --echo # Validating old_slave_pos == new_slave_pos..
245 if ($old_slave_pos != $new_slave_pos)
246 {
247 die gtid_slave_pos unexpectedly changed after running reset_slave.inc;
248 }
249 --echo # ..success
250
251 --echo # Using reset_slave_keep_gtid_state=0 should empty GTID state
252 --let $master_use_gtid_option=Slave_Pos
253 --let $reset_slave_keep_gtid_state=0
254 --source include/reset_slave.inc
255
256 --echo # Tagging gtid_slave_pos as new_slave_pos
257 --let $new_slave_pos= `SELECT @@gtid_slave_pos`
258 --echo # Validating new_slave_pos is empty..
259 if (`SELECT strcmp("$new_slave_pos","") != 0`)
260 {
261 die gtid_slave_pos should be empty after reset_slave.inc without keeping gtid state;
262 }
263 --echo # ..success
264 --replace_result $old_slave_pos old_slave_pos
265 eval set global gtid_slave_pos="$old_slave_pos";
266 --source include/start_slave.inc
267
268 --echo #
269 --echo # A replica issued CHANGE MASTER TO specified with log coordinates but
270 --echo # not master_use_gtid=no should warn the user that Using_Gtid is being
271 --echo # changed to No.
272 --echo #
273 --connection master
274 --source include/save_master_pos.inc
275 --connection slave
276 --source include/sync_io_with_master.inc
277 --let $io_log_pos= query_get_value('SHOW SLAVE STATUS', Read_Master_Log_Pos, 1)
278 --let $io_log_file= query_get_value('SHOW SLAVE STATUS', Master_Log_File, 1)
279 --source include/stop_slave.inc
280 --replace_result $io_log_file io_log_file $io_log_pos io_log_pos
281 --eval CHANGE MASTER TO master_log_pos=$io_log_pos, master_log_file='$io_log_file'
282 --source include/start_slave.inc
283
284
285 --echo #
286 --echo # A replica issued CHANGE MASTER TO specified with log coordinates and
287 --echo # master_use_gtid=Slave_Pos should warn the user that the log
288 --echo # coordinates will be ignored.
289 --echo #
290 --connection slave
291 --let $io_log_pos= query_get_value('SHOW SLAVE STATUS', Read_Master_Log_Pos, 1)
292 --let $io_log_file= query_get_value('SHOW SLAVE STATUS', Master_Log_File, 1)
293 --let $relay_log_pos= 4
294 --let $relay_log_file= slave-relay-bin.000001
295 --source include/stop_slave.inc
296 --replace_result $io_log_file io_log_file $io_log_pos io_log_pos
297 --eval CHANGE MASTER TO master_log_pos=$io_log_pos, master_log_file='$io_log_file', master_use_gtid=Slave_Pos
298 --replace_result $relay_log_file relay_log_file $relay_log_pos relay_log_pos
299 --eval CHANGE MASTER TO relay_log_pos=$relay_log_pos, relay_log_file='$relay_log_file', master_use_gtid=Slave_Pos
300 --source include/start_slave.inc
301
302 --source include/rpl_end.inc
303
304 --echo #
305 --echo # End of rpl_using_gtid_default.test