diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2019-02-20 11:48:40 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2019-02-21 13:59:05 -0500 |
commit | 9cf0e378392c2c45131602e45b9ee9c2dc6c28bd (patch) | |
tree | e48d9d3258fa3299156f567262d5c887e9565dcd /src/mongo/db/repl | |
parent | 2d94abc280fc57cd1417776dd8431149eca05615 (diff) | |
download | mongo-9cf0e378392c2c45131602e45b9ee9c2dc6c28bd.tar.gz |
SERVER-39473 Should not report isMaster while stepping down conditionally
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.cpp | 2 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 8ccb4e7747d..c98aaaa0254 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -2440,8 +2440,7 @@ TEST_F(StepDownTest, UnconditionalStepDownFailsStepDownCommand) { } // Test that if a stepdown command is blocked waiting for secondaries to catch up when an -// unconditional stepdown happens, and then is interrupted, we stay stepped down, even though -// normally if we were just interrupted we would step back up. +// unconditional stepdown happens, and then is interrupted, we step back up. TEST_F(StepDownTest, InterruptingStepDownCommandRestoresWriteAvailability) { OpTime optime1(Timestamp(100, 1), 1); OpTime optime2(Timestamp(100, 2), 1); @@ -2463,6 +2462,12 @@ TEST_F(StepDownTest, InterruptingStepDownCommandRestoresWriteAvailability) { // We should still be primary at this point ASSERT_TRUE(getReplCoord()->getMemberState().primary()); + // We should not indicate that we are master, nor that we are secondary. + IsMasterResponse response; + getReplCoord()->fillIsMasterForReplSet(&response); + ASSERT_FALSE(response.isMaster()); + ASSERT_FALSE(response.isSecondary()); + // Interrupt the ongoing stepdown command. { stdx::lock_guard<Client> lk(*result.first.client.get()); @@ -2473,8 +2478,13 @@ TEST_F(StepDownTest, InterruptingStepDownCommandRestoresWriteAvailability) { ASSERT_EQUALS(*result.second.get(), ErrorCodes::Interrupted); ASSERT_TRUE(getReplCoord()->getMemberState().primary()); - // This is the important check, that we didn't accidentally step back up when aborting the - // stepdown command attempt. + // We should now report that we are master. + getReplCoord()->fillIsMasterForReplSet(&response); + ASSERT_TRUE(response.isMaster()); + ASSERT_FALSE(response.isSecondary()); + + // This is the important check, that we stepped back up when aborting the stepdown command + // attempt. const auto opCtx = makeOperationContext(); Lock::GlobalLock lock(opCtx.get(), MODE_IX); ASSERT_TRUE(getReplCoord()->canAcceptWritesForDatabase(opCtx.get(), "admin")); @@ -2504,6 +2514,12 @@ TEST_F(StepDownTest, InterruptingAfterUnconditionalStepdownDoesNotRestoreWriteAv // We should still be primary at this point ASSERT_TRUE(getReplCoord()->getMemberState().primary()); + // We should not indicate that we are master, nor that we are secondary. + IsMasterResponse response; + getReplCoord()->fillIsMasterForReplSet(&response); + ASSERT_FALSE(response.isMaster()); + ASSERT_FALSE(response.isSecondary()); + // Interrupt the ongoing stepdown command. { stdx::lock_guard<Client> lk(*result.first.client.get()); @@ -2524,6 +2540,10 @@ TEST_F(StepDownTest, InterruptingAfterUnconditionalStepdownDoesNotRestoreWriteAv stepDownStatus == ErrorCodes::Interrupted); ASSERT_TRUE(getReplCoord()->getMemberState().secondary()); + // We should still be indicating that we are not master. + getReplCoord()->fillIsMasterForReplSet(&response); + ASSERT_FALSE(response.isMaster()); + // This is the important check, that we didn't accidentally step back up when aborting the // stepdown command attempt. Lock::GlobalLock lock(opCtx.get(), MODE_IX); diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index 46165018ce7..667ecfb545c 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -1720,7 +1720,7 @@ void TopologyCoordinator::fillIsMasterForReplSet(IsMasterResponse* response) { // "ismaster" is false if we are not primary. If we're stepping down, we're waiting for the // Replication State Transition Lock before we can change to secondary, but we should report // "ismaster" false to indicate that we can't accept new writes. - response->setIsMaster(myState.primary() && _leaderMode != LeaderMode::kSteppingDown); + response->setIsMaster(myState.primary() && !isSteppingDown()); response->setIsSecondary(myState.secondary()); const MemberConfig* curPrimary = _currentPrimaryMember(); |