| 1 |
# Testing master to slave heartbeat protocol |
| 2 |
# |
| 3 |
# Including: |
| 4 |
# - user interface, grammar, checking the range and warnings about |
| 5 |
# unreasonable values for the heartbeat period |
| 6 |
# - no rotation of relay log if heartbeat is less that replica_net_timeout |
| 7 |
# - SELECT COUNT_RECEIVED_HEARTBEATS FROM p_S.replication_connection_status |
| 8 |
# - SELECT HEARTBEAT_INTERVAL FROM p_s.replication_connection_configuration |
| 9 |
# - SELECT LAST_HEARTBEAT_TIMESTAMP FROM p_s.replication_connection_status |
| 10 |
|
| 11 |
--source include/not_group_replication_plugin.inc |
| 12 |
--let $rpl_skip_start_slave= 1 |
| 13 |
--let $rpl_skip_reset_master_and_slave= 1 |
| 14 |
--let $rpl_skip_change_master= 1 |
| 15 |
--source include/master-slave.inc |
| 16 |
|
| 17 |
--let $rpl_connection_name= slave |
| 18 |
--source include/rpl_connection.inc |
| 19 |
|
| 20 |
set @restore_replica_net_timeout= @@global.replica_net_timeout; |
| 21 |
set @@global.replica_net_timeout= 10; |
| 22 |
|
| 23 |
# |
| 24 |
# check for null value of the last_heartbeat_timestamp variable when the slave is not enabled |
| 25 |
# |
| 26 |
--query_vertical SELECT LAST_HEARTBEAT_TIMESTAMP FROM performance_schema.replication_connection_status |
| 27 |
|
| 28 |
### |
| 29 |
### Checking the range |
| 30 |
### |
| 31 |
|
| 32 |
# |
| 33 |
# default period replica_net_timeout/2 |
| 34 |
# |
| 35 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 36 |
--replace_column 2 #### |
| 37 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root'; |
| 38 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 39 |
|
| 40 |
# |
| 41 |
# the max for the heartbeat_interval is ULONG_MAX/1000; an attempt to exceed it is denied |
| 42 |
# |
| 43 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 44 |
--replace_column 2 #### |
| 45 |
--error ER_REPLICA_HEARTBEAT_VALUE_OUT_OF_RANGE |
| 46 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 4294968; |
| 47 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 48 |
|
| 49 |
# |
| 50 |
# the min value for the heartbeat_interval is 1 millisecond an attempt to assign a |
| 51 |
# lesser will be warned with treating the value as zero |
| 52 |
# |
| 53 |
--let $rpl_connection_name= slave |
| 54 |
--source include/rpl_connection.inc |
| 55 |
|
| 56 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 57 |
--replace_column 2 #### |
| 58 |
### 5.1 mtr does not have --warning ER_REPLICA_HEARTBEAT_VALUE_OUT_OF_RANGE |
| 59 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 0.0009999; |
| 60 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 61 |
|
| 62 |
# |
| 63 |
# the actual max and min must be accepted |
| 64 |
# |
| 65 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 66 |
--replace_column 2 #### |
| 67 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 4294967; |
| 68 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 69 |
|
| 70 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 71 |
--replace_column 2 #### |
| 72 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 0.001; |
| 73 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 74 |
|
| 75 |
reset slave; |
| 76 |
|
| 77 |
# |
| 78 |
# A warning if heartbeat_interval greater than replica_net_timeout |
| 79 |
# |
| 80 |
set @@global.replica_net_timeout= 5; |
| 81 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 82 |
--replace_column 2 #### |
| 83 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 5.001; |
| 84 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 85 |
|
| 86 |
reset slave; |
| 87 |
|
| 88 |
# |
| 89 |
# A warning if replica_net_timeout is set to less than the current HB period |
| 90 |
# |
| 91 |
set @@global.replica_net_timeout= 5; |
| 92 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 93 |
--replace_column 2 #### |
| 94 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 4; |
| 95 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 96 |
set @@global.replica_net_timeout= 3 /* must be a warning */; |
| 97 |
|
| 98 |
reset slave; |
| 99 |
|
| 100 |
### |
| 101 |
### checking no rotation |
| 102 |
### |
| 103 |
|
| 104 |
--let $rpl_connection_name= master |
| 105 |
--source include/rpl_connection.inc |
| 106 |
--disable_warnings |
| 107 |
drop table if exists t1; |
| 108 |
--enable_warnings |
| 109 |
# |
| 110 |
# Even though master_heartbeat_period= 0.5 is 20 times less than |
| 111 |
# @@global.replica_net_timeout= 10 in some circumstances master will |
| 112 |
# not be able to send any heartbeat during the slave's net timeout |
| 113 |
# and slave's relay log will rotate. |
| 114 |
# The probability for such a scenario is pretty small so the following |
| 115 |
# part is almost deterministic. |
| 116 |
# |
| 117 |
|
| 118 |
--let $rpl_connection_name= slave |
| 119 |
--source include/rpl_connection.inc |
| 120 |
set @@global.replica_net_timeout= 10; |
| 121 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 122 |
# no error this time but rather a warning |
| 123 |
--replace_column 2 #### |
| 124 |
eval CHANGE REPLICATION SOURCE to SOURCE_HOST='127.0.0.1',SOURCE_PORT=$MASTER_MYPORT, SOURCE_USER='root', SOURCE_HEARTBEAT_PERIOD= 0.5; |
| 125 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 126 |
|
| 127 |
start slave; |
| 128 |
|
| 129 |
--let $rpl_connection_name= master |
| 130 |
--source include/rpl_connection.inc |
| 131 |
create table t1 (f1 int); |
| 132 |
|
| 133 |
--source include/sync_slave_sql_with_master.inc |
| 134 |
|
| 135 |
let $slave_param= Relay_Log_File; |
| 136 |
let $slave_param_value= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1); |
| 137 |
|
| 138 |
# there is an explicit sleep lasting longer than replica_net_timeout |
| 139 |
# to ensure that nothing will come to slave from master for that period. |
| 140 |
# That would cause reconnecting and relaylog rotation w/o the fix i.e |
| 141 |
# without a heartbeat received. |
| 142 |
|
| 143 |
sleep 15; |
| 144 |
|
| 145 |
# check (compare with the previous show's results) that no rotation happened |
| 146 |
source include/check_slave_param.inc; |
| 147 |
|
| 148 |
### |
| 149 |
### Check the values of HEARTBEAT_INTERVAL and COUNT_RECEIVED_HEARTBEATS |
| 150 |
### |
| 151 |
|
| 152 |
--query_vertical SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration |
| 153 |
|
| 154 |
# |
| 155 |
# proof that there has been received at least one heartbeat; |
| 156 |
# The exact number of received heartbeat is an indeterministic value |
| 157 |
# and therefore it's not recorded into results. |
| 158 |
# |
| 159 |
|
| 160 |
# Checking the fact that at least one heartbeat is received |
| 161 |
--let $wait_condition = SELECT COUNT_RECEIVED_HEARTBEATS > 0 FROM performance_schema.replication_connection_status |
| 162 |
--source include/wait_condition.inc |
| 163 |
|
| 164 |
--echo A heartbeat has been received by the slave |
| 165 |
|
| 166 |
# |
| 167 |
# check for non-null value of the last_heartbeat_timestamp variable when the slave is enabled |
| 168 |
# |
| 169 |
--let $assert_text= last_heartbeat_timestamp should not be empty |
| 170 |
--let $assert_cond= \'[SELECT LAST_HEARTBEAT_TIMESTAMP FROM performance_schema.replication_connection_status]\' != "" |
| 171 |
--source include/assert.inc |
| 172 |
|
| 173 |
# cleanup |
| 174 |
|
| 175 |
--let $rpl_connection_name= master |
| 176 |
--source include/rpl_connection.inc |
| 177 |
drop table t1; |
| 178 |
|
| 179 |
--source include/sync_slave_sql_with_master.inc |
| 180 |
set @@global.replica_net_timeout= @restore_replica_net_timeout; |
| 181 |
|
| 182 |
|
| 183 |
# ==== Bug#18185490: IF MASTER_HEARTBEAT_PERIOD OPTION IS NOT PROVIDED IT IS AUTO SETTING TO DEFAULT ==== |
| 184 |
|
| 185 |
# Change master was always resetting the heartbeat_interval to default value |
| 186 |
# and count_received_heartbeats to 0 on change master. After the bug fix, |
| 187 |
# change master should only change heartbeat_interval if the corresponding option |
| 188 |
# is given and never change count_received_heartbeats |
| 189 |
|
| 190 |
--let $rpl_connection_name= slave |
| 191 |
--source include/rpl_connection.inc |
| 192 |
--source include/stop_slave.inc |
| 193 |
|
| 194 |
CHANGE REPLICATION SOURCE TO SOURCE_HEARTBEAT_PERIOD= 10; |
| 195 |
|
| 196 |
--let $assert_text= HEARTBEAT_INTERVAL should be 10.000 |
| 197 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = 10.000 |
| 198 |
--source include/assert.inc |
| 199 |
|
| 200 |
--echo |
| 201 |
--echo # Verify that heartbeat period is not reset to default implicitly and |
| 202 |
--echo # received_heartbeat is not set to 0 by this. |
| 203 |
--echo |
| 204 |
|
| 205 |
CHANGE REPLICATION SOURCE TO SOURCE_RETRY_COUNT= 3; |
| 206 |
|
| 207 |
--let $assert_text= HEARTBEAT_INTERVAL should be 10.000 |
| 208 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = 10.000 |
| 209 |
--source include/assert.inc |
| 210 |
|
| 211 |
--let $assert_text= COUNT_RECEIVED_HEARTBEATS should NOT be set to 0 |
| 212 |
--let $assert_cond= [SELECT COUNT_RECEIVED_HEARTBEATS FROM performance_schema.replication_connection_status] <> 0 |
| 213 |
--source include/assert.inc |
| 214 |
|
| 215 |
|
| 216 |
############################################################################### |
| 217 |
# BUG#18777899 HEARTBEAT_PERIOD AUTOMATICALLY SETS TO DEFAULT POST RESET SLAVE |
| 218 |
# COMMAND |
| 219 |
# |
| 220 |
# Due to the buggy behaviour, a RESET SLAVE command on the slave server |
| 221 |
# reset heartbeat_period to default. RESET SLAVE is generally expected to |
| 222 |
# delete slave logs and forget the replicaiton positions. This erroneous |
| 223 |
# behavior was therefore un-intuitive. |
| 224 |
# |
| 225 |
# In the test we test the behaviour of heartbeat_period with RESET SLAVE, |
| 226 |
# STOP SLAVE, CHANGE MASTER, START SLAVE and RESET SLAVE ALL. |
| 227 |
# |
| 228 |
# 1. RESET SLAVE: |
| 229 |
# =========== |
| 230 |
# |
| 231 |
# Execute a RESET SLAVE and verify that the heartbeat_period is what we |
| 232 |
# set in the latest CHANGE MASTER and not the the default value. |
| 233 |
# |
| 234 |
# 2. CHANGE MASTER, START SLAVE: |
| 235 |
# ========================== |
| 236 |
# |
| 237 |
# a. Changing host resets heartbeat_period to default. |
| 238 |
# b. Changing port resets heartbeat_period to default. |
| 239 |
# c. changing host and port resets heartbeat_period to default. |
| 240 |
# |
| 241 |
# 3. RESET SLAVE ALL: |
| 242 |
# =============== |
| 243 |
# |
| 244 |
# Execute a RESET SLAVE ALL and verify that the heartbeat_period is set to 0. |
| 245 |
############################################################################### |
| 246 |
|
| 247 |
--source include/stop_slave.inc |
| 248 |
RESET SLAVE; |
| 249 |
RESET MASTER; |
| 250 |
|
| 251 |
--let $MASTER_AUTO_POSITION=SOURCE_AUTO_POSITION=0 |
| 252 |
if (`SELECT @@GLOBAL.gtid_mode = 'ON'`) |
| 253 |
{ |
| 254 |
--let $MASTER_AUTO_POSITION=SOURCE_AUTO_POSITION=1 |
| 255 |
} |
| 256 |
--replace_result $MASTER_AUTO_POSITION SOURCE_AUTO_POSITION |
| 257 |
--eval CHANGE REPLICATION SOURCE TO $MASTER_AUTO_POSITION |
| 258 |
|
| 259 |
--source include/start_slave.inc |
| 260 |
|
| 261 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = 10.000 |
| 262 |
--let $assert_text= HEARTBEAT_INTERVAL should still be 10.000 after RESET SLAVE. |
| 263 |
--source include/assert.inc |
| 264 |
|
| 265 |
--source include/stop_slave_io.inc |
| 266 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 267 |
eval CHANGE REPLICATION SOURCE TO SOURCE_HOST= 'localhost', SOURCE_PORT= $MASTER_MYPORT; |
| 268 |
--source include/start_slave.inc |
| 269 |
|
| 270 |
--let $default_heartbeat_period= @@global.replica_net_timeout/2; |
| 271 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = $default_heartbeat_period |
| 272 |
--let $assert_text= HEARTBEAT_INTERVAL should reset to default. |
| 273 |
--source include/assert.inc |
| 274 |
|
| 275 |
--echo # |
| 276 |
--echo # Change from default to make sure changing HOST resets heartbeat_interval |
| 277 |
--echo # to default. |
| 278 |
--echo # |
| 279 |
--source include/stop_slave_io.inc |
| 280 |
CHANGE REPLICATION SOURCE TO SOURCE_HEARTBEAT_PERIOD = 10; |
| 281 |
--source include/start_slave.inc |
| 282 |
|
| 283 |
# The DROP TABLE below is a transaction that will make MTS to be synced |
| 284 |
# properly on very slow systems. |
| 285 |
--connection master |
| 286 |
--disable_warnings |
| 287 |
DROP TABLE IF EXISTS t1; |
| 288 |
--enable_warnings |
| 289 |
--source include/sync_slave_sql_with_master.inc |
| 290 |
|
| 291 |
--source include/stop_slave.inc |
| 292 |
eval CHANGE REPLICATION SOURCE TO SOURCE_HOST= '127.0.0.1'; |
| 293 |
--source include/start_slave.inc |
| 294 |
|
| 295 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = $default_heartbeat_period |
| 296 |
--let $assert_text= heartbeat_interval should reset to default on changing host. |
| 297 |
--source include/assert.inc |
| 298 |
|
| 299 |
# The DROP TABLE below is a transaction that will make MTS to be synced |
| 300 |
# properly on very slow systems. |
| 301 |
--connection master |
| 302 |
--disable_warnings |
| 303 |
DROP TABLE IF EXISTS t1; |
| 304 |
--enable_warnings |
| 305 |
--source include/sync_slave_sql_with_master.inc |
| 306 |
|
| 307 |
--echo # |
| 308 |
--echo # Change from default to make sure changing PORT resets heartbeat_interval |
| 309 |
--echo # to default. |
| 310 |
--echo # |
| 311 |
--source include/stop_slave.inc |
| 312 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 313 |
CHANGE REPLICATION SOURCE TO SOURCE_HEARTBEAT_PERIOD = 10; |
| 314 |
--source include/start_slave.inc |
| 315 |
|
| 316 |
# The DROP TABLE below is a transaction that will make MTS to be synced |
| 317 |
# properly on very slow systems. |
| 318 |
--connection master |
| 319 |
--disable_warnings |
| 320 |
DROP TABLE IF EXISTS t1; |
| 321 |
--enable_warnings |
| 322 |
--source include/sync_slave_sql_with_master.inc |
| 323 |
|
| 324 |
--source include/stop_slave.inc |
| 325 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 326 |
eval CHANGE REPLICATION SOURCE TO SOURCE_PORT= $MASTER_MYPORT; |
| 327 |
--source include/start_slave.inc |
| 328 |
|
| 329 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = $default_heartbeat_period |
| 330 |
--let $assert_text= heartbeat_interval should reset to default on changing port. |
| 331 |
--source include/assert.inc |
| 332 |
|
| 333 |
# The DROP TABLE below is a transaction that will make MTS to be synced |
| 334 |
# properly on very slow systems. |
| 335 |
--connection master |
| 336 |
--disable_warnings |
| 337 |
DROP TABLE IF EXISTS t1; |
| 338 |
--enable_warnings |
| 339 |
--source include/sync_slave_sql_with_master.inc |
| 340 |
|
| 341 |
--echo # |
| 342 |
--echo # Change from default to make sure changing HOST and PORT resets |
| 343 |
--echo # heartbeat_period to default. |
| 344 |
--echo # |
| 345 |
--source include/stop_slave.inc |
| 346 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 347 |
eval CHANGE REPLICATION SOURCE TO SOURCE_HOST= '127.0.0.1', SOURCE_PORT= $MASTER_MYPORT; |
| 348 |
--source include/start_slave.inc |
| 349 |
|
| 350 |
--let $assert_cond= [SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration] = $default_heartbeat_period |
| 351 |
--let $assert_text= heartbeat_interval should reset to default on changing host and port. |
| 352 |
--source include/assert.inc |
| 353 |
|
| 354 |
# The DROP TABLE below is a transaction that will make MTS to be synced |
| 355 |
# properly on very slow systems. |
| 356 |
--connection master |
| 357 |
--disable_warnings |
| 358 |
DROP TABLE IF EXISTS t1; |
| 359 |
--enable_warnings |
| 360 |
--source include/sync_slave_sql_with_master.inc |
| 361 |
|
| 362 |
--source include/stop_slave.inc |
| 363 |
RESET SLAVE ALL; |
| 364 |
|
| 365 |
--let $assert_cond= \'[SELECT HEARTBEAT_INTERVAL FROM performance_schema.replication_connection_configuration]\' = "" |
| 366 |
--let $assert_text= heartbeat_interval should reset to zero by RESET SLAVE ALL. |
| 367 |
--source include/assert.inc |
| 368 |
|
| 369 |
# Make this a slave again to successfully pass through cleanup routines. |
| 370 |
--replace_result $MASTER_MYPORT SOURCE_PORT |
| 371 |
--replace_column 2 #### |
| 372 |
--eval CHANGE REPLICATION SOURCE to SOURCE_HOST= '127.0.0.1', SOURCE_PORT= $MASTER_MYPORT, SOURCE_USER= 'root' |
| 373 |
|
| 374 |
# The table might have replicated again after RESET SLAVE. |
| 375 |
--source include/start_slave.inc |
| 376 |
--connection master |
| 377 |
--disable_warnings |
| 378 |
DROP TABLE IF EXISTS t1; |
| 379 |
--source include/sync_slave_sql_with_master.inc |
| 380 |
--enable_warnings |
| 381 |
|
| 382 |
--source include/rpl_end.inc |