From 993fc5e4ed9264965f16a948d3732d3fc55d1255 Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Fri, 29 May 2015 18:14:03 -0400 Subject: Revert "SERVER-18277 Clarify locking of Client when accessing its stored OperationContext." This reverts commit 5c2d133871b2ad2adf6c617364d036ca25261f2d. --- src/mongo/db/service_context_d.cpp | 59 ++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 34 deletions(-) (limited to 'src/mongo/db/service_context_d.cpp') diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index eb00449c625..eaef2f6f639 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -205,11 +205,11 @@ namespace mongo { } void ServiceContextMongoD::setKillAllOperations() { - stdx::lock_guard clientLock(_mutex); + boost::lock_guard clientLock(_mutex); _globalKill = true; - for (const auto listener : _killOpListeners) { + for (size_t i = 0; i < _killOpListeners.size(); i++) { try { - listener->interruptAll(); + _killOpListeners[i]->interruptAll(); } catch (...) { std::terminate(); @@ -223,38 +223,30 @@ namespace mongo { bool ServiceContextMongoD::_killOperationsAssociatedWithClientAndOpId_inlock( Client* client, unsigned int opId) { - OperationContext* opCtx = client->getOperationContext(); - if (!opCtx) { - return false; - } - for( CurOp *k = CurOp::get(opCtx); k; k = k->parent() ) { + for( CurOp *k = CurOp::getFromClient(client); k; k = k->parent() ) { if ( k->opNum() != opId ) continue; - _killOperation_inlock(opCtx); - return true; - } - return false; - } - - void ServiceContextMongoD::_killOperation_inlock(OperationContext* opCtx) { - for(CurOp *l = CurOp::get(opCtx); l; l = l->parent()) { - l->kill(); - } - - for (const auto listener : _killOpListeners) { - try { - listener->interrupt(opCtx->getOpID()); + k->kill(); + for( CurOp *l = CurOp::getFromClient(client); l; l = l->parent() ) { + l->kill(); } - catch (...) { - std::terminate(); + + for (size_t i = 0; i < _killOpListeners.size(); i++) { + try { + _killOpListeners[i]->interrupt(opId); + } + catch (...) { + std::terminate(); + } } + return true; } + return false; } bool ServiceContextMongoD::killOperation(unsigned int opId) { for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { - stdx::lock_guard lk(*client); bool found = _killOperationsAssociatedWithClientAndOpId_inlock(client, opId); if (found) { return true; @@ -271,18 +263,17 @@ namespace mongo { continue; } - stdx::lock_guard lk(*client); - OperationContext* toKill = client->getOperationContext(); - if (!toKill) { - continue; - } - - if (toKill->getOpID() == txn->getOpID()) { + if (CurOp::getFromClient(client)->opNum() == txn->getOpID()) { // Don't kill ourself. continue; } - _killOperation_inlock(toKill); + bool found = _killOperationsAssociatedWithClientAndOpId_inlock( + client, CurOp::getFromClient(client)->opNum()); + if (!found) { + warning() << "Attempted to kill operation " << CurOp::getFromClient(client)->opNum() + << " but the opId changed"; + } } } @@ -291,7 +282,7 @@ namespace mongo { } void ServiceContextMongoD::registerKillOpListener(KillOpListenerInterface* listener) { - stdx::lock_guard clientLock(_mutex); + boost::lock_guard clientLock(_mutex); _killOpListeners.push_back(listener); } -- cgit v1.2.1