summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2015-09-18 09:39:35 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2015-09-21 08:52:17 -0400
commit516a00f148078483b1162a43a4086322e16a0d59 (patch)
tree73d56afac06dc1781d6ab3d8cc88584a58a8e7f6 /src/mongo/db/repl
parent1282823cdb82747323435d05b0bd79b33c032177 (diff)
downloadmongo-516a00f148078483b1162a43a4086322e16a0d59.tar.gz
SERVER-20245 use candidate index instead of candidate id in last vote
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/last_vote.cpp16
-rw-r--r--src/mongo/db/repl/last_vote.h6
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp2
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp2
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp4
6 files changed, 17 insertions, 18 deletions
diff --git a/src/mongo/db/repl/last_vote.cpp b/src/mongo/db/repl/last_vote.cpp
index 94e88231bac..0b125624019 100644
--- a/src/mongo/db/repl/last_vote.cpp
+++ b/src/mongo/db/repl/last_vote.cpp
@@ -36,11 +36,11 @@ namespace mongo {
namespace repl {
namespace {
-const std::string kCandidateIdFieldName = "candidateId";
+const std::string kCandidateIndexFieldName = "candidateIndex";
const std::string kTermFieldName = "term";
const std::string kLegalFieldNames[] = {
- kCandidateIdFieldName, kTermFieldName,
+ kCandidateIndexFieldName, kTermFieldName,
};
} // namespace
@@ -54,7 +54,7 @@ Status LastVote::initialize(const BSONObj& argsObj) {
if (!status.isOK())
return status;
- status = bsonExtractIntegerField(argsObj, kCandidateIdFieldName, &_candidateId);
+ status = bsonExtractIntegerField(argsObj, kCandidateIndexFieldName, &_candidateIndex);
if (!status.isOK())
return status;
@@ -65,23 +65,23 @@ void LastVote::setTerm(long long term) {
_term = term;
}
-void LastVote::setCandidateId(long long candidateId) {
- _candidateId = candidateId;
+void LastVote::setCandidateIndex(long long candidateIndex) {
+ _candidateIndex = candidateIndex;
}
long long LastVote::getTerm() const {
return _term;
}
-long long LastVote::getCandidateId() const {
- return _candidateId;
+long long LastVote::getCandidateIndex() const {
+ return _candidateIndex;
}
BSONObj LastVote::toBSON() const {
BSONObjBuilder builder;
builder.append(kTermFieldName, _term);
- builder.append(kCandidateIdFieldName, _candidateId);
+ builder.append(kCandidateIndexFieldName, _candidateIndex);
return builder.obj();
}
diff --git a/src/mongo/db/repl/last_vote.h b/src/mongo/db/repl/last_vote.h
index fe1d67a3fe9..0466ffccbec 100644
--- a/src/mongo/db/repl/last_vote.h
+++ b/src/mongo/db/repl/last_vote.h
@@ -41,14 +41,14 @@ public:
Status initialize(const BSONObj& argsObj);
long long getTerm() const;
- long long getCandidateId() const;
+ long long getCandidateIndex() const;
void setTerm(long long term);
- void setCandidateId(long long candidateId);
+ void setCandidateIndex(long long candidateIndex);
BSONObj toBSON() const;
private:
- long long _candidateId = -1;
+ long long _candidateIndex = -1;
long long _term = -1;
};
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index ea05e1258e6..e18897c90fe 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -2731,7 +2731,7 @@ Status ReplicationCoordinatorImpl::processReplSetRequestVotes(
if (response->getVoteGranted()) {
LastVote lastVote;
lastVote.setTerm(args.getTerm());
- lastVote.setCandidateId(args.getCandidateId());
+ lastVote.setCandidateIndex(_rsConfig.findMemberIndexByConfigId(args.getCandidateId()));
Status status = _externalState->storeLocalLastVoteDocument(txn, lastVote);
if (!status.isOK()) {
@@ -3105,8 +3105,7 @@ void ReplicationCoordinatorImpl::_resetElectionInfoOnProtocolVersionUpgrade(
LastVote lastVote;
lastVote.setTerm(OpTime::kInitialTerm);
- // TODO(sz) Change candidate Id to index.
- lastVote.setCandidateId(-1);
+ lastVote.setCandidateIndex(-1);
auto status = _externalState->storeLocalLastVoteDocument(cbData.txn, lastVote);
invariant(status.isOK());
});
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
index 03f2c31afb4..d1f97c94c16 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
@@ -189,7 +189,7 @@ void ReplicationCoordinatorImpl::_onDryRunComplete(long long originalTerm) {
// Store the vote in persistent storage.
LastVote lastVote;
lastVote.setTerm(originalTerm + 1);
- lastVote.setCandidateId(getMyId());
+ lastVote.setCandidateIndex(_selfIndex);
auto cbStatus = _replExecutor.scheduleDBWork(
[this, lastVote](const ReplicationExecutor::CallbackArgs& cbData) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
index c9ddd278ae3..7dcdd06b5b6 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
@@ -214,7 +214,7 @@ TEST_F(ReplCoordElectV1Test, ElectManyNodesSuccess) {
// Check last vote
auto lastVote = getExternalState()->loadLocalLastVoteDocument(nullptr);
ASSERT(lastVote.isOK());
- ASSERT_EQ(1, lastVote.getValue().getCandidateId());
+ ASSERT_EQ(0, lastVote.getValue().getCandidateIndex());
ASSERT_EQ(1, lastVote.getValue().getTerm());
stopCapturingLogMessages();
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index 9a8c091072e..baa8080e7a1 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -2388,7 +2388,7 @@ void TopologyCoordinatorImpl::processReplSetRequestVotes(const ReplSetRequestVot
} else {
if (!args.isADryRun()) {
_lastVote.setTerm(args.getTerm());
- _lastVote.setCandidateId(args.getCandidateId());
+ _lastVote.setCandidateIndex(_rsConfig.findMemberIndexByConfigId(args.getCandidateId()));
}
response->setVoteGranted(true);
}
@@ -2416,7 +2416,7 @@ void TopologyCoordinatorImpl::loadLastVote(const LastVote& lastVote) {
void TopologyCoordinatorImpl::voteForMyselfV1() {
_lastVote.setTerm(_term);
- _lastVote.setCandidateId(_selfConfig().getId());
+ _lastVote.setCandidateIndex(_selfIndex);
}
void TopologyCoordinatorImpl::setPrimaryIndex(long long primaryIndex) {