1
# Testing master to slave heartbeat protocol
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
10
-- source include/have_log_bin.inc
12
connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
13
connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
20
# there can be a warning if mtr set the global init value bigger than
21
# the following assignment. The warning is a grace for the user
22
# to warn her that the new value of the global var is bigger than
23
# the current value of the hb period, i.e the sanity condition
24
# 0 < hb < slave_net_timeout does not hold.
25
# The warning has to be disabled as mtr can change the init value
26
# for slave_net_timeout
28
set @@global.slave_net_timeout= 10;
31
### Checking the range
35
# default period slave_net_timeout/2
37
--replace_result $MASTER_MYPORT MASTER_PORT
38
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
39
--query_vertical show status like 'Slave_heartbeat_period';
42
# the max for the period is ULONG_MAX/1000; an attempt to exceed it is denied
44
--replace_result $MASTER_MYPORT MASTER_PORT
45
--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
46
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294968;
47
--query_vertical show status like 'Slave_heartbeat_period';
50
# the min value for the period is 1 millisecond an attempt to assign a
51
# lesser will be warned with treating the value as zero
54
--replace_result $MASTER_MYPORT MASTER_PORT
55
#--warning ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
56
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.0009999;
57
--query_vertical show status like 'Slave_heartbeat_period';
60
# the actual max and min must be accepted
62
--replace_result $MASTER_MYPORT MASTER_PORT
63
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294967;
64
--query_vertical show status like 'Slave_heartbeat_period';
66
--replace_result $MASTER_MYPORT MASTER_PORT
67
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.001;
68
--query_vertical show status like 'Slave_heartbeat_period';
73
# A warning if period greater than slave_net_timeout
75
set @@global.slave_net_timeout= 5;
76
--replace_result $MASTER_MYPORT MASTER_PORT
77
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 5.001;
78
--query_vertical show status like 'Slave_heartbeat_period';
83
# A warning if slave_net_timeout is set to less than the current HB period
85
set @@global.slave_net_timeout= 5;
86
--replace_result $MASTER_MYPORT MASTER_PORT
87
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4;
88
--query_vertical show status like 'Slave_heartbeat_period';
89
set @@global.slave_net_timeout= 3 /* must be a warning */;
95
### checking no rotation
100
drop table if exists t1;
103
# Even though master_heartbeat_period= 0.5 is 20 times less than
104
# @@global.slave_net_timeout= 10 in some circumstances master will
105
# not be able to send any heartbeat during the slave's net timeout
106
# and slave's relay log will rotate.
107
# The probability for such a scenario is pretty small so the following
108
# part is almost deterministic.
112
set @@global.slave_net_timeout= 10;
113
--replace_result $MASTER_MYPORT MASTER_PORT
114
# no error this time but rather a warning
115
eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.5;
116
--query_vertical show status like 'Slave_heartbeat_period';
121
create table t1 (f1 int);
124
sync_slave_with_master;
125
source include/show_slave_status.inc;
127
# there is an explicit sleep lasting longer than slave_net_timeout
128
# to ensure that nothing will come to slave from master for that period.
129
# That would cause reconnecting and relaylog rotation w/o the fix i.e
130
# without a heartbeat received.
134
# check (compare with the previous show's results) that no rotation happened
135
source include/show_slave_status.inc;
138
### SHOW STATUS like 'Slave_heartbeat_period' and 'Slave_received_heartbeats'
141
--query_vertical show status like 'Slave_heartbeat_period';
144
# proof that there has been received at least one heartbeat;
145
# The exact number of received heartbeat is an indeterministic value
146
# and therefore it's not recorded into results.
149
let $slave_wait_param_counter= 300;
150
let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1);
151
# Checking the fact that at least one heartbeat is received
152
while (`select $slave_value = 0`)
154
dec $slave_wait_param_counter;
155
if (!$slave_wait_param_counter)
157
--echo ERROR: failed while waiting for slave parameter $slave_param: $slave_param_value
158
query_vertical show slave status;
159
SHOW STATUS like 'Slave_received_heartbeats';
163
let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1);
165
--echo A heartbeat has been received by the slave
172
sync_slave_with_master;