Skip to content

Commit 18b5dbd

Browse files
SERVER-19953: arbiters ignore heartbeat interval
1 parent ae7acef commit 18b5dbd

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/mongo/db/repl/topology_coordinator_impl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,11 +900,16 @@ HeartbeatResponseAction TopologyCoordinatorImpl::processHeartbeatResponse(
900900
}
901901
}
902902

903-
// If a node is not PRIMARY and has no sync source, we increase the heartbeat rate in order
904-
// to help it find a sync source more quickly, which helps ensure the PRIMARY will continue to
903+
// If a node is not PRIMARY and has no sync source,
904+
// we increase the heartbeat rate in order
905+
// to help it find a sync source more quickly,
906+
// which helps ensure the PRIMARY will continue to
905907
// see the majority of the cluster.
908+
//
909+
// Arbiters also use half the election timeout period for their heartbeat frequency
906910
Milliseconds heartbeatInterval;
907-
if (_rsConfig.getProtocolVersion() == 1 && getSyncSourceAddress().empty() && !_iAmPrimary()) {
911+
if (_rsConfig.getProtocolVersion() == 1 &&
912+
(getMemberState().arbiter() || (getSyncSourceAddress().empty() && !_iAmPrimary()))) {
908913
heartbeatInterval = _rsConfig.getElectionTimeoutPeriod() / 2;
909914
} else {
910915
heartbeatInterval = _rsConfig.getHeartbeatInterval();

src/mongo/db/repl/topology_coordinator_impl_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,29 @@ TEST_F(TopoCoordTest, PrepareFreshResponse) {
14261426
ASSERT_TRUE(responseBuilder12.obj().isEmpty());
14271427
}
14281428

1429+
TEST_F(TopoCoordTest, ArbiterHeartbeatFrequency) {
1430+
// This tests that arbiters issue heartbeats at electionTimeout/2 frequencies
1431+
TopoCoordTest::setUp();
1432+
updateConfig(fromjson(
1433+
"{_id:'mySet', version:1, protocolVersion:1, members:["
1434+
"{_id:1, host:'node1:12345', arbiterOnly:true}, "
1435+
"{_id:2, host:'node2:12345'}], "
1436+
"settings:{heartbeatIntervalMillis:10, electionTimeoutMillis:5000}}"),
1437+
0);
1438+
HostAndPort target("host2", 27017);
1439+
Date_t requestDate = now();
1440+
std::pair<ReplSetHeartbeatArgs, Milliseconds> uppingRequest =
1441+
getTopoCoord().prepareHeartbeatRequest(requestDate, "myset", target);
1442+
auto action =
1443+
getTopoCoord().processHeartbeatResponse(requestDate,
1444+
Milliseconds(0),
1445+
target,
1446+
makeStatusWith<ReplSetHeartbeatResponse>(),
1447+
OpTime(Timestamp(0, 0), 0));
1448+
Date_t expected(now() + Milliseconds(2500));
1449+
ASSERT_EQUALS(expected, action.getNextHeartbeatStartDate());
1450+
}
1451+
14291452
class HeartbeatResponseTest : public TopoCoordTest {
14301453
public:
14311454
virtual void setUp() {

0 commit comments

Comments
 (0)