diff options
author | matt dannenberg <matt.dannenberg@10gen.com> | 2015-09-03 04:57:40 -0400 |
---|---|---|
committer | matt dannenberg <matt.dannenberg@10gen.com> | 2015-09-04 09:42:48 -0400 |
commit | 815a170af4f9579e7f9130dae6265ad274805e39 (patch) | |
tree | ac3ab1e1fd9ceaedd704d4a4e908b05273a6e338 /src/mongo/db/repl/replica_set_config.cpp | |
parent | a0f913f121b0be75638d12bc878fc8acc63ec476 (diff) | |
download | mongo-815a170af4f9579e7f9130dae6265ad274805e39.tar.gz |
SERVER-19836 implement priority logic for PV1 elections
Diffstat (limited to 'src/mongo/db/repl/replica_set_config.cpp')
-rw-r--r-- | src/mongo/db/repl/replica_set_config.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replica_set_config.cpp b/src/mongo/db/repl/replica_set_config.cpp index ff881dce42b..f5f7c495ef2 100644 --- a/src/mongo/db/repl/replica_set_config.cpp +++ b/src/mongo/db/repl/replica_set_config.cpp @@ -649,5 +649,39 @@ std::vector<std::string> ReplicaSetConfig::getWriteConcernNames() const { return names; } +Milliseconds ReplicaSetConfig::getPriorityTakeoverDelay(int memberIdx) const { + auto member = getMemberAt(memberIdx); + int priorityRank = _calculatePriorityRank(member.getPriority()); + Milliseconds nodeSpecificDelay = + getVoterPosition(memberIdx) * getElectionTimeoutPeriod() / getTotalVotingMembers(); + return (priorityRank + 1) * getElectionTimeoutPeriod() + nodeSpecificDelay; +} + +int ReplicaSetConfig::_calculatePriorityRank(int priority) const { + int count = 0; + for (MemberIterator mem = membersBegin(); mem != membersEnd(); mem++) { + if (mem->getPriority() > priority) { + count++; + } + } + return count; +} + +int ReplicaSetConfig::getVoterPosition(int memberIdx) const { + int pos = 0; + int idx = 0; + for (auto mem = membersBegin(); mem != membersEnd(); ++mem) { + if (idx == memberIdx) { + break; + } + + if (mem->isVoter()) { + pos++; + } + idx++; + } + return pos; +} + } // namespace repl } // namespace mongo |