Storage Engine API
heap_record_store_btree.h
Go to the documentation of this file.
1 // heap_record_store_btree.h
2 
31 #pragma once
32 
33 #include <boost/shared_array.hpp>
34 #include <map>
35 
38 
39 namespace mongo {
40 
46  struct MmapV1RecordHeader;
47 
48 public:
49  // RecordId(0,0) isn't valid for records.
50  explicit HeapRecordStoreBtree(StringData ns) : RecordStore(ns), _nextId(1) {}
51 
52  virtual RecordData dataFor(OperationContext* opCtx, const RecordId& loc) const;
53 
54  virtual bool findRecord(OperationContext* opCtx, const RecordId& loc, RecordData* out) const;
55 
56  virtual void deleteRecord(OperationContext* opCtx, const RecordId& dl);
57 
59  OperationContext* opCtx, const char* data, int len, Timestamp, bool enforceQuota);
60 
61  virtual Status insertRecordsWithDocWriter(OperationContext* opCtx,
62  const DocWriter* const* docs,
63  const Timestamp*,
64  size_t nDocs,
65  RecordId* idsOut);
66 
67  virtual long long numRecords(OperationContext* opCtx) const {
68  return _records.size();
69  }
70 
71  virtual Status touch(OperationContext* opCtx, BSONObjBuilder* output) const;
72 
73  // public methods below here are not necessary to test btree, and will crash when called.
74 
75  // ------------------------------
76 
77  virtual Status updateRecord(OperationContext* opCtx,
78  const RecordId& oldLocation,
79  const char* data,
80  int len,
81  bool enforceQuota,
82  UpdateNotifier* notifier) {
83  MONGO_UNREACHABLE;
84  }
85 
86  virtual bool updateWithDamagesSupported() const {
87  return true;
88  }
89 
90  virtual StatusWith<RecordData> updateWithDamages(OperationContext* opCtx,
91  const RecordId& loc,
92  const RecordData& oldRec,
93  const char* damageSource,
94  const mutablebson::DamageVector& damages) {
95  MONGO_UNREACHABLE;
96  }
97 
98  std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
99  bool forward) const final {
100  MONGO_UNREACHABLE;
101  }
102 
103 
104  virtual Status truncate(OperationContext* opCtx) {
105  MONGO_UNREACHABLE;
106  }
107 
108  virtual void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive) {
109  MONGO_UNREACHABLE;
110  }
111 
112  virtual bool compactSupported() const {
113  MONGO_UNREACHABLE;
114  }
115 
116  virtual Status validate(OperationContext* opCtx,
117  ValidateCmdLevel level,
118  ValidateAdaptor* adaptor,
119  ValidateResults* results,
120  BSONObjBuilder* output) {
121  MONGO_UNREACHABLE;
122  }
123 
124  virtual void appendCustomStats(OperationContext* opCtx,
125  BSONObjBuilder* result,
126  double scale) const {
127  MONGO_UNREACHABLE;
128  }
129 
130  virtual void increaseStorageSize(OperationContext* opCtx, int size, bool enforceQuota) {
131  MONGO_UNREACHABLE;
132  }
133 
134  virtual int64_t storageSize(OperationContext* opCtx,
135  BSONObjBuilder* extraInfo = NULL,
136  int infoLevel = 0) const {
137  MONGO_UNREACHABLE;
138  }
139 
140  virtual long long dataSize(OperationContext* opCtx) const {
141  MONGO_UNREACHABLE;
142  }
143 
144  virtual MmapV1RecordHeader* recordFor(const RecordId& loc) const {
145  MONGO_UNREACHABLE;
146  }
147 
148  virtual bool isCapped() const {
149  MONGO_UNREACHABLE;
150  }
151 
152  virtual const char* name() const {
153  MONGO_UNREACHABLE;
154  }
155 
156  void waitForAllEarlierOplogWritesToBeVisible(OperationContext* opCtx) const override {
157  MONGO_UNREACHABLE;
158  }
159 
160  virtual void updateStatsAfterRepair(OperationContext* opCtx,
161  long long numRecords,
162  long long dataSize) {
163  MONGO_UNREACHABLE;
164  }
165  // more things that we actually care about below
166 
167 private:
169  MmapV1RecordHeader() : dataSize(-1), data() {}
170  explicit MmapV1RecordHeader(int size) : dataSize(size), data(new char[size]) {}
171 
172  int dataSize;
173  boost::shared_array<char> data;
174  };
175 
176  RecordId allocateLoc();
177 
178  typedef std::map<RecordId, HeapRecordStoreBtree::MmapV1RecordHeader> Records;
179  Records _records;
180  int64_t _nextId;
181 };
182 
187 public:
188  void beginUnitOfWork(OperationContext* opCtx) final{};
189  void commitUnitOfWork() final;
190  void abortUnitOfWork() final;
191 
192  virtual bool waitUntilDurable() {
193  return true;
194  }
195 
196  virtual void abandonSnapshot() {}
197 
198  virtual void registerChange(Change* change) {
199  change->commit(boost::none);
200  delete change;
201  }
202 
203  virtual void* writingPtr(void* data, size_t len);
204 
205  virtual void setRollbackWritesDisabled() {}
206 
207  virtual SnapshotId getSnapshotId() const {
208  return SnapshotId();
209  }
210 
211  virtual void setOrderedCommit(bool orderedCommit) {}
212 
213  // -----------------------
214 
215  void notifyInsert(HeapRecordStoreBtree* rs, const RecordId& loc);
216  static void notifyInsert(OperationContext* ctx, HeapRecordStoreBtree* rs, const RecordId& loc);
217 
218 private:
219  struct InsertEntry {
221  RecordId loc;
222  };
223  std::vector<InsertEntry> _insertions;
224 
225  struct ModEntry {
226  void* data;
227  size_t len;
228  boost::shared_array<char> old;
229  };
230  std::vector<ModEntry> _mods;
231 };
232 
233 } // namespace mongo
Definition: heap_record_store_btree.h:219
RecordId allocateLoc()
Definition: heap_record_store_btree.cpp:103
ValidateCmdLevel
Definition: record_store.h:93
virtual long long dataSize(OperationContext *opCtx) const
The dataSize is an approximation of the sum of the sizes (in bytes) of the documents or entries in th...
Definition: heap_record_store_btree.h:140
Definition: heap_record_store_btree.h:168
Definition: record_store.h:671
virtual bool compactSupported() const
does this RecordStore support the compact operation?
Definition: heap_record_store_btree.h:112
virtual void registerChange(Change *change)
The RecoveryUnit takes ownership of the change.
Definition: heap_record_store_btree.h:198
virtual StatusWith< RecordData > updateWithDamages(OperationContext *opCtx, const RecordId &loc, const RecordData &oldRec, const char *damageSource, const mutablebson::DamageVector &damages)
Updates the record positioned at &#39;loc&#39; in-place using the deltas described by &#39;damages&#39;.
Definition: heap_record_store_btree.h:90
HeapRecordStoreBtree(StringData ns)
Definition: heap_record_store_btree.h:50
virtual void setOrderedCommit(bool orderedCommit)
Definition: heap_record_store_btree.h:211
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
void * data
Definition: heap_record_store_btree.h:226
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
virtual SnapshotId getSnapshotId() const
Gets the local SnapshotId.
Definition: heap_record_store_btree.h:207
size_t len
Definition: heap_record_store_btree.h:227
A replacement for the Record class.
Definition: record_data.h:43
virtual RecordData dataFor(OperationContext *opCtx, const RecordId &loc) const
Get the RecordData at loc, which must exist.
Definition: heap_record_store_btree.cpp:45
virtual MmapV1RecordHeader * recordFor(const RecordId &loc) const
Definition: heap_record_store_btree.h:144
This is so when a RecordStore is validating all records it can call back to someone to check if a rec...
Definition: record_store.h:685
Definition: record_store.h:78
Definition: heap_record_store_btree.h:225
bool inclusive
Definition: btree_interface.cpp:335
RecordId loc
Definition: heap_record_store_btree.h:221
Allows inserting a Record "in-place" without creating a copy ahead of time.
Definition: record_store.h:62
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
virtual const char * name() const
Definition: heap_record_store_btree.h:152
std::unique_ptr< RecordStore > rs
Definition: kv_engine_test_timestamps.cpp:207
virtual void setRollbackWritesDisabled()
Sets a flag that declares this RecoveryUnit will skip rolling back writes, for the duration of the cu...
Definition: heap_record_store_btree.h:205
HeapRecordStoreBtree * rs
Definition: heap_record_store_btree.h:220
virtual void abandonSnapshot()
If there is an open transaction, it is closed.
Definition: heap_record_store_btree.h:196
A RecoveryUnit for HeapRecordStoreBtree, this is for testing btree only.
Definition: heap_record_store_btree.h:186
A RecordStore that stores all data on the heap.
Definition: heap_record_store_btree.h:45
Definition: index_key_validate.h:40
virtual void commit(boost::optional< Timestamp > commitTime)=0
A RecoveryUnit is responsible for ensuring that data is persisted.
Definition: recovery_unit.h:51
virtual bool findRecord(OperationContext *opCtx, const RecordId &loc, RecordData *out) const
Definition: heap_record_store_btree.cpp:53
std::vector< ModEntry > _mods
Definition: heap_record_store_btree.h:230
An abstraction used for storing documents in a collection or entries in an index. ...
Definition: record_store.h:282
virtual Status insertRecordsWithDocWriter(OperationContext *opCtx, const DocWriter *const *docs, const Timestamp *, size_t nDocs, RecordId *idsOut)
Inserts nDocs documents into this RecordStore using the DocWriter interface.
Definition: heap_record_store_btree.cpp:81
virtual const std::string & ns() const
Definition: record_store.h:295
MmapV1RecordHeader(int size)
Definition: heap_record_store_btree.h:170
virtual Status truncate(OperationContext *opCtx)
removes all Records
Definition: heap_record_store_btree.h:104
virtual void updateStatsAfterRepair(OperationContext *opCtx, long long numRecords, long long dataSize)
Called after a repair operation is run with the recomputed numRecords and dataSize.
Definition: heap_record_store_btree.h:160
virtual Status validate(OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output)
Definition: heap_record_store_btree.h:116
virtual bool waitUntilDurable()
Waits until all commits that happened before this call are durable in the journal.
Definition: heap_record_store_btree.h:192
std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *opCtx, bool forward) const final
Returns a new cursor over this record store.
Definition: heap_record_store_btree.h:98
std::map< RecordId, HeapRecordStoreBtree::MmapV1RecordHeader > Records
Definition: heap_record_store_btree.h:178
virtual void increaseStorageSize(OperationContext *opCtx, int size, bool enforceQuota)
Definition: heap_record_store_btree.h:130
A Change is an action that is registerChange()&#39;d while a WriteUnitOfWork exists.
Definition: recovery_unit.h:281
virtual void appendCustomStats(OperationContext *opCtx, BSONObjBuilder *result, double scale) const
Definition: heap_record_store_btree.h:124
virtual void deleteRecord(OperationContext *opCtx, const RecordId &dl)
Definition: heap_record_store_btree.cpp:64
virtual int64_t storageSize(OperationContext *opCtx, BSONObjBuilder *extraInfo=NULL, int infoLevel=0) const
Definition: heap_record_store_btree.h:134
Records _records
Definition: heap_record_store_btree.h:179
Definition: snapshot.h:37
MmapV1RecordHeader()
Definition: heap_record_store_btree.h:169
virtual bool isCapped() const
Definition: heap_record_store_btree.h:148
virtual Status touch(OperationContext *opCtx, BSONObjBuilder *output) const
Load all data into cache.
Definition: heap_record_store_btree.cpp:113
virtual bool updateWithDamagesSupported() const
Definition: heap_record_store_btree.h:86
void waitForAllEarlierOplogWritesToBeVisible(OperationContext *opCtx) const override
Waits for all writes that completed before this call to be visible to forward scans.
Definition: heap_record_store_btree.h:156
int64_t _nextId
Definition: heap_record_store_btree.h:180
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
boost::shared_array< char > old
Definition: heap_record_store_btree.h:228
virtual Status updateRecord(OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier)
Definition: heap_record_store_btree.h:77
std::vector< InsertEntry > _insertions
Definition: heap_record_store_btree.h:223
int dataSize
Definition: heap_record_store_btree.h:172
virtual void cappedTruncateAfter(OperationContext *opCtx, RecordId end, bool inclusive)
Truncate documents newer than the document at &#39;end&#39; from the capped collection.
Definition: heap_record_store_btree.h:108
virtual long long numRecords(OperationContext *opCtx) const
Total number of record in the RecordStore.
Definition: heap_record_store_btree.h:67
virtual StatusWith< RecordId > insertRecord(OperationContext *opCtx, const char *data, int len, Timestamp, bool enforceQuota)
Definition: heap_record_store_btree.cpp:68
void beginUnitOfWork(OperationContext *opCtx) final
Marks the beginning of a unit of work.
Definition: heap_record_store_btree.h:188
boost::shared_array< char > data
Definition: heap_record_store_btree.h:173