diff options
Diffstat (limited to 'src/mongo/db/db_raii.h')
-rw-r--r-- | src/mongo/db/db_raii.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h index 1f9cd4bf768..0348fcbf4c0 100644 --- a/src/mongo/db/db_raii.h +++ b/src/mongo/db/db_raii.h @@ -39,22 +39,35 @@ namespace mongo { /** - * RAII-style class which automatically tracks the operation namespace in CurrentOp and records the - * operation via Top upon destruction. + * RAII-style class which can update the diagnostic state on the operation's CurOp object and record + * the operation via Top upon destruction. Can be configured to only update the Top counters if + * desired. */ 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. + * Describes which diagnostics to update during the lifetime of this object. + */ + enum class LogMode { + kUpdateTop, // Increments the Top counter for this operation type and this namespace upon + // destruction. + kUpdateTopAndCurop, // In addition to incrementing the Top counter, adjusts state on the + // CurOp object associated with the OperationContext. Updates the + // namespace to be 'nss', starts a timer for the operation (if it + // hasn't started already), and figures out and records the profiling + // level of the operation. + }; + + /** + * If 'logMode' is 'kUpdateTopAndCurop', sets up and records state on the CurOp object attached + * to 'opCtx', as described above. */ AutoStatsTracker(OperationContext* opCtx, const NamespaceString& nss, Top::LockType lockType, + LogMode logMode, boost::optional<int> dbProfilingLevel, Date_t deadline = Date_t::max()); @@ -66,6 +79,7 @@ public: private: OperationContext* _opCtx; Top::LockType _lockType; + const NamespaceString _nss; }; /** @@ -143,7 +157,8 @@ public: OperationContext* opCtx, const NamespaceStringOrUUID& nsOrUUID, AutoGetCollection::ViewMode viewMode = AutoGetCollection::ViewMode::kViewsForbidden, - Date_t deadline = Date_t::max()); + Date_t deadline = Date_t::max(), + AutoStatsTracker::LogMode logMode = AutoStatsTracker::LogMode::kUpdateTopAndCurop); Database* getDb() const { return _autoCollForRead.getDb(); |