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.h | |
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.h')
-rw-r--r-- | src/mongo/db/service_context.h | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index 675b9dfd1ae..3153558f63b 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -94,28 +94,46 @@ namespace mongo { }; /** - * Observer interface implemented to hook client creation and destruction. + * Observer interface implemented to hook client and operation context creation and + * destruction. */ class ClientObserver { public: virtual ~ClientObserver() = default; /** - * Hook called after a new client "client" is created on "service" by + * Hook called after a new client "client" is created on a service by * service->makeClient(). * * For a given client and registered instance of ClientObserver, if onCreateClient * returns without throwing an exception, onDestroyClient will be called when "client" * is deleted. */ - virtual void onCreateClient(ServiceContext* service, Client* client) = 0; + virtual void onCreateClient(Client* client) = 0; /** - * Hook called on a "client" created by "service" before deleting "client". + * Hook called on a "client" created by a service before deleting "client". * * Like a destructor, must not throw exceptions. */ - virtual void onDestroyClient(ServiceContext* service, Client* client) = 0; + virtual void onDestroyClient(Client* client) = 0; + + /** + * Hook called after a new operation context is created on a client by + * service->makeOperationContext(client) or client->makeOperationContext(). + * + * For a given operation context and registered instance of ClientObserver, if + * onCreateOperationContext returns without throwing an exception, + * onDestroyOperationContext will be called when "opCtx" is deleted. + */ + virtual void onCreateOperationContext(OperationContext* opCtx) = 0; + + /** + * Hook called on a "opCtx" created by a service before deleting "opCtx". + * + * Like a destructor, must not throw exceptions. + */ + virtual void onDestroyOperationContext(OperationContext* opCtx) = 0; }; using ClientSet = unordered_set<Client*>; @@ -145,10 +163,24 @@ namespace mongo { }; /** + * Special deleter used for cleaning up OperationContext objects owned by a ServiceContext. + * See UniqueOperationContext, below. + */ + class OperationContextDeleter { + public: + void operator()(OperationContext* opCtx) const; + }; + + /** * This is the unique handle type for Clients created by a ServiceContext. */ using UniqueClient = std::unique_ptr<Client, ClientDeleter>; + /** + * This is the unique handle type for OperationContexts created by a ServiceContext. + */ + using UniqueOperationContext = std::unique_ptr<OperationContext, OperationContextDeleter>; + virtual ~ServiceContext(); /** @@ -172,6 +204,13 @@ namespace mongo { */ UniqueClient makeClient(std::string desc, AbstractMessagingPort* p = nullptr); + /** + * Creates a new OperationContext on "client". + * + * "client" must not have an active operation context. + */ + UniqueOperationContext makeOperationContext(Client* client); + // // Storage // @@ -250,11 +289,6 @@ namespace mongo { */ virtual void registerKillOpListener(KillOpListenerInterface* listener) = 0; - /** - * Returns a new OperationContext. - */ - virtual std::unique_ptr<OperationContext> newOpCtx() = 0; - // // Global OpObserver. // @@ -280,6 +314,11 @@ namespace mongo { private: /** + * Returns a new OperationContext. Private, for use by makeOperationContext. + */ + virtual std::unique_ptr<OperationContext> _newOpCtx(Client* client) = 0; + + /** * Vector of registered observers. */ std::vector<std::unique_ptr<ClientObserver>> _clientObservers; |