diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2015-06-04 18:32:23 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2015-06-05 14:21:57 -0400 |
commit | 6c2a61091396087f85c58bd6298519688a98e5d8 (patch) | |
tree | 201822868554014a882b85a86cb3e291ba6acf4a /src/mongo/db/service_context.cpp | |
parent | 54040db4fa000284cb1148b93e85f81c54ca12d6 (diff) | |
download | mongo-6c2a61091396087f85c58bd6298519688a98e5d8.tar.gz |
SERVER-18515 Put OperationContext into mongos client request path.
Diffstat (limited to 'src/mongo/db/service_context.cpp')
-rw-r--r-- | src/mongo/db/service_context.cpp | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index a1d38162c5e..175702aebad 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -120,14 +120,14 @@ namespace mongo { auto observer = _clientObservers.cbegin(); try { for (; observer != _clientObservers.cend(); ++observer) { - observer->get()->onCreateClient(this, client.get()); + observer->get()->onCreateClient(client.get()); } } catch (...) { try { while (observer != _clientObservers.cbegin()) { --observer; - observer->get()->onDestroyClient(this, client.get()); + observer->get()->onDestroyClient(client.get()); } } catch (...) { @@ -150,7 +150,7 @@ namespace mongo { } try { for (const auto& observer : service->_clientObservers) { - observer->onDestroyClient(service, client); + observer->onDestroyClient(client); } } catch (...) { @@ -159,6 +159,57 @@ namespace mongo { delete client; } + ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Client* client) { + auto opCtx = _newOpCtx(client); + auto observer = _clientObservers.begin(); + try { + for (; observer != _clientObservers.cend(); ++observer) { + observer->get()->onCreateOperationContext(opCtx.get()); + } + } + catch (...) { + try { + while (observer != _clientObservers.cbegin()) { + --observer; + observer->get()->onDestroyOperationContext(opCtx.get()); + } + } + catch (...) { + std::terminate(); + } + throw; + } + // // TODO(schwerin): When callers no longer construct their own OperationContexts directly, + // // but only through the ServiceContext, uncomment the following. Until then, it must + // // be done in the operation context destructors, which introduces a potential race. + // { + // stdx::lock_guard<Client> lk(*client); + // client->setOperationContext(opCtx.get()); + // } + return UniqueOperationContext(opCtx.release()); + }; + + void ServiceContext::OperationContextDeleter::operator()(OperationContext* opCtx) const { + auto client = opCtx->getClient(); + auto service = client->getServiceContext(); + // // TODO(schwerin): When callers no longer construct their own OperationContexts directly, + // // but only through the ServiceContext, uncomment the following. Until then, it must + // // be done in the operation context destructors, which introduces a potential race. + // { + // stdx::lock_guard<Client> lk(*client); + // client->resetOperationContext(); + // } + try { + for (const auto& observer : service->_clientObservers) { + observer->onDestroyOperationContext(opCtx); + } + } + catch (...) { + std::terminate(); + } + delete opCtx; + } + void ServiceContext::registerClientObserver(std::unique_ptr<ClientObserver> observer) { _clientObservers.push_back(std::move(observer)); } |