summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2016-07-28 18:10:31 -0400
committerAndy Schwerin <schwerin@mongodb.com>2016-08-12 16:10:37 -0400
commit6b566f73f49bc936f47e7bffc139d400924fea9b (patch)
tree7b60b867e2ee155c9de03069ea506fe63d8f9b2c
parent42ae7ce8eb214f9d5b0db1e534cbf68059945ac7 (diff)
downloadmongo-6b566f73f49bc936f47e7bffc139d400924fea9b.tar.gz
SERVER-25166 Put more information in log messages when a node receives a vote, log on yes votes as well as no.
-rw-r--r--src/mongo/db/repl/vote_requester.cpp42
-rw-r--r--src/mongo/db/repl/vote_requester_test.cpp32
2 files changed, 37 insertions, 37 deletions
diff --git a/src/mongo/db/repl/vote_requester.cpp b/src/mongo/db/repl/vote_requester.cpp
index 4f710827884..ad7b4594e71 100644
--- a/src/mongo/db/repl/vote_requester.cpp
+++ b/src/mongo/db/repl/vote_requester.cpp
@@ -90,32 +90,32 @@ std::vector<RemoteCommandRequest> VoteRequester::Algorithm::getRequests() const
void VoteRequester::Algorithm::processResponse(const RemoteCommandRequest& request,
const ResponseStatus& response) {
+ auto logLine = log();
+ logLine << "VoteRequester(term " << _term << (_dryRun ? " dry run" : "") << ") ";
_responsesProcessed++;
if (!response.isOK()) { // failed response
- log() << "VoteRequester: Got failed response from " << request.target << ": "
- << response.status;
- } else {
- _responders.insert(request.target);
- ReplSetRequestVotesResponse voteResponse;
- const auto status = voteResponse.initialize(response.data);
- if (!status.isOK()) {
- log() << "VoteRequester: Got error processing response with status: " << status
- << ", resp:" << response.data;
- }
+ logLine << "failed to receive response from " << request.target << ": " << response.status;
+ return;
+ }
+ _responders.insert(request.target);
+ ReplSetRequestVotesResponse voteResponse;
+ const auto status = voteResponse.initialize(response.data);
+ if (!status.isOK()) {
+ logLine << "received an invalid response from " << request.target << ": " << status;
+ }
- if (voteResponse.getVoteGranted()) {
- LOG(3) << "VoteRequester: Got yes vote from " << request.target
- << ", resp:" << response.data;
- _votes++;
- } else {
- log() << "VoteRequester: Got no vote from " << request.target
- << " because: " << voteResponse.getReason() << ", resp:" << response.data;
- }
+ if (voteResponse.getVoteGranted()) {
+ logLine << "received a yes vote from " << request.target;
+ _votes++;
+ } else {
+ logLine << "received a no vote from " << request.target << " with reason \""
+ << voteResponse.getReason() << '"';
+ }
- if (voteResponse.getTerm() > _term) {
- _staleTerm = true;
- }
+ if (voteResponse.getTerm() > _term) {
+ _staleTerm = true;
}
+ logLine << "; response message: " << response.data;
}
bool VoteRequester::Algorithm::hasReceivedSufficientResponses() const {
diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp
index 799fff1817c..8b158609fea 100644
--- a/src/mongo/db/repl/vote_requester_test.cpp
+++ b/src/mongo/db/repl/vote_requester_test.cpp
@@ -241,7 +241,7 @@ TEST_F(VoteRequesterTest, BadConfigVersionWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseConfigVersionDoesNotMatch());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -254,7 +254,7 @@ TEST_F(VoteRequesterTest, SetNameDiffersWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -267,7 +267,7 @@ TEST_F(VoteRequesterTest, LastOpTimeIsGreaterWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -280,7 +280,7 @@ TEST_F(VoteRequesterTest, FailedToContactWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), badResponseStatus());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got failed response from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -293,7 +293,7 @@ TEST_F(VoteRequesterTest, AlreadyVotedWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseAlreadyVoted());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -305,7 +305,7 @@ TEST_F(VoteRequesterTest, StaleTermLoseElection) {
startCapturingLogMessages();
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseTermIsGreater());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kStaleTerm == getResult());
ASSERT_EQUALS(1, getNumResponders());
@@ -317,9 +317,9 @@ TEST_F(VoteRequesterTest, NotEnoughVotesLoseElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), badResponseStatus());
- ASSERT_EQUALS(1, countLogLinesContaining("Got failed response from host2"));
+ ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host2:27017"));
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kInsufficientVotes == getResult());
ASSERT_EQUALS(1, getNumResponders());
@@ -339,7 +339,7 @@ TEST_F(VoteRequesterDryRunTest, BadConfigVersionWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseConfigVersionDoesNotMatch());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -352,7 +352,7 @@ TEST_F(VoteRequesterDryRunTest, SetNameDiffersWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -365,7 +365,7 @@ TEST_F(VoteRequesterDryRunTest, LastOpTimeIsGreaterWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -378,7 +378,7 @@ TEST_F(VoteRequesterDryRunTest, FailedToContactWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), badResponseStatus());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got failed response from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -391,7 +391,7 @@ TEST_F(VoteRequesterDryRunTest, AlreadyVotedWinElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseAlreadyVoted());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), votedYes());
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult());
@@ -403,7 +403,7 @@ TEST_F(VoteRequesterDryRunTest, StaleTermLoseElection) {
startCapturingLogMessages();
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseTermIsGreater());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kStaleTerm == getResult());
ASSERT_EQUALS(1, getNumResponders());
@@ -415,9 +415,9 @@ TEST_F(VoteRequesterDryRunTest, NotEnoughVotesLoseElection) {
ASSERT_FALSE(hasReceivedSufficientResponses());
processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers());
ASSERT_FALSE(hasReceivedSufficientResponses());
- ASSERT_EQUALS(1, countLogLinesContaining("Got no vote from host1"));
+ ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017"));
processResponse(requestFrom("host2"), badResponseStatus());
- ASSERT_EQUALS(1, countLogLinesContaining("Got failed response from host2"));
+ ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host2:27017"));
ASSERT_TRUE(hasReceivedSufficientResponses());
ASSERT(VoteRequester::Result::kInsufficientVotes == getResult());
ASSERT_EQUALS(1, getNumResponders());