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  const std::string& getIdent() const override {
50  MONGO_UNREACHABLE;
51  }
52 
53  // RecordId(0,0) isn't valid for records.
54  explicit HeapRecordStoreBtree(StringData ns) : RecordStore(ns), _nextId(1) {}
55 
56  virtual RecordData dataFor(OperationContext* opCtx, const RecordId& loc) const;
57 
58  virtual bool findRecord(OperationContext* opCtx, const RecordId& loc, RecordData* out) const;
59 
60  virtual void deleteRecord(OperationContext* opCtx, const RecordId& dl);
61 
63  OperationContext* opCtx, const char* data, int len, Timestamp, bool enforceQuota);
64 
65  virtual Status insertRecordsWithDocWriter(OperationContext* opCtx,
66  const DocWriter* const* docs,
67  const Timestamp*,
68  size_t nDocs,
69  RecordId* idsOut);
70 
71  virtual long long numRecords(OperationContext* opCtx) const {
72  return _records.size();
73  }
74 
75  virtual Status touch(OperationContext* opCtx, BSONObjBuilder* output) const;
76 
77  // public methods below here are not necessary to test btree, and will crash when called.
78 
79  // ------------------------------
80 
81  virtual Status updateRecord(OperationContext* opCtx,
82  const RecordId& oldLocation,
83  const char* data,
84  int len,
85  bool enforceQuota,
86  UpdateNotifier* notifier) {
87  MONGO_UNREACHABLE;
88  }
89 
90  virtual bool updateWithDamagesSupported() const {
91  return true;
92  }
93 
94  virtual StatusWith<RecordData> updateWithDamages(OperationContext* opCtx,
95  const RecordId& loc,
96  const RecordData& oldRec,
97  const char* damageSource,
98  const mutablebson::DamageVector& damages) {
99  MONGO_UNREACHABLE;
100  }
101 
102  std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
103  bool forward) const final {
104  MONGO_UNREACHABLE;
105  }
106 
107 
108  virtual Status truncate(OperationContext* opCtx) {
109  MONGO_UNREACHABLE;
110  }
111 
112  virtual void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive) {
113  MONGO_UNREACHABLE;
114  }
115 
116  virtual bool compactSupported() const {
117  MONGO_UNREACHABLE;
118  }
119 
120  virtual Status validate(OperationContext* opCtx,
121  ValidateCmdLevel level,
122  ValidateAdaptor* adaptor,
123  ValidateResults* results,
124  BSONObjBuilder* output) {
125  MONGO_UNREACHABLE;
126  }
127 
128  virtual void appendCustomStats(OperationContext* opCtx,
129  BSONObjBuilder* result,
130  double scale) const {
131  MONGO_UNREACHABLE;
132  }
133 
134  virtual void increaseStorageSize(OperationContext* opCtx, int size, bool enforceQuota) {
135  MONGO_UNREACHABLE;
136  }
137 
138  virtual int64_t storageSize(OperationContext* opCtx,
139  BSONObjBuilder* extraInfo = NULL,
140  int infoLevel = 0) const {
141  MONGO_UNREACHABLE;
142  }
143 
144  virtual long long dataSize(OperationContext* opCtx) const {
145  MONGO_UNREACHABLE;
146  }
147 
148  virtual MmapV1RecordHeader* recordFor(const RecordId& loc) const {
149  MONGO_UNREACHABLE;
150  }
151 
152  virtual bool isCapped() const {
153  MONGO_UNREACHABLE;
154  }
155 
156  virtual const char* name() const {
157  MONGO_UNREACHABLE;
158  }
159 
160  void waitForAllEarlierOplogWritesToBeVisible(OperationContext* opCtx) const override {
161  MONGO_UNREACHABLE;
162  }
163 
164  virtual void updateStatsAfterRepair(OperationContext* opCtx,
165  long long numRecords,
166  long long dataSize) {
167  MONGO_UNREACHABLE;
168  }
169  // more things that we actually care about below
170 
171 private:
174  explicit MmapV1RecordHeader(int size) : dataSize(size), data(new char[size]) {}
175 
176  int dataSize;
177  boost::shared_array<char> data;
178  };
179 
180  RecordId allocateLoc();
181 
182  typedef std::map<RecordId, HeapRecordStoreBtree::MmapV1RecordHeader> Records;
184  int64_t _nextId;
185 };
186 
191 public:
192  void beginUnitOfWork(OperationContext* opCtx) final{};
193  void commitUnitOfWork() final;
194  void abortUnitOfWork() final;
195 
196  virtual bool waitUntilDurable() {
197  return true;
198  }
199 
200  virtual void abandonSnapshot() {}
201 
202  virtual void registerChange(Change* change) {
203  change->commit(boost::none);
204  delete change;
205  }
206 
207  virtual void* writingPtr(void* data, size_t len);
208 
209  virtual void setRollbackWritesDisabled() {}
210 
211  virtual SnapshotId getSnapshotId() const {
212  return SnapshotId();
213  }
214 
215  virtual void setOrderedCommit(bool orderedCommit) {}
216 
217  // -----------------------
218 
219  void notifyInsert(HeapRecordStoreBtree* rs, const RecordId& loc);
220  static void notifyInsert(OperationContext* ctx, HeapRecordStoreBtree* rs, const RecordId& loc);
221 
222 private:
223  struct InsertEntry {
225  RecordId loc;
226  };
227  std::vector<InsertEntry> _insertions;
228 
229  struct ModEntry {
230  void* data;
231  size_t len;
232  boost::shared_array<char> old;
233  };
234  std::vector<ModEntry> _mods;
235 };
236 
237 } // namespace mongo
void notifyInsert(HeapRecordStoreBtree *rs, const RecordId &loc)
Definition: heap_record_store_btree.cpp:142
Definition: heap_record_store_btree.h:223
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:144
Definition: heap_record_store_btree.h:172
Definition: record_store.h:673
virtual bool compactSupported() const
does this RecordStore support the compact operation?
Definition: heap_record_store_btree.h:116
virtual void registerChange(Change *change)
The RecoveryUnit takes ownership of the change.
Definition: heap_record_store_btree.h:202
virtual StatusWith< RecordData > updateWithDamages(OperationContext *opCtx, const RecordId &loc, const RecordData &oldRec, const char *damageSource, const mutablebson::DamageVector &damages)
Updates the record positioned at 'loc' in-place using the deltas described by 'damages'.
Definition: heap_record_store_btree.h:94
HeapRecordStoreBtree(StringData ns)
Definition: heap_record_store_btree.h:54
virtual void setOrderedCommit(bool orderedCommit)
Definition: heap_record_store_btree.h:215
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
void * data
Definition: heap_record_store_btree.h:230
virtual SnapshotId getSnapshotId() const
Gets the local SnapshotId.
Definition: heap_record_store_btree.h:211
size_t len
Definition: heap_record_store_btree.h:231
void commitUnitOfWork() final
Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerCh...
Definition: heap_record_store_btree.cpp:120
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:148
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:687
Definition: record_store.h:78
Definition: heap_record_store_btree.h:229
bool inclusive
Definition: btree_interface.cpp:335
RecordId loc
Definition: heap_record_store_btree.h:225
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:156
std::unique_ptr< RecordStore > rs
Definition: kv_engine_test_timestamps.cpp:207
virtual void * writingPtr(void *data, size_t len)
Declare that the data at [x, x + len) is being written.
Definition: heap_record_store_btree.cpp:135
OperationContext Database StringData CollectionOptions bool const BSONObj &idIndex Status
Definition: database_impl.cpp:955
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:209
HeapRecordStoreBtree * rs
Definition: heap_record_store_btree.h:224
virtual void abandonSnapshot()
If there is an open transaction, it is closed.
Definition: heap_record_store_btree.h:200
A RecoveryUnit for HeapRecordStoreBtree, this is for testing btree only.
Definition: heap_record_store_btree.h:190
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
const std::string & getIdent() const override
Definition: heap_record_store_btree.h:49
void abortUnitOfWork() final
Marks the end of a unit of work and rolls back all changes registered by calls to onRollback or regis...
Definition: heap_record_store_btree.cpp:125
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:234
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:174
virtual Status truncate(OperationContext *opCtx)
removes all Records
Definition: heap_record_store_btree.h:108
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:164
virtual Status validate(OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output)
Definition: heap_record_store_btree.h:120
virtual bool waitUntilDurable()
Waits until all commits that happened before this call are durable in the journal.
Definition: heap_record_store_btree.h:196
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:102
std::map< RecordId, HeapRecordStoreBtree::MmapV1RecordHeader > Records
Definition: heap_record_store_btree.h:182
virtual void increaseStorageSize(OperationContext *opCtx, int size, bool enforceQuota)
Definition: heap_record_store_btree.h:134
A Change is an action that is registerChange()'d while a WriteUnitOfWork exists.
Definition: recovery_unit.h:295
virtual void appendCustomStats(OperationContext *opCtx, BSONObjBuilder *result, double scale) const
Definition: heap_record_store_btree.h:128
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:138
Records _records
Definition: heap_record_store_btree.h:183
Definition: snapshot.h:37
MmapV1RecordHeader()
Definition: heap_record_store_btree.h:173
virtual bool isCapped() const
Definition: heap_record_store_btree.h:152
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:90
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:160
int64_t _nextId
Definition: heap_record_store_btree.h:184
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
boost::shared_array< char > old
Definition: heap_record_store_btree.h:232
virtual Status updateRecord(OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier)
Definition: heap_record_store_btree.h:81
std::vector< InsertEntry > _insertions
Definition: heap_record_store_btree.h:227
int dataSize
Definition: heap_record_store_btree.h:176
virtual void cappedTruncateAfter(OperationContext *opCtx, RecordId end, bool inclusive)
Truncate documents newer than the document at 'end' from the capped collection.
Definition: heap_record_store_btree.h:112
virtual long long numRecords(OperationContext *opCtx) const
Total number of record in the RecordStore.
Definition: heap_record_store_btree.h:71
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:192
boost::shared_array< char > data
Definition: heap_record_store_btree.h:177