From 584ca76de9ee66b3e11987e640f5317ae40975e4 Mon Sep 17 00:00:00 2001 From: Charlie Swanson Date: Tue, 15 Nov 2016 16:17:19 -0500 Subject: SERVER-22541 Manage aggregation cursors on global cursor manager. Moves registration of aggregation cursors to the global cursor manager. This simplifies the logic for acquiring locks and resolving view namespaces within the getMore and killCursors commands. --- src/mongo/db/db_raii.h | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/mongo/db/db_raii.h') diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h index 8060d06f000..42444775bad 100644 --- a/src/mongo/db/db_raii.h +++ b/src/mongo/db/db_raii.h @@ -35,6 +35,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" +#include "mongo/db/stats/top.h" #include "mongo/db/views/view.h" #include "mongo/util/timer.h" @@ -169,6 +170,36 @@ private: bool _justCreated; }; +/** + * RAII-style class which automatically tracks the operation namespace in CurrentOp and records the + * operation via Top upon destruction. + */ +class AutoStatsTracker { + MONGO_DISALLOW_COPYING(AutoStatsTracker); + +public: + /** + * Sets the namespace of the CurOp object associated with 'opCtx' to be 'nss' and starts the + * CurOp timer. 'lockType' describes which type of lock is held by this operation, and will be + * used for reporting via Top. If 'dbProfilingLevel' is not given, this constructor will acquire + * and then drop a database lock in order to determine the database's profiling level. + */ + AutoStatsTracker(OperationContext* opCtx, + const NamespaceString& nss, + Top::LockType lockType, + boost::optional dbProfilingLevel); + + /** + * Records stats about the current operation via Top. + */ + ~AutoStatsTracker(); + +private: + const Timer _timer; + OperationContext* _opCtx; + Top::LockType _lockType; +}; + /** * RAII-style class, which would acquire the appropriate hierarchy of locks for obtaining * a particular collection and would retrieve a reference to the collection. In addition, this @@ -236,8 +267,6 @@ public: : AutoGetCollectionForReadCommand( opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden) {} - ~AutoGetCollectionForReadCommand(); - Database* getDb() const { return _autoCollForRead->getDb(); } @@ -246,21 +275,18 @@ public: return _autoCollForRead->getCollection(); } -private: - OperationContext* const _opCtx; - const Timer _timer; - protected: AutoGetCollectionForReadCommand(OperationContext* opCtx, const NamespaceString& nss, AutoGetCollection::ViewMode viewMode); - /** - * This protected section must come after the private section because - * AutoGetCollectionOrViewForRead needs access to _autoColl, but _autoColl must be initialized - * after _transaction. - */ + // '_autoCollForRead' may need to be reset by AutoGetCollectionOrViewForReadCommand, so needs to + // be a boost::optional. boost::optional _autoCollForRead; + + // This needs to be initialized after 'autoCollForRead', since we need to consult the Database + // object to get the profiling level. Thus, it needs to be a boost::optional. + boost::optional _statsTracker; }; /** -- cgit v1.2.1