Storage Engine API
index_catalog_entry.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <boost/optional.hpp>
32 #include <string>
33 
34 #include "mongo/base/owned_pointer_vector.h"
35 #include "mongo/base/shim.h"
36 #include "mongo/bson/ordering.h"
37 #include "mongo/bson/timestamp.h"
38 #include "mongo/db/index/multikey_paths.h"
39 #include "mongo/db/record_id.h"
41 #include "mongo/platform/atomic_word.h"
42 #include "mongo/stdx/functional.h"
43 #include "mongo/stdx/mutex.h"
44 #include "mongo/util/debug_util.h"
45 
46 namespace mongo {
47 class CollatorInterface;
48 class CollectionCatalogEntry;
49 class CollectionInfoCache;
50 class HeadManager;
51 class IndexAccessMethod;
52 class IndexDescriptor;
53 class MatchExpression;
54 class OperationContext;
55 
57 public:
58  // This class represents the internal vtable for the (potentially polymorphic) implementation of
59  // the `IndexCatalogEntry` class. This allows us to expose an interface to this object without
60  // requiring a dependency upon the implementation's definition library.
61  class Impl {
62  public:
63  virtual ~Impl() = 0;
64 
65  virtual const std::string& ns() const = 0;
66 
67  virtual void init(std::unique_ptr<IndexAccessMethod> accessMethod) = 0;
68 
69  virtual IndexDescriptor* descriptor() = 0;
70 
71  virtual const IndexDescriptor* descriptor() const = 0;
72 
73  virtual IndexAccessMethod* accessMethod() = 0;
74 
75  virtual const IndexAccessMethod* accessMethod() const = 0;
76 
77  virtual const Ordering& ordering() const = 0;
78 
79  virtual const MatchExpression* getFilterExpression() const = 0;
80 
81  virtual const CollatorInterface* getCollator() const = 0;
82 
83  virtual const RecordId& head(OperationContext* opCtx) const = 0;
84 
85  virtual void setHead(OperationContext* opCtx, RecordId newHead) = 0;
86 
87  virtual void setIsReady(bool newIsReady) = 0;
88 
89  virtual HeadManager* headManager() const = 0;
90 
91  virtual bool isMultikey(OperationContext* opCtx) const = 0;
92 
93  virtual MultikeyPaths getMultikeyPaths(OperationContext* opCtx) const = 0;
94 
95  virtual void setMultikey(OperationContext* opCtx, const MultikeyPaths& multikeyPaths) = 0;
96 
97  virtual bool isReady(OperationContext* opCtx) const = 0;
98 
99  virtual KVPrefix getPrefix() const = 0;
100 
101  virtual boost::optional<Timestamp> getMinimumVisibleSnapshot() = 0;
102 
103  virtual void setMinimumVisibleSnapshot(Timestamp name) = 0;
104  };
105 
106 public:
108  OperationContext* opCtx,
109  StringData ns,
111  std::unique_ptr<IndexDescriptor> descriptor,
113  PrivateTo<IndexCatalogEntry>)
114  ->std::unique_ptr<Impl>) makeImpl;
115 
116  explicit IndexCatalogEntry(
117  OperationContext* opCtx,
118  StringData ns,
119  CollectionCatalogEntry* collection, // not owned
120  std::unique_ptr<IndexDescriptor> descriptor, // ownership passes to me
121  CollectionInfoCache* infoCache); // not owned, optional
122 
123  // Do not call this function. It exists for use with test drivers that need to inject
124  // alternative implementations.
125  explicit IndexCatalogEntry(std::unique_ptr<Impl> impl) : _pimpl(std::move(impl)) {}
126 
127  inline ~IndexCatalogEntry() = default;
128 
129  inline IndexCatalogEntry(IndexCatalogEntry&&) = delete;
130  inline IndexCatalogEntry& operator=(IndexCatalogEntry&&) = delete;
131 
132  inline const std::string& ns() const {
133  return this->_impl().ns();
134  }
135 
136  void init(std::unique_ptr<IndexAccessMethod> accessMethod);
137 
138  inline IndexDescriptor* descriptor() {
139  return this->_impl().descriptor();
140  }
141 
142  inline const IndexDescriptor* descriptor() const {
143  return this->_impl().descriptor();
144  }
145 
146  inline IndexAccessMethod* accessMethod() {
147  return this->_impl().accessMethod();
148  }
149 
150  inline const IndexAccessMethod* accessMethod() const {
151  return this->_impl().accessMethod();
152  }
153 
154  inline const Ordering& ordering() const {
155  return this->_impl().ordering();
156  }
157 
158  inline const MatchExpression* getFilterExpression() const {
159  return this->_impl().getFilterExpression();
160  }
161 
162  inline const CollatorInterface* getCollator() const {
163  return this->_impl().getCollator();
164  }
165 
167 
168  inline const RecordId& head(OperationContext* const opCtx) const {
169  return this->_impl().head(opCtx);
170  }
171 
172  inline void setHead(OperationContext* const opCtx, const RecordId newHead) {
173  return this->_impl().setHead(opCtx, newHead);
174  }
175 
176  inline void setIsReady(const bool newIsReady) {
177  return this->_impl().setIsReady(newIsReady);
178  }
179 
180  inline HeadManager* headManager() const {
181  return this->_impl().headManager();
182  }
183 
184  // --
185 
189  inline bool isMultikey(OperationContext* opCtx) const {
190  return this->_impl().isMultikey(opCtx);
191  }
192 
202  inline MultikeyPaths getMultikeyPaths(OperationContext* const opCtx) const {
203  return this->_impl().getMultikeyPaths(opCtx);
204  }
205 
221  void setMultikey(OperationContext* const opCtx, const MultikeyPaths& multikeyPaths) {
222  return this->_impl().setMultikey(opCtx, multikeyPaths);
223  }
224 
225  // if this ready is ready for queries
226  bool isReady(OperationContext* const opCtx) const {
227  return this->_impl().isReady(opCtx);
228  }
229 
230  KVPrefix getPrefix() const {
231  return this->_impl().getPrefix();
232  }
233 
238  boost::optional<Timestamp> getMinimumVisibleSnapshot() {
239  return this->_impl().getMinimumVisibleSnapshot();
240  }
241 
242  void setMinimumVisibleSnapshot(const Timestamp name) {
243  return this->_impl().setMinimumVisibleSnapshot(name);
244  }
245 
246 private:
247  // This structure exists to give us a customization point to decide how to force users of this
248  // class to depend upon the corresponding `index_catalog_entry.cpp` Translation Unit (TU). All
249  // public forwarding functions call `_impl(), and `_impl` creates an instance of this structure.
250  struct TUHook {
251  static void hook() noexcept;
252 
253  explicit inline TUHook() noexcept {
254  if (kDebugBuild)
255  this->hook();
256  }
257  };
258 
259  inline const Impl& _impl() const {
260  TUHook{};
261  return *this->_pimpl;
262  }
263 
264  inline Impl& _impl() {
265  TUHook{};
266  return *this->_pimpl;
267  }
268 
269  std::unique_ptr<Impl> _pimpl;
270 };
271 
273 public:
274  typedef std::vector<std::unique_ptr<IndexCatalogEntry>>::const_iterator const_iterator;
275  typedef std::vector<std::unique_ptr<IndexCatalogEntry>>::const_iterator iterator;
276 
277  const_iterator begin() const {
278  return _entries.begin();
279  }
280 
281  const_iterator end() const {
282  return _entries.end();
283  }
284 
285  iterator begin() {
286  return _entries.begin();
287  }
288 
289  iterator end() {
290  return _entries.end();
291  }
292 
293  // TODO: these have to be SUPER SUPER FAST
294  // maybe even some pointer trickery is in order
295  const IndexCatalogEntry* find(const IndexDescriptor* desc) const;
296  IndexCatalogEntry* find(const IndexDescriptor* desc);
297 
298  IndexCatalogEntry* find(const std::string& name);
299 
300 
301  unsigned size() const {
302  return _entries.size();
303  }
304 
305  // -----------------
306 
310  IndexCatalogEntry* release(const IndexDescriptor* desc);
311 
312  bool remove(const IndexDescriptor* desc) {
313  IndexCatalogEntry* entry = release(desc);
314  delete entry;
315  return entry;
316  }
317 
318  // pass ownership to EntryContainer
319  void add(IndexCatalogEntry* entry) {
320  _entries.push_back(std::unique_ptr<IndexCatalogEntry>{entry});
321  }
322 
323 private:
324  std::vector<std::unique_ptr<IndexCatalogEntry>> _entries;
325 };
326 } // namespace mongo
IndexCatalogEntry *const OperationContext *const const StringData CollectionCatalogEntry *const std::unique_ptr< IndexDescriptor > CollectionInfoCache *const infoCache
Definition: index_catalog_entry_impl.cpp:58
const Impl & _impl() const
Definition: index_catalog_entry.h:259
virtual void setMultikey(OperationContext *opCtx, const MultikeyPaths &multikeyPaths)=0
iterator end()
Definition: index_catalog_entry.h:289
KVPrefix getPrefix() const
Definition: index_catalog_entry.h:230
const_iterator begin() const
Definition: index_catalog_entry.h:277
IndexCatalogEntry & operator=(IndexCatalogEntry &&)=delete
void setMultikey(OperationContext *const opCtx, const MultikeyPaths &multikeyPaths)
Sets this index to be multikey.
Definition: index_catalog_entry.h:221
boost::optional< Timestamp > getMinimumVisibleSnapshot()
If return value is not boost::none, reads with majority read concern using an older snapshot must tre...
Definition: index_catalog_entry.h:238
Definition: index_catalog_entry.h:272
void setMinimumVisibleSnapshot(const Timestamp name)
Definition: index_catalog_entry.h:242
const RecordId & head(OperationContext *const opCtx) const
Definition: index_catalog_entry.h:168
Definition: index_catalog_entry.h:61
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
IndexCatalogEntryContainer * _entries
Definition: index_catalog_impl.cpp:1017
Definition: collection_catalog_entry.h:47
Database *const this_
Definition: database_impl.cpp:82
static MONGO_DECLARE_SHIM((IndexCatalogEntry *this_, OperationContext *opCtx, StringData ns, CollectionCatalogEntry *collection, std::unique_ptr< IndexDescriptor > descriptor, CollectionInfoCache *infoCache, PrivateTo< IndexCatalogEntry >) ->std::unique_ptr< Impl >) makeImpl
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
virtual IndexDescriptor * descriptor()=0
IndexCatalogEntry(OperationContext *opCtx, StringData ns, CollectionCatalogEntry *collection, std::unique_ptr< IndexDescriptor > descriptor, CollectionInfoCache *infoCache)
Definition: index_catalog_entry.cpp:45
bool isMultikey(OperationContext *opCtx) const
Returns true if this index is multikey and false otherwise.
Definition: index_catalog_entry.h:189
virtual const CollatorInterface * getCollator() const =0
virtual HeadManager * headManager() const =0
const std::string & ns() const
Definition: index_catalog_entry.h:132
TUHook() noexcept
Definition: index_catalog_entry.h:253
virtual const std::string & ns() const =0
const IndexAccessMethod * accessMethod() const
Definition: index_catalog_entry.h:150
const Ordering & ordering() const
Definition: index_catalog_entry.h:154
virtual KVPrefix getPrefix() const =0
virtual boost::optional< Timestamp > getMinimumVisibleSnapshot()=0
virtual bool isReady(OperationContext *opCtx) const =0
IndexDescriptor * descriptor()
Definition: index_catalog_entry.h:138
IndexCatalogEntry(std::unique_ptr< Impl > impl)
Definition: index_catalog_entry.h:125
void setHead(OperationContext *const opCtx, const RecordId newHead)
Definition: index_catalog_entry.h:172
virtual IndexAccessMethod * accessMethod()=0
const CollatorInterface * getCollator() const
Definition: index_catalog_entry.h:162
HeadManager * headManager() const
Definition: index_catalog_entry.h:180
Definition: index_catalog_entry.h:56
std::vector< std::unique_ptr< IndexCatalogEntry > > _entries
Definition: index_catalog_entry.h:324
const IndexDescriptor * descriptor() const
Definition: index_catalog_entry.h:142
unsigned size() const
Definition: index_catalog_entry.h:301
iterator begin()
Definition: index_catalog_entry.h:285
virtual MultikeyPaths getMultikeyPaths(OperationContext *opCtx) const =0
virtual const MatchExpression * getFilterExpression() const =0
Impl & _impl()
Definition: index_catalog_entry.h:264
void setIsReady(const bool newIsReady)
Definition: index_catalog_entry.h:176
bool isReady(OperationContext *const opCtx) const
Definition: index_catalog_entry.h:226
virtual void setMinimumVisibleSnapshot(Timestamp name)=0
MultikeyPaths getMultikeyPaths(OperationContext *const opCtx) const
Returns the path components that cause this index to be multikey if this index supports path-level mu...
Definition: index_catalog_entry.h:202
std::vector< std::unique_ptr< IndexCatalogEntry > >::const_iterator const_iterator
Definition: index_catalog_entry.h:274
virtual bool isMultikey(OperationContext *opCtx) const =0
virtual const RecordId & head(OperationContext *opCtx) const =0
void add(IndexCatalogEntry *entry)
Definition: index_catalog_entry.h:319
A KVPrefix may be prepended to the keys of entries in an underlying KV store.
Definition: kv_prefix.h:44
An abstraction for setting and getting data about the &#39;head&#39; of an index.
Definition: head_manager.h:41
virtual const Ordering & ordering() const =0
std::vector< std::unique_ptr< IndexCatalogEntry > >::const_iterator iterator
Definition: index_catalog_entry.h:275
virtual void setIsReady(bool newIsReady)=0
const MatchExpression * getFilterExpression() const
Definition: index_catalog_entry.h:158
Database *const OperationContext *const const StringData name
Definition: database_impl.cpp:82
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
std::unique_ptr< Impl > _pimpl
Definition: index_catalog_entry.h:269
virtual void setHead(OperationContext *opCtx, RecordId newHead)=0
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_iterator end() const
Definition: index_catalog_entry.h:281
IndexAccessMethod * accessMethod()
Definition: index_catalog_entry.h:146
virtual void init(std::unique_ptr< IndexAccessMethod > accessMethod)=0
Definition: index_catalog_entry.h:250