| 1 |
# |
| 2 |
# Purpose: |
| 3 |
# |
| 4 |
# This test suite ensures that the MASTER_DEMOTE_TO_SLAVE option of |
| 5 |
# CHANGE MASTER TO will merge the binlog GTID position (gtid_binlog_pos) into |
| 6 |
# the replication state (gtid_slave_pos). |
| 7 |
# |
| 8 |
# |
| 9 |
# Methodology: |
| 10 |
# |
| 11 |
# A series of test cases validate that MASTER_DEMOTE_TO_SLAVE correctly |
| 12 |
# merges the binlog GTID state into the replication state. Each test case |
| 13 |
# sets up the context in which it will demote the master to a slave, and then |
| 14 |
# calls into an include file to perform the actual demotion and validation. |
| 15 |
# Specifically, the include file will demote the master to be the slave, |
| 16 |
# promote the slave to be the master, ensure that gtid_slave_pos matches |
| 17 |
# gtid_current_pos, ensure replication works correctly in this new |
| 18 |
# configuration, and return the master and slave to their previous roles. |
| 19 |
# |
| 20 |
# The test cases are as follows: |
| 21 |
# 1) When both gtid_binlog_pos and gtid_slave_pos are empty, |
| 22 |
# MASTER_DEMOTE_TO_SLAVE=1 results in no change to replication state. |
| 23 |
# |
| 24 |
# 2) If gtid_slave_pos is empty, gtid_binlog_pos will completely |
| 25 |
# overwrite it with MASTER_DEMOTE_TO_SLAVE=1. |
| 26 |
# |
| 27 |
# 3) Using a single domain id, if neither gtid_slave_pos nor |
| 28 |
# gtid_binlog_pos are empty, and gtid_binlog_pos is more recent, then |
| 29 |
# gtid_binlog_pos will overwrite gtid_slave_pos when MASTER_DEMOTE_TO_SLAVE=1. |
| 30 |
# |
| 31 |
# 4) If gtid_slave_pos and gtid_binlog_pos are equivalent, |
| 32 |
# MASTER_DEMOTE_TO_SLAVE=1 will not change gtid_slave_pos. |
| 33 |
# |
| 34 |
# 5) If multiple new domain ids are added into gtid_binlog_pos while |
| 35 |
# gtid_slave_pos already has a state, MASTER_DEMOTE_TO_SLAVE=1 will append |
| 36 |
# new GTIDs to gtid_slave_pos with the latest seq_no from each domain. |
| 37 |
# |
| 38 |
# 6) If gtid_slave_pos has multiple GTID positions and gtid_binlog_pos |
| 39 |
# contains updates on existing domain ids, new domains, and differing |
| 40 |
# server_ids, MASTER_DEMOTE_TO_SLAVE=1 will update gtid_slave_pos such that |
| 41 |
# it will have the seq_nos only from the GTIDs last applied by this server. |
| 42 |
# In other words, any GTIDs with server ids that don't match that of the |
| 43 |
# demoting server will be ignored in the update. |
| 44 |
# |
| 45 |
# 7) If MASTER_DEMOTE_TO_SLAVE=1 is combined with IGNORE_DOMAIN_IDS such |
| 46 |
# that gtid_binlog_pos has more recent GTIDs than gtid_slave_pos in ignored |
| 47 |
# domains, the CHANGE MASTER TO command will still update gtid_slave_pos with |
| 48 |
# the most recent transactions from gtid_binlog_pos, despite being ignored by |
| 49 |
# CHANGE MASTER TO because they were already applied on the server. |
| 50 |
# |
| 51 |
# 8) If gtid_binlog_pos is more recent than gtid_slave_pos, and |
| 52 |
# MASTER_DEMOTE_TO_SLAVE=1 is combined with a later call to |
| 53 |
# START SLAVE UNTIL master_gtid_pos=<G> such that |
| 54 |
# gtid_slave_pos < G < gtid_binlog_pos, then the slave should stop |
| 55 |
# immediately after SSU because gtid_slave_pos should already be after the |
| 56 |
# UNTIL GTID. |
| 57 |
# |
| 58 |
# 9) If gtid_slave_pos is more recent than gtid_binlog_pos when demoting |
| 59 |
# the master to become a slave, the replication state should be preserved. |
| 60 |
# |
| 61 |
# 10) MASTER_DEMOTE_TO_SLAVE=0 should not change replication state, |
| 62 |
# regardless of gtid_slave_pos in comparison to gtid_binlog_pos. |
| 63 |
# |
| 64 |
# |
| 65 |
# Error cases: |
| 66 |
# Error Case 1) MASTER_DEMOTE_TO_SLAVE=1 combined with |
| 67 |
# MASTER_USE_GTID=NO should result in an error. |
| 68 |
# |
| 69 |
# Error Case 2) Error when MASTER_DEMOTE_TO_SLAVE=1 is used without |
| 70 |
# binary logging enabled. |
| 71 |
# |
| 72 |
# Error Case 3) Error when MASTER_DEMOTE_TO_SLAVE is provided a |
| 73 |
# non-boolean value. |
| 74 |
# |
| 75 |
# |
| 76 |
# Additionally ensure MASTER_DEMOTE_TO_REPLICA aliases MASTER_DEMOTE_TO_SLAVE |
| 77 |
# |
| 78 |
# |
| 79 |
# References: |
| 80 |
# MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based |
| 81 |
# replication is used by default if master supports it |
| 82 |
# |
| 83 |
--source include/master-slave.inc |
| 84 |
--source include/have_log_bin.inc |
| 85 |
--source include/have_binlog_format_mixed.inc |
| 86 |
|
| 87 |
--connection slave |
| 88 |
--source include/stop_slave.inc |
| 89 |
change master to master_use_gtid=slave_pos; |
| 90 |
--source include/start_slave.inc |
| 91 |
--source include/sync_with_master_gtid.inc |
| 92 |
|
| 93 |
--echo # |
| 94 |
--echo # Test Case 1: When both gtid_binlog_pos and gtid_slave_pos are |
| 95 |
--echo # empty, MASTER_DEMOTE_TO_SLAVE=1 results in no change to replication |
| 96 |
--echo # state. |
| 97 |
--echo # |
| 98 |
--source include/rpl_change_master_demote.inc |
| 99 |
|
| 100 |
|
| 101 |
--echo # |
| 102 |
--echo # Test Case 2: If gtid_slave_pos is empty, gtid_binlog_pos will |
| 103 |
--echo # completely overwrite it with MASTER_DEMOTE_TO_SLAVE=1. |
| 104 |
--echo # |
| 105 |
--connection slave |
| 106 |
--source include/stop_slave.inc |
| 107 |
RESET MASTER; |
| 108 |
set @@global.gtid_slave_pos=""; |
| 109 |
--source include/start_slave.inc |
| 110 |
--connection master |
| 111 |
RESET MASTER; |
| 112 |
set @@global.gtid_slave_pos=""; |
| 113 |
set session gtid_domain_id= 0; |
| 114 |
CREATE TABLE t1 (a int); |
| 115 |
INSERT INTO t1 VALUES (1); |
| 116 |
--source include/save_master_gtid.inc |
| 117 |
--connection slave |
| 118 |
--source include/sync_with_master_gtid.inc |
| 119 |
--source include/rpl_change_master_demote.inc |
| 120 |
|
| 121 |
|
| 122 |
--echo # |
| 123 |
--echo # Test Case 3: Using a single domain id, if neither gtid_slave_pos nor |
| 124 |
--echo # gtid_binlog_pos are empty, and gtid_binlog_pos is more recent, then |
| 125 |
--echo # gtid_binlog_pos will overwrite gtid_slave_pos when |
| 126 |
--echo # MASTER_DEMOTE_TO_SLAVE=1. |
| 127 |
--echo # |
| 128 |
--connection master |
| 129 |
INSERT INTO t1 VALUES (2); |
| 130 |
--source include/save_master_gtid.inc |
| 131 |
--connection slave |
| 132 |
--source include/sync_with_master_gtid.inc |
| 133 |
--source include/rpl_change_master_demote.inc |
| 134 |
|
| 135 |
|
| 136 |
--echo # |
| 137 |
--echo # Test Case 4: If gtid_slave_pos and gtid_binlog_pos are equivalent, |
| 138 |
--echo # MASTER_DEMOTE_TO_SLAVE=1 will not change gtid_slave_pos. |
| 139 |
--echo # |
| 140 |
--connection master |
| 141 |
|
| 142 |
--echo # update gtid_binlog_pos and demote it (we have proven this works) |
| 143 |
INSERT INTO t1 VALUES (3); |
| 144 |
--echo # Update to account for statements to verify replication in include file |
| 145 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 146 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 |
| 147 |
RESET SLAVE ALL; |
| 148 |
|
| 149 |
--source include/save_master_gtid.inc |
| 150 |
--connection slave |
| 151 |
--source include/sync_with_master_gtid.inc |
| 152 |
--source include/rpl_change_master_demote.inc |
| 153 |
|
| 154 |
|
| 155 |
--echo # |
| 156 |
--echo # Test Case 5: If a new domain id is added into gtid_binlog_pos while |
| 157 |
--echo # gtid_slave_pos already has a state, MASTER_DEMOTE_TO_SLAVE=1 will |
| 158 |
--echo # append a new GTID to gtid_slave_pos with the latest seq_no from that |
| 159 |
--echo # domain. |
| 160 |
--echo # |
| 161 |
--connection master |
| 162 |
|
| 163 |
--echo # Domain_id |
| 164 |
set session gtid_domain_id= 0; |
| 165 |
INSERT INTO t1 VALUES (4); |
| 166 |
|
| 167 |
set session gtid_domain_id= 1; |
| 168 |
CREATE TABLE t2 (a int); |
| 169 |
INSERT INTO t2 VALUES (1); |
| 170 |
|
| 171 |
--source include/save_master_gtid.inc |
| 172 |
--connection slave |
| 173 |
--source include/sync_with_master_gtid.inc |
| 174 |
--source include/rpl_change_master_demote.inc |
| 175 |
|
| 176 |
|
| 177 |
--echo # |
| 178 |
--echo # Test Case 6: If gtid_slave_pos has multiple GTID positions and |
| 179 |
--echo # gtid_binlog_pos contains updates on existing domain ids, new |
| 180 |
--echo # domains, and differing server_ids, MASTER_DEMOTE_TO_SLAVE=1 will |
| 181 |
--echo # update gtid_slave_pos such that it will have the seq_nos only from |
| 182 |
--echo # the GTIDs last applied by this server. In other words, any GTIDs |
| 183 |
--echo # with server ids that don't match that of the demoting server will be |
| 184 |
--echo # ignored in the update. |
| 185 |
--echo # |
| 186 |
|
| 187 |
--connection master |
| 188 |
--echo # Update to account for statements to verify replication in include file |
| 189 |
set session gtid_domain_id= 0; |
| 190 |
INSERT INTO t1 VALUES (5); |
| 191 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 192 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 |
| 193 |
RESET SLAVE ALL; |
| 194 |
|
| 195 |
set session gtid_domain_id= 1; |
| 196 |
INSERT INTO t2 VALUES (2); |
| 197 |
|
| 198 |
set session gtid_domain_id= 2; |
| 199 |
CREATE TABLE t3 (a int); |
| 200 |
INSERT INTO t3 VALUES (1); |
| 201 |
|
| 202 |
--echo # The following events have a different server_id and should not go into |
| 203 |
--echo # gtid_slave_pos |
| 204 |
set @old_server_id = @@server_id; |
| 205 |
set session gtid_domain_id= 1; |
| 206 |
set session server_id= 3; |
| 207 |
INSERT INTO t2 VALUES (3); |
| 208 |
|
| 209 |
set session gtid_domain_id= 4; |
| 210 |
set session server_id= 3; |
| 211 |
CREATE TABLE t5 (a int); |
| 212 |
INSERT INTO t5 VALUES (1); |
| 213 |
set session server_id= @old_server_id; |
| 214 |
|
| 215 |
--source include/save_master_gtid.inc |
| 216 |
--connection slave |
| 217 |
--source include/sync_with_master_gtid.inc |
| 218 |
--source include/rpl_change_master_demote.inc |
| 219 |
|
| 220 |
|
| 221 |
--echo # |
| 222 |
--echo # Test Case 7: If MASTER_DEMOTE_TO_SLAVE=1 is combined with |
| 223 |
--echo # IGNORE_DOMAIN_IDS such that gtid_binlog_pos has more recent GTIDs |
| 224 |
--echo # than gtid_slave_pos in ignored domains, the CHANGE MASTER TO command |
| 225 |
--echo # will still update gtid_slave_pos with the most recent transactions |
| 226 |
--echo # from gtid_binlog_pos, despite being ignored by CHANGE MASTER TO |
| 227 |
--echo # because they were already applied on the server. |
| 228 |
--echo # |
| 229 |
--connection master |
| 230 |
|
| 231 |
set session gtid_domain_id= 2; |
| 232 |
INSERT INTO t3 VALUES (2); |
| 233 |
|
| 234 |
set session gtid_domain_id= 3; |
| 235 |
CREATE TABLE t4 (a int); |
| 236 |
INSERT INTO t4 VALUES (1); |
| 237 |
|
| 238 |
--source include/save_master_gtid.inc |
| 239 |
--connection slave |
| 240 |
--source include/sync_with_master_gtid.inc |
| 241 |
--let $ignore_domain_ids=2,3 |
| 242 |
--source include/rpl_change_master_demote.inc |
| 243 |
|
| 244 |
|
| 245 |
--echo # |
| 246 |
--echo # Test Case 8: If gtid_binlog_pos is more recent than gtid_slave_pos, |
| 247 |
--echo # and MASTER_DEMOTE_TO_SLAVE=1 is combined with a later call to |
| 248 |
--echo # START SLAVE UNTIL master_gtid_pos=<G> such that |
| 249 |
--echo # gtid_slave_pos < G < gtid_binlog_pos, then the slave should stop |
| 250 |
--echo # immediately after SSU because gtid_slave_pos should be updated to be |
| 251 |
--echo # after G. |
| 252 |
--echo # |
| 253 |
|
| 254 |
--connection master |
| 255 |
set session gtid_domain_id= 0; |
| 256 |
INSERT INTO t1 VALUES (6); |
| 257 |
--let $ssu_middle_binlog_pos= `SELECT @@GLOBAL.gtid_binlog_pos` |
| 258 |
--echo # Tagging ssu_middle_binlog_pos here to be used for START SLAVE UNTIL |
| 259 |
INSERT INTO t1 VALUES (7); |
| 260 |
--source include/save_master_gtid.inc |
| 261 |
|
| 262 |
--echo # Ensure slave is up-to-date with master and then disable slave status |
| 263 |
--connection slave |
| 264 |
--source include/sync_with_master_gtid.inc |
| 265 |
--source include/stop_slave.inc |
| 266 |
|
| 267 |
--connection master |
| 268 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC; |
| 269 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 270 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=1 |
| 271 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC; |
| 272 |
|
| 273 |
--echo # GTID ssu_middle_binlog_pos should be considered in the past because |
| 274 |
--echo # gtid_slave_pos should be updated using the latest binlog gtids. |
| 275 |
--echo # The following call to sync_with_master_gtid.inc uses the latest |
| 276 |
--echo # binlog position and should still succeed despite the SSU stop |
| 277 |
--echo # position pointing to a previous event (because |
| 278 |
--echo # master_demote_to_slave=1 merges gtid_binlog_pos into gtid_slave_pos). |
| 279 |
|
| 280 |
# Note that we can't use sync_with_master_gtid.inc, |
| 281 |
# wait_for_slave_to_start.inc, or wait_for_slave_to_stop.inc because our MTR |
| 282 |
# connection thread races with the start/stop of the SQL/IO threads. So |
| 283 |
# instead, for slave start, we prove the threads started by waiting for the |
| 284 |
# connection count to increase by 2; and for slave stop, we wait for the |
| 285 |
# processlist count to return to its pre start slave number. |
| 286 |
|
| 287 |
--let $pre_start_slave_conn_count= query_get_value(SHOW STATUS LIKE 'Connections', Value, 1) |
| 288 |
--let $pre_start_slave_process_count= `SELECT count(*) from information_schema.PROCESSLIST` |
| 289 |
|
| 290 |
--replace_result $ssu_middle_binlog_pos ssu_middle_binlog_pos |
| 291 |
eval START SLAVE UNTIL master_gtid_pos="$ssu_middle_binlog_pos"; |
| 292 |
|
| 293 |
--echo # Slave needs time to start and stop automatically |
| 294 |
--echo # Waiting for both SQL and IO threads to have started.. |
| 295 |
--let $expected_cons_after_start_slave= `SELECT ($pre_start_slave_conn_count + 2)` |
| 296 |
--let $status_var= Connections |
| 297 |
--let $status_var_value= $expected_cons_after_start_slave |
| 298 |
--let $status_var_comparsion= >= |
| 299 |
--source include/wait_for_status_var.inc |
| 300 |
--let $status_var_comparsion= |
| 301 |
|
| 302 |
--echo # Waiting for Slave SQL and IO threads to be killed.. |
| 303 |
--let $wait_condition= SELECT count(*)=$pre_start_slave_process_count from information_schema.PROCESSLIST |
| 304 |
--source include/wait_condition.inc |
| 305 |
|
| 306 |
--echo # Validating neither SQL nor IO threads are running.. |
| 307 |
--let $io_state= query_get_value("SHOW SLAVE STATUS", Slave_IO_State, 1) |
| 308 |
if (`SELECT strcmp("$io_state","") != 0`) |
| 309 |
{ |
| 310 |
--echo # Slave_IO_State is "$io_state" but should be empty |
| 311 |
die "IO thread should not be running after START SLAVE UNTIL master_gtid_pos using a pre-existing GTID"; |
| 312 |
} |
| 313 |
--let $sql_state= query_get_value("SHOW SLAVE STATUS", Slave_SQL_Running_State, 1) |
| 314 |
if (`SELECT strcmp("$sql_state","") != 0`) |
| 315 |
{ |
| 316 |
--echo # Slave_SQL_Running_State is "$sql_state" but should be empty |
| 317 |
die "SQL thread should not be running after START SLAVE UNTIL master_gtid_pos using a pre-existing GTID"; |
| 318 |
} |
| 319 |
--echo # ..success |
| 320 |
|
| 321 |
--echo # Clean slave state of master |
| 322 |
RESET SLAVE ALL; |
| 323 |
|
| 324 |
|
| 325 |
--echo # |
| 326 |
--echo # Test Case 9: If gtid_slave_pos is more recent than gtid_binlog_pos |
| 327 |
--echo # when demoting the master to become a slave, the replication state |
| 328 |
--echo # should be preserved. |
| 329 |
--echo # |
| 330 |
|
| 331 |
--echo # rpl_change_master_demote.inc should force |
| 332 |
--echo # gtid_slave_pos > gtid_binlog_pos in domain 0 (due to the step which |
| 333 |
--echo # validates replication works) |
| 334 |
--connection master |
| 335 |
--source include/rpl_change_master_demote.inc |
| 336 |
|
| 337 |
--let $current_pos= `SELECT @@gtid_current_pos` |
| 338 |
|
| 339 |
--echo # Demote master to slave with the more recent gtid_slave_pos |
| 340 |
--connection master |
| 341 |
--let $old_slave_pos= `SELECT @@gtid_slave_pos` |
| 342 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 343 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 |
| 344 |
--let $new_slave_pos= `SELECT @@gtid_slave_pos` |
| 345 |
|
| 346 |
--echo # Validating gtid_slave_pos is unchanged.. |
| 347 |
if ($old_slave_pos != $new_slave_pos) |
| 348 |
{ |
| 349 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC; |
| 350 |
die "gtid_slave_pos should not change when MASTER_DEMOTE_TO_SLAVE=0"; |
| 351 |
} |
| 352 |
--echo # ..success |
| 353 |
|
| 354 |
--echo # Validating gtid_slave_pos == gtid_binlog_pos.. |
| 355 |
if ($new_slave_pos != $current_pos) |
| 356 |
{ |
| 357 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' OR VARIABLE_NAME LIKE 'gtid_current_pos' ORDER BY VARIABLE_NAME ASC; |
| 358 |
die gtid_slave_pos calculation after master_demote_to_slave=1 differs from gtid_current_pos; |
| 359 |
} |
| 360 |
--echo # ..success |
| 361 |
|
| 362 |
--echo # Clean slave state of master |
| 363 |
RESET SLAVE ALL; |
| 364 |
|
| 365 |
|
| 366 |
--echo # |
| 367 |
--echo # Test Case 10: MASTER_DEMOTE_TO_SLAVE=0 should not change replication |
| 368 |
--echo # state, regardless of gtid_slave_pos in comparison to gtid_binlog_pos. |
| 369 |
--echo # |
| 370 |
|
| 371 |
--echo # In domain 0, make gtid_slave_pos > gtid_binlog_pos |
| 372 |
--connection master |
| 373 |
--source include/rpl_change_master_demote.inc |
| 374 |
|
| 375 |
--echo # Tag gtid_slave_pos now (before binlog updates) for later comparison |
| 376 |
--let $old_slave_pos= `SELECT @@gtid_slave_pos` |
| 377 |
|
| 378 |
--connection master |
| 379 |
--echo # In domain 1, make gtid_slave_pos < gtid_binlog_pos |
| 380 |
set session gtid_domain_id= 1; |
| 381 |
INSERT INTO t2 VALUES (4); |
| 382 |
|
| 383 |
--echo # In domains 2, 3 and 4, gtid_slave_pos == gtid_binlog_pos |
| 384 |
|
| 385 |
--echo # Include a new domain id (5) |
| 386 |
set session gtid_domain_id= 5; |
| 387 |
CREATE TABLE t6 (a int); |
| 388 |
INSERT INTO t6 VALUES (1); |
| 389 |
|
| 390 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC; |
| 391 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 392 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=0 |
| 393 |
|
| 394 |
--echo # Validating gtid_slave_pos is unchanged.. |
| 395 |
--let $new_slave_pos= `SELECT @@gtid_slave_pos` |
| 396 |
if ($old_slave_pos != $new_slave_pos) |
| 397 |
{ |
| 398 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC; |
| 399 |
die gtid_slave_pos should not change when MASTER_DEMOTE_TO_SLAVE=0; |
| 400 |
} |
| 401 |
--echo # ..success |
| 402 |
|
| 403 |
--echo # Clean slave state of master |
| 404 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 405 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=slave_pos, master_demote_to_slave=1 |
| 406 |
RESET SLAVE ALL; |
| 407 |
SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME LIKE 'gtid_binlog_pos' OR VARIABLE_NAME LIKE 'gtid_slave_pos' ORDER BY VARIABLE_NAME ASC; |
| 408 |
|
| 409 |
|
| 410 |
--echo # |
| 411 |
--echo # |
| 412 |
--echo # Stop slave for error test cases |
| 413 |
--connection slave |
| 414 |
--source include/stop_slave.inc |
| 415 |
|
| 416 |
--echo # |
| 417 |
--echo # Error Case 1: MASTER_DEMOTE_TO_SLAVE=1 combined with |
| 418 |
--echo # MASTER_USE_GTID=NO should result in an error. |
| 419 |
--echo # |
| 420 |
--connection master |
| 421 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 422 |
--error 4191 |
| 423 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=no, master_demote_to_slave=1 |
| 424 |
|
| 425 |
|
| 426 |
--echo # |
| 427 |
--echo # Error Case 2: Error when MASTER_DEMOTE_TO_SLAVE=1 is used without |
| 428 |
--echo # binary logging enabled. |
| 429 |
--echo # |
| 430 |
--connection master |
| 431 |
|
| 432 |
--echo # Restarting master without binary log |
| 433 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 434 |
wait |
| 435 |
EOF |
| 436 |
--shutdown_server |
| 437 |
--source include/wait_until_disconnected.inc |
| 438 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 439 |
restart: --skip-slave-start=1 --skip-log-bin |
| 440 |
EOF |
| 441 |
--enable_reconnect |
| 442 |
--source include/wait_until_connected_again.inc |
| 443 |
|
| 444 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 445 |
--error 1381 |
| 446 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=1 |
| 447 |
|
| 448 |
--echo # Restarting master to re-enable binary log |
| 449 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 450 |
wait |
| 451 |
EOF |
| 452 |
--shutdown_server |
| 453 |
--source include/wait_until_disconnected.inc |
| 454 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 455 |
restart: --skip-slave-start=1 |
| 456 |
EOF |
| 457 |
--enable_reconnect |
| 458 |
--source include/wait_until_connected_again.inc |
| 459 |
|
| 460 |
--connection server_1 |
| 461 |
--enable_reconnect |
| 462 |
--source include/wait_until_connected_again.inc |
| 463 |
|
| 464 |
--connection default |
| 465 |
--enable_reconnect |
| 466 |
--source include/wait_until_connected_again.inc |
| 467 |
|
| 468 |
|
| 469 |
--echo # |
| 470 |
--echo # Error Case 3: Error when MASTER_DEMOTE_TO_SLAVE is provided a |
| 471 |
--echo # non-boolean value. |
| 472 |
--echo # |
| 473 |
|
| 474 |
--connection master |
| 475 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 476 |
--error 1064 |
| 477 |
--eval CHANGE MASTER TO master_host='127.0.0.1', master_port=$SLAVE_MYPORT, master_user='root', master_use_gtid=Slave_Pos, master_demote_to_slave=invalid |
| 478 |
|
| 479 |
|
| 480 |
--echo # |
| 481 |
--echo # MDEV-31768 |
| 482 |
--echo # Ensure MASTER_DEMOTE_TO_REPLICA aliases MASTER_DEMOTE_TO_SLAVE |
| 483 |
--echo # |
| 484 |
--connection slave |
| 485 |
RESET MASTER; |
| 486 |
--source include/reset_slave.inc |
| 487 |
CREATE TABLE t_mdev_31768 (a int); |
| 488 |
--let $gtid_binlog_pos= `SELECT @@GLOBAL.gtid_binlog_pos` |
| 489 |
CHANGE MASTER TO master_use_gtid=Replica_Pos, master_demote_to_replica=1; |
| 490 |
--let $gtid_slave_pos= `SELECT @@GLOBAL.gtid_slave_pos` |
| 491 |
|
| 492 |
--echo # Validating alias MASTER_DEMOTE_TO_REPLICA provides intended behavior.. |
| 493 |
if (`SELECT strcmp("$gtid_binlog_pos","$gtid_slave_pos") != 0`) |
| 494 |
{ |
| 495 |
--echo # ..failed |
| 496 |
--echo # Binlog pos: $gtid_binlog_pos |
| 497 |
--echo # Replica pos: $gtid_slave_pos |
| 498 |
die MASTER_DEMOTE_TO_REPLICA does not alias MASTER_DEMOTE_TO_SLAVE correctly; |
| 499 |
} |
| 500 |
--echo # ..success |
| 501 |
|
| 502 |
DROP TABLE t_mdev_31768; |
| 503 |
RESET MASTER; |
| 504 |
--source include/reset_slave.inc |
| 505 |
|
| 506 |
--echo # Clear primary binlog state to match replica |
| 507 |
--connection master |
| 508 |
RESET MASTER; |
| 509 |
|
| 510 |
|
| 511 |
--echo # |
| 512 |
--echo # Cleanup |
| 513 |
--echo # |
| 514 |
--connection master |
| 515 |
DROP TABLE t1, t2, t3, t4, t5, t6; |
| 516 |
--source include/save_master_gtid.inc |
| 517 |
|
| 518 |
--connection slave |
| 519 |
--source include/start_slave.inc |
| 520 |
--source include/sync_with_master_gtid.inc |
| 521 |
|
| 522 |
--source include/rpl_end.inc |
| 523 |
--echo # |
| 524 |
--echo ### End rpl_change_master_demote.test |