| 1 |
--source include/have_innodb.inc |
| 2 |
--let $rpl_topology=1->2, 1->3, 1->4, 1->5 |
| 3 |
--source include/rpl_init.inc |
| 4 |
|
| 5 |
# Set up a topology with one master and 4 slaves. |
| 6 |
# |
| 7 |
# Replicate some events leaving the four slaves at different points |
| 8 |
# in different domains. |
| 9 |
# |
| 10 |
# Then promote one slave as new master, bringing it ahead of all others |
| 11 |
# using START SLAVE UNTIL master_gtid_pos. |
| 12 |
|
| 13 |
--connection server_1 |
| 14 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 15 |
CREATE TABLE t4 (a INT, b INT, PRIMARY KEY (a,b)) Engine=InnoDB; |
| 16 |
|
| 17 |
# Function to extract one GTID from a list. |
| 18 |
delimiter |; |
| 19 |
CREATE FUNCTION extract_gtid(d VARCHAR(100), s VARCHAR(100)) |
| 20 |
RETURNS VARCHAR(100) DETERMINISTIC |
| 21 |
BEGIN |
| 22 |
SET s= CONCAT(",", s, ","); |
| 23 |
SET s= SUBSTR(s FROM LOCATE(CONCAT(",", d, "-"), s) + 1); |
| 24 |
SET s= SUBSTR(s FROM 1 FOR LOCATE(",", s) - 1); |
| 25 |
RETURN s; |
| 26 |
END| |
| 27 |
delimiter ;| |
| 28 |
|
| 29 |
--save_master_pos |
| 30 |
|
| 31 |
--connection server_2 |
| 32 |
--sync_with_master |
| 33 |
--source include/stop_slave.inc |
| 34 |
|
| 35 |
--connection server_3 |
| 36 |
--sync_with_master |
| 37 |
--source include/stop_slave.inc |
| 38 |
|
| 39 |
--connection server_4 |
| 40 |
--sync_with_master |
| 41 |
--source include/stop_slave.inc |
| 42 |
|
| 43 |
--connection server_5 |
| 44 |
--sync_with_master |
| 45 |
--source include/stop_slave.inc |
| 46 |
|
| 47 |
|
| 48 |
# Create three separate replication streams on master server_1. |
| 49 |
# |
| 50 |
# Then use START SLAVE UNTIL to get the different streams interleaved |
| 51 |
# differently spread over multiple binlogs on the different slaves, to |
| 52 |
# test that new master promotion is able to deal with this. |
| 53 |
|
| 54 |
--connection server_1 |
| 55 |
|
| 56 |
SET gtid_domain_id= 1; |
| 57 |
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; |
| 58 |
--let $d1_begin= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)` |
| 59 |
INSERT INTO t1 VALUES (1); |
| 60 |
INSERT INTO t1 VALUES (2); |
| 61 |
INSERT INTO t4 VALUES (1, 1); |
| 62 |
--let $d1_mid= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)` |
| 63 |
INSERT INTO t1 VALUES (3); |
| 64 |
INSERT INTO t1 VALUES (4); |
| 65 |
INSERT INTO t4 VALUES (1, 3); |
| 66 |
--let $d1_end= `SELECT extract_gtid("1", @@GLOBAL.gtid_binlog_pos)` |
| 67 |
|
| 68 |
SET gtid_domain_id= 2; |
| 69 |
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; |
| 70 |
--let $d2_begin= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)` |
| 71 |
INSERT INTO t2 VALUES (1); |
| 72 |
INSERT INTO t2 VALUES (2); |
| 73 |
INSERT INTO t4 VALUES (2, 1); |
| 74 |
--let $d2_mid= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)` |
| 75 |
INSERT INTO t2 VALUES (3); |
| 76 |
INSERT INTO t2 VALUES (4); |
| 77 |
INSERT INTO t4 VALUES (2, 3); |
| 78 |
--let $d2_end= `SELECT extract_gtid("2", @@GLOBAL.gtid_binlog_pos)` |
| 79 |
|
| 80 |
SET gtid_domain_id= 3; |
| 81 |
CREATE TABLE t3 (a INT PRIMARY KEY) ENGINE=InnoDB; |
| 82 |
--let $d3_begin= `SELECT extract_gtid("3", @@GLOBAL.gtid_binlog_pos)` |
| 83 |
INSERT INTO t3 VALUES (1); |
| 84 |
INSERT INTO t3 VALUES (2); |
| 85 |
INSERT INTO t4 VALUES (3, 1); |
| 86 |
--let $d3_mid= `SELECT extract_gtid("3", @@GLOBAL.gtid_binlog_pos)` |
| 87 |
INSERT INTO t3 VALUES (3); |
| 88 |
INSERT INTO t3 VALUES (4); |
| 89 |
INSERT INTO t4 VALUES (3, 3); |
| 90 |
--let $d3_end= `SELECT extract_gtid("3", @@GLOBAL.gtid_binlog_pos)` |
| 91 |
|
| 92 |
|
| 93 |
# Slave server_2 (that will be promoted to master) is in the middle |
| 94 |
# of each stream. |
| 95 |
--connection server_2 |
| 96 |
eval START SLAVE UNTIL master_gtid_pos= "$d1_mid,$d2_mid,$d3_mid"; |
| 97 |
|
| 98 |
# The remaining slaves sit at different points each in different domains. |
| 99 |
--connection server_3 |
| 100 |
eval START SLAVE UNTIL master_gtid_pos= "$d1_begin,$d2_mid,$d3_end"; |
| 101 |
--connection server_4 |
| 102 |
eval START SLAVE UNTIL master_gtid_pos= "$d2_begin,$d3_mid,$d1_end"; |
| 103 |
--connection server_5 |
| 104 |
eval START SLAVE UNTIL master_gtid_pos= "$d3_begin,$d1_mid,$d2_end"; |
| 105 |
--connection server_2 |
| 106 |
--source include/wait_for_slave_to_stop.inc |
| 107 |
SELECT * FROM t1 ORDER BY a; |
| 108 |
SELECT * FROM t2 ORDER BY a; |
| 109 |
SELECT * FROM t3 ORDER BY a; |
| 110 |
SELECT * FROM t4 ORDER BY a,b; |
| 111 |
--connection server_3 |
| 112 |
--source include/wait_for_slave_to_stop.inc |
| 113 |
SELECT * FROM t1 ORDER BY a; |
| 114 |
SELECT * FROM t2 ORDER BY a; |
| 115 |
SELECT * FROM t3 ORDER BY a; |
| 116 |
SELECT * FROM t4 ORDER BY a,b; |
| 117 |
--connection server_4 |
| 118 |
--source include/wait_for_slave_to_stop.inc |
| 119 |
SELECT * FROM t1 ORDER BY a; |
| 120 |
SELECT * FROM t2 ORDER BY a; |
| 121 |
SELECT * FROM t3 ORDER BY a; |
| 122 |
SELECT * FROM t4 ORDER BY a,b; |
| 123 |
--connection server_5 |
| 124 |
--source include/wait_for_slave_to_stop.inc |
| 125 |
SELECT * FROM t1 ORDER BY a; |
| 126 |
SELECT * FROM t2 ORDER BY a; |
| 127 |
SELECT * FROM t3 ORDER BY a; |
| 128 |
SELECT * FROM t4 ORDER BY a,b; |
| 129 |
|
| 130 |
|
| 131 |
--echo *** Now replicate all extra changes from 3,4,5 to 2, in preparation for making 2 the new master. *** |
| 132 |
|
| 133 |
--connection server_3 |
| 134 |
--let $server3_pos= `SELECT @@GLOBAL.gtid_slave_pos` |
| 135 |
--connection server_2 |
| 136 |
--replace_result $SERVER_MYPORT_3 SERVER_MYPORT_3 |
| 137 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_3; |
| 138 |
--replace_result $server3_pos SERVER3_POS |
| 139 |
eval START SLAVE UNTIL master_gtid_pos = "$server3_pos"; |
| 140 |
--source include/wait_for_slave_to_stop.inc |
| 141 |
SELECT * FROM t1 ORDER BY a; |
| 142 |
SELECT * FROM t2 ORDER BY a; |
| 143 |
SELECT * FROM t3 ORDER BY a; |
| 144 |
SELECT * FROM t4 ORDER BY a,b; |
| 145 |
|
| 146 |
--connection server_4 |
| 147 |
--let $server4_pos= `SELECT @@GLOBAL.gtid_slave_pos` |
| 148 |
--connection server_2 |
| 149 |
--replace_result $SERVER_MYPORT_4 SERVER_MYPORT_4 |
| 150 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_4; |
| 151 |
--replace_result $server4_pos SERVER4_POS |
| 152 |
eval START SLAVE UNTIL master_gtid_pos = "$server4_pos"; |
| 153 |
--source include/wait_for_slave_to_stop.inc |
| 154 |
SELECT * FROM t1 ORDER BY a; |
| 155 |
SELECT * FROM t2 ORDER BY a; |
| 156 |
SELECT * FROM t3 ORDER BY a; |
| 157 |
SELECT * FROM t4 ORDER BY a,b; |
| 158 |
|
| 159 |
--connection server_5 |
| 160 |
--let $server5_pos= `SELECT @@GLOBAL.gtid_slave_pos` |
| 161 |
--connection server_2 |
| 162 |
--replace_result $SERVER_MYPORT_5 SERVER_MYPORT_5 |
| 163 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_5; |
| 164 |
--replace_result $server5_pos SERVER5_POS |
| 165 |
eval START SLAVE UNTIL master_gtid_pos = "$server5_pos"; |
| 166 |
--source include/wait_for_slave_to_stop.inc |
| 167 |
SELECT * FROM t1 ORDER BY a; |
| 168 |
SELECT * FROM t2 ORDER BY a; |
| 169 |
SELECT * FROM t3 ORDER BY a; |
| 170 |
SELECT * FROM t4 ORDER BY a,b; |
| 171 |
|
| 172 |
--echo *** Now make 2 master and point 3,4,5 to the new master 2 |
| 173 |
--connection server_2 |
| 174 |
SET gtid_domain_id= 1; |
| 175 |
INSERT INTO t1 values (5); |
| 176 |
INSERT INTO t4 values (1,5); |
| 177 |
SET gtid_domain_id= 2; |
| 178 |
INSERT INTO t2 values (5); |
| 179 |
INSERT INTO t4 values (2,5); |
| 180 |
SET gtid_domain_id= 3; |
| 181 |
INSERT INTO t3 values (5); |
| 182 |
INSERT INTO t4 values (3,5); |
| 183 |
|
| 184 |
--connection server_3 |
| 185 |
--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2 |
| 186 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_2; |
| 187 |
--source include/start_slave.inc |
| 188 |
--connection server_4 |
| 189 |
--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2 |
| 190 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_2; |
| 191 |
--source include/start_slave.inc |
| 192 |
--connection server_5 |
| 193 |
--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2 |
| 194 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_2; |
| 195 |
--source include/start_slave.inc |
| 196 |
|
| 197 |
--connection server_2 |
| 198 |
--save_master_pos |
| 199 |
|
| 200 |
--connection server_3 |
| 201 |
--sync_with_master |
| 202 |
SELECT * FROM t1 ORDER BY a; |
| 203 |
SELECT * FROM t2 ORDER BY a; |
| 204 |
SELECT * FROM t3 ORDER BY a; |
| 205 |
SELECT * FROM t4 ORDER BY a,b; |
| 206 |
--connection server_5 |
| 207 |
--sync_with_master |
| 208 |
SELECT * FROM t1 ORDER BY a; |
| 209 |
SELECT * FROM t2 ORDER BY a; |
| 210 |
SELECT * FROM t3 ORDER BY a; |
| 211 |
SELECT * FROM t4 ORDER BY a,b; |
| 212 |
--connection server_5 |
| 213 |
--sync_with_master |
| 214 |
SELECT * FROM t1 ORDER BY a; |
| 215 |
SELECT * FROM t2 ORDER BY a; |
| 216 |
SELECT * FROM t3 ORDER BY a; |
| 217 |
SELECT * FROM t4 ORDER BY a,b; |
| 218 |
|
| 219 |
|
| 220 |
--echo *** Now let the old master join up as slave. *** |
| 221 |
--connection server_1 |
| 222 |
--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2 |
| 223 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_2, |
| 224 |
master_user = "root", master_ssl_verify_server_cert=0, |
| 225 |
master_use_gtid = slave_pos, master_demote_to_slave=1; |
| 226 |
--source include/start_slave.inc |
| 227 |
--sync_with_master |
| 228 |
SELECT * FROM t1 ORDER BY a; |
| 229 |
SELECT * FROM t2 ORDER BY a; |
| 230 |
SELECT * FROM t3 ORDER BY a; |
| 231 |
SELECT * FROM t4 ORDER BY a,b; |
| 232 |
|
| 233 |
|
| 234 |
--echo *** Finally move things back and clean up. *** |
| 235 |
--connection server_1 |
| 236 |
--source include/stop_slave.inc |
| 237 |
RESET SLAVE ALL; |
| 238 |
|
| 239 |
--connection server_2 |
| 240 |
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1 |
| 241 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_1; |
| 242 |
--source include/start_slave.inc |
| 243 |
--connection server_3 |
| 244 |
--source include/stop_slave.inc |
| 245 |
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1 |
| 246 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_1; |
| 247 |
--source include/start_slave.inc |
| 248 |
--connection server_4 |
| 249 |
--source include/stop_slave.inc |
| 250 |
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1 |
| 251 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_1; |
| 252 |
--source include/start_slave.inc |
| 253 |
--connection server_5 |
| 254 |
--source include/stop_slave.inc |
| 255 |
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1 |
| 256 |
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $SERVER_MYPORT_1; |
| 257 |
--source include/start_slave.inc |
| 258 |
|
| 259 |
--connection server_1 |
| 260 |
SET gtid_domain_id = 0; |
| 261 |
DROP TABLE t1; |
| 262 |
DROP TABLE t2; |
| 263 |
DROP TABLE t3; |
| 264 |
DROP TABLE t4; |
| 265 |
DROP FUNCTION extract_gtid; |
| 266 |
|
| 267 |
--source include/rpl_end.inc |