Storage Engine API
collection_info_cache_impl.h
Go to the documentation of this file.
1 
29 #pragma once
30 
32 
33 #include "mongo/base/shim.h"
34 #include "mongo/db/collection_index_usage_tracker.h"
35 #include "mongo/db/query/plan_cache.h"
36 #include "mongo/db/query/query_settings.h"
37 #include "mongo/db/update_index_data.h"
38 
39 namespace mongo {
40 
41 class Collection;
42 class IndexDescriptor;
43 class OperationContext;
44 
50 public:
51  explicit CollectionInfoCacheImpl(Collection* collection, const NamespaceString& ns);
52 
54 
58  PlanCache* getPlanCache() const;
59 
63  QuerySettings* getQuerySettings() const;
64 
65  /* get set of index keys for this namespace. handy to quickly check if a given
66  field is indexed (Note it might be a secondary component of a compound index.)
67  */
68  const UpdateIndexData& getIndexKeys(OperationContext* opCtx) const;
69 
77  CollectionIndexUsageMap getIndexUsageStats() const;
78 
82  void init(OperationContext* opCtx);
83 
90  void addedIndex(OperationContext* opCtx, const IndexDescriptor* desc);
91 
98  void droppedIndex(OperationContext* opCtx, StringData indexName);
99 
103  void clearQueryCache();
104 
109  void notifyOfQuery(OperationContext* opCtx, const std::set<std::string>& indexesUsed);
110 
111 private:
112  void computeIndexKeys(OperationContext* opCtx);
113  void updatePlanCacheIndexEntries(OperationContext* opCtx);
114 
119  void rebuildIndexData(OperationContext* opCtx);
120 
121  Collection* _collection; // not owned
122  const NamespaceString _ns;
123 
124  // --- index keys cache
126  UpdateIndexData _indexedPaths;
127 
128  // A cache for query plans.
129  std::unique_ptr<PlanCache> _planCache;
130 
131  // Query settings.
132  // Includes index filters.
133  std::unique_ptr<QuerySettings> _querySettings;
134 
135  // Tracks index usage statistics for this collection.
136  CollectionIndexUsageTracker _indexUsageTracker;
137 
138  bool _hasTTLIndex = false;
139 };
140 
141 } // namespace mongo
PlanCache * getPlanCache() const
Get the PlanCache for this collection.
Definition: collection_info_cache_impl.cpp:169
UpdateIndexData _indexedPaths
Definition: collection_info_cache_impl.h:126
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
void updatePlanCacheIndexEntries(OperationContext *opCtx)
Definition: collection_info_cache_impl.cpp:177
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
Collection * _collection
Definition: collection_info_cache_impl.h:121
QuerySettings * getQuerySettings() const
Get the QuerySettings for this collection.
Definition: collection_info_cache_impl.cpp:173
bool _keysComputed
Definition: collection_info_cache_impl.h:125
void rebuildIndexData(OperationContext *opCtx)
Rebuilds cached information that is dependent on index composition.
Definition: collection_info_cache_impl.cpp:236
std::unique_ptr< QuerySettings > _querySettings
Definition: collection_info_cache_impl.h:133
CollectionIndexUsageMap getIndexUsageStats() const
Returns cached index usage statistics for this collection.
Definition: collection_info_cache_impl.cpp:244
Definition: collection_info_cache.h:49
this is NOT safe through a yield right now.
Definition: collection.h:160
CollectionInfoCacheImpl(Collection *collection, const NamespaceString &ns)
Definition: collection_info_cache_impl.cpp:58
void computeIndexKeys(OperationContext *opCtx)
Definition: collection_info_cache_impl.cpp:81
const NamespaceString _ns
Definition: collection_info_cache_impl.h:122
CollectionIndexUsageTracker _indexUsageTracker
Definition: collection_info_cache_impl.h:136
const UpdateIndexData & getIndexKeys(OperationContext *opCtx) const
Definition: collection_info_cache_impl.cpp:74
void addedIndex(OperationContext *opCtx, const IndexDescriptor *desc)
Register a newly-created index with the cache.
Definition: collection_info_cache_impl.cpp:218
void init(OperationContext *opCtx)
Builds internal cache state based on the current state of the Collection&#39;s IndexCatalog.
Definition: collection_info_cache_impl.cpp:203
bool _hasTTLIndex
Definition: collection_info_cache_impl.h:138
std::unique_ptr< PlanCache > _planCache
Definition: collection_info_cache_impl.h:129
this is for storing things that you want to cache about a single collection life cycle is managed for...
Definition: collection_info_cache_impl.h:49
void droppedIndex(OperationContext *opCtx, StringData indexName)
Deregister a newly-dropped index with the cache.
Definition: collection_info_cache_impl.cpp:228
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
void clearQueryCache()
Removes all cached query plans.
Definition: collection_info_cache_impl.cpp:162
OperationContext const IndexDescriptor * desc
Definition: index_catalog_impl.cpp:97
~CollectionInfoCacheImpl()
Definition: collection_info_cache_impl.cpp:66
void notifyOfQuery(OperationContext *opCtx, const std::set< std::string > &indexesUsed)
Signal to the cache that a query operation has completed.
Definition: collection_info_cache_impl.cpp:150