diff options
Diffstat (limited to 'src/mongo/db/collection_index_usage_tracker.h')
-rw-r--r-- | src/mongo/db/collection_index_usage_tracker.h | 21 |
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 |