summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.h
diff options
context:
space:
mode:
authorDevin Hilly <devin.hilly@mongodb.com>2018-11-13 17:55:50 -0500
committerCharlie Swanson <charlie.swanson@mongodb.com>2019-02-06 18:19:07 -0500
commit93f8e8b2df10c2ec28090d9bbfd533b45f3b58e2 (patch)
treee98c6abd0edf8a9e39916e3f0b3519be0dbf9764 /src/mongo/db/db_raii.h
parent5598d54afdfdd5efc418016aeb927cef0a62e3f3 (diff)
downloadmongo-93f8e8b2df10c2ec28090d9bbfd533b45f3b58e2.tar.gz
SERVER-31098 Wrong ns in system.profile for aggregation query
(cherry picked from commit 1862b00862a6ea9c3fdd08bba52ea6a016eccbc5)
Diffstat (limited to 'src/mongo/db/db_raii.h')
-rw-r--r--src/mongo/db/db_raii.h29
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();