Skip to content

Commit c45a34b

Browse files
QWenQParadoxV5
authored andcommitted
MDEV-36002 --master-retry-count=0 can still stop
When master-retry-count equals 0, it means the slave will try to reconnect to the master continuously. But, when the number of tries err_count overflows to 0, the connection will abort. So, when an overflow occurs, we still need to check master-retry-cout value. If master-retry-count equals 0, reconnection should continue. Reviewed-by: ParadoxV5 <paradox.ver5@gmail.com>
1 parent 60ebf3f commit c45a34b

8 files changed

+174
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
include/master-slave.inc
2+
[connection master]
3+
connection slave;
4+
CHANGE MASTER TO MASTER_CONNECT_RETRY= 1;
5+
include/start_slave.inc
6+
SET @saved_dbug= @@GLOBAL.debug_dbug;
7+
SET @@GLOBAL.debug_dbug= '+d,set_slave_err_count_near_overflow';
8+
SET @@GLOBAL.debug_dbug= '+d,sync_master_retry';
9+
include/rpl_stop_server.inc [server_number=1]
10+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
11+
include/wait_for_slave_param.inc [Slave_IO_Running]
12+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
13+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
14+
include/wait_for_slave_param.inc [Slave_IO_Running]
15+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
16+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
17+
include/wait_for_slave_param.inc [Slave_IO_Running]
18+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
19+
Slave_IO_Running status should be Connecting
20+
include/wait_for_slave_param.inc [Slave_IO_Running]
21+
SET @@GLOBAL.debug_dbug= @saved_dbug;
22+
include/rpl_start_server.inc [server_number=1]
23+
connection slave;
24+
START SLAVE;
25+
include/wait_for_slave_io_to_start.inc
26+
include/rpl_end.inc
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include/master-slave.inc
2+
[connection master]
3+
connection slave;
4+
CHANGE MASTER TO MASTER_CONNECT_RETRY= 1;
5+
include/start_slave.inc
6+
SET @saved_dbug= @@GLOBAL.debug_dbug;
7+
SET @@GLOBAL.debug_dbug= '+d,sync_master_retry';
8+
include/rpl_stop_server.inc [server_number=1]
9+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
10+
include/wait_for_slave_param.inc [Slave_IO_Running]
11+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
12+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
13+
include/wait_for_slave_param.inc [Slave_IO_Running]
14+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
15+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
16+
include/wait_for_slave_param.inc [Slave_IO_Running]
17+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
18+
Slave_IO_Running status should be No
19+
include/wait_for_slave_param.inc [Slave_IO_Running]
20+
SET @@GLOBAL.debug_dbug= @saved_dbug;
21+
include/rpl_start_server.inc [server_number=1]
22+
connection slave;
23+
START SLAVE;
24+
include/wait_for_slave_io_to_start.inc
25+
include/rpl_end.inc
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ==== Purpose ====
2+
#
3+
# During shutdown of the master, check Slave_IO_Running status
4+
# after reconnecting a specified number of times.
5+
#
6+
# ==== Usage ====
7+
#
8+
# --let $overflow= 0
9+
# --let $retry_count= 3
10+
# --let $expected_Slave_IO_Running_status= Connecting
11+
# --source rpl_mdev36002.inc
12+
#
13+
# Parameters:
14+
# $overflow
15+
# If overflow equals 1, the DEBUG flag 'set_slave_err_count_near_overflow'
16+
# will be activated, and the number of tries made will be initialized to
17+
# ULONG_MAX - 2.
18+
#
19+
# $retry_count
20+
# The number of reconnections the slave will do during shutdown of the master.
21+
#
22+
# $expected_Slave_IO_Running_status
23+
# Whether Slave_IO_Running should be Connecting/No
24+
# after reconnecting $retry_count times.
25+
#
26+
27+
28+
--source include/have_debug.inc
29+
--source include/have_debug_sync.inc
30+
31+
# Set MASTER_CONNECT_RETRY as 1 second
32+
--let $rpl_skip_start_slave= 1
33+
--source include/master-slave.inc
34+
35+
--connection slave
36+
CHANGE MASTER TO MASTER_CONNECT_RETRY= 1;
37+
--source include/start_slave.inc
38+
39+
40+
# Set err_count as ULONG_MAX if necessary and starts up sync points
41+
SET @saved_dbug= @@GLOBAL.debug_dbug;
42+
43+
if ($overflow)
44+
{
45+
SET @@GLOBAL.debug_dbug= '+d,set_slave_err_count_near_overflow';
46+
}
47+
SET @@GLOBAL.debug_dbug= '+d,sync_master_retry';
48+
49+
50+
# stop the master
51+
--let $rpl_server_number= 1
52+
--source include/rpl_stop_server.inc
53+
54+
# Everytime the reconnection is done, check the status of Slave_IO_Running
55+
while ($retry_count)
56+
{
57+
SET @@SESSION.debug_sync= 'now WAIT_FOR master_retry_sleep';
58+
--let $slave_param= Slave_IO_Running
59+
--let $slave_param_value= Connecting
60+
--source include/wait_for_slave_param.inc
61+
62+
SET @@SESSION.debug_sync= 'now SIGNAL master_retry_continue';
63+
--dec $retry_count
64+
}
65+
66+
# after exhausting exactly that many number of tries,
67+
# the Slave_IO_Running status should be expected.
68+
69+
--echo Slave_IO_Running status should be $expected_Slave_IO_Running_status
70+
--let $slave_param= Slave_IO_Running
71+
--let $slave_param_value= $expected_Slave_IO_Running_status
72+
--source include/wait_for_slave_param.inc
73+
74+
SET @@GLOBAL.debug_dbug= @saved_dbug;
75+
76+
77+
# Restart the master to reestablish a successful slave connection for clean-up
78+
--let $rpl_server_number= 1
79+
--source include/rpl_start_server.inc
80+
81+
--connection slave
82+
--disable_warnings
83+
START SLAVE;
84+
--enable_warnings
85+
--let $rpl_allow_error= 1
86+
--source include/wait_for_slave_io_to_start.inc
87+
88+
--source include/rpl_end.inc
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
!include ../my.cnf
2+
3+
[mysqld.2]
4+
master-retry-count= 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test:
2+
# master-retry-count= 0 and retry_count= ULONG_MAX - 2,
3+
# after exhausting retry_cnt attempts with an overflow of err_count occurs,
4+
# the connection should be Connecting;
5+
#
6+
--let $overflow= 1
7+
--let $retry_count= 3
8+
--let $expected_Slave_IO_Running_status= Connecting
9+
--source rpl_retry_count.inc
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
!include ../my.cnf
2+
3+
[mysqld.2]
4+
master-retry-count= 4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test:
2+
# master-retry-count= 4 and retry_count= 3,
3+
# after exhuasting master-retry-count attempts, the connection should abort.
4+
#
5+
6+
--let $overflow= 0
7+
--let $retry_count= 3
8+
--let $expected_Slave_IO_Running_status= No
9+
--source rpl_retry_count.inc

