Storage Engine API
ephemeral_for_test_record_store.h
Go to the documentation of this file.
1 // ephemeral_for_test_record_store.h
2 
31 #pragma once
32 
33 #include <boost/shared_array.hpp>
34 #include <map>
35 
39 #include "mongo/stdx/mutex.h"
40 
41 namespace mongo {
42 
49 public:
50  explicit EphemeralForTestRecordStore(StringData ns,
51  std::shared_ptr<void>* dataInOut,
52  bool isCapped = false,
53  int64_t cappedMaxSize = -1,
54  int64_t cappedMaxDocs = -1,
55  CappedCallback* cappedCallback = nullptr);
56 
57  virtual const char* name() const;
58 
59  virtual RecordData dataFor(OperationContext* opCtx, const RecordId& loc) const;
60 
61  virtual bool findRecord(OperationContext* opCtx, const RecordId& loc, RecordData* rd) const;
62 
63  virtual void deleteRecord(OperationContext* opCtx, const RecordId& dl);
64 
66  OperationContext* opCtx, const char* data, int len, Timestamp, bool enforceQuota);
67 
68  virtual Status insertRecordsWithDocWriter(OperationContext* opCtx,
69  const DocWriter* const* docs,
70  const Timestamp*,
71  size_t nDocs,
72  RecordId* idsOut);
73 
74  virtual Status updateRecord(OperationContext* opCtx,
75  const RecordId& oldLocation,
76  const char* data,
77  int len,
78  bool enforceQuota,
79  UpdateNotifier* notifier);
80 
81  virtual bool updateWithDamagesSupported() const;
82 
83  virtual StatusWith<RecordData> updateWithDamages(OperationContext* opCtx,
84  const RecordId& loc,
85  const RecordData& oldRec,
86  const char* damageSource,
87  const mutablebson::DamageVector& damages);
88 
89  std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
90  bool forward) const final;
91 
92  virtual Status truncate(OperationContext* opCtx);
93 
94  virtual void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive);
95 
96  virtual Status validate(OperationContext* opCtx,
97  ValidateCmdLevel level,
98  ValidateAdaptor* adaptor,
99  ValidateResults* results,
100  BSONObjBuilder* output);
101 
102  virtual void appendCustomStats(OperationContext* opCtx,
103  BSONObjBuilder* result,
104  double scale) const;
105 
106  virtual Status touch(OperationContext* opCtx, BSONObjBuilder* output) const;
107 
108  virtual void increaseStorageSize(OperationContext* opCtx, int size, bool enforceQuota);
109 
110  virtual int64_t storageSize(OperationContext* opCtx,
111  BSONObjBuilder* extraInfo = NULL,
112  int infoLevel = 0) const;
113 
114  virtual long long dataSize(OperationContext* opCtx) const {
115  return _data->dataSize;
116  }
117 
118  virtual long long numRecords(OperationContext* opCtx) const {
119  return _data->records.size();
120  }
121 
122  virtual boost::optional<RecordId> oplogStartHack(OperationContext* opCtx,
123  const RecordId& startingPosition) const;
124 
125  void waitForAllEarlierOplogWritesToBeVisible(OperationContext* opCtx) const override {}
126 
127  virtual void updateStatsAfterRepair(OperationContext* opCtx,
128  long long numRecords,
129  long long dataSize) {
130  invariant(_data->records.size() == size_t(numRecords));
132  }
133 
134 protected:
136  EphemeralForTestRecord() : size(0) {}
137  EphemeralForTestRecord(int size) : size(size), data(new char[size]) {}
138 
140  return RecordData(data.get(), size);
141  }
142 
143  int size;
144  boost::shared_array<char> data;
145  };
146 
147  virtual const EphemeralForTestRecord* recordFor(const RecordId& loc) const;
148  virtual EphemeralForTestRecord* recordFor(const RecordId& loc);
149 
150 public:
151  //
152  // Not in RecordStore interface
153  //
154 
155  typedef std::map<RecordId, EphemeralForTestRecord> Records;
156 
157  bool isCapped() const {
158  return _isCapped;
159  }
161  _cappedCallback = cb;
162  }
163 
164 private:
165  class InsertChange;
166  class RemoveChange;
167  class TruncateChange;
168 
169  class Cursor;
170  class ReverseCursor;
171 
172  StatusWith<RecordId> extractAndCheckLocForOplog(const char* data, int len) const;
173 
174  RecordId allocateLoc();
175  bool cappedAndNeedDelete_inlock(OperationContext* opCtx) const;
176  void cappedDeleteAsNeeded_inlock(OperationContext* opCtx);
177  void deleteRecord_inlock(OperationContext* opCtx, const RecordId& dl);
178 
179  // TODO figure out a proper solution to metadata
180  const bool _isCapped;
181  const int64_t _cappedMaxSize;
182  const int64_t _cappedMaxDocs;
184 
185  // This is the "persistent" data.
186  struct Data {
187  Data(StringData ns, bool isOplog)
188  : dataSize(0), recordsMutex(), nextId(1), isOplog(isOplog) {}
189 
190  int64_t dataSize;
191  stdx::recursive_mutex recordsMutex;
192  Records records;
193  int64_t nextId;
194  const bool isOplog;
195  };
196 
197  Data* const _data;
198 };
199 
200 } // namespace mongo
virtual bool findRecord(OperationContext *opCtx, const RecordId &loc, RecordData *rd) const
Definition: ephemeral_for_test_record_store.cpp:327
ValidateCmdLevel
Definition: record_store.h:93
virtual Status validate(OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output)
Definition: ephemeral_for_test_record_store.cpp:577
void cappedDeleteAsNeeded_inlock(OperationContext *opCtx)
Definition: ephemeral_for_test_record_store.cpp:367
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: ephemeral_for_test_record_store.cpp:431
Definition: record_store.h:671
A RecordStore that stores all data in-memory.
Definition: ephemeral_for_test_record_store.h:48
virtual void appendCustomStats(OperationContext *opCtx, BSONObjBuilder *result, double scale) const
Definition: ephemeral_for_test_record_store.cpp:605
const int64_t _cappedMaxDocs
Definition: ephemeral_for_test_record_store.h:182
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: ephemeral_for_test_record_store.h:114
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
bool cappedAndNeedDelete_inlock(OperationContext *opCtx) const
Definition: ephemeral_for_test_record_store.cpp:354
A replacement for the Record class.
Definition: record_data.h:43
CappedCallback * _cappedCallback
Definition: ephemeral_for_test_record_store.h:183
virtual const EphemeralForTestRecord * recordFor(const RecordId &loc) const
Definition: ephemeral_for_test_record_store.cpp:305
const bool isOplog
Definition: ephemeral_for_test_record_store.h:194
virtual Status truncate(OperationContext *opCtx)
removes all Records
Definition: ephemeral_for_test_record_store.cpp:550
EphemeralForTestRecord(int size)
Definition: ephemeral_for_test_record_store.h:137
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
RecordId allocateLoc()
Definition: ephemeral_for_test_record_store.cpp:638
const bool _isCapped
Definition: ephemeral_for_test_record_store.h:180
void deleteRecord_inlock(OperationContext *opCtx, const RecordId &dl)
Definition: ephemeral_for_test_record_store.cpp:346
bool inclusive
Definition: btree_interface.cpp:335
Definition: ephemeral_for_test_record_store.cpp:126
virtual StatusWith< RecordId > insertRecord(OperationContext *opCtx, const char *data, int len, Timestamp, bool enforceQuota)
Definition: ephemeral_for_test_record_store.cpp:400
virtual void deleteRecord(OperationContext *opCtx, const RecordId &dl)
Definition: ephemeral_for_test_record_store.cpp:340
Definition: ephemeral_for_test_record_store.cpp:72
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
Data(StringData ns, bool isOplog)
Definition: ephemeral_for_test_record_store.h:187
virtual int64_t storageSize(OperationContext *opCtx, BSONObjBuilder *extraInfo=NULL, int infoLevel=0) const
Definition: ephemeral_for_test_record_store.cpp:630
stdx::recursive_mutex recordsMutex
Definition: ephemeral_for_test_record_store.h:191
virtual bool updateWithDamagesSupported() const
Definition: ephemeral_for_test_record_store.cpp:505
Records records
Definition: ephemeral_for_test_record_store.h:192
Definition: ephemeral_for_test_record_store.h:186
virtual boost::optional< RecordId > oplogStartHack(OperationContext *opCtx, const RecordId &startingPosition) const
Return the RecordId of an oplog entry as close to startingPosition as possible without being higher...
Definition: ephemeral_for_test_record_store.cpp:644
EphemeralForTestRecord()
Definition: ephemeral_for_test_record_store.h:136
virtual RecordData dataFor(OperationContext *opCtx, const RecordId &loc) const
Get the RecordData at loc, which must exist.
Definition: ephemeral_for_test_record_store.cpp:299
Definition: ephemeral_for_test_record_store.cpp:189
virtual void increaseStorageSize(OperationContext *opCtx, int size, bool enforceQuota)
Definition: ephemeral_for_test_record_store.cpp:623
Definition: index_key_validate.h:40
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: ephemeral_for_test_record_store.cpp:509
EphemeralForTestRecordStore(StringData ns, std::shared_ptr< void > *dataInOut, bool isCapped=false, int64_t cappedMaxSize=-1, int64_t cappedMaxDocs=-1, CappedCallback *cappedCallback=nullptr)
Definition: ephemeral_for_test_record_store.cpp:269
Definition: ephemeral_for_test_record_store.h:135
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: ephemeral_for_test_record_store.h:127
An abstraction used for storing documents in a collection or entries in an index. ...
Definition: record_store.h:282
When a capped collection is modified (delete/insert/etc) then certain notifications need to be made...
Definition: capped_callback.h:44
virtual const std::string & ns() const
Definition: record_store.h:295
void setCappedCallback(CappedCallback *cb)
Definition: ephemeral_for_test_record_store.h:160
Definition: ephemeral_for_test_record_store.cpp:50
int64_t nextId
Definition: ephemeral_for_test_record_store.h:193
const int64_t _cappedMaxSize
Definition: ephemeral_for_test_record_store.h:181
virtual Status touch(OperationContext *opCtx, BSONObjBuilder *output) const
Load all data into cache.
Definition: ephemeral_for_test_record_store.cpp:615
RecordData toRecordData() const
Definition: ephemeral_for_test_record_store.h:139
boost::shared_array< char > data
Definition: ephemeral_for_test_record_store.h:144
Definition: ephemeral_for_test_record_store.cpp:100
std::uint64_t nextId
Definition: d_concurrency.cpp:104
virtual long long numRecords(OperationContext *opCtx) const
Total number of record in the RecordStore.
Definition: ephemeral_for_test_record_store.h:118
virtual void cappedTruncateAfter(OperationContext *opCtx, RecordId end, bool inclusive)
Truncate documents newer than the document at &#39;end&#39; from the capped collection.
Definition: ephemeral_for_test_record_store.cpp:557
Data *const _data
Definition: ephemeral_for_test_record_store.h:197
void waitForAllEarlierOplogWritesToBeVisible(OperationContext *opCtx) const override
Waits for all writes that completed before this call to be visible to forward scans.
Definition: ephemeral_for_test_record_store.h:125
bool isCapped() const
Definition: ephemeral_for_test_record_store.h:157
StatusWith< RecordId > extractAndCheckLocForOplog(const char *data, int len) const
Definition: ephemeral_for_test_record_store.cpp:382
int size
Definition: ephemeral_for_test_record_store.h:143
std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *opCtx, bool forward) const final
Returns a new cursor over this record store.
Definition: ephemeral_for_test_record_store.cpp:543
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
virtual Status updateRecord(OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier)
Definition: ephemeral_for_test_record_store.cpp:472
virtual const char * name() const
Definition: ephemeral_for_test_record_store.cpp:295
int64_t dataSize
Definition: ephemeral_for_test_record_store.h:190
std::map< RecordId, EphemeralForTestRecord > Records
Definition: ephemeral_for_test_record_store.h:155