Skip to content

Commit cbc6a79

Browse files
committed
SERVER-20928 Heartbeat shouldn't cause stepdown in protocol version 1.
1 parent 0c48b42 commit cbc6a79

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponseAction(
224224
case HeartbeatResponseAction::StepDownSelf:
225225
invariant(action.getPrimaryConfigIndex() == _selfIndex);
226226
log() << "Stepping down from primary in response to heartbeat";
227+
_topCoord->prepareForStepDown();
227228
_stepDownStart();
228229
break;
229230
case HeartbeatResponseAction::StepDownRemotePrimary: {

src/mongo/db/repl/topology_coordinator_impl.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,18 +1118,9 @@ HeartbeatResponseAction TopologyCoordinatorImpl::_updatePrimaryFromHBDataV1(
11181118

11191119
// We do not believe any remote to be primary.
11201120

1121-
// If we are primary, check if we can still see majority of the set; stepdown if we can't.
1121+
// Return if we are primary. The stepdown decision is based on liveness rather than
1122+
// heartbeats in pv 1.
11221123
if (_iAmPrimary()) {
1123-
if (CannotSeeMajority & _getMyUnelectableReason(now, lastOpApplied)) {
1124-
if (_stepDownPending) {
1125-
return HeartbeatResponseAction::makeNoAction();
1126-
}
1127-
_stepDownPending = true;
1128-
log() << "can't see a majority of the set, relinquishing primary";
1129-
return HeartbeatResponseAction::makeStepDownSelfAction(_selfIndex);
1130-
}
1131-
1132-
LOG(2) << "Choosing to remain primary";
11331124
return HeartbeatResponseAction::makeNoAction();
11341125
}
11351126

src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataRemoteDoesNotExist) {
26652665
ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole());
26662666
}
26672667

2668-
TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataRelinquishPrimaryDueToNodeDisappearing) {
2668+
TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataDoesNotRelinquishPrimary) {
26692669
// Become PRIMARY.
26702670
ASSERT_EQUALS(-1, getCurrentPrimaryIndex());
26712671
makeSelfPrimary(Timestamp(2, 0));
@@ -2679,20 +2679,15 @@ TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataRelinquishPrimaryDueToNodeDis
26792679
heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, OpTime());
26802680
heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, OpTime());
26812681

2682-
// Lose that awareness and be sure we are going to stepdown.
2682+
// Lose that awareness, but we are not going to step down, because stepdown only
2683+
// depends on liveness.
26832684
HeartbeatResponseAction nextAction =
26842685
receiveDownHeartbeat(HostAndPort("host2"), "rs0", OpTime(Timestamp(100, 0), 0));
26852686
ASSERT_NO_ACTION(nextAction.getAction());
26862687
nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", OpTime(Timestamp(100, 0), 0));
2687-
ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, nextAction.getAction());
2688-
ASSERT_EQUALS(0, nextAction.getPrimaryConfigIndex());
2688+
ASSERT_NO_ACTION(nextAction.getAction());
26892689
ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole());
26902690
ASSERT_EQUALS(0, getCurrentPrimaryIndex());
2691-
// Doesn't actually do the stepdown until stepDownIfPending is called.
2692-
2693-
ASSERT_TRUE(getTopoCoord().stepDownIfPending());
2694-
ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole());
2695-
ASSERT_EQUALS(-1, getCurrentPrimaryIndex());
26962691
}
26972692

26982693
TEST_F(HeartbeatResponseTestV1, UpdateHeartbeatDataPriorTakeoverDueToHigherPriority) {

0 commit comments

Comments
 (0)