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 { _responders.insert(request.target); ReplSetRequestVotesResponse voteResponse; const auto status = voteResponse.initialize(response.getValue().data); if (!status.isOK()) { log() << "VoteRequester: Got error processing response with status: " << status << ", resp:" << response.getValue().data; } if (voteResponse.getVoteGranted()) { LOG(3) << "VoteRequester: Got yes vote from " << request.target << ", resp:" << response.getValue().data; _votes++; } else { log() << "VoteRequester: Got no vote from " << request.target << " because: " << voteResponse.getReason() << ", resp:" << response.getValue().data; } if (voteResponse.getTerm() > _term) { _staleTerm = true; } } }
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; } } }
void VoteRequester::Algorithm::processResponse(const RemoteCommandRequest& request, const RemoteCommandResponse& response) { auto logLine = log(); logLine << "VoteRequester(term " << _term << (_dryRun ? " dry run" : "") << ") "; _responsesProcessed++; if (!response.isOK()) { // failed response logLine << "failed to receive response from " << request.target << ": " << response.status; return; } _responders.insert(request.target); // If the primary's vote is a yes, we will set _primaryVote to be Yes. if (_primaryHost == request.target) { _primaryVote = PrimaryVote::No; } ReplSetRequestVotesResponse voteResponse; auto status = getStatusFromCommandResult(response.data); if (status.isOK()) { status = voteResponse.initialize(response.data); } if (!status.isOK()) { logLine << "received an invalid response from " << request.target << ": " << status; logLine << "; response message: " << response.data; return; } if (voteResponse.getVoteGranted()) { logLine << "received a yes vote from " << request.target; if (_primaryHost == request.target) { _primaryVote = PrimaryVote::Yes; } _votes++; } else { logLine << "received a no vote from " << request.target << " with reason \"" << voteResponse.getReason() << '"'; } if (voteResponse.getTerm() > _term) { _staleTerm = true; } logLine << "; response message: " << response.data; }
bool run(OperationContext* opCtx, const std::string&, const BSONObj& cmdObj, BSONObjBuilder& result) final { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) { return appendCommandStatus(result, status); } ReplSetRequestVotesArgs parsedArgs; status = parsedArgs.initialize(cmdObj); if (!status.isOK()) { return appendCommandStatus(result, status); } // We want to keep request vote connection open when relinquishing primary. // Tag it here. transport::Session::TagMask originalTag = 0; auto session = opCtx->getClient()->session(); if (session) { originalTag = session->getTags(); session->replaceTags(originalTag | transport::Session::kKeepOpen); } // Untag the connection on exit. ON_BLOCK_EXIT([session, originalTag]() { if (session) { session->replaceTags(originalTag); } }); ReplSetRequestVotesResponse response; status = getGlobalReplicationCoordinator()->processReplSetRequestVotes( opCtx, parsedArgs, &response); response.addToBSON(&result); return appendCommandStatus(result, status); }