1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
#############################################################
# Author: Serge Kozlov <Serge.Kozlov@Sun.COM>
# Date: 02/19/2009
# Purpose: Testing basic functionality of heartbeat.
# Description:
# * Testing different values for slave_heartbeat_period.
# * How to affect various statements to slave_heartbeat_period
# * Various states of slave and heartbeat
# * Various states of master and heartbeat
# * Circular replication
#############################################################
--source include/master-slave.inc
#
# The test runs long and does not have any specifics to
# binlog_format. It is chosen therefore to run with MIXED mode
# in order to not slow down much `make test'.
#
--source include/have_binlog_format_mixed.inc
--echo
--enable_prepare_warnings
# Set number of retries to connect to master
let $connect_retry= 20;
--echo *** Preparing ***
--connection slave
--source include/stop_slave.inc
RESET SLAVE;
SET @restore_slave_net_timeout=@@global.slave_net_timeout;
let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
--disable_query_log
eval SET @restore_slave_heartbeat_timeout=$slave_heartbeat_timeout;
--enable_query_log
--connection master
RESET MASTER;
SET @restore_slave_net_timeout=@@global.slave_net_timeout;
--echo
#
# Test slave_heartbeat_period
#
--connection slave
# Default value of slave_heartbeat_timeout = slave_net_timeout/2
--echo *** Default value ***
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
let $slave_net_timeout= query_get_value(SHOW VARIABLES LIKE 'slave_net_timeout', Value, 1);
let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
let $result= query_get_value(SELECT $slave_net_timeout/$slave_heartbeat_timeout AS Result, Result, 1);
--echo slave_net_timeout/slave_heartbeat_timeout=$result
--source include/reset_slave.inc
--echo
# Reset slave set slave_heartbeat_timeout = slave_net_timeout/2
--echo *** Reset slave affect ***
--disable_warnings
SET @@global.slave_net_timeout=30;
--enable_warnings
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=5;
--source include/reset_slave.inc
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
--echo
# Check default value of slave_heartbeat_timeout if slave_net_timeout is changed
--echo *** Default value if slave_net_timeout changed ***
--disable_warnings
SET @@global.slave_net_timeout=50;
--enable_warnings
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry;
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
--source include/reset_slave.inc
--echo
# Set slave_net_timeout less than current value of slave_heartbeat_period
--echo *** Warning if updated slave_net_timeout < slave_heartbeat_timeout ***
let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
--replace_result $slave_heartbeat_timeout SLAVE_HEARTBEAT_TIMEOUT
eval SET @@global.slave_net_timeout=FLOOR($slave_heartbeat_timeout)-1;
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
RESET SLAVE;
--echo
# Set value of slave_heartbeat_period greater than slave_net_timeout
--echo *** Warning if updated slave_heartbeat_timeout > slave_net_timeout ***
let $slave_net_timeout= query_get_value(SHOW VARIABLES LIKE 'slave_net_timeout', Value, 1);
inc $slave_net_timeout;
--replace_result $MASTER_MYPORT MASTER_PORT $slave_net_timeout SLAVE_NET_TIMEOUT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=$slave_net_timeout;
RESET SLAVE;
--echo
# Changing of slave_net_timeout shouldn't affect to current value of slave_heartbeat_period
--echo *** CHANGE MASTER statement only updates slave_heartbeat_period ***
--disable_warnings
SET @@global.slave_net_timeout=20;
--enable_warnings
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=5;
SHOW VARIABLES LIKE 'slave_net_timeout';
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SET @@global.slave_net_timeout=2*@@global.slave_net_timeout;
SHOW VARIABLES LIKE 'slave_net_timeout';
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
RESET SLAVE;
--echo
# Master value of slave_net_timeout shouldn't affect to slave's slave_heartbeat_period
--echo *** Update slave_net_timeout on master ***
--connection master
--disable_warnings
SET @@global.slave_net_timeout=500;
--enable_warnings
--connection slave
SET @@global.slave_net_timeout=200;
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry;
--source include/start_slave.inc
--connection master
--sync_slave_with_master
SHOW VARIABLES LIKE 'slave_net_timeout';
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
--source include/stop_slave.inc
RESET SLAVE;
--connection master
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
--echo
# Start/stop slave shouldn't change slave_heartbeat_period
--echo *** Start/stop slave ***
--connection slave
--disable_warnings
SET @@global.slave_net_timeout=100;
--enable_warnings
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=20;
--source include/start_slave.inc
--connection master
--sync_slave_with_master
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
--source include/stop_slave.inc
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
--echo
# Reload slave shouldn't change slave_heartbeat_period
--echo *** Reload slave ***
--connection slave
--disable_warnings
SET @@global.slave_net_timeout=50;
--enable_warnings
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=30;
--let $rpl_server_number= 2
--source include/rpl_restart_server.inc
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SET @restore_slave_net_timeout=@@global.slave_net_timeout;
--echo
# Disable heartbeat
--echo *** Disable heartbeat ***
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0;
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SHOW STATUS LIKE 'slave_received_heartbeats';
--source include/start_slave.inc
--connection master
--sync_slave_with_master
--sleep 2
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SHOW STATUS LIKE 'slave_received_heartbeats';
--source include/stop_slave.inc
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
SHOW STATUS LIKE 'slave_received_heartbeats';
RESET SLAVE;
let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
--replace_result $slave_heartbeat_timeout SLAVE_HEARTBEAT_TIMEOUT
--eval SELECT $slave_heartbeat_timeout = 0 AS Result
--echo
#
# Check limits for slave_heartbeat_timeout
#
--echo *** Min slave_heartbeat_timeout ***
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.001;
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.0009;
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
RESET SLAVE;
--echo
--echo *** Max slave_heartbeat_timeout ***
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=4294967;
SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=4294968;
RESET SLAVE;
# Check double size of max allowed value for master_heartbeat_period
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=8589935;
RESET SLAVE;
# Check 2^32
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=4294967296;
RESET SLAVE;
--echo
--echo *** Misc incorrect values ***
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_PARSE_ERROR
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD='-1';
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_PARSE_ERROR
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD='123abc';
RESET SLAVE;
--replace_result $MASTER_MYPORT MASTER_PORT
--error ER_PARSE_ERROR
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD='';
RESET SLAVE;
--echo
#
# Testing heartbeat
#
# Check received heartbeat events for running slave
--echo *** Running slave ***
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.1;
--source include/start_slave.inc
--connection master
--sync_slave_with_master
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var= slave_received_heartbeats;
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--echo
# Check received heartbeat events for stopped slave
--echo *** Stopped slave ***
--source include/stop_slave.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
sleep 2;
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) AS Result, Result, 1);
--echo Number of received heartbeat events while slave stopped: $result
--echo
# Check received heartbeat events for started slave
--echo *** Started slave ***
--source include/start_slave.inc
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--echo
# Check received heartbeat events for stopped IO thread
--echo *** Stopped IO thread ***
--source include/stop_slave_io.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
sleep 2;
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) AS Result, Result, 1);
--echo Number of received heartbeat events while io thread stopped: $result
--echo
# Check received heartbeat events for started IO thread
--echo *** Started IO thread ***
START SLAVE IO_THREAD;
--source include/wait_for_slave_io_to_start.inc
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--echo
# Check received heartbeat events for stopped SQL thread
--echo *** Stopped SQL thread ***
--source include/stop_slave_sql.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
sleep 2;
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
--echo Heartbeat events are received while sql thread stopped (1 means 'yes'): $result
--echo
# Check received heartbeat events for started SQL thread
--echo *** Started SQL thread ***
START SLAVE SQL_THREAD;
--source include/wait_for_slave_sql_to_start.inc
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--echo
# Check received heartbeat event for stopped SQL thread by error
--echo *** Stopped SQL thread by error ***
--connection master
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10), c LONGTEXT);
--sync_slave_with_master
INSERT INTO t1 VALUES (1, 'on slave', NULL);
--connection master
INSERT INTO t1 VALUES (1, 'on master', NULL);
--connection slave
set sql_log_bin= 0;
call mtr.add_suppression("Slave SQL.*Duplicate entry .1. for key .PRIMARY.. on query.* error.* 1062");
call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
set sql_log_bin= 1;
let $slave_errno= ER_DUP_ENTRY
--source include/wait_for_slave_sql_error.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
sleep 4;
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
--echo Heartbeat events are received while sql thread stopped (1 means 'yes'): $result
--source include/stop_slave.inc
set sql_log_bin= 0;
DROP TABLE t1;
set sql_log_bin= 1;
--echo
# Check received heartbeat events while master send events to slave
--echo *** Master send to slave ***
--connection master
# Create the event that will update table t1 every second
DELIMITER |;
CREATE EVENT e1
ON SCHEDULE EVERY 1 SECOND
DO
BEGIN
UPDATE test.t1 SET a = a + 1 WHERE a < 10;
END|
DELIMITER ;|
--connection slave
--source include/reset_slave.inc
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=5;
--source include/start_slave.inc
--connection master
# Enable scheduler
SET @@global.event_scheduler=1;
--sync_slave_with_master
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--connection master
# Whether or not to send a heartbeat is decided on the master, based on
# whether the binlog was updated during the period or not.
# Even with the 1-second event, we cannot make the master to write binary
# logs (or execute SQL) in a timely manner. We can only check that they
# were executed in a timely manner, and if they were not, neutralize the
# heartbeat check on the slave.
# We will wait for 5 events, and keep checking 'Binlog_commits' on master.
# Time interval between consequent events will be measured.
# We can only expect that no heartbeats have been sent if the interval
# between events never exceeded MASTER_HEARTBEAT_PERIOD.
# If it has exceeded the value at least once, the slave can legitimately
# receive a heartbeat (but we cannot require it, because the delay
# could have occurred somewhere else, e.g. upon checking the status).
# So, if the delay is detected, we will signal slave to ignore possible
# heartbeats.
let $possible_heartbeats= 0;
let $commits_to_wait= 5;
while ($commits_to_wait)
{
let $tm= `SELECT UNIX_TIMESTAMP(NOW(3))`;
let $binlog_commits= query_get_value(SHOW STATUS LIKE 'Binlog_commits', Value, 1);
let $wait_condition= SELECT VARIABLE_VALUE > $binlog_commits FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME= 'BINLOG_COMMITS';
--source include/wait_condition.inc
dec $commits_to_wait;
if (`SELECT UNIX_TIMESTAMP(NOW(3)) > $tm + 5`)
{
let $possible_heartbeats= 1;
let $commits_to_wait= 0;
}
}
--connection slave
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= `SELECT CASE WHEN $possible_heartbeats THEN 'TRUE' WHEN $rcvd_heartbeats_after - $rcvd_heartbeats_before > 0 THEN 'FALSE' ELSE 'TRUE' END`;
--echo Received heartbeats meet expectations: $result
--connection master
DELETE FROM t1;
DROP EVENT e1;
--sync_slave_with_master
--echo
# Check received heartbeat events while logs flushed on slave
--echo *** Flush logs on slave ***
STOP SLAVE;
--source include/reset_slave.inc
set sql_log_bin= 0;
DROP TABLE t1;
set sql_log_bin= 1;
--connection master
DROP TABLE t1;
RESET MASTER;
--connection slave
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.5;
let $slave_param_comparison= =;
--source include/start_slave.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
# Flush logs every 0.1 second during 5 sec
--disable_query_log
let $i=100;
while ($i) {
FLUSH LOGS;
dec $i;
sleep 0.1;
}
--enable_query_log
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
--echo Heartbeat events are received while rotation of relay logs (1 means 'yes'): $result
--echo
# Use compressed protocol between master and slave
--echo *** Compressed protocol ***
--connection master
SET @@global.slave_compressed_protocol=1;
--connection slave
--source include/stop_slave.inc
--source include/reset_slave.inc
SET @@global.slave_compressed_protocol=1;
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.1;
--source include/start_slave.inc
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var= slave_received_heartbeats;
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received
SET @@global.slave_compressed_protocol=0;
--connection master
SET @@global.slave_compressed_protocol=0;
--echo
# Check received heartbeat events after reset of master
--echo *** Reset master ***
--connection slave
STOP SLAVE;
--source include/reset_slave.inc
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.1;
--source include/start_slave.inc
let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--connection master
RESET MASTER;
--enable_query_log
--sync_slave_with_master
--sleep 2
let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
--echo Heartbeat events are received after reset of master (1 means 'yes'): $result
--echo
# Reloaded master should restore heartbeat
--echo *** Reload master ***
--connection slave
STOP SLAVE;
--source include/reset_slave.inc
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=0.1;
--source include/start_slave.inc
# Wait until slave_received_heartbeats will be incremented
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var= slave_received_heartbeats;
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--let $rpl_server_number= 1
--source include/rpl_restart_server.inc
# make sure IO thread has re-connected
# due to slow valgrind env the following wait_for_status may time out
--let $rpl_allow_error= 1
--source include/wait_for_slave_io_to_start.inc
# Wait until slave_received_heartbeats will be incremented
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var= slave_received_heartbeats;
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received
--echo
# Circular replication: demonstrating bidirectional hearbeat flow
--echo *** Circular replication ***
# Configure circular replication
--source include/rpl_reset.inc
--source include/stop_slave.inc
--let $rpl_topology= 1->2->1
--source include/rpl_change_topology.inc
#--connection slave
#--source include/stop_slave.inc
#let $slave_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
--connection master
#--replace_result $SLAVE_MYPORT SLAVE_PORT $slave_binlog SLAVE_BINLOG
#eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SLAVE_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='$slave_binlog';
# BUG#12403008 RPL_HEARTBEAT_BASIC FAILS SPORADICALLY ON PUSHBUILD
# MASTER_HEARTBEAT_PERIOD had the default value (slave_net_timeout/2)
# so wait on "Heartbeat event received on master", that only waits for
# 1 minute, sometimes timeout before heartbeat arrives.
CHANGE MASTER TO MASTER_HEARTBEAT_PERIOD=1;
--source include/start_slave.inc
# Insert data on master and on slave and make sure that it replicated for both directions
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10));
INSERT INTO t1 VALUES(1, 'on master');
--save_master_pos
--connection slave
## set slave period 1/10 of master's
CHANGE MASTER TO MASTER_HEARTBEAT_PERIOD=0.1;
--source include/start_slave.inc
--sync_with_master
INSERT INTO t1 VALUES(2, 'on slave');
--sync_slave_with_master master
SELECT * FROM t1 ORDER BY a;
let $master_rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
--connection slave
SELECT * FROM t1 ORDER BY a;
# Wait for heartbeat event on master
--connection master
let $status_var= slave_received_heartbeats;
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received on master
# Wait heartbeat events on slave
--connection slave
let $status_var= slave_received_heartbeats;
let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
let $status_var_comparsion= >;
--source include/wait_for_status_var.inc
--echo Heartbeat event received on slave
let $slave_rcvd_heartbeats= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
#
# Clean up and restore system variables
#
--echo *** Clean up ***
--connection master
#--source include/stop_slave.inc
DROP TABLE t1;
--sync_slave_with_master
SET @@global.slave_net_timeout=@restore_slave_net_timeout;
--disable_prepare_warnings
#--let $rpl_only_running_threads= 1
--source include/rpl_end.inc
|