Storage Engine API
index_catalog_entry_impl.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/bson/ordering.h"
36 #include "mongo/bson/timestamp.h"
38 #include "mongo/db/index/multikey_paths.h"
39 #include "mongo/db/matcher/expression.h"
40 #include "mongo/db/record_id.h"
42 #include "mongo/platform/atomic_word.h"
43 #include "mongo/stdx/mutex.h"
44 
45 namespace mongo {
46 
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 
58 
59 public:
60  explicit IndexCatalogEntryImpl(
62  OperationContext* opCtx,
63  StringData ns,
64  CollectionCatalogEntry* collection, // not owned
65  std::unique_ptr<IndexDescriptor> descriptor, // ownership passes to me
66  CollectionInfoCache* infoCache); // not owned, optional
67 
68  ~IndexCatalogEntryImpl() final;
69 
70  const std::string& ns() const final {
71  return _ns;
72  }
73 
74  void init(std::unique_ptr<IndexAccessMethod> accessMethod) final;
75 
76  IndexDescriptor* descriptor() final {
77  return _descriptor.get();
78  }
79  const IndexDescriptor* descriptor() const final {
80  return _descriptor.get();
81  }
82 
83  IndexAccessMethod* accessMethod() final {
84  return _accessMethod.get();
85  }
86  const IndexAccessMethod* accessMethod() const final {
87  return _accessMethod.get();
88  }
89 
90  const Ordering& ordering() const final {
91  return _ordering;
92  }
93 
94  const MatchExpression* getFilterExpression() const final {
95  return _filterExpression.get();
96  }
97 
98  const CollatorInterface* getCollator() const final {
99  return _collator.get();
100  }
101 
103 
104  const RecordId& head(OperationContext* opCtx) const final;
105 
106  void setHead(OperationContext* opCtx, RecordId newHead) final;
107 
108  void setIsReady(bool newIsReady) final;
109 
110  HeadManager* headManager() const final {
111  return _headManager.get();
112  }
113 
114  // --
115 
119  bool isMultikey(OperationContext* opCtx) const final;
120 
130  MultikeyPaths getMultikeyPaths(OperationContext* opCtx) const final;
131 
147  void setMultikey(OperationContext* opCtx, const MultikeyPaths& multikeyPaths) final;
148 
149  // if this ready is ready for queries
150  bool isReady(OperationContext* opCtx) const final;
151 
152  KVPrefix getPrefix() const final {
153  return _prefix;
154  }
155 
160  boost::optional<Timestamp> getMinimumVisibleSnapshot() final {
161  return _minVisibleSnapshot;
162  }
163 
164  void setMinimumVisibleSnapshot(Timestamp name) final {
166  }
167 
168 private:
169  class SetMultikeyChange;
170  class SetHeadChange;
171 
172  bool _catalogIsReady(OperationContext* opCtx) const;
173  RecordId _catalogHead(OperationContext* opCtx) const;
174 
180  bool _catalogIsMultikey(OperationContext* opCtx, MultikeyPaths* multikeyPaths) const;
181 
182  KVPrefix _catalogGetPrefix(OperationContext* opCtx) const;
183 
184  // -----
185 
186  std::string _ns;
187 
189 
190  std::unique_ptr<IndexDescriptor> _descriptor; // owned here
191 
192  CollectionInfoCache* _infoCache; // not owned here
193 
194  std::unique_ptr<IndexAccessMethod> _accessMethod;
195 
196  // Owned here.
197  std::unique_ptr<HeadManager> _headManager;
198  std::unique_ptr<CollatorInterface> _collator;
199  std::unique_ptr<MatchExpression> _filterExpression;
200 
201  // cached stuff
202 
203  Ordering _ordering; // TODO: this might be b-tree specific
204  bool _isReady; // cache of NamespaceDetails info
205  RecordId _head; // cache of IndexDetails
206 
207  // Set to true if this index supports path-level multikey tracking.
208  // '_indexTracksPathLevelMultikeyInfo' is effectively const after IndexCatalogEntry::init() is
209  // called.
211 
212  // Set to true if this index is multikey. '_isMultikey' serves as a cache of the information
213  // stored in the NamespaceDetails or KVCatalog.
214  AtomicWord<bool> _isMultikey;
215 
216  // Controls concurrent access to '_indexMultikeyPaths'. We acquire this mutex rather than the
217  // RESOURCE_METADATA lock as a performance optimization so that it is cheaper to detect whether
218  // there is actually any path-level multikey information to update or not.
219  mutable stdx::mutex _indexMultikeyPathsMutex;
220 
221  // Non-empty only if '_indexTracksPathLevelMultikeyInfo' is true.
222  //
223  // If non-empty, '_indexMultikeyPaths' is a vector with size equal to the number of elements
224  // in the index key pattern. Each element in the vector is an ordered set of positions (starting
225  // at 0) into the corresponding indexed field that represent what prefixes of the indexed field
226  // causes the index to be multikey.
227  MultikeyPaths _indexMultikeyPaths;
228 
229  // KVPrefix used to differentiate between index entries in different logical indexes sharing the
230  // same underlying sorted data interface.
232 
233  // The earliest snapshot that is allowed to read this index.
234  boost::optional<Timestamp> _minVisibleSnapshot;
235 };
236 } // namespace mongo
const RecordId & head(OperationContext *opCtx) const final
Definition: index_catalog_entry_impl.cpp:159
std::string _ns
Definition: index_catalog_entry_impl.h:186
IndexAccessMethod * accessMethod() final
Definition: index_catalog_entry_impl.h:83
IndexCatalogEntry *const OperationContext *const const StringData CollectionCatalogEntry *const std::unique_ptr< IndexDescriptor > CollectionInfoCache *const infoCache
Definition: index_catalog_entry_impl.cpp:58
boost::optional< Timestamp > getMinimumVisibleSnapshot() final
If return value is not boost::none, reads with majority read concern using an older snapshot must tre...
Definition: index_catalog_entry_impl.h:160
MONGO_DISALLOW_COPYING(IndexCatalogEntryImpl)
boost::optional< Timestamp > _minVisibleSnapshot
Definition: index_catalog_entry_impl.h:234
bool isMultikey(OperationContext *opCtx) const final
Returns true if this index is multikey, and returns false otherwise.
Definition: index_catalog_entry_impl.cpp:169
bool _catalogIsReady(OperationContext *opCtx) const
Definition: index_catalog_entry_impl.cpp:344
const MatchExpression * getFilterExpression() const final
Definition: index_catalog_entry_impl.h:94
void setIsReady(bool newIsReady) final
Definition: index_catalog_entry_impl.cpp:216
Definition: index_catalog_entry.h:61
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
MultikeyPaths getMultikeyPaths(OperationContext *opCtx) const final
Returns the path components that cause this index to be multikey if this index supports path-level mu...
Definition: index_catalog_entry_impl.cpp:196
Definition: collection_catalog_entry.h:47
std::unique_ptr< IndexAccessMethod > _accessMethod
Definition: index_catalog_entry_impl.h:194
AtomicWord< bool > _isMultikey
Definition: index_catalog_entry_impl.h:214
bool _indexTracksPathLevelMultikeyInfo
Definition: index_catalog_entry_impl.h:210
Database *const this_
Definition: database_impl.cpp:82
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
const IndexAccessMethod * accessMethod() const final
Definition: index_catalog_entry_impl.h:86
Definition: index_catalog_entry_impl.h:56
const Ordering & ordering() const final
Definition: index_catalog_entry_impl.h:90
IndexDescriptor * descriptor() final
Definition: index_catalog_entry_impl.h:76
void init(std::unique_ptr< IndexAccessMethod > accessMethod) final
Definition: index_catalog_entry_impl.cpp:154
std::unique_ptr< CollatorInterface > _collator
Definition: index_catalog_entry_impl.h:198
KVPrefix _catalogGetPrefix(OperationContext *opCtx) const
Definition: index_catalog_entry_impl.cpp:357
void setMultikey(OperationContext *opCtx, const MultikeyPaths &multikeyPaths) final
Sets this index to be multikey.
Definition: index_catalog_entry_impl.cpp:240
void setHead(OperationContext *opCtx, RecordId newHead) final
Definition: index_catalog_entry_impl.cpp:233
std::unique_ptr< IndexDescriptor > _descriptor
Definition: index_catalog_entry_impl.h:190
bool _catalogIsMultikey(OperationContext *opCtx, MultikeyPaths *multikeyPaths) const
Retrieves the multikey information associated with this index from &#39;_collection&#39;,.
Definition: index_catalog_entry_impl.cpp:352
bool isReady(OperationContext *opCtx) const final
Definition: index_catalog_entry_impl.cpp:164
const std::string & ns() const final
Definition: index_catalog_entry_impl.h:70
MultikeyPaths _indexMultikeyPaths
Definition: index_catalog_entry_impl.h:227
RecordId _head
Definition: index_catalog_entry_impl.h:205
void setMinimumVisibleSnapshot(Timestamp name) final
Definition: index_catalog_entry_impl.h:164
Definition: index_catalog_entry_impl.cpp:220
Definition: index_catalog_entry.h:56
const CollatorInterface * getCollator() const final
Definition: index_catalog_entry_impl.h:98
~IndexCatalogEntryImpl() final
Definition: index_catalog_entry_impl.cpp:147
CollectionInfoCache * _infoCache
Definition: index_catalog_entry_impl.h:192
KVPrefix getPrefix() const final
Definition: index_catalog_entry_impl.h:152
stdx::mutex _indexMultikeyPathsMutex
Definition: index_catalog_entry_impl.h:219
const IndexDescriptor * descriptor() const final
Definition: index_catalog_entry_impl.h:79
HeadManager * headManager() const final
Definition: index_catalog_entry_impl.h:110
IndexCatalogEntryImpl(IndexCatalogEntry *this_, OperationContext *opCtx, StringData ns, CollectionCatalogEntry *collection, std::unique_ptr< IndexDescriptor > descriptor, CollectionInfoCache *infoCache)
Definition: index_catalog_entry_impl.cpp:90
Ordering _ordering
Definition: index_catalog_entry_impl.h:203
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
const KVPrefix _prefix
Definition: index_catalog_entry_impl.h:231
RecordId _catalogHead(OperationContext *opCtx) const
Definition: index_catalog_entry_impl.cpp:348
Database *const OperationContext *const const StringData name
Definition: database_impl.cpp:82
bool _isReady
Definition: index_catalog_entry_impl.h:204
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
std::unique_ptr< MatchExpression > _filterExpression
Definition: index_catalog_entry_impl.h:199
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
CollectionCatalogEntry * _collection
Definition: index_catalog_entry_impl.h:188
std::unique_ptr< HeadManager > _headManager
Definition: index_catalog_entry_impl.h:197