summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishnu Kaushik <vishnu.kaushik@mongodb.com>2021-06-22 21:52:00 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-23 14:28:14 +0000
commitfccf8ac6de56efaadea73a659b8b5ada12844a04 (patch)
treeb562f98945a7e81a680968135cf292df2872e9dc
parent229ddfbd1e5d235e726f2e47d923231e6a9187f7 (diff)
downloadmongo-fccf8ac6de56efaadea73a659b8b5ada12844a04.tar.gz
SERVER-55589 setMaintenanceMode should take RSTL in X mode
-rw-r--r--jstests/replsets/maintenance_non-blocking.js54
-rw-r--r--src/mongo/db/commands/compact.cpp3
-rw-r--r--src/mongo/db/repl/bgsync.cpp6
-rw-r--r--src/mongo/db/repl/repl_set_commands.cpp2
-rw-r--r--src/mongo/db/repl/replication_coordinator.h7
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp10
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h2
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp55
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.cpp2
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.h2
-rw-r--r--src/mongo/db/repl/replication_coordinator_noop.cpp2
-rw-r--r--src/mongo/db/repl/replication_coordinator_noop.h2
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp5
-rw-r--r--src/mongo/db/repl/topology_coordinator.h5
-rw-r--r--src/mongo/db/service_entry_point_common.cpp40
-rw-r--r--src/mongo/embedded/replication_coordinator_embedded.cpp2
-rw-r--r--src/mongo/embedded/replication_coordinator_embedded.h2
17 files changed, 63 insertions, 138 deletions
diff --git a/jstests/replsets/maintenance_non-blocking.js b/jstests/replsets/maintenance_non-blocking.js
deleted file mode 100644
index d2936c7b4a5..00000000000
--- a/jstests/replsets/maintenance_non-blocking.js
+++ /dev/null
@@ -1,54 +0,0 @@
-// This test ensures that the replSetMaintenance command will not block, nor block-on, a db write
-doTest = function() {
- "use strict";
- var replTest = new ReplSetTest({name: 'testSet', nodes: 2});
- var nodes = replTest.startSet();
- replTest.initiate();
-
- var m = replTest.getPrimary();
- var mColl = m.getDB("test").maint;
- var s = replTest.getSecondary();
- var sDB = s.getDB("test");
- var sColl = sDB.maint;
-
- // The default WC is majority and fsyncLock will prevent satisfying any majority writes.
- assert.commandWorked(replTest.getPrimary().adminCommand(
- {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}));
-
- var status = assert.commandWorked(sDB.adminCommand("replSetGetStatus"));
- printjson(status);
-
- print("******* fsyncLock'n secondary ************* ");
- s.getDB("admin").fsyncLock();
-
- // save some records
- var len = 100;
- for (var i = 0; i < len; ++i) {
- assert.commandWorked(mColl.save({a: i}));
- }
-
- print("******* replSetMaintenance called on secondary ************* ");
- assert.commandWorked(sDB.adminCommand("replSetMaintenance"));
-
- var hello = assert.commandWorked(sColl.runCommand("hello"));
- assert.eq(false, hello.isWritablePrimary);
- assert.eq(false, hello.secondary);
-
- print("******* writing to primary ************* ");
- assert.commandWorked(mColl.save({_id: -1}));
- assert.neq(null, mColl.findOne());
-
- var hello = assert.commandWorked(sColl.runCommand("hello"));
- assert.eq(false, hello.isWritablePrimary);
- assert.eq(false, hello.secondary);
-
- print("******* fsyncUnlock'n secondary ************* ");
- sDB.fsyncUnlock();
-
- print("******* unset replSetMaintenance on secondary ************* ");
- assert.commandWorked(sDB.adminCommand({replSetMaintenance: 0}));
- replTest.stopSet();
-};
-
-doTest();
-print("SUCCESS");
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp
index 0eede8c5c2c..ca5e15affa9 100644
--- a/src/mongo/db/commands/compact.cpp
+++ b/src/mongo/db/commands/compact.cpp
@@ -59,9 +59,6 @@ public:
AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
return AllowedOnSecondary::kAlways;
}
- virtual bool maintenanceMode() const {
- return true;
- }
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) const {
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index c3b51e891c4..fa454a38619 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -377,7 +377,7 @@ void BackgroundSync::_produce() {
"earliestOpTimeSeen"_attr = syncSourceResp.earliestOpTimeSeen);
// Activate maintenance mode and transition to RECOVERING.
- auto status = _replCoord->setMaintenanceMode(true);
+ auto status = _replCoord->setMaintenanceMode(opCtx.get(), true);
if (!status.isOK()) {
LOGV2_WARNING(21116,
"Failed to transition into maintenance mode: {error}",
@@ -459,7 +459,9 @@ void BackgroundSync::_produce() {
"No longer too stale. Able to sync from {syncSource}",
"No longer too stale. Able to start syncing",
"syncSource"_attr = source);
- auto status = _replCoord->setMaintenanceMode(false);
+
+ auto opCtx = cc().makeOperationContext();
+ auto status = _replCoord->setMaintenanceMode(opCtx.get(), false);
if (!status.isOK()) {
LOGV2_WARNING(21118,
"Failed to leave maintenance mode: {error}",
diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp
index bab337d9109..135bdd13614 100644
--- a/src/mongo/db/repl/repl_set_commands.cpp
+++ b/src/mongo/db/repl/repl_set_commands.cpp
@@ -594,7 +594,7 @@ public:
uassertStatusOK(status);
uassertStatusOK(ReplicationCoordinator::get(opCtx)->setMaintenanceMode(
- cmdObj["replSetMaintenance"].trueValue()));
+ opCtx, cmdObj["replSetMaintenance"].trueValue()));
return true;
}
diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h
index f65a26ccb7d..fcb9d2a44d0 100644
--- a/src/mongo/db/repl/replication_coordinator.h
+++ b/src/mongo/db/repl/replication_coordinator.h
@@ -738,9 +738,12 @@ public:
/**
* Toggles maintenanceMode to the value expressed by 'activate'
* return Status::OK if the change worked, NotSecondary if it failed because we are
- * PRIMARY, and OperationFailed if we are not currently in maintenance mode
+ * PRIMARY, and OperationFailed if we are not currently in maintenance mode.
+ *
+ * Takes the ReplicationStateTransitionLock (RSTL) in X mode, since the state can potentially
+ * change to and from RECOVERING.
*/
- virtual Status setMaintenanceMode(bool activate) = 0;
+ virtual Status setMaintenanceMode(OperationContext* opCtx, bool activate) = 0;
/**
* Retrieves the current count of maintenanceMode and returns 'true' if greater than 0.
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index ec79e107684..590d019ee35 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -754,11 +754,8 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
const auto lastApplied = opTimeStatus.getValue();
_setMyLastAppliedOpTimeAndWallTime(lock, lastApplied, false);
- }
- // Clear maint. mode.
- while (getMaintenanceMode()) {
- setMaintenanceMode(false).transitional_ignore();
+ _topCoord->resetMaintenanceCount();
}
if (startCompleted) {
@@ -3168,12 +3165,15 @@ bool ReplicationCoordinatorImpl::getMaintenanceMode() {
return _topCoord->getMaintenanceCount() > 0;
}
-Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) {
+Status ReplicationCoordinatorImpl::setMaintenanceMode(OperationContext* opCtx, bool activate) {
if (getReplicationMode() != modeReplSet) {
return Status(ErrorCodes::NoReplicationEnabled,
"can only set maintenance mode on replica set members");
}
+ // It is possible that we change state to or from RECOVERING. Thus, we need the RSTL in X mode.
+ ReplicationStateTransitionLockGuard transitionGuard(opCtx, MODE_X);
+
stdx::unique_lock<Latch> lk(_mutex);
if (_topCoord->getRole() == TopologyCoordinator::Role::kCandidate ||
MONGO_unlikely(setMaintenanceModeFailsWithNotSecondary.shouldFail())) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index 00a35685df0..5c7ec29b3dd 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -266,7 +266,7 @@ public:
virtual void cancelAndRescheduleElectionTimeout() override;
- virtual Status setMaintenanceMode(bool activate) override;
+ virtual Status setMaintenanceMode(OperationContext* opCtx, bool activate) override;
virtual bool getMaintenanceMode() override;
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index ce1896fe4a0..512bc420508 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -2508,7 +2508,7 @@ TEST_F(
// Go into maintenance mode.
ASSERT_EQUALS(0, getTopoCoord().getMaintenanceCount());
ASSERT_FALSE(getReplCoord()->getMaintenanceMode());
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
ASSERT_EQUALS(1, getTopoCoord().getMaintenanceCount());
ASSERT_TRUE(getReplCoord()->getMaintenanceMode());
@@ -2947,8 +2947,10 @@ TEST_F(ReplCoordTest,
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
+ const auto opCtx = makeOperationContext();
+
// Can't unset maintenance mode if it was never set to begin with.
- Status status = getReplCoord()->setMaintenanceMode(false);
+ Status status = getReplCoord()->setMaintenanceMode(opCtx.get(), false);
ASSERT_EQUALS(ErrorCodes::OperationFailed, status);
ASSERT_TRUE(getReplCoord()->getMemberState().secondary());
}
@@ -2969,12 +2971,14 @@ TEST_F(ReplCoordTest,
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
+
+ const auto opCtx = makeOperationContext();
+
// valid set
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
ASSERT_TRUE(getReplCoord()->getMemberState().recovering());
// We must take the RSTL in mode X before transitioning to RS_ROLLBACK.
- const auto opCtx = makeOperationContext();
ReplicationStateTransitionLockGuard transitionGuard(opCtx.get(), MODE_X);
// If we go into rollback while in maintenance mode, our state changes to RS_ROLLBACK.
@@ -2998,17 +3002,21 @@ TEST_F(ReplCoordTest, AllowAsManyUnsetMaintenanceModesAsThereHaveBeenSetMaintena
<< BSON("_id" << 2 << "host"
<< "test3:1234"))),
HostAndPort("test2", 1234));
+
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
replCoordSetMyLastAppliedOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
replCoordSetMyLastDurableOpTime(OpTimeWithTermOne(100, 1), Date_t() + Seconds(100));
+
+ const auto opCtx = makeOperationContext();
+
// Can set multiple times
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
// Need to unset the number of times you set.
- ASSERT_OK(getReplCoord()->setMaintenanceMode(false));
- ASSERT_OK(getReplCoord()->setMaintenanceMode(false));
- Status status = getReplCoord()->setMaintenanceMode(false);
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), false));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), false));
+ Status status = getReplCoord()->setMaintenanceMode(opCtx.get(), false);
// third one fails b/c we only set two times.
ASSERT_EQUALS(ErrorCodes::OperationFailed, status);
// Unsetting maintenance mode changes our state to secondary if maintenance mode was
@@ -3040,19 +3048,19 @@ TEST_F(ReplCoordTest, SettingAndUnsettingMaintenanceModeShouldNotAffectRollbackS
// state.
ASSERT_OK(getReplCoord()->setFollowerModeRollback(opCtx.get()));
ASSERT_TRUE(getReplCoord()->getMemberState().rollback());
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
ASSERT_TRUE(getReplCoord()->getMemberState().rollback());
- ASSERT_OK(getReplCoord()->setMaintenanceMode(false));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), false));
ASSERT_TRUE(getReplCoord()->getMemberState().rollback());
// Rollback is sticky even if entered while in maintenance mode.
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
ASSERT_TRUE(getReplCoord()->getMemberState().secondary());
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
ASSERT_TRUE(getReplCoord()->getMemberState().recovering());
ASSERT_OK(getReplCoord()->setFollowerModeRollback(opCtx.get()));
ASSERT_TRUE(getReplCoord()->getMemberState().rollback());
- ASSERT_OK(getReplCoord()->setMaintenanceMode(false));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), false));
ASSERT_TRUE(getReplCoord()->getMemberState().rollback());
ASSERT_OK(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY));
ASSERT_TRUE(getReplCoord()->getMemberState().secondary());
@@ -3076,21 +3084,20 @@ TEST_F(ReplCoordTest, DoNotAllowMaintenanceModeWhilePrimary) {
// Can't modify maintenance mode when PRIMARY
simulateSuccessfulV1Election();
- Status status = getReplCoord()->setMaintenanceMode(true);
- ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
- ASSERT_TRUE(getReplCoord()->getMemberState().primary());
-
auto opCtx = makeOperationContext();
+ Status status = getReplCoord()->setMaintenanceMode(opCtx.get(), true);
+ ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
+ ASSERT_TRUE(getReplCoord()->getMemberState().primary());
// Step down from primary.
getReplCoord()->updateTerm(opCtx.get(), getReplCoord()->getTerm() + 1).transitional_ignore();
ASSERT_OK(getReplCoord()->waitForMemberState(MemberState::RS_SECONDARY, Seconds(1)));
- status = getReplCoord()->setMaintenanceMode(false);
+ status = getReplCoord()->setMaintenanceMode(opCtx.get(), false);
ASSERT_EQUALS(ErrorCodes::OperationFailed, status);
- ASSERT_OK(getReplCoord()->setMaintenanceMode(true));
- ASSERT_OK(getReplCoord()->setMaintenanceMode(false));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), true));
+ ASSERT_OK(getReplCoord()->setMaintenanceMode(opCtx.get(), false));
}
TEST_F(ReplCoordTest, DoNotAllowSettingMaintenanceModeWhileConductingAnElection) {
@@ -3136,16 +3143,16 @@ TEST_F(ReplCoordTest, DoNotAllowSettingMaintenanceModeWhileConductingAnElection)
ASSERT_EQUALS(when, net->now());
net->exitNetwork();
ASSERT_EQUALS(TopologyCoordinator::Role::kCandidate, getTopoCoord().getRole());
- Status status = getReplCoord()->setMaintenanceMode(false);
+ Status status = getReplCoord()->setMaintenanceMode(opCtx.get(), false);
ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
- status = getReplCoord()->setMaintenanceMode(true);
+ status = getReplCoord()->setMaintenanceMode(opCtx.get(), true);
ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
simulateSuccessfulDryRun();
ASSERT_EQUALS(TopologyCoordinator::Role::kCandidate, getTopoCoord().getRole());
- status = getReplCoord()->setMaintenanceMode(false);
+ status = getReplCoord()->setMaintenanceMode(opCtx.get(), false);
ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
- status = getReplCoord()->setMaintenanceMode(true);
+ status = getReplCoord()->setMaintenanceMode(opCtx.get(), true);
ASSERT_EQUALS(ErrorCodes::NotSecondary, status);
// We must take the RSTL in mode X before transitioning to RS_ROLLBACK.
diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp
index 9271531772e..c0743251410 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.cpp
+++ b/src/mongo/db/repl/replication_coordinator_mock.cpp
@@ -466,7 +466,7 @@ void ReplicationCoordinatorMock::appendSecondaryInfoData(BSONObjBuilder* result)
void ReplicationCoordinatorMock::appendConnectionStats(executor::ConnectionPoolStats* stats) const {
}
-Status ReplicationCoordinatorMock::setMaintenanceMode(bool activate) {
+Status ReplicationCoordinatorMock::setMaintenanceMode(OperationContext* opCtx, bool activate) {
return Status::OK();
}
diff --git a/src/mongo/db/repl/replication_coordinator_mock.h b/src/mongo/db/repl/replication_coordinator_mock.h
index 7a9df246def..74cf6bad540 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.h
+++ b/src/mongo/db/repl/replication_coordinator_mock.h
@@ -233,7 +233,7 @@ public:
virtual void cancelAndRescheduleElectionTimeout() override;
- virtual Status setMaintenanceMode(bool activate);
+ virtual Status setMaintenanceMode(OperationContext* opCtx, bool activate);
virtual bool getMaintenanceMode();
diff --git a/src/mongo/db/repl/replication_coordinator_noop.cpp b/src/mongo/db/repl/replication_coordinator_noop.cpp
index 44a3f49acbb..63cd0785f1d 100644
--- a/src/mongo/db/repl/replication_coordinator_noop.cpp
+++ b/src/mongo/db/repl/replication_coordinator_noop.cpp
@@ -361,7 +361,7 @@ void ReplicationCoordinatorNoOp::cancelAndRescheduleElectionTimeout() {
MONGO_UNREACHABLE;
}
-Status ReplicationCoordinatorNoOp::setMaintenanceMode(bool) {
+Status ReplicationCoordinatorNoOp::setMaintenanceMode(OperationContext*, bool) {
MONGO_UNREACHABLE;
}
diff --git a/src/mongo/db/repl/replication_coordinator_noop.h b/src/mongo/db/repl/replication_coordinator_noop.h
index 72ec99fbee5..85ca9de0a2a 100644
--- a/src/mongo/db/repl/replication_coordinator_noop.h
+++ b/src/mongo/db/repl/replication_coordinator_noop.h
@@ -208,7 +208,7 @@ public:
void cancelAndRescheduleElectionTimeout() final;
- Status setMaintenanceMode(bool) final;
+ Status setMaintenanceMode(OperationContext*, bool) final;
Status processReplSetSyncFrom(OperationContext*, const HostAndPort&, BSONObjBuilder*) final;
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index 8a8cde6e5ff..b8f3b0abccb 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -2961,6 +2961,11 @@ void TopologyCoordinator::adjustMaintenanceCountBy(int inc) {
invariant(_maintenanceModeCalls >= 0);
}
+void TopologyCoordinator::resetMaintenanceCount() {
+ invariant(_role == Role::kFollower);
+ _maintenanceModeCalls = 0;
+}
+
int TopologyCoordinator::getMaintenanceCount() const {
return _maintenanceModeCalls;
}
diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h
index d828bca6f03..91ee17012c2 100644
--- a/src/mongo/db/repl/topology_coordinator.h
+++ b/src/mongo/db/repl/topology_coordinator.h
@@ -339,6 +339,11 @@ public:
*/
void adjustMaintenanceCountBy(int inc);
+ /**
+ * Sets the value of the maintenance mode counter to 0.
+ */
+ void resetMaintenanceCount();
+
////////////////////////////////////////////////////////////
//
// Methods that prepare responses to command requests.
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 12898e85ceb..0b7ec6d4ee3 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -245,40 +245,6 @@ void generateErrorResponse(OperationContext* opCtx,
}
/**
- * Guard object for making a good-faith effort to enter maintenance mode and leave it when it
- * goes out of scope.
- *
- * Sometimes we cannot set maintenance mode, in which case the call to setMaintenanceMode will
- * return a non-OK status. This class does not treat that case as an error which means that
- * anybody using it is assuming it is ok to continue execution without maintenance mode.
- *
- * TODO: This assumption needs to be audited and documented, or this behavior should be moved
- * elsewhere.
- */
-class MaintenanceModeSetter {
- MaintenanceModeSetter(const MaintenanceModeSetter&) = delete;
- MaintenanceModeSetter& operator=(const MaintenanceModeSetter&) = delete;
-
-public:
- MaintenanceModeSetter(OperationContext* opCtx)
- : _opCtx(opCtx),
- _maintenanceModeSet(
- repl::ReplicationCoordinator::get(_opCtx)->setMaintenanceMode(true).isOK()) {}
-
- ~MaintenanceModeSetter() {
- if (_maintenanceModeSet) {
- repl::ReplicationCoordinator::get(_opCtx)
- ->setMaintenanceMode(false)
- .transitional_ignore();
- }
- }
-
-private:
- OperationContext* const _opCtx;
- const bool _maintenanceModeSet;
-};
-
-/**
* Given the specified command, returns an effective read concern which should be used or an error
* if the read concern is not valid for the command.
* Note that the validation performed is not necessarily exhaustive.
@@ -1354,8 +1320,6 @@ void ExecCommandDatabase::_initiateCommand() {
validateSessionOptions(
_sessionOptions, command->getName(), _invocation->ns(), allowTransactionsOnConfigDatabase);
- std::unique_ptr<MaintenanceModeSetter> mmSetter;
-
BSONElement cmdOptionMaxTimeMSField;
BSONElement maxTimeMSOpOnlyField;
BSONElement helpField;
@@ -1463,10 +1427,6 @@ void ExecCommandDatabase::_initiateCommand() {
"command"_attr = request.getCommandName());
}
- if (command->maintenanceMode()) {
- mmSetter.reset(new MaintenanceModeSetter(opCtx));
- }
-
if (command->shouldAffectCommandCounter()) {
globalOpCounters.gotCommand();
}
diff --git a/src/mongo/embedded/replication_coordinator_embedded.cpp b/src/mongo/embedded/replication_coordinator_embedded.cpp
index d30d4e5fcde..4a27c84ce0d 100644
--- a/src/mongo/embedded/replication_coordinator_embedded.cpp
+++ b/src/mongo/embedded/replication_coordinator_embedded.cpp
@@ -385,7 +385,7 @@ void ReplicationCoordinatorEmbedded::cancelAndRescheduleElectionTimeout() {
UASSERT_NOT_IMPLEMENTED;
}
-Status ReplicationCoordinatorEmbedded::setMaintenanceMode(bool) {
+Status ReplicationCoordinatorEmbedded::setMaintenanceMode(OperationContext*, bool) {
UASSERT_NOT_IMPLEMENTED;
}
diff --git a/src/mongo/embedded/replication_coordinator_embedded.h b/src/mongo/embedded/replication_coordinator_embedded.h
index 09eb7aba12a..71cf923e5ee 100644
--- a/src/mongo/embedded/replication_coordinator_embedded.h
+++ b/src/mongo/embedded/replication_coordinator_embedded.h
@@ -217,7 +217,7 @@ public:
void cancelAndRescheduleElectionTimeout() override;
- Status setMaintenanceMode(bool) override;
+ Status setMaintenanceMode(OperationContext*, bool) override;
Status processReplSetSyncFrom(OperationContext*, const HostAndPort&, BSONObjBuilder*) override;