diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2017-08-04 21:55:14 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2017-08-07 02:48:52 -0400 |
commit | d90fcb7446cd6b68273f588c67a41b98d5c38268 (patch) | |
tree | 0b7f0929830560b04a4fef5f5d750ff128accf76 /src/mongo/db/repl/vote_requester_test.cpp | |
parent | c6f9f146b15b6f84613ee5f6b97572c6f9f5a1ba (diff) | |
download | mongo-d90fcb7446cd6b68273f588c67a41b98d5c38268.tar.gz |
SERVER-29502 Require the vote from the current primary in the dry run for catchup takeover
This reverts commit 1ba6539b20a55378b4ecab2ab4f9281db25bc313.
Diffstat (limited to 'src/mongo/db/repl/vote_requester_test.cpp')
-rw-r--r-- | src/mongo/db/repl/vote_requester_test.cpp | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp index e3edf89fe6c..04142a340a3 100644 --- a/src/mongo/db/repl/vote_requester_test.cpp +++ b/src/mongo/db/repl/vote_requester_test.cpp @@ -89,7 +89,8 @@ public: candidateId, term, false, // not a dryRun - lastOplogEntry)); + lastOplogEntry, + -1)); } virtual void tearDown() { @@ -218,7 +219,42 @@ public: candidateId, term, true, // dryRun - lastOplogEntry)); + lastOplogEntry, + -1)); + } +}; + +class VoteRequesterCatchupTakeoverDryRunTest : public VoteRequesterTest { +public: + virtual void setUp() { + ReplSetConfig config; + ASSERT_OK(config.initialize(BSON("_id" + << "rs0" + << "version" + << 2 + << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "host0") + << BSON("_id" << 1 << "host" + << "host1") + << BSON("_id" << 2 << "host" + << "host2") + << BSON("_id" << 3 << "host" + << "host3") + << BSON("_id" << 4 << "host" + << "host4"))))); + ASSERT_OK(config.validate()); + long long candidateId = 0; + long long term = 2; + int primaryIndex = 1; + OpTime lastOplogEntry = OpTime(Timestamp(999, 0), 1); + + _requester.reset(new VoteRequester::Algorithm(config, + candidateId, + term, + true, // dryRun + lastOplogEntry, + primaryIndex)); } }; @@ -418,6 +454,49 @@ TEST_F(VoteRequesterDryRunTest, NotEnoughVotesLoseElection) { stopCapturingLogMessages(); } +TEST_F(VoteRequesterCatchupTakeoverDryRunTest, CatchupTakeoverPrimarySaysYesWinElection) { + ASSERT_FALSE(hasReceivedSufficientResponses()); + processResponse(requestFrom("host1"), votedYes()); + processResponse(requestFrom("host2"), votedYes()); + ASSERT_TRUE(hasReceivedSufficientResponses()); + ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); + ASSERT_EQUALS(2, getNumResponders()); +} + +TEST_F(VoteRequesterCatchupTakeoverDryRunTest, CatchupTakeoverPrimarySaysYesButNotEnoughVotes) { + ASSERT_FALSE(hasReceivedSufficientResponses()); + processResponse(requestFrom("host1"), votedYes()); + ASSERT(VoteRequester::Result::kInsufficientVotes == getResult()); + processResponse(requestFrom("host2"), votedNoBecauseLastOpTimeIsGreater()); + processResponse(requestFrom("host3"), votedNoBecauseLastOpTimeIsGreater()); + processResponse(requestFrom("host4"), votedNoBecauseLastOpTimeIsGreater()); + ASSERT_TRUE(hasReceivedSufficientResponses()); + ASSERT(VoteRequester::Result::kInsufficientVotes == getResult()); + ASSERT_EQUALS(4, getNumResponders()); +} + +TEST_F(VoteRequesterCatchupTakeoverDryRunTest, CatchupTakeoverPrimarySaysNoLoseElection) { + startCapturingLogMessages(); + ASSERT_FALSE(hasReceivedSufficientResponses()); + processResponse(requestFrom("host2"), votedYes()); + processResponse(requestFrom("host3"), votedYes()); + + // This covers the case that the Vote Requester is cancelled partway through + // the dry run before the primary responded. + ASSERT(VoteRequester::Result::kPrimaryRespondedNo == getResult()); + + // It also tests that even if a majority of yes votes have already been received, + // it still needs to wait for a yes response from the primary. + ASSERT_FALSE(hasReceivedSufficientResponses()); + + processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater()); + ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_TRUE(hasReceivedSufficientResponses()); + ASSERT(VoteRequester::Result::kPrimaryRespondedNo == getResult()); + ASSERT_EQUALS(3, getNumResponders()); + stopCapturingLogMessages(); +} + } // namespace } // namespace repl } // namespace mongo |