| 1 |
if (`SELECT $PS_PROTOCOL + $CURSOR_PROTOCOL > 0`) |
| 2 |
{ |
| 3 |
--skip Test temporarily disabled for ps-protocol and cursor-protocol |
| 4 |
} |
| 5 |
--source include/no_valgrind_without_big.inc |
| 6 |
--let $rpl_topology=1->2 |
| 7 |
--source include/rpl_init.inc |
| 8 |
--source include/have_innodb.inc |
| 9 |
|
| 10 |
--echo *** Test normal shutdown/restart of slave server configured as a GTID slave. *** |
| 11 |
|
| 12 |
--connection server_1 |
| 13 |
CREATE TABLE t1 (a INT PRIMARY KEY); |
| 14 |
INSERT INTO t1 VALUES (1); |
| 15 |
--save_master_pos |
| 16 |
|
| 17 |
--connection server_2 |
| 18 |
--sync_with_master |
| 19 |
--source include/stop_slave.inc |
| 20 |
|
| 21 |
--let $status_items= Master_Log_File,Using_Gtid |
| 22 |
--source include/show_slave_status.inc |
| 23 |
|
| 24 |
|
| 25 |
# Now try to restart the slave mysqld server without starting the slave first |
| 26 |
# threads after the CHANGE MASTER. |
| 27 |
# When the slave restarts, it should reconnect using GTID. |
| 28 |
# We test that it really uses GTID by purging on the master the |
| 29 |
# old binlog the slave would need if connecting with old style |
| 30 |
# file name/offset. |
| 31 |
|
| 32 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 33 |
wait |
| 34 |
EOF |
| 35 |
FLUSH LOGS; |
| 36 |
--shutdown_server |
| 37 |
--source include/wait_until_disconnected.inc |
| 38 |
|
| 39 |
--connection server_1 |
| 40 |
FLUSH LOGS; |
| 41 |
--let $purge_binlogs_to=master-bin.000002 |
| 42 |
--source include/wait_for_purge.inc |
| 43 |
--source include/show_binary_logs.inc |
| 44 |
INSERT INTO t1 VALUES (2); |
| 45 |
FLUSH LOGS; |
| 46 |
INSERT INTO t1 VALUES (3); |
| 47 |
--source include/save_master_gtid.inc |
| 48 |
--source include/show_binary_logs.inc |
| 49 |
|
| 50 |
# Let the slave mysqld server start again. |
| 51 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 52 |
restart: --skip-slave-start=0 |
| 53 |
EOF |
| 54 |
|
| 55 |
--connection server_2 |
| 56 |
--enable_reconnect |
| 57 |
--source include/wait_until_connected_again.inc |
| 58 |
|
| 59 |
--source include/sync_with_master_gtid.inc |
| 60 |
SELECT * FROM t1 ORDER BY a; |
| 61 |
|
| 62 |
|
| 63 |
--echo *** Test normal shutdown/restart of master server, check binlog state is preserved. *** |
| 64 |
|
| 65 |
--connection server_1 |
| 66 |
SET SESSION gtid_domain_id= 1; |
| 67 |
INSERT INTO t1 VALUES (4); |
| 68 |
--replace_column 2 # 4 # 5 # |
| 69 |
SHOW BINLOG EVENTS IN 'master-bin.000003' LIMIT 1,1; |
| 70 |
FLUSH LOGS; |
| 71 |
--replace_column 2 # 4 # 5 # 6 # |
| 72 |
SHOW BINLOG EVENTS IN 'master-bin.000004' LIMIT 1,1; |
| 73 |
|
| 74 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 75 |
wait |
| 76 |
EOF |
| 77 |
--shutdown_server |
| 78 |
--source include/wait_until_disconnected.inc |
| 79 |
|
| 80 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 81 |
restart |
| 82 |
EOF |
| 83 |
|
| 84 |
--connection default |
| 85 |
--enable_reconnect |
| 86 |
--source include/wait_until_connected_again.inc |
| 87 |
--connection server_1 |
| 88 |
--enable_reconnect |
| 89 |
--source include/wait_until_connected_again.inc |
| 90 |
|
| 91 |
--replace_column 2 # 4 # 5 # 6 # |
| 92 |
SHOW BINLOG EVENTS IN 'master-bin.000005' LIMIT 1,1; |
| 93 |
--source include/show_binary_logs.inc |
| 94 |
|
| 95 |
INSERT INTO t1 VALUES(5); |
| 96 |
--source include/save_master_gtid.inc |
| 97 |
|
| 98 |
--connection server_2 |
| 99 |
--source include/sync_with_master_gtid.inc |
| 100 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 101 |
SELECT * FROM t1 ORDER BY a; |
| 102 |
|
| 103 |
--echo *** Test that @@gtid_slave_pos and @@gtid_current_pos are correctly loaded even if slave threads have not started. *** |
| 104 |
--let $slave_pos1= `SELECT @@GLOBAL.gtid_slave_pos` |
| 105 |
--let $current_pos1= `SELECT @@GLOBAL.gtid_current_pos` |
| 106 |
|
| 107 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 108 |
wait |
| 109 |
EOF |
| 110 |
--shutdown_server |
| 111 |
--source include/wait_until_disconnected.inc |
| 112 |
|
| 113 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 114 |
restart: --skip-slave-start=1 --skip-log-bin |
| 115 |
EOF |
| 116 |
--enable_reconnect |
| 117 |
--source include/wait_until_connected_again.inc |
| 118 |
--disable_query_log |
| 119 |
eval SET @slave_pos1= "$slave_pos1"; |
| 120 |
eval SET @current_pos1= "$current_pos1"; |
| 121 |
--enable_query_log |
| 122 |
SET @slave_pos2= @@GLOBAL.gtid_slave_pos; |
| 123 |
SET @current_pos2= @@GLOBAL.gtid_current_pos; |
| 124 |
SELECT IF(@slave_pos1=@slave_pos2, "OK", CONCAT(@slave_pos1, " != ", @slave_pos2)); |
| 125 |
SELECT IF(@current_pos1=@current_pos2, "OK", CONCAT(@current_pos1, " != ", @current_pos2)); |
| 126 |
|
| 127 |
--connection server_1 |
| 128 |
INSERT INTO t1 VALUES (6); |
| 129 |
--save_master_pos |
| 130 |
|
| 131 |
--connection server_2 |
| 132 |
--source include/start_slave.inc |
| 133 |
--sync_with_master |
| 134 |
SELECT * FROM t1 ORDER BY a; |
| 135 |
|
| 136 |
|
| 137 |
--echo *** MDEV-4490: Old-style master position points at the last GTID event after slave restart *** |
| 138 |
|
| 139 |
--connection server_1 |
| 140 |
INSERT INTO t1 VALUES (7); |
| 141 |
--save_master_pos |
| 142 |
|
| 143 |
--connection server_2 |
| 144 |
--sync_with_master |
| 145 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 146 |
SELECT * FROM t1 ORDER BY a; |
| 147 |
|
| 148 |
# Now we restart the slave server. When it restarts, there is nothing new |
| 149 |
# to replicate. Check that the position is nevertheless updated and |
| 150 |
# MASTER_POS_WAIT() works correctly and detects that we are up-to-date. |
| 151 |
|
| 152 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 153 |
wait |
| 154 |
EOF |
| 155 |
--shutdown_server |
| 156 |
--source include/wait_until_disconnected.inc |
| 157 |
|
| 158 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 159 |
restart: --skip-slave-start=0 |
| 160 |
EOF |
| 161 |
--enable_reconnect |
| 162 |
--source include/wait_until_connected_again.inc |
| 163 |
|
| 164 |
--source include/wait_for_slave_to_start.inc |
| 165 |
|
| 166 |
--connection server_1 |
| 167 |
--save_master_pos |
| 168 |
|
| 169 |
--connection server_2 |
| 170 |
--sync_with_master |
| 171 |
SELECT * FROM t1 ORDER BY a; |
| 172 |
|
| 173 |
|
| 174 |
--echo *** MDEV-4486: Allow to start old-style replication even if mysql.gtid_slave_pos is unavailable |
| 175 |
|
| 176 |
# In GTID mode, the old-style replication position is also updated. But during |
| 177 |
# GTID connect, the old-style position is not known until receiving the fake |
| 178 |
# GTID list event, which contains the required position value. If we happened |
| 179 |
# to stop the slave above before this fake GTID list event, the test could fail |
| 180 |
# with duplicate key errors due to switching to non-GTID mode at a wrong |
| 181 |
# position too far back in the binlog. |
| 182 |
# |
| 183 |
# Work-around this by injecting an extra dummt event and syncing the slave to |
| 184 |
# it, ensuring the old-style position will be updated. |
| 185 |
# |
| 186 |
# This work-around could be removed after MDEV-33996 is fixed. |
| 187 |
--connection server_1 |
| 188 |
INSERT INTO t1 VALUES (8); |
| 189 |
DELETE FROM t1 WHERE a=8; |
| 190 |
--save_master_pos |
| 191 |
--connection server_2 |
| 192 |
--sync_with_master |
| 193 |
|
| 194 |
--connection server_2 |
| 195 |
--source include/stop_slave.inc |
| 196 |
CHANGE MASTER TO master_use_gtid= no; |
| 197 |
--source include/start_slave.inc |
| 198 |
|
| 199 |
--connection server_1 |
| 200 |
INSERT INTO t1 VALUES (8); |
| 201 |
--save_master_pos |
| 202 |
|
| 203 |
--connection server_2 |
| 204 |
--sync_with_master |
| 205 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 206 |
SELECT * FROM t1 ORDER BY a; |
| 207 |
--source include/stop_slave.inc |
| 208 |
|
| 209 |
SET sql_log_bin= 0; |
| 210 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 211 |
SET sql_log_bin= 1; |
| 212 |
|
| 213 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 214 |
wait |
| 215 |
EOF |
| 216 |
--shutdown_server |
| 217 |
--source include/wait_until_disconnected.inc |
| 218 |
|
| 219 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 220 |
restart: --skip-slave-start=1 --skip-innodb |
| 221 |
EOF |
| 222 |
--enable_reconnect |
| 223 |
--source include/wait_until_connected_again.inc |
| 224 |
|
| 225 |
--error ER_UNKNOWN_STORAGE_ENGINE |
| 226 |
SELECT * FROM mysql.gtid_slave_pos; |
| 227 |
SET sql_log_bin=0; |
| 228 |
call mtr.add_suppression("Failed to load slave replication state from table"); |
| 229 |
call mtr.add_suppression("Unable to load replication GTID slave state"); |
| 230 |
SET sql_log_bin=1; |
| 231 |
--let rpl_allow_error= 1 |
| 232 |
--source include/start_slave.inc |
| 233 |
--connection server_1 |
| 234 |
INSERT INTO t1 VALUES (9); |
| 235 |
--save_master_pos |
| 236 |
|
| 237 |
--connection server_2 |
| 238 |
--sync_with_master |
| 239 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 240 |
SELECT * FROM t1 ORDER BY a; |
| 241 |
|
| 242 |
# Put things back as they were. |
| 243 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 244 |
wait |
| 245 |
EOF |
| 246 |
--shutdown_server |
| 247 |
--source include/wait_until_disconnected.inc |
| 248 |
|
| 249 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 250 |
restart: |
| 251 |
EOF |
| 252 |
--enable_reconnect |
| 253 |
--source include/wait_until_connected_again.inc |
| 254 |
SET sql_log_bin= 0; |
| 255 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; |
| 256 |
SET sql_log_bin= 1; |
| 257 |
# Do a second restart to get the mysql.gtid_slave_pos table loaded with |
| 258 |
# the right engine. |
| 259 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 260 |
wait |
| 261 |
EOF |
| 262 |
--shutdown_server |
| 263 |
--source include/wait_until_disconnected.inc |
| 264 |
|
| 265 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 266 |
restart: |
| 267 |
EOF |
| 268 |
--enable_reconnect |
| 269 |
--source include/wait_until_connected_again.inc |
| 270 |
|
| 271 |
--source include/start_slave.inc |
| 272 |
|
| 273 |
--connection server_1 |
| 274 |
INSERT INTO t1 VALUES (10); |
| 275 |
--save_master_pos |
| 276 |
|
| 277 |
--connection server_2 |
| 278 |
--sync_with_master |
| 279 |
--source include/stop_slave.inc |
| 280 |
CHANGE MASTER TO master_use_gtid= slave_pos; |
| 281 |
--source include/start_slave.inc |
| 282 |
|
| 283 |
--echo *** MDEV-4692: mysql.gtid_slave_pos accumulates values for a domain *** |
| 284 |
SELECT domain_id, COUNT(*) FROM mysql.gtid_slave_pos GROUP BY domain_id; |
| 285 |
|
| 286 |
--connection server_1 |
| 287 |
INSERT INTO t1 VALUES (11); |
| 288 |
--save_master_pos |
| 289 |
|
| 290 |
--connection server_2 |
| 291 |
--sync_with_master |
| 292 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 293 |
SELECT domain_id, COUNT(*) FROM mysql.gtid_slave_pos GROUP BY domain_id; |
| 294 |
|
| 295 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 296 |
wait |
| 297 |
EOF |
| 298 |
--shutdown_server |
| 299 |
--source include/wait_until_disconnected.inc |
| 300 |
|
| 301 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 302 |
restart: |
| 303 |
EOF |
| 304 |
--enable_reconnect |
| 305 |
--source include/wait_until_connected_again.inc |
| 306 |
--source include/start_slave.inc |
| 307 |
|
| 308 |
--connection server_1 |
| 309 |
INSERT INTO t1 VALUES (12); |
| 310 |
INSERT INTO t1 VALUES (13); |
| 311 |
--save_master_pos |
| 312 |
|
| 313 |
--connection server_2 |
| 314 |
--sync_with_master |
| 315 |
FLUSH NO_WRITE_TO_BINLOG TABLES; |
| 316 |
SELECT domain_id, COUNT(*) FROM mysql.gtid_slave_pos GROUP BY domain_id; |
| 317 |
|
| 318 |
|
| 319 |
--echo *** MDEV-4650: show variables; ERROR 1946 (HY000): Failed to load replication slave GTID position *** |
| 320 |
|
| 321 |
--connection server_2 |
| 322 |
SET sql_log_bin=0; |
| 323 |
--let $old_pos= `SELECT @@GLOBAL.gtid_slave_pos` |
| 324 |
RENAME TABLE mysql.gtid_slave_pos TO mysql.old_gtid_slave_pos; |
| 325 |
SET sql_log_bin=1; |
| 326 |
|
| 327 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 328 |
wait |
| 329 |
EOF |
| 330 |
--shutdown_server |
| 331 |
--source include/wait_until_disconnected.inc |
| 332 |
|
| 333 |
# Let the slave mysqld server start again. |
| 334 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 335 |
restart |
| 336 |
EOF |
| 337 |
|
| 338 |
--enable_reconnect |
| 339 |
--source include/wait_until_connected_again.inc |
| 340 |
|
| 341 |
--disable_result_log |
| 342 |
SHOW VARIABLES; |
| 343 |
--enable_result_log |
| 344 |
SHOW VARIABLES LIKE 'gtid_slave_pos'; |
| 345 |
--error ER_CANNOT_LOAD_SLAVE_GTID_STATE,ER_NO_SUCH_TABLE |
| 346 |
SET GLOBAL gtid_slave_pos = '0-1-2'; |
| 347 |
SHOW WARNINGS; |
| 348 |
|
| 349 |
# Restore things. |
| 350 |
|
| 351 |
SET sql_log_bin=0; |
| 352 |
RENAME TABLE mysql.old_gtid_slave_pos TO mysql.gtid_slave_pos; |
| 353 |
CALL mtr.add_suppression("Failed to load slave replication state from table mysql.gtid_slave_pos"); |
| 354 |
SET sql_log_bin=1; |
| 355 |
|
| 356 |
SHOW VARIABLES LIKE 'gtid_slave_pos'; |
| 357 |
SET GLOBAL gtid_slave_pos = '0-1-2'; |
| 358 |
SHOW VARIABLES LIKE 'gtid_slave_pos'; |
| 359 |
|
| 360 |
# Don't let .result file depend on old state of gtid_slave_pos |
| 361 |
--disable_query_log |
| 362 |
--disable_result_log |
| 363 |
eval SET GLOBAL gtid_slave_pos = '$old_pos'; |
| 364 |
--enable_query_log |
| 365 |
--enable_result_log |
| 366 |
|
| 367 |
--source include/start_slave.inc |
| 368 |
|
| 369 |
|
| 370 |
--connection server_1 |
| 371 |
DROP TABLE t1; |
| 372 |
|
| 373 |
--source include/rpl_end.inc |