sql/slave.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7591,6 +7591,7 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
75917591
int slave_was_killed;
75927592
int last_errno= -2; // impossible error
75937593
ulong err_count=0;
7594+
DBUG_EXECUTE_IF("set_slave_err_count_near_overflow", err_count = ULONG_MAX - 2;);
75947595
my_bool my_true= 1;
75957596
DBUG_ENTER("connect_to_master");
75967597
set_slave_max_allowed_packet(thd, mysql);
@@ -7639,13 +7640,20 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
76397640
do not want to have election triggered on the first failure to
76407641
connect
76417642
*/
7642-
if (++err_count == master_retry_count)
7643+
if ((++err_count == master_retry_count) && master_retry_count )
76437644
{
76447645
slave_was_killed=1;
76457646
if (reconnect)
76467647
change_rpl_status(RPL_ACTIVE_SLAVE,RPL_LOST_SOLDIER);
76477648
break;
76487649
}
7650+
7651+
DBUG_EXECUTE_IF("sync_master_retry",
7652+
debug_sync_set_action(thd, STRING_WITH_LEN(
7653+
"now SIGNAL master_retry_sleep WAIT_FOR master_retry_continue"
7654+
));
7655+
);
7656+
76497657
slave_sleep(thd,mi->connect_retry,io_slave_killed, mi);
76507658
}
76517659

0 commit comments

Comments
 (0)