| 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 slave_net_timeout |
| 7 |
# - SHOW STATUS like 'Slave_received_heartbeats' action |
| 8 |
# - SHOW STATUS like 'Slave_heartbeat_period' report |
| 9 |
|
| 10 |
-- source include/have_log_bin.inc |
| 11 |
-- source include/master-slave.inc |
| 12 |
|
| 13 |
connection master; |
| 14 |
reset master; |
| 15 |
|
| 16 |
connection slave; |
| 17 |
-- source include/stop_slave.inc |
| 18 |
set @restore_slave_net_timeout= @@global.slave_net_timeout; |
| 19 |
--disable_warnings |
| 20 |
set @@global.slave_net_timeout= 10; |
| 21 |
--enable_warnings |
| 22 |
|
| 23 |
--enable_prepare_warnings |
| 24 |
### |
| 25 |
### Checking the range |
| 26 |
### |
| 27 |
|
| 28 |
# |
| 29 |
# default period slave_net_timeout/2 |
| 30 |
# |
| 31 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 32 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; |
| 33 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 34 |
|
| 35 |
# |
| 36 |
# the max for the period is ULONG_MAX/1000; an attempt to exceed it is denied |
| 37 |
# |
| 38 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 39 |
--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE |
| 40 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294968; |
| 41 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 42 |
|
| 43 |
# |
| 44 |
# the min value for the period is 1 millisecond an attempt to assign a |
| 45 |
# lesser will be warned with treating the value as zero |
| 46 |
# |
| 47 |
connection slave; |
| 48 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 49 |
### 5.1 mtr does not have --warning ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE |
| 50 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.0009999; |
| 51 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 52 |
|
| 53 |
# |
| 54 |
# the actual max and min must be accepted |
| 55 |
# |
| 56 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 57 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294967; |
| 58 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 59 |
|
| 60 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 61 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.001; |
| 62 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 63 |
|
| 64 |
reset slave; |
| 65 |
|
| 66 |
# |
| 67 |
# A warning if period greater than slave_net_timeout |
| 68 |
# |
| 69 |
set @@global.slave_net_timeout= 5; |
| 70 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 71 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 5.001; |
| 72 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 73 |
|
| 74 |
reset slave; |
| 75 |
|
| 76 |
# |
| 77 |
# A warning if slave_net_timeout is set to less than the current HB period |
| 78 |
# |
| 79 |
set @@global.slave_net_timeout= 5; |
| 80 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 81 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4; |
| 82 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 83 |
set @@global.slave_net_timeout= 3 /* must be a warning */; |
| 84 |
|
| 85 |
reset slave; |
| 86 |
|
| 87 |
|
| 88 |
### |
| 89 |
### checking no rotation |
| 90 |
### |
| 91 |
|
| 92 |
connection master; |
| 93 |
--disable_warnings |
| 94 |
drop table if exists t1; |
| 95 |
--enable_warnings |
| 96 |
# |
| 97 |
# Even though master_heartbeat_period= 0.5 is 20 times less than |
| 98 |
# @@global.slave_net_timeout= 10 in some circumstances master will |
| 99 |
# not be able to send any heartbeat during the slave's net timeout |
| 100 |
# and slave's relay log will rotate. |
| 101 |
# The probability for such a scenario is pretty small so the following |
| 102 |
# part is almost deterministic. |
| 103 |
# |
| 104 |
|
| 105 |
connection slave; |
| 106 |
set @@global.slave_net_timeout= 10; |
| 107 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 108 |
# no error this time but rather a warning |
| 109 |
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_ssl_verify_server_cert=0, master_heartbeat_period= 0.5; |
| 110 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 111 |
|
| 112 |
start slave; |
| 113 |
|
| 114 |
connection master; |
| 115 |
create table t1 (f1 int); |
| 116 |
|
| 117 |
#connection slave; |
| 118 |
sync_slave_with_master; |
| 119 |
let $slave_param= Relay_Log_File; |
| 120 |
let $slave_param_value= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1); |
| 121 |
|
| 122 |
# there is an explicit sleep lasting longer than slave_net_timeout |
| 123 |
# to ensure that nothing will come to slave from master for that period. |
| 124 |
# That would cause reconnecting and relaylog rotation w/o the fix i.e |
| 125 |
# without a heartbeat received. |
| 126 |
|
| 127 |
real_sleep 15; |
| 128 |
|
| 129 |
# check (compare with the previous show's results) that no rotation happened |
| 130 |
source include/check_slave_param.inc; |
| 131 |
|
| 132 |
### |
| 133 |
### SHOW STATUS like 'Slave_heartbeat_period' and 'Slave_received_heartbeats' |
| 134 |
### |
| 135 |
|
| 136 |
--query_vertical show status like 'Slave_heartbeat_period'; |
| 137 |
|
| 138 |
# |
| 139 |
# proof that there has been received at least one heartbeat; |
| 140 |
# The exact number of received heartbeat is an indeterministic value |
| 141 |
# and therefore it's not recorded into results. |
| 142 |
# |
| 143 |
|
| 144 |
let $slave_wait_param_counter= 300; |
| 145 |
let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1); |
| 146 |
# Checking the fact that at least one heartbeat is received |
| 147 |
while (!$slave_value) |
| 148 |
{ |
| 149 |
dec $slave_wait_param_counter; |
| 150 |
if (!$slave_wait_param_counter) |
| 151 |
{ |
| 152 |
--echo ERROR: failed while waiting for slave parameter $slave_param: $slave_param_value |
| 153 |
query_vertical show slave status; |
| 154 |
SHOW STATUS like 'Slave_received_heartbeats'; |
| 155 |
exit; |
| 156 |
} |
| 157 |
sleep 0.1; |
| 158 |
let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1); |
| 159 |
} |
| 160 |
--echo A heartbeat has been received by the slave |
| 161 |
# cleanup |
| 162 |
|
| 163 |
connection master; |
| 164 |
drop table t1; |
| 165 |
|
| 166 |
#connection slave; |
| 167 |
sync_slave_with_master; |
| 168 |
set @@global.slave_net_timeout= @restore_slave_net_timeout; |
| 169 |
|
| 170 |
--disable_prepare_warnings |
| 171 |
|
| 172 |
--source include/rpl_end.inc |
| 173 |
--echo End of tests |