summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-07-21 22:55:51 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-07-22 11:38:33 -0400
commit5f756d65b25704facdc3b98a7ddd93d7df0be846 (patch)
treeddb31c39d7a1e4f5bc5e2374067eedcb22b9a7b9 /src/mongo
parente6c13ebd16684b22b3916ccbbca4a72de9f72277 (diff)
downloadmongo-5f756d65b25704facdc3b98a7ddd93d7df0be846.tar.gz
SERVER-14645 Switch LockState usages to OperationContext
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/dbcommands.cpp13
-rw-r--r--src/mongo/db/repl/manager.cpp30
-rw-r--r--src/mongo/db/repl/manager.h11
-rw-r--r--src/mongo/db/repl/network_interface_impl.cpp8
-rw-r--r--src/mongo/db/repl/repl_coordinator.h12
-rw-r--r--src/mongo/db/repl/repl_coordinator_hybrid.cpp27
-rw-r--r--src/mongo/db/repl/repl_coordinator_hybrid.h12
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.cpp9
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.h12
-rw-r--r--src/mongo/db/repl/repl_coordinator_legacy.cpp22
-rw-r--r--src/mongo/db/repl/repl_coordinator_legacy.h15
-rw-r--r--src/mongo/db/repl/repl_coordinator_mock.cpp9
-rw-r--r--src/mongo/db/repl/repl_coordinator_mock.h12
-rw-r--r--src/mongo/db/repl/repl_set.h2
-rw-r--r--src/mongo/db/repl/repl_set_impl.cpp20
-rw-r--r--src/mongo/db/repl/repl_set_impl.h8
-rw-r--r--src/mongo/db/repl/replset_commands.cpp2
-rw-r--r--src/mongo/db/restapi.cpp3
18 files changed, 137 insertions, 90 deletions
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 147f86d9161..27105525e91 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -109,6 +109,7 @@ namespace mongo {
}
Status status = repl::getGlobalReplicationCoordinator()->stepDownAndWaitForSecondary(
+ txn,
repl::ReplicationCoordinator::Milliseconds(timeoutSecs * 1000),
repl::ReplicationCoordinator::Milliseconds(120 * 1000),
repl::ReplicationCoordinator::Milliseconds(60 * 1000));
@@ -1172,14 +1173,18 @@ namespace mongo {
assumption needs to be audited and documented. */
class MaintenanceModeSetter {
public:
- MaintenanceModeSetter() :
- maintenanceModeSet(repl::getGlobalReplicationCoordinator()->setMaintenanceMode(true))
+ MaintenanceModeSetter(OperationContext* txn) :
+ _txn(txn),
+ maintenanceModeSet(
+ repl::getGlobalReplicationCoordinator()->setMaintenanceMode(txn, true))
{}
~MaintenanceModeSetter() {
if (maintenanceModeSet)
- repl::getGlobalReplicationCoordinator()->setMaintenanceMode(false);
+ repl::getGlobalReplicationCoordinator()->setMaintenanceMode(_txn, false);
}
private:
+ // Not owned.
+ OperationContext* _txn;
bool maintenanceModeSet;
};
@@ -1319,7 +1324,7 @@ namespace mongo {
if (c->maintenanceMode() &&
repl::getGlobalReplicationCoordinator()->getReplicationMode() ==
repl::ReplicationCoordinator::modeReplSet) {
- mmSetter.reset(new MaintenanceModeSetter());
+ mmSetter.reset(new MaintenanceModeSetter(txn));
}
if (c->shouldAffectCommandCounter()) {
diff --git a/src/mongo/db/repl/manager.cpp b/src/mongo/db/repl/manager.cpp
index 68559ca4ffc..79b76ac8dfb 100644
--- a/src/mongo/db/repl/manager.cpp
+++ b/src/mongo/db/repl/manager.cpp
@@ -31,6 +31,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/repl/connections.h"
#include "mongo/db/repl/isself.h"
#include "mongo/db/repl/rs.h"
@@ -44,7 +45,7 @@ namespace mongo {
namespace repl {
/* check members OTHER THAN US to see if they think they are primary */
- const Member * Manager::findOtherPrimary(bool& two) {
+ const Member * Manager::findOtherPrimary(OperationContext* txn, bool& two) {
two = false;
Member *m = rs->head();
Member *p = 0;
@@ -60,7 +61,7 @@ namespace repl {
m = m->next();
}
if( p )
- noteARemoteIsPrimary(p);
+ noteARemoteIsPrimary(txn, p);
return p;
}
@@ -82,7 +83,7 @@ namespace repl {
replLocalAuth();
}
- void Manager::noteARemoteIsPrimary(const Member *m) {
+ void Manager::noteARemoteIsPrimary(OperationContext* txn, const Member *m) {
if( rs->box.getPrimary() == m )
return;
rs->_self->lhb() = "";
@@ -100,12 +101,12 @@ namespace repl {
// This primary didn't deliver an electionTime in its heartbeat;
// assume it's a pre-2.6 primary and always step down ourselves.
log() << "stepping down; another primary seen in replicaset";
- rs->relinquish();
+ rs->relinquish(txn);
}
// 2.6 or greater primary. Step down whoever has the older election time.
else if (remoteElectionTime > rs->getElectionTime()) {
log() << "stepping down; another primary was elected more recently";
- rs->relinquish();
+ rs->relinquish(txn);
}
else {
// else, stick around
@@ -118,7 +119,7 @@ namespace repl {
rs->box.noteRemoteIsPrimary(m);
}
- void Manager::checkElectableSet() {
+ void Manager::checkElectableSet(OperationContext* txn) {
unsigned otherOp = rs->lastOtherOpTime().getSecs();
// make sure the electable set is up-to-date
@@ -149,7 +150,7 @@ namespace repl {
// replSetStepDown tries to acquire the same lock
// msgCheckNewState takes, so we can't call replSetStepDown on
// ourselves.
- rs->relinquish();
+ rs->relinquish(txn);
}
else {
BSONObj cmd = BSON( "replSetStepDown" << 1 );
@@ -170,7 +171,7 @@ namespace repl {
}
}
- void Manager::checkAuth() {
+ void Manager::checkAuth(OperationContext* txn) {
int down = 0, authIssue = 0, total = 0;
for( Member *m = rs->head(); m; m=m->next() ) {
@@ -193,7 +194,7 @@ namespace repl {
if (rs->box.getPrimary() == rs->_self) {
log() << "auth problems, relinquishing primary" << rsLog;
- rs->relinquish();
+ rs->relinquish(txn);
}
rs->blockSync(true);
@@ -206,12 +207,13 @@ namespace repl {
/** called as the health threads get new results */
void Manager::msgCheckNewState() {
{
+ OperationContextImpl txn;
RSBase::lock lk(rs);
if( busyWithElectSelf ) return;
- checkElectableSet();
- checkAuth();
+ checkElectableSet(&txn);
+ checkAuth(&txn);
const Member *p = rs->box.getPrimary();
@@ -225,7 +227,7 @@ namespace repl {
const Member *p2;
{
bool two;
- p2 = findOtherPrimary(two);
+ p2 = findOtherPrimary(&txn, two);
if( two ) {
/* two other nodes think they are primary (asynchronously polled) -- wait for things to settle down. */
log() << "replSet info two primaries (transiently)" << rsLog;
@@ -234,7 +236,7 @@ namespace repl {
}
if( p2 ) {
- noteARemoteIsPrimary(p2);
+ noteARemoteIsPrimary(&txn, p2);
return;
}
@@ -252,7 +254,7 @@ namespace repl {
if( rs->elect.shouldRelinquish() ) {
log() << "can't see a majority of the set, relinquishing primary" << rsLog;
- rs->relinquish();
+ rs->relinquish(&txn);
}
return;
diff --git a/src/mongo/db/repl/manager.h b/src/mongo/db/repl/manager.h
index 39ef53069b8..bf90290966a 100644
--- a/src/mongo/db/repl/manager.h
+++ b/src/mongo/db/repl/manager.h
@@ -32,6 +32,9 @@
#include "mongo/db/repl/server.h"
namespace mongo {
+
+ class OperationContext;
+
namespace repl {
class Member;
class ReplSetImpl;
@@ -44,11 +47,11 @@ namespace repl {
* to our polling being only occasional. in this case null is returned, but the caller
* should not assume primary itself in that situation.
*/
- const Member* findOtherPrimary(bool& two);
+ const Member* findOtherPrimary(OperationContext* txn, bool& two);
- void noteARemoteIsPrimary(const Member *);
- void checkElectableSet();
- void checkAuth();
+ void noteARemoteIsPrimary(OperationContext* txn, const Member *);
+ void checkElectableSet(OperationContext* txn);
+ void checkAuth(OperationContext* txn);
virtual void starting();
public:
Manager(ReplSetImpl *rs);
diff --git a/src/mongo/db/repl/network_interface_impl.cpp b/src/mongo/db/repl/network_interface_impl.cpp
index ef14ea11b97..57cf6c4a51a 100644
--- a/src/mongo/db/repl/network_interface_impl.cpp
+++ b/src/mongo/db/repl/network_interface_impl.cpp
@@ -32,7 +32,7 @@
#include "mongo/client/connpool.h"
#include "mongo/db/d_concurrency.h"
-#include "mongo/db/lockstate.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/util/assert_util.h"
namespace mongo {
@@ -97,8 +97,10 @@ namespace repl {
void NetworkInterfaceImpl::runCallbackWithGlobalExclusiveLock(
const stdx::function<void ()>& callback) {
- LockState lockState;
- Lock::GlobalWrite lk(&lockState);
+ OperationContextImpl txn;
+ Lock::GlobalWrite lk(txn.lockState());
+
+ // TODO: OperationContext will have to be given to callback
callback();
}
diff --git a/src/mongo/db/repl/repl_coordinator.h b/src/mongo/db/repl/repl_coordinator.h
index d24293c1973..2f09acc483d 100644
--- a/src/mongo/db/repl/repl_coordinator.h
+++ b/src/mongo/db/repl/repl_coordinator.h
@@ -164,7 +164,8 @@ namespace repl {
* catch up, and then should wait till a secondary is completely caught up rather than
* within 10 seconds.
*/
- virtual Status stepDown(bool force,
+ virtual Status stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime) = 0;
@@ -174,7 +175,8 @@ namespace repl {
* TODO(spencer): This method should be removed and all callers should use shutDown, after
* shutdown has been fixed to block new writes while waiting for secondaries to catch up.
*/
- virtual Status stepDownAndWaitForSecondary(const Milliseconds& initialWaitTime,
+ virtual Status stepDownAndWaitForSecondary(OperationContext* txn,
+ const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) = 0;
@@ -264,7 +266,7 @@ namespace repl {
* Toggles maintenanceMode to the value expressed by 'activate'
* return true, if the change worked and false otherwise
*/
- virtual bool setMaintenanceMode(bool activate) = 0;
+ virtual bool setMaintenanceMode(OperationContext* txn, bool activate) = 0;
/**
* Handles an incoming replSetSyncFrom command. Adds BSON to 'result'
@@ -280,7 +282,9 @@ namespace repl {
* returns Status::OK() if maintenanceMode is successfully changed, otherwise returns a
* Status containing an error message about the failure
*/
- virtual Status processReplSetMaintenance(bool activate, BSONObjBuilder* resultObj) = 0;
+ virtual Status processReplSetMaintenance(OperationContext* txn,
+ bool activate,
+ BSONObjBuilder* resultObj) = 0;
/**
* Handles an incoming replSetFreeze command. Adds BSON to 'resultObj'
diff --git a/src/mongo/db/repl/repl_coordinator_hybrid.cpp b/src/mongo/db/repl/repl_coordinator_hybrid.cpp
index 5ee96763174..ac7b8a4c0ce 100644
--- a/src/mongo/db/repl/repl_coordinator_hybrid.cpp
+++ b/src/mongo/db/repl/repl_coordinator_hybrid.cpp
@@ -89,22 +89,26 @@ namespace repl {
return legacyStatus;
}
- Status HybridReplicationCoordinator::stepDown(bool force,
+ Status HybridReplicationCoordinator::stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime) {
- Status legacyStatus = _legacy.stepDown(force, waitTime, stepdownTime);
- Status implStatus = _impl.stepDown(force, waitTime, stepdownTime);
+ Status legacyStatus = _legacy.stepDown(txn, force, waitTime, stepdownTime);
+ Status implStatus = _impl.stepDown(txn, force, waitTime, stepdownTime);
return legacyStatus;
}
Status HybridReplicationCoordinator::stepDownAndWaitForSecondary(
+ OperationContext* txn,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
- Status legacyStatus = _legacy.stepDownAndWaitForSecondary(initialWaitTime,
+ Status legacyStatus = _legacy.stepDownAndWaitForSecondary(txn,
+ initialWaitTime,
stepdownTime,
postStepdownWaitTime);
- Status implStatus = _impl.stepDownAndWaitForSecondary(initialWaitTime,
+ Status implStatus = _impl.stepDownAndWaitForSecondary(txn,
+ initialWaitTime,
stepdownTime,
postStepdownWaitTime);
return legacyStatus;
@@ -165,9 +169,9 @@ namespace repl {
_impl.processReplSetGetStatus(&implResult);
}
- bool HybridReplicationCoordinator::setMaintenanceMode(bool activate) {
- bool legacyResponse = _legacy.setMaintenanceMode(activate);
- _impl.setMaintenanceMode(activate);
+ bool HybridReplicationCoordinator::setMaintenanceMode(OperationContext* txn, bool activate) {
+ bool legacyResponse = _legacy.setMaintenanceMode(txn, activate);
+ _impl.setMaintenanceMode(txn, activate);
return legacyResponse;
}
@@ -231,11 +235,12 @@ namespace repl {
return legacyStatus;
}
- Status HybridReplicationCoordinator::processReplSetMaintenance(bool activate,
+ Status HybridReplicationCoordinator::processReplSetMaintenance(OperationContext* txn,
+ bool activate,
BSONObjBuilder* resultObj) {
- Status legacyStatus = _legacy.processReplSetMaintenance(activate, resultObj);
+ Status legacyStatus = _legacy.processReplSetMaintenance(txn, activate, resultObj);
BSONObjBuilder implResult;
- Status implStatus = _impl.processReplSetMaintenance(activate, &implResult);
+ Status implStatus = _impl.processReplSetMaintenance(txn, activate, &implResult);
return legacyStatus;
}
diff --git a/src/mongo/db/repl/repl_coordinator_hybrid.h b/src/mongo/db/repl/repl_coordinator_hybrid.h
index f359e5eb13f..0408b207de0 100644
--- a/src/mongo/db/repl/repl_coordinator_hybrid.h
+++ b/src/mongo/db/repl/repl_coordinator_hybrid.h
@@ -71,11 +71,13 @@ namespace repl {
const OperationContext* txn,
const WriteConcernOptions& writeConcern);
- virtual Status stepDown(bool force,
+ virtual Status stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime);
- virtual Status stepDownAndWaitForSecondary(const Milliseconds& initialWaitTime,
+ virtual Status stepDownAndWaitForSecondary(OperationContext* txn,
+ const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime);
@@ -100,9 +102,11 @@ namespace repl {
virtual void processReplSetGetStatus(BSONObjBuilder* result);
- virtual bool setMaintenanceMode(bool activate);
+ virtual bool setMaintenanceMode(OperationContext* txn, bool activate);
- virtual Status processReplSetMaintenance(bool activate, BSONObjBuilder* resultObj);
+ virtual Status processReplSetMaintenance(OperationContext* txn,
+ bool activate,
+ BSONObjBuilder* resultObj);
virtual Status processReplSetSyncFrom(const std::string& target,
BSONObjBuilder* resultObj);
diff --git a/src/mongo/db/repl/repl_coordinator_impl.cpp b/src/mongo/db/repl/repl_coordinator_impl.cpp
index b1cc99d2b02..0d23ed6988c 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl.cpp
@@ -280,7 +280,8 @@ namespace repl {
return StatusAndDuration(Status::OK(), Milliseconds(0));
}
- Status ReplicationCoordinatorImpl::stepDown(bool force,
+ Status ReplicationCoordinatorImpl::stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime) {
// TODO
@@ -288,6 +289,7 @@ namespace repl {
}
Status ReplicationCoordinatorImpl::stepDownAndWaitForSecondary(
+ OperationContext* txn,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
@@ -358,7 +360,7 @@ namespace repl {
// TODO
}
- bool ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) {
+ bool ReplicationCoordinatorImpl::setMaintenanceMode(OperationContext* txn, bool activate) {
// TODO
return false;
}
@@ -369,7 +371,8 @@ namespace repl {
return Status::OK();
}
- Status ReplicationCoordinatorImpl::processReplSetMaintenance(bool activate,
+ Status ReplicationCoordinatorImpl::processReplSetMaintenance(OperationContext* txn,
+ bool activate,
BSONObjBuilder* resultObj) {
// TODO
return Status::OK();
diff --git a/src/mongo/db/repl/repl_coordinator_impl.h b/src/mongo/db/repl/repl_coordinator_impl.h
index 3365126546a..1b74ded4625 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.h
+++ b/src/mongo/db/repl/repl_coordinator_impl.h
@@ -81,11 +81,13 @@ namespace repl {
const OperationContext* txn,
const WriteConcernOptions& writeConcern);
- virtual Status stepDown(bool force,
+ virtual Status stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime);
- virtual Status stepDownAndWaitForSecondary(const Milliseconds& initialWaitTime,
+ virtual Status stepDownAndWaitForSecondary(OperationContext* txn,
+ const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime);
@@ -110,9 +112,11 @@ namespace repl {
virtual void processReplSetGetStatus(BSONObjBuilder* result);
- virtual bool setMaintenanceMode(bool activate);
+ virtual bool setMaintenanceMode(OperationContext* txn, bool activate);
- virtual Status processReplSetMaintenance(bool activate, BSONObjBuilder* resultObj);
+ virtual Status processReplSetMaintenance(OperationContext* txn,
+ bool activate,
+ BSONObjBuilder* resultObj);
virtual Status processReplSetSyncFrom(const std::string& target,
BSONObjBuilder* resultObj);
diff --git a/src/mongo/db/repl/repl_coordinator_legacy.cpp b/src/mongo/db/repl/repl_coordinator_legacy.cpp
index c8bb9bf3a50..e1f1abb38b3 100644
--- a/src/mongo/db/repl/repl_coordinator_legacy.cpp
+++ b/src/mongo/db/repl/repl_coordinator_legacy.cpp
@@ -178,17 +178,19 @@ namespace repl {
return awaitReplication(txn, cc().getLastOp(), writeConcern);
}
- Status LegacyReplicationCoordinator::stepDown(bool force,
+ Status LegacyReplicationCoordinator::stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime) {
- return _stepDownHelper(force, waitTime, stepdownTime, Milliseconds(0));
+ return _stepDownHelper(txn, force, waitTime, stepdownTime, Milliseconds(0));
}
Status LegacyReplicationCoordinator::stepDownAndWaitForSecondary(
+ OperationContext* txn,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
- return _stepDownHelper(false, initialWaitTime, stepdownTime, postStepdownWaitTime);
+ return _stepDownHelper(txn, false, initialWaitTime, stepdownTime, postStepdownWaitTime);
}
namespace {
@@ -234,7 +236,8 @@ namespace {
}
} // namespace
- Status LegacyReplicationCoordinator::_stepDownHelper(bool force,
+ Status LegacyReplicationCoordinator::_stepDownHelper(OperationContext* txn,
+ bool force,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
@@ -251,7 +254,7 @@ namespace {
}
// step down
- bool worked = repl::theReplSet->stepDown(stepdownTime.total_seconds());
+ bool worked = repl::theReplSet->stepDown(txn, stepdownTime.total_seconds());
if (!worked) {
return Status(ErrorCodes::NotMaster, "not primary so can't step down");
}
@@ -459,8 +462,8 @@ namespace {
theReplSet->summarizeStatus(*result);
}
- bool LegacyReplicationCoordinator::setMaintenanceMode(bool activate) {
- return theReplSet->setMaintenanceMode(activate);
+ bool LegacyReplicationCoordinator::setMaintenanceMode(OperationContext* txn, bool activate) {
+ return theReplSet->setMaintenanceMode(txn, activate);
}
Status LegacyReplicationCoordinator::processHeartbeat(const BSONObj& cmdObj,
@@ -897,13 +900,14 @@ namespace {
return Status::OK();
}
- Status LegacyReplicationCoordinator::processReplSetMaintenance(bool activate,
+ Status LegacyReplicationCoordinator::processReplSetMaintenance(OperationContext* txn,
+ bool activate,
BSONObjBuilder* resultObj) {
Status status = _checkReplEnabledForCommand(resultObj);
if (!status.isOK()) {
return status;
}
- if (!setMaintenanceMode(activate)) {
+ if (!setMaintenanceMode(txn, activate)) {
if (theReplSet->isPrimary()) {
return Status(ErrorCodes::NotSecondary, "primaries can't modify maintenance mode");
}
diff --git a/src/mongo/db/repl/repl_coordinator_legacy.h b/src/mongo/db/repl/repl_coordinator_legacy.h
index 64f69f1bee1..d499a2f661c 100644
--- a/src/mongo/db/repl/repl_coordinator_legacy.h
+++ b/src/mongo/db/repl/repl_coordinator_legacy.h
@@ -67,11 +67,13 @@ namespace repl {
const OperationContext* txn,
const WriteConcernOptions& writeConcern);
- virtual Status stepDown(bool force,
+ virtual Status stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime);
- virtual Status stepDownAndWaitForSecondary(const Milliseconds& initialWaitTime,
+ virtual Status stepDownAndWaitForSecondary(OperationContext* txn,
+ const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime);
@@ -96,9 +98,11 @@ namespace repl {
virtual void processReplSetGetStatus(BSONObjBuilder* result);
- virtual bool setMaintenanceMode(bool activate);
+ virtual bool setMaintenanceMode(OperationContext* txn, bool activate);
- virtual Status processReplSetMaintenance(bool activate, BSONObjBuilder* resultObj);
+ virtual Status processReplSetMaintenance(OperationContext* txn,
+ bool activate,
+ BSONObjBuilder* resultObj);
virtual Status processReplSetSyncFrom(const std::string& target,
BSONObjBuilder* resultObj);
@@ -140,7 +144,8 @@ namespace repl {
virtual std::vector<BSONObj> getHostsWrittenTo(const OpTime& op);
private:
- Status _stepDownHelper(bool force,
+ Status _stepDownHelper(OperationContext* txn,
+ bool force,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime);
diff --git a/src/mongo/db/repl/repl_coordinator_mock.cpp b/src/mongo/db/repl/repl_coordinator_mock.cpp
index ef16aff8f61..97c07ad246b 100644
--- a/src/mongo/db/repl/repl_coordinator_mock.cpp
+++ b/src/mongo/db/repl/repl_coordinator_mock.cpp
@@ -87,13 +87,15 @@ namespace repl {
return StatusAndDuration(Status::OK(), Milliseconds(0));
}
- Status ReplicationCoordinatorMock::stepDown(bool force,
+ Status ReplicationCoordinatorMock::stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime) {
return Status::OK();
}
Status ReplicationCoordinatorMock::stepDownAndWaitForSecondary(
+ OperationContext* txn,
const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime) {
@@ -142,7 +144,7 @@ namespace repl {
//TODO
}
- bool ReplicationCoordinatorMock::setMaintenanceMode(bool activate) {
+ bool ReplicationCoordinatorMock::setMaintenanceMode(OperationContext* txn, bool activate) {
// TODO
return false;
}
@@ -153,7 +155,8 @@ namespace repl {
return Status::OK();
}
- Status ReplicationCoordinatorMock::processReplSetMaintenance(bool activate,
+ Status ReplicationCoordinatorMock::processReplSetMaintenance(OperationContext* txn,
+ bool activate,
BSONObjBuilder* resultObj) {
// TODO
return Status::OK();
diff --git a/src/mongo/db/repl/repl_coordinator_mock.h b/src/mongo/db/repl/repl_coordinator_mock.h
index a3b970b338a..aa4289ca013 100644
--- a/src/mongo/db/repl/repl_coordinator_mock.h
+++ b/src/mongo/db/repl/repl_coordinator_mock.h
@@ -70,11 +70,13 @@ namespace repl {
const OperationContext* txn,
const WriteConcernOptions& writeConcern);
- virtual Status stepDown(bool force,
+ virtual Status stepDown(OperationContext* txn,
+ bool force,
const Milliseconds& waitTime,
const Milliseconds& stepdownTime);
- virtual Status stepDownAndWaitForSecondary(const Milliseconds& initialWaitTime,
+ virtual Status stepDownAndWaitForSecondary(OperationContext* txn,
+ const Milliseconds& initialWaitTime,
const Milliseconds& stepdownTime,
const Milliseconds& postStepdownWaitTime);
@@ -99,9 +101,11 @@ namespace repl {
virtual void processReplSetGetStatus(BSONObjBuilder* result);
- virtual bool setMaintenanceMode(bool activate);
+ virtual bool setMaintenanceMode(OperationContext* txn, bool activate);
- virtual Status processReplSetMaintenance(bool activate, BSONObjBuilder* resultObj);
+ virtual Status processReplSetMaintenance(OperationContext* txn,
+ bool activate,
+ BSONObjBuilder* resultObj);
virtual Status processReplSetSyncFrom(const std::string& target,
BSONObjBuilder* resultObj);
diff --git a/src/mongo/db/repl/repl_set.h b/src/mongo/db/repl/repl_set.h
index 57d2b715a0a..a29e8f99a36 100644
--- a/src/mongo/db/repl/repl_set.h
+++ b/src/mongo/db/repl/repl_set.h
@@ -41,7 +41,7 @@ namespace repl {
// for the replSetStepDown command
// Returns false if this node isn't currently primary
- bool stepDown(int secs) { return _stepDown(secs); }
+ bool stepDown(OperationContext* txn, int secs) { return _stepDown(txn, secs); }
// for the replSetFreeze command
bool freeze(int secs) { return _freeze(secs); }
diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp
index a098cd6ffbd..c0df2b8dce3 100644
--- a/src/mongo/db/repl/repl_set_impl.cpp
+++ b/src/mongo/db/repl/repl_set_impl.cpp
@@ -148,12 +148,11 @@ namespace {
void ReplSetImpl::changeState(MemberState s) { box.change(s, _self); }
- bool ReplSetImpl::setMaintenanceMode(const bool inc) {
+ bool ReplSetImpl::setMaintenanceMode(OperationContext* txn, const bool inc) {
lock replLock(this);
// Lock here to prevent state from changing between checking the state and changing it
- LockState lockState;
- Lock::GlobalWrite writeLock(&lockState);
+ Lock::GlobalWrite writeLock(txn->lockState());
if (box.getState().primary()) {
return false;
@@ -203,10 +202,9 @@ namespace {
return max;
}
- void ReplSetImpl::relinquish() {
+ void ReplSetImpl::relinquish(OperationContext* txn) {
{
- LockState lockState;
- Lock::GlobalWrite writeLock(&lockState); // so we are synchronized with _logOp()
+ Lock::GlobalWrite writeLock(txn->lockState()); // so we are synchronized with _logOp()
LOG(2) << "replSet attempting to relinquish" << endl;
if (box.getState().primary()) {
@@ -234,21 +232,21 @@ namespace {
}
// look freshly for who is primary - includes relinquishing ourself.
- void ReplSetImpl::forgetPrimary() {
+ void ReplSetImpl::forgetPrimary(OperationContext* txn) {
if (box.getState().primary())
- relinquish();
+ relinquish(txn);
else {
box.setOtherPrimary(0);
}
}
// for the replSetStepDown command
- bool ReplSetImpl::_stepDown(int secs) {
+ bool ReplSetImpl::_stepDown(OperationContext* txn, int secs) {
lock lk(this);
if (box.getState().primary()) {
elect.steppedDown = time(0) + secs;
log() << "replSet info stepping down as primary secs=" << secs << rsLog;
- relinquish();
+ relinquish(txn);
return true;
}
return false;
@@ -672,7 +670,7 @@ namespace {
if (p)
oldPrimaryId = p->id();
}
- forgetPrimary();
+ forgetPrimary(txn);
// not setting _self to 0 as other threads use _self w/o locking
int me = 0;
diff --git a/src/mongo/db/repl/repl_set_impl.h b/src/mongo/db/repl/repl_set_impl.h
index 5b010e65d50..b6ac4c278ca 100644
--- a/src/mongo/db/repl/repl_set_impl.h
+++ b/src/mongo/db/repl/repl_set_impl.h
@@ -113,10 +113,10 @@ namespace repl {
void startHealthTaskFor(Member *m);
Consensus elect;
- void relinquish();
- void forgetPrimary();
+ void relinquish(OperationContext* txn);
+ void forgetPrimary(OperationContext* txn);
protected:
- bool _stepDown(int secs);
+ bool _stepDown(OperationContext* txn, int secs);
bool _freeze(int secs);
private:
void _assumePrimary();
@@ -254,7 +254,7 @@ namespace repl {
* call this and it will leave maintenance mode once all of the callers
* have called it again, passing in false.
*/
- bool setMaintenanceMode(const bool inc);
+ bool setMaintenanceMode(OperationContext* txn, const bool inc);
// Records a new slave's id in the GhostSlave map, at handshake time.
bool registerSlave(const OID& rid, const int memberId);
diff --git a/src/mongo/db/repl/replset_commands.cpp b/src/mongo/db/repl/replset_commands.cpp
index c77c1761f41..4f52273bb35 100644
--- a/src/mongo/db/repl/replset_commands.cpp
+++ b/src/mongo/db/repl/replset_commands.cpp
@@ -268,6 +268,7 @@ namespace repl {
secs = 60;
Status status = getGlobalReplicationCoordinator()->stepDown(
+ txn,
force,
ReplicationCoordinator::Milliseconds(0),
ReplicationCoordinator::Milliseconds(secs * 1000));
@@ -293,6 +294,7 @@ namespace repl {
return appendCommandStatus(
result,
getGlobalReplicationCoordinator()->processReplSetMaintenance(
+ txn,
cmdObj["replSetMaintenance"].trueValue(),
&result));
}
diff --git a/src/mongo/db/restapi.cpp b/src/mongo/db/restapi.cpp
index 031612b59cd..d1a6430ff2d 100644
--- a/src/mongo/db/restapi.cpp
+++ b/src/mongo/db/restapi.cpp
@@ -302,8 +302,7 @@ namespace mongo {
virtual void run(OperationContext* txn, stringstream& ss ) {
Timer t;
- LockState lockState;
- readlocktry lk(&lockState, 300);
+ readlocktry lk(txn->lockState(), 300);
if ( lk.got() ) {
_gotLock( t.millis() , ss );
}