diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/repl/vote_requester.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/repl/vote_requester.cpp')
-rw-r--r-- | src/mongo/db/repl/vote_requester.cpp | 219 |
1 files changed, 103 insertions, 116 deletions
diff --git a/src/mongo/db/repl/vote_requester.cpp b/src/mongo/db/repl/vote_requester.cpp index 81691edf5d7..c23bd7d6916 100644 --- a/src/mongo/db/repl/vote_requester.cpp +++ b/src/mongo/db/repl/vote_requester.cpp @@ -42,128 +42,115 @@ namespace mongo { namespace repl { - VoteRequester::Algorithm::Algorithm(const ReplicaSetConfig& rsConfig, - long long candidateId, - long long term, - bool dryRun, - OpTime lastOplogEntry) : - _rsConfig(rsConfig), - _candidateId(candidateId), - _term(term), - _dryRun(dryRun), - _lastOplogEntry(lastOplogEntry) { - - // populate targets with all voting members that aren't this node - for (auto member = _rsConfig.membersBegin(); member != _rsConfig.membersEnd(); member++) { - if (member->isVoter() && member->getId() != candidateId) { - _targets.push_back(member->getHostAndPort()); - } +VoteRequester::Algorithm::Algorithm(const ReplicaSetConfig& rsConfig, + long long candidateId, + long long term, + bool dryRun, + OpTime lastOplogEntry) + : _rsConfig(rsConfig), + _candidateId(candidateId), + _term(term), + _dryRun(dryRun), + _lastOplogEntry(lastOplogEntry) { + // populate targets with all voting members that aren't this node + for (auto member = _rsConfig.membersBegin(); member != _rsConfig.membersEnd(); member++) { + if (member->isVoter() && member->getId() != candidateId) { + _targets.push_back(member->getHostAndPort()); } } - - VoteRequester::Algorithm::~Algorithm() {} - - std::vector<RemoteCommandRequest> - VoteRequester::Algorithm::getRequests() const { - BSONObjBuilder requestVotesCmdBuilder; - requestVotesCmdBuilder.append("replSetRequestVotes", 1); - requestVotesCmdBuilder.append("setName", _rsConfig.getReplSetName()); - requestVotesCmdBuilder.append("dryRun", _dryRun); - requestVotesCmdBuilder.append("term", _term); - requestVotesCmdBuilder.append("candidateId", _candidateId); - requestVotesCmdBuilder.append("configVersion", _rsConfig.getConfigVersion()); - - BSONObjBuilder lastCommittedOp(requestVotesCmdBuilder.subobjStart("lastCommittedOp")); - lastCommittedOp.append("ts", _lastOplogEntry.getTimestamp()); - lastCommittedOp.append("term", _lastOplogEntry.getTerm()); - lastCommittedOp.done(); - - const BSONObj requestVotesCmd = requestVotesCmdBuilder.obj(); - - std::vector<RemoteCommandRequest> requests; - for (const auto& target : _targets) { - requests.push_back(RemoteCommandRequest( - target, - "admin", - requestVotesCmd, - Milliseconds(30*1000))); // trying to match current Socket timeout - } - - return requests; +} + +VoteRequester::Algorithm::~Algorithm() {} + +std::vector<RemoteCommandRequest> VoteRequester::Algorithm::getRequests() const { + BSONObjBuilder requestVotesCmdBuilder; + requestVotesCmdBuilder.append("replSetRequestVotes", 1); + requestVotesCmdBuilder.append("setName", _rsConfig.getReplSetName()); + requestVotesCmdBuilder.append("dryRun", _dryRun); + requestVotesCmdBuilder.append("term", _term); + requestVotesCmdBuilder.append("candidateId", _candidateId); + requestVotesCmdBuilder.append("configVersion", _rsConfig.getConfigVersion()); + + BSONObjBuilder lastCommittedOp(requestVotesCmdBuilder.subobjStart("lastCommittedOp")); + lastCommittedOp.append("ts", _lastOplogEntry.getTimestamp()); + lastCommittedOp.append("term", _lastOplogEntry.getTerm()); + lastCommittedOp.done(); + + const BSONObj requestVotesCmd = requestVotesCmdBuilder.obj(); + + std::vector<RemoteCommandRequest> requests; + for (const auto& target : _targets) { + requests.push_back(RemoteCommandRequest( + target, + "admin", + requestVotesCmd, + Milliseconds(30 * 1000))); // trying to match current Socket timeout } - void VoteRequester::Algorithm::processResponse( - const RemoteCommandRequest& request, - const ResponseStatus& response) { - _responsesProcessed++; - if (!response.isOK()) { // failed response - log() << "VoteRequester: Got failed response from " << request.target - << ": " << response.getStatus(); - } - else { - ReplSetRequestVotesResponse voteResponse; - voteResponse.initialize(response.getValue().data); - if (voteResponse.getVoteGranted()) { - _votes++; - } - else { - log() << "VoteRequester: Got no vote from " << request.target - << " because: " << voteResponse.getReason(); - } - - if (voteResponse.getTerm() > _term) { - _staleTerm = true; - } + return requests; +} + +void VoteRequester::Algorithm::processResponse(const RemoteCommandRequest& request, + const ResponseStatus& response) { + _responsesProcessed++; + if (!response.isOK()) { // failed response + log() << "VoteRequester: Got failed response from " << request.target << ": " + << response.getStatus(); + } else { + ReplSetRequestVotesResponse voteResponse; + voteResponse.initialize(response.getValue().data); + if (voteResponse.getVoteGranted()) { + _votes++; + } else { + log() << "VoteRequester: Got no vote from " << request.target + << " because: " << voteResponse.getReason(); } - } - bool VoteRequester::Algorithm::hasReceivedSufficientResponses() const { - return _staleTerm || - _votes == _rsConfig.getMajorityVoteCount() || - _responsesProcessed == static_cast<int>(_targets.size()); - } - - VoteRequester::VoteRequestResult VoteRequester::Algorithm::getResult() const { - if (_staleTerm) { - return StaleTerm; - } - else if (_votes >= _rsConfig.getMajorityVoteCount()) { - return SuccessfullyElected; + if (voteResponse.getTerm() > _term) { + _staleTerm = true; } - else { - return InsufficientVotes; - } - } - - VoteRequester::VoteRequester() : _isCanceled(false) {} - VoteRequester::~VoteRequester() {} - - StatusWith<ReplicationExecutor::EventHandle> VoteRequester::start( - ReplicationExecutor* executor, - const ReplicaSetConfig& rsConfig, - long long candidateId, - long long term, - bool dryRun, - OpTime lastOplogEntry, - const stdx::function<void ()>& onCompletion) { - - _algorithm.reset(new Algorithm(rsConfig, - candidateId, - term, - dryRun, - lastOplogEntry)); - _runner.reset(new ScatterGatherRunner(_algorithm.get())); - return _runner->start(executor, onCompletion); } - - void VoteRequester::cancel(ReplicationExecutor* executor) { - _isCanceled = true; - _runner->cancel(executor); +} + +bool VoteRequester::Algorithm::hasReceivedSufficientResponses() const { + return _staleTerm || _votes == _rsConfig.getMajorityVoteCount() || + _responsesProcessed == static_cast<int>(_targets.size()); +} + +VoteRequester::VoteRequestResult VoteRequester::Algorithm::getResult() const { + if (_staleTerm) { + return StaleTerm; + } else if (_votes >= _rsConfig.getMajorityVoteCount()) { + return SuccessfullyElected; + } else { + return InsufficientVotes; } - - VoteRequester::VoteRequestResult VoteRequester::getResult() const { - return _algorithm->getResult(); - } - -} // namespace repl -} // namespace mongo +} + +VoteRequester::VoteRequester() : _isCanceled(false) {} +VoteRequester::~VoteRequester() {} + +StatusWith<ReplicationExecutor::EventHandle> VoteRequester::start( + ReplicationExecutor* executor, + const ReplicaSetConfig& rsConfig, + long long candidateId, + long long term, + bool dryRun, + OpTime lastOplogEntry, + const stdx::function<void()>& onCompletion) { + _algorithm.reset(new Algorithm(rsConfig, candidateId, term, dryRun, lastOplogEntry)); + _runner.reset(new ScatterGatherRunner(_algorithm.get())); + return _runner->start(executor, onCompletion); +} + +void VoteRequester::cancel(ReplicationExecutor* executor) { + _isCanceled = true; + _runner->cancel(executor); +} + +VoteRequester::VoteRequestResult VoteRequester::getResult() const { + return _algorithm->getResult(); +} + +} // namespace repl +} // namespace mongo |