summaryrefslogtreecommitdiff
path: root/src/mongo/db/collection_index_usage_tracker.h
diff options
context:
space:
mode:
authorsamontea <merciers.merciers@gmail.com>2019-07-11 11:28:07 -0400
committersamontea <merciers.merciers@gmail.com>2019-07-12 11:53:57 -0400
commita8a8fabb17e9700aab633a67b24fe6147290bb92 (patch)
tree6c3f617f3afad7e2363af59607de3e56146dcc8c /src/mongo/db/collection_index_usage_tracker.h
parenta4b8e4e0549ebfffebb545459d34ee4faa4f1521 (diff)
downloadmongo-a8a8fabb17e9700aab633a67b24fe6147290bb92.tar.gz
SERVER-40755 Expose statistics which indicate how many collection scans have executed
Diffstat (limited to 'src/mongo/db/collection_index_usage_tracker.h')
-rw-r--r--src/mongo/db/collection_index_usage_tracker.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/mongo/db/collection_index_usage_tracker.h b/src/mongo/db/collection_index_usage_tracker.h
index 62c3b610f41..b70d7887723 100644
--- a/src/mongo/db/collection_index_usage_tracker.h
+++ b/src/mongo/db/collection_index_usage_tracker.h
@@ -44,6 +44,9 @@ class ClockSource;
* considered "used" when it appears as part of a winning plan for an operation that uses the
* query system.
*
+ * It also tracks non-usage of indexes. I.e. it collects information about collection scans that
+ * occur on a collection.
+ *
* Indexes must be registered and deregistered on creation/destruction.
*/
class CollectionIndexUsageTracker {
@@ -51,6 +54,11 @@ class CollectionIndexUsageTracker {
CollectionIndexUsageTracker& operator=(const CollectionIndexUsageTracker&) = delete;
public:
+ struct CollectionScanStats {
+ unsigned long long collectionScans{0};
+ unsigned long long collectionScansNonTailable{0};
+ };
+
struct IndexUsageStats {
IndexUsageStats() = default;
explicit IndexUsageStats(Date_t now, const BSONObj& key)
@@ -111,6 +119,15 @@ public:
*/
StringMap<CollectionIndexUsageTracker::IndexUsageStats> getUsageStats() const;
+ /**
+ * Get the current state of the usage of collection scans. This struct will only include
+ * information about the collection scans that have occured at the time of calling.
+ */
+ CollectionScanStats getCollectionScanStats() const;
+
+ void recordCollectionScans(unsigned long long collectionScans);
+ void recordCollectionScansNonTailable(unsigned long long collectionScansNonTailable);
+
private:
// Map from index name to usage statistics.
StringMap<CollectionIndexUsageTracker::IndexUsageStats> _indexUsageMap;
@@ -118,8 +135,10 @@ private:
// Clock source. Used when the 'trackerStartTime' time for an IndexUsageStats object needs to
// be set.
ClockSource* _clockSource;
+
+ AtomicWord<unsigned long long> _collectionScans{0};
+ AtomicWord<unsigned long long> _collectionScansNonTailable{0};
};
typedef StringMap<CollectionIndexUsageTracker::IndexUsageStats> CollectionIndexUsageMap;
-
} // namespace mongo