summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/topology_coordinator_impl.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2015-10-19 18:07:52 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2015-10-21 18:48:43 -0400
commitce438c5dcac373a272eb7dc80ce8d37a74394e4d (patch)
tree9e5090b31e75e7001cfd37456418080915768330 /src/mongo/db/repl/topology_coordinator_impl.cpp
parent4e038148f1567e58d17fc6b3df7beef84b2b411d (diff)
downloadmongo-ce438c5dcac373a272eb7dc80ce8d37a74394e4d.tar.gz
SERVER-21018 Prevent priority takeover during an outstanding election
Diffstat (limited to 'src/mongo/db/repl/topology_coordinator_impl.cpp')
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index 24a3dfef74f..f200dcd1f5d 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -1093,8 +1093,19 @@ HeartbeatResponseAction TopologyCoordinatorImpl::_updatePrimaryFromHBDataV1(
setMyHeartbeatMessage(now, "");
_currentPrimaryIndex = remotePrimaryIndex;
- if (_rsConfig.getMemberAt(remotePrimaryIndex).getPriority() <
- _rsConfig.getMemberAt(_selfIndex).getPriority()) {
+
+ // Priority takeover when the replset is stable.
+ //
+ // Take over the primary only if the remote primary is in the latest term I know.
+ // Otherwise, there must be an outstanding election, which may succeed or not, but
+ // the remote primary will become aware of that election eventually and step down.
+ if (_hbdata[remotePrimaryIndex].getTerm() == _term &&
+ _rsConfig.getMemberAt(remotePrimaryIndex).getPriority() <
+ _rsConfig.getMemberAt(_selfIndex).getPriority()) {
+ LOG(4) << "I can take over the primary due to higher priority."
+ << " Current primary index: " << remotePrimaryIndex << " in term "
+ << _hbdata[remotePrimaryIndex].getTerm();
+
return HeartbeatResponseAction::makePriorityTakeoverAction();
}
return HeartbeatResponseAction::makeNoAction();