Storage Engine API
collection_info_cache.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include "mongo/base/shim.h"
32 #include "mongo/db/collection_index_usage_tracker.h"
33 #include "mongo/db/query/plan_cache.h"
34 #include "mongo/db/query/query_settings.h"
35 #include "mongo/db/update_index_data.h"
36 #include "mongo/stdx/functional.h"
37 
38 namespace mongo {
39 class Collection;
40 class IndexDescriptor;
41 class OperationContext;
42 
48 public:
49  class Impl {
50  public:
51  virtual ~Impl() = 0;
52 
53  virtual PlanCache* getPlanCache() const = 0;
54 
55  virtual QuerySettings* getQuerySettings() const = 0;
56 
57  virtual const UpdateIndexData& getIndexKeys(OperationContext* opCtx) const = 0;
58 
59  virtual CollectionIndexUsageMap getIndexUsageStats() const = 0;
60 
61  virtual void init(OperationContext* opCtx) = 0;
62 
63  virtual void addedIndex(OperationContext* opCtx, const IndexDescriptor* desc) = 0;
64 
65  virtual void droppedIndex(OperationContext* opCtx, StringData indexName) = 0;
66 
67  virtual void clearQueryCache() = 0;
68 
69  virtual void notifyOfQuery(OperationContext* opCtx,
70  const std::set<std::string>& indexesUsed) = 0;
71  };
72 
73 
74 public:
76  const NamespaceString& ns,
77  PrivateTo<CollectionInfoCache>)
78  ->std::unique_ptr<Impl>) makeImpl;
79 
80  explicit inline CollectionInfoCache(Collection* const collection, const NamespaceString& ns)
81  : _pimpl(makeImpl(collection, ns, PrivateCall<CollectionInfoCache>{})) {}
82 
83  inline ~CollectionInfoCache() = default;
84 
88  inline void init(OperationContext* const opCtx) {
89  return this->_impl().init(opCtx);
90  }
91 
95  inline PlanCache* getPlanCache() const {
96  return this->_impl().getPlanCache();
97  }
98 
102  inline QuerySettings* getQuerySettings() const {
103  return this->_impl().getQuerySettings();
104  }
105 
106  /* get set of index keys for this namespace. handy to quickly check if a given
107  field is indexed (Note it might be a secondary component of a compound index.)
108  */
109  inline const UpdateIndexData& getIndexKeys(OperationContext* const opCtx) const {
110  return this->_impl().getIndexKeys(opCtx);
111  }
112 
120  inline CollectionIndexUsageMap getIndexUsageStats() const {
121  return this->_impl().getIndexUsageStats();
122  }
123 
130  inline void addedIndex(OperationContext* const opCtx, const IndexDescriptor* const desc) {
131  return this->_impl().addedIndex(opCtx, desc);
132  }
133 
140  inline void droppedIndex(OperationContext* const opCtx, const StringData indexName) {
141  return this->_impl().droppedIndex(opCtx, indexName);
142  }
143 
147  inline void clearQueryCache() {
148  return this->_impl().clearQueryCache();
149  }
150 
155  inline void notifyOfQuery(OperationContext* const opCtx,
156  const std::set<std::string>& indexesUsed) {
157  return this->_impl().notifyOfQuery(opCtx, indexesUsed);
158  }
159 
160  std::unique_ptr<Impl> _pimpl;
161 
162  // This structure exists to give us a customization point to decide how to force users of this
163  // class to depend upon the corresponding `collection_info_cache.cpp` Translation Unit (TU).
164  // All public forwarding functions call `_impl(), and `_impl` creates an instance of this
165  // structure.
166  struct TUHook {
167  static void hook() noexcept;
168 
169  explicit inline TUHook() noexcept {
170  if (kDebugBuild)
171  this->hook();
172  }
173  };
174 
175  inline const Impl& _impl() const {
176  TUHook{};
177  return *this->_pimpl;
178  }
179 
180  inline Impl& _impl() {
181  TUHook{};
182  return *this->_pimpl;
183  }
184 };
185 } // namespace mongo
Impl & _impl()
Definition: collection_info_cache.h:180
virtual void init(OperationContext *opCtx)=0
const UpdateIndexData & getIndexKeys(OperationContext *const opCtx) const
Definition: collection_info_cache.h:109
void clearQueryCache()
Removes all cached query plans.
Definition: collection_info_cache.h:147
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
TUHook() noexcept
Definition: collection_info_cache.h:169
static MONGO_DECLARE_SHIM((Collection *collection, const NamespaceString &ns, PrivateTo< CollectionInfoCache >) ->std::unique_ptr< Impl >) makeImpl
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
void init(OperationContext *const opCtx)
Builds internal cache state based on the current state of the Collection&#39;s IndexCatalog.
Definition: collection_info_cache.h:88
void droppedIndex(OperationContext *const opCtx, const StringData indexName)
Deregister a newly-dropped index with the cache.
Definition: collection_info_cache.h:140
std::unique_ptr< Impl > _pimpl
Definition: collection_info_cache.h:160
CollectionInfoCache(Collection *const collection, const NamespaceString &ns)
Definition: collection_info_cache.h:80
void notifyOfQuery(OperationContext *const opCtx, const std::set< std::string > &indexesUsed)
Signal to the cache that a query operation has completed.
Definition: collection_info_cache.h:155
virtual QuerySettings * getQuerySettings() const =0
Definition: collection_info_cache.h:49
virtual void addedIndex(OperationContext *opCtx, const IndexDescriptor *desc)=0
virtual void droppedIndex(OperationContext *opCtx, StringData indexName)=0
this is NOT safe through a yield right now.
Definition: collection.h:160
virtual void notifyOfQuery(OperationContext *opCtx, const std::set< std::string > &indexesUsed)=0
QuerySettings * getQuerySettings() const
Get the QuerySettings for this collection.
Definition: collection_info_cache.h:102
Definition: collection_info_cache.h:166
virtual PlanCache * getPlanCache() const =0
CollectionIndexUsageMap getIndexUsageStats() const
Returns cached index usage statistics for this collection.
Definition: collection_info_cache.h:120
virtual const UpdateIndexData & getIndexKeys(OperationContext *opCtx) const =0
PlanCache * getPlanCache() const
Get the PlanCache for this collection.
Definition: collection_info_cache.h:95
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
virtual CollectionIndexUsageMap getIndexUsageStats() const =0
void addedIndex(OperationContext *const opCtx, const IndexDescriptor *const desc)
Register a newly-created index with the cache.
Definition: collection_info_cache.h:130
OperationContext const IndexDescriptor * desc
Definition: index_catalog_impl.cpp:97
this is for storing things that you want to cache about a single collection life cycle is managed for...
Definition: collection_info_cache.h:47
const Impl & _impl() const
Definition: collection_info_cache.h:175