Storage Engine API
mobile_index.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <set>
32 
38 #include "mongo/platform/basic.h"
39 
40 namespace mongo {
41 
43 public:
44  MobileIndex(OperationContext* opCtx, const IndexDescriptor* desc, const std::string& ident);
45 
46  MobileIndex(bool isUnique, const Ordering& ordering, const std::string& ident);
47 
48  virtual ~MobileIndex() {}
49 
50  Status insert(OperationContext* opCtx,
51  const BSONObj& key,
52  const RecordId& recId,
53  bool dupsAllowed) override;
54 
55  void unindex(OperationContext* opCtx,
56  const BSONObj& key,
57  const RecordId& recId,
58  bool dupsAllowed) override;
59 
60  void fullValidate(OperationContext* opCtx,
61  long long* numKeysOut,
62  ValidateResults* fullResults) const override;
63 
64  bool appendCustomStats(OperationContext* opCtx,
65  BSONObjBuilder* output,
66  double scale) const override;
67 
68  long long getSpaceUsedBytes(OperationContext* opCtx) const override;
69 
70  long long numEntries(OperationContext* opCtx) const override;
71 
72  bool isEmpty(OperationContext* opCtx) override;
73 
74  Status initAsEmpty(OperationContext* opCtx) override;
75 
76  Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key, const RecordId& recId) override;
77 
78  // Beginning of MobileIndex-specific methods
79 
83  static Status create(OperationContext* opCtx, const std::string& ident);
84 
88  template <typename ValueType>
89  Status doInsert(OperationContext* opCtx,
90  const KeyString& key,
91  const ValueType& value,
92  bool isTransactional = true);
93 
94  Ordering getOrdering() const {
95  return _ordering;
96  }
97 
99  return _keyStringVersion;
100  }
101 
102  bool isUnique() {
103  return _isUnique;
104  }
105 
106  std::string getIdent() const {
107  return _ident;
108  }
109 
110 protected:
111  bool _isDup(OperationContext* opCtx, const BSONObj& key, RecordId recId);
112 
113  Status _dupKeyError(const BSONObj& key);
114 
118  static Status _checkKeySize(const BSONObj& key);
119 
123  void _doDelete(OperationContext* opCtx, const KeyString& key, KeyString* value = nullptr);
124 
125  virtual Status _insert(OperationContext* opCtx,
126  const BSONObj& key,
127  const RecordId& recId,
128  bool dupsAllowed) = 0;
129 
130  virtual void _unindex(OperationContext* opCtx,
131  const BSONObj& key,
132  const RecordId& recId,
133  bool dupsAllowed) = 0;
134 
135  class BulkBuilderBase;
136  class BulkBuilderStandard;
138 
139  const bool _isUnique;
140  const Ordering _ordering;
142  const std::string _ident;
143 };
144 
145 class MobileIndexStandard final : public MobileIndex {
146 public:
147  MobileIndexStandard(OperationContext* opCtx,
148  const IndexDescriptor* desc,
149  const std::string& ident);
150 
151  MobileIndexStandard(const Ordering& ordering, const std::string& ident);
152 
153  SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) override;
154 
155  std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx,
156  bool isForward) const override;
157 
158 protected:
159  Status _insert(OperationContext* opCtx,
160  const BSONObj& key,
161  const RecordId& recId,
162  bool dupsAllowed) override;
163 
164  void _unindex(OperationContext* opCtx,
165  const BSONObj& key,
166  const RecordId& recId,
167  bool dupsAllowed) override;
168 };
169 
170 class MobileIndexUnique final : public MobileIndex {
171 public:
172  MobileIndexUnique(OperationContext* opCtx,
173  const IndexDescriptor* desc,
174  const std::string& ident);
175 
176  MobileIndexUnique(const Ordering& ordering, const std::string& ident);
177 
178  SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) override;
179 
180  std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx,
181  bool isForward) const override;
182 
183 protected:
184  Status _insert(OperationContext* opCtx,
185  const BSONObj& key,
186  const RecordId& recId,
187  bool dupsAllowed) override;
188 
189  void _unindex(OperationContext* opCtx,
190  const BSONObj& key,
191  const RecordId& recId,
192  bool dupsAllowed) override;
193 
194  const bool _isPartial = false;
195 };
196 } // namespace mongo
virtual std::unique_ptr< Cursor > newCursor(OperationContext *opCtx, bool isForward=true) const =0
Returns an unpositioned cursor over &#39;this&#39; index.
Bulk builds a unique index.
Definition: mobile_index.cpp:367
Status dupKeyCheck(OperationContext *opCtx, const BSONObj &key, const RecordId &recId) override
Return ErrorCodes::DuplicateKey if &#39;key&#39; already exists in &#39;this&#39; index at a RecordId other than &#39;loc...
Definition: mobile_index.cpp:241
Definition: record_store.h:671
const bool _isUnique
Definition: mobile_index.h:137
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
static Status create(OperationContext *opCtx, const std::string &ident)
Creates a SQLite table suitable for a new Mobile index.
Definition: mobile_index.cpp:231
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
Definition: key_string.h:47
Definition: mobile_index.cpp:297
Version
Selects version of KeyString to use.
Definition: key_string.h:52
BSONObj key
Definition: btree_interface.cpp:334
virtual Status _insert(OperationContext *opCtx, const BSONObj &key, const RecordId &recId, bool dupsAllowed)=0
const Ordering _ordering
Definition: mobile_index.h:140
static const Version kLatestVersion
Provides the latest version of KeyString available.
Definition: key_string.h:60
const KeyString::Version _keyStringVersion
Definition: mobile_index.h:141
void unindex(OperationContext *opCtx, const BSONObj &key, const RecordId &recId, bool dupsAllowed) override
Remove the entry from the index with the specified key and RecordId.
Definition: mobile_index.cpp:135
bool _isDup(OperationContext *opCtx, const BSONObj &key, RecordId recId)
Definition: mobile_index.cpp:252
virtual SortedDataBuilderInterface * getBulkBuilder(OperationContext *opCtx, bool dupsAllowed)=0
Return a bulk builder for &#39;this&#39; index.
Status doInsert(OperationContext *opCtx, const KeyString &key, const ValueType &value, bool isTransactional=true)
Performs the insert into the table with the given key and value.
Definition: mobile_index.cpp:98
static Status _checkKeySize(const BSONObj &key)
Checks if key size is too long.
Definition: mobile_index.cpp:290
Definition: mobile_index.h:170
bool isEmpty(OperationContext *opCtx) override
Return true if &#39;this&#39; index is empty, and false otherwise.
Definition: mobile_index.cpp:213
A version-hiding wrapper around the bulk builder for the Btree.
Definition: sorted_data_interface.h:394
KeyString::Version getKeyStringVersion() const
Definition: mobile_index.h:98
void fullValidate(OperationContext *opCtx, long long *numKeysOut, ValidateResults *fullResults) const override
Note: this validates the entire database file, not just the table used by this index.
Definition: mobile_index.cpp:166
MobileIndex(OperationContext *opCtx, const IndexDescriptor *desc, const std::string &ident)
Definition: mobile_index.cpp:74
Ordering getOrdering() const
Definition: mobile_index.h:94
long long getSpaceUsedBytes(OperationContext *opCtx) const override
Return the number of bytes consumed by &#39;this&#39; index.
Definition: mobile_index.cpp:186
virtual void _unindex(OperationContext *opCtx, const BSONObj &key, const RecordId &recId, bool dupsAllowed)=0
Bulk builds a non-unique index.
Definition: mobile_index.cpp:351
Definition: mobile_index.h:42
bool isUnique()
Definition: mobile_index.h:102
std::string getIdent() const
Definition: mobile_index.h:106
Status insert(OperationContext *opCtx, const BSONObj &key, const RecordId &recId, bool dupsAllowed) override
Insert an entry into the index with the specified key and RecordId.
Definition: mobile_index.cpp:82
Definition: mobile_index.h:145
bool appendCustomStats(OperationContext *opCtx, BSONObjBuilder *output, double scale) const override
Definition: mobile_index.cpp:180
const std::string _ident
Definition: mobile_index.h:142
long long numEntries(OperationContext *opCtx) const override
Return the number of entries in &#39;this&#39; index.
Definition: mobile_index.cpp:203
virtual ~MobileIndex()
Definition: mobile_index.h:48
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
void _doDelete(OperationContext *opCtx, const KeyString &key, KeyString *value=nullptr)
Performs the deletion from the table matching the given key.
Definition: mobile_index.cpp:145
OperationContext const IndexDescriptor * desc
Definition: index_catalog_impl.cpp:97
Status _dupKeyError(const BSONObj &key)
Definition: mobile_index.cpp:282
This interface is a work in progress.
Definition: sorted_data_interface.h:64
Status initAsEmpty(OperationContext *opCtx) override
Definition: mobile_index.cpp:226