![]() |
Storage Engine API
|
An abstraction used for storing documents in a collection or entries in an index. More...
#include <record_store.h>
An abstraction used for storing documents in a collection or entries in an index.
In storage engines implementing the KVEngine, record stores are also used for implementing catalogs.
Many methods take an OperationContext parameter. This contains the RecoveryUnit, with all RecordStore specific transaction information, as well as the LockState. Methods that take an OperationContext may throw a WriteConflictException.
This class must be thread-safe for document-level locking storage engines. In addition, for storage engines implementing the KVEngine some methods must be thread safe, see KVCatalog. Only for MMAPv1 is this class not thread-safe.
Public Member Functions | |
RecordStore (StringData ns) | |
virtual | ~RecordStore () |
virtual const char * | name () const =0 |
virtual const std::string & | ns () const |
virtual long long | dataSize (OperationContext *opCtx) const =0 |
The dataSize is an approximation of the sum of the sizes (in bytes) of the documents or entries in the recordStore. More... | |
virtual long long | numRecords (OperationContext *opCtx) const =0 |
Total number of record in the RecordStore. More... | |
virtual bool | isCapped () const =0 |
virtual void | setCappedCallback (CappedCallback *) |
virtual int64_t | storageSize (OperationContext *opCtx, BSONObjBuilder *extraInfo=NULL, int infoLevel=0) const =0 |
virtual RecordData | dataFor (OperationContext *opCtx, const RecordId &loc) const |
Get the RecordData at loc, which must exist. More... | |
virtual bool | findRecord (OperationContext *opCtx, const RecordId &loc, RecordData *out) const |
virtual void | deleteRecord (OperationContext *opCtx, const RecordId &dl)=0 |
virtual StatusWith< RecordId > | insertRecord (OperationContext *opCtx, const char *data, int len, Timestamp timestamp, bool enforceQuota)=0 |
virtual Status | insertRecords (OperationContext *opCtx, std::vector< Record > *records, std::vector< Timestamp > *timestamps, bool enforceQuota) |
virtual Status | insertRecordsWithDocWriter (OperationContext *opCtx, const DocWriter *const *docs, const Timestamp *timestamps, size_t nDocs, RecordId *idsOut=nullptr)=0 |
Inserts nDocs documents into this RecordStore using the DocWriter interface. More... | |
StatusWith< RecordId > | insertRecordWithDocWriter (OperationContext *opCtx, const DocWriter *doc, Timestamp timestamp) |
A thin wrapper around insertRecordsWithDocWriter() to simplify handling of single DocWriters. More... | |
virtual Status | updateRecord (OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier)=0 |
virtual bool | updateWithDamagesSupported () const =0 |
virtual StatusWith< RecordData > | updateWithDamages (OperationContext *opCtx, const RecordId &loc, const RecordData &oldRec, const char *damageSource, const mutablebson::DamageVector &damages)=0 |
Updates the record positioned at 'loc' in-place using the deltas described by 'damages'. More... | |
virtual std::unique_ptr< SeekableRecordCursor > | getCursor (OperationContext *opCtx, bool forward=true) const =0 |
Returns a new cursor over this record store. More... | |
virtual std::unique_ptr< RecordCursor > | getCursorForRepair (OperationContext *opCtx) const |
Constructs a cursor over a potentially corrupted store, which can be used to salvage damaged records. More... | |
virtual std::unique_ptr< RecordCursor > | getRandomCursor (OperationContext *opCtx) const |
Constructs a cursor over a record store that returns documents in a randomized order, and allows storage engines to provide a more efficient way of random sampling of a record store than MongoDB's default sampling methods, which is used when this method returns {}. More... | |
virtual std::vector< std::unique_ptr< RecordCursor > > | getManyCursors (OperationContext *opCtx) const |
Returns many RecordCursors that partition the RecordStore into many disjoint sets. More... | |
virtual Status | truncate (OperationContext *opCtx)=0 |
removes all Records More... | |
virtual void | cappedTruncateAfter (OperationContext *opCtx, RecordId end, bool inclusive)=0 |
Truncate documents newer than the document at 'end' from the capped collection. More... | |
virtual bool | compactSupported () const |
does this RecordStore support the compact operation? More... | |
virtual bool | compactsInPlace () const |
Does compact() leave RecordIds alone or can they change. More... | |
virtual Status | compact (OperationContext *opCtx, RecordStoreCompactAdaptor *adaptor, const CompactOptions *options, CompactStats *stats) |
Attempt to reduce the storage space used by this RecordStore. More... | |
virtual bool | isInRecordIdOrder () const |
Does the RecordStore cursor retrieve its document in RecordId Order? More... | |
virtual Status | validate (OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output)=0 |
virtual void | appendCustomStats (OperationContext *opCtx, BSONObjBuilder *result, double scale) const =0 |
virtual Status | touch (OperationContext *opCtx, BSONObjBuilder *output) const |
Load all data into cache. More... | |
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. More... | |
virtual Status | oplogDiskLocRegister (OperationContext *opCtx, const Timestamp &opTime, bool orderedCommit) |
When we write to an oplog, we call this so that if the storage engine supports doc locking, it can manage the visibility of oplog entries to ensure they are ordered. More... | |
virtual void | waitForAllEarlierOplogWritesToBeVisible (OperationContext *opCtx) const =0 |
Waits for all writes that completed before this call to be visible to forward scans. More... | |
virtual void | updateStatsAfterRepair (OperationContext *opCtx, long long numRecords, long long dataSize)=0 |
Called after a repair operation is run with the recomputed numRecords and dataSize. More... | |
virtual Status | updateCappedSize (OperationContext *opCtx, long long cappedSize) |
used to support online change oplog size. More... | |
Protected Attributes | |
std::string | _ns |
Private Member Functions | |
MONGO_DISALLOW_COPYING (RecordStore) | |
|
inline |
|
inlinevirtual |
|
pure virtual |
scaleSize | - amount by which to scale size metrics appends any custom stats from the RecordStore or other unique stats |
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::MobileRecordStore, and mongo::EphemeralForTestRecordStore.
|
pure virtual |
Truncate documents newer than the document at 'end' from the capped collection.
The collection cannot be completely emptied using this function. An assertion will be thrown if that is attempted.
inclusive | - Truncate 'end' as well iff true |
Implemented in mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, mongo::CappedRecordStoreV1, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
Attempt to reduce the storage space used by this RecordStore.
Only called if compactSupported() returns true. No RecordStoreCompactAdaptor will be passed if compactsInPlace() returns true.
Reimplemented in mongo::WiredTigerRecordStore, mongo::MobileRecordStore, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
Does compact() leave RecordIds alone or can they change.
Only called if compactSupported() returns true.
Reimplemented in mongo::WiredTigerRecordStore, mongo::MobileRecordStore, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
does this RecordStore support the compact operation?
If you return true, you must provide implementations of all compact methods.
Reimplemented in mongo::WiredTigerRecordStore, mongo::HeapRecordStoreBtree, mongo::MobileRecordStore, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
Get the RecordData at loc, which must exist.
If unowned data is returned, it is valid until the next modification of this Record or the lock on this collection is released.
In general, prefer findRecord or RecordCursor::seekExact since they can tell you if a record has been removed.
Reimplemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, and mongo::HeapRecordStoreBtree.
|
pure virtual |
The dataSize is an approximation of the sum of the sizes (in bytes) of the documents or entries in the recordStore.
Implemented in mongo::RecordStoreV1Base, mongo::HeapRecordStoreBtree, mongo::WiredTigerRecordStore, mongo::MobileRecordStore, mongo::EphemeralForTestRecordStore, and mongo::DevNullRecordStore.
|
pure virtual |
|
inlinevirtual |
out | - If the record exists, the contents of this are set. |
If unowned data is returned, it is valid until the next modification of this Record or the lock on this collection is released.
In general prefer RecordCursor::seekExact since it can avoid copying data in more storageEngines.
Warning: MMAPv1 cannot detect if RecordIds are valid. Therefore callers should only pass potentially deleted RecordIds to seek methods if they know that MMAPv1 is not the current storage engine. All new storage engines must support detecting the existence of Records.
Reimplemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, and mongo::HeapRecordStoreBtree.
|
pure virtual |
Returns a new cursor over this record store.
The cursor is logically positioned before the first (or last if !forward) Record in the collection so that Record will be returned on the first call to next(). Implementations are allowed to lazily seek to the first Record when next() is called rather than doing it on construction.
Implemented in mongo::PrefixedWiredTigerRecordStore, mongo::StandardWiredTigerRecordStore, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, mongo::CappedRecordStoreV1, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
Constructs a cursor over a potentially corrupted store, which can be used to salvage damaged records.
The iterator might return every record in the store if all of them are reachable and not corrupted. Returns NULL if not supported.
Reimplemented in mongo::RecordStoreV1Base.
|
inlinevirtual |
Returns many RecordCursors that partition the RecordStore into many disjoint sets.
Iterating all returned RecordCursors is equivalent to iterating the full store.
Reimplemented in mongo::WiredTigerRecordStore, mongo::CappedRecordStoreV1, and mongo::SimpleRecordStoreV1.
|
inlinevirtual |
Constructs a cursor over a record store that returns documents in a randomized order, and allows storage engines to provide a more efficient way of random sampling of a record store than MongoDB's default sampling methods, which is used when this method returns {}.
This method may be implemented using a pseudo-random walk over B-trees or a similar approach. Different cursors should return documents in a different order. Random cursors may return the same document more than once and, as a result, may return more documents than exist in the record store. Implementations should avoid obvious biases toward older, newer, larger smaller or other specific classes of documents.
Reimplemented in mongo::WiredTigerRecordStore.
|
pure virtual |
|
inlinevirtual |
Reimplemented in mongo::WiredTigerRecordStore.
|
pure virtual |
Inserts nDocs documents into this RecordStore using the DocWriter interface.
This allows the storage engine to reserve space for a record and have it built in-place rather than building the record then copying it into its destination.
On success, if idsOut is non-null the RecordIds of the inserted records will be written into it. It must have space for nDocs RecordIds.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, and mongo::HeapRecordStoreBtree.
|
inline |
A thin wrapper around insertRecordsWithDocWriter() to simplify handling of single DocWriters.
|
pure virtual |
|
inlinevirtual |
Does the RecordStore cursor retrieve its document in RecordId Order?
If a subclass overrides the default value to true, the RecordStore cursor must retrieve its documents in RecordId order.
This enables your storage engine to run collection validation in the background.
Reimplemented in mongo::WiredTigerRecordStore.
|
private |
|
pure virtual |
|
inlinevirtual |
|
pure virtual |
Total number of record in the RecordStore.
You may need to cache it, so this call takes constant time, as it is called often.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::MobileRecordStore, mongo::EphemeralForTestRecordStore, mongo::DevNullRecordStore, and mongo::HeapRecordStoreBtree.
|
inlinevirtual |
When we write to an oplog, we call this so that if the storage engine supports doc locking, it can manage the visibility of oplog entries to ensure they are ordered.
Since this is called inside of a WriteUnitOfWork while holding a std::mutex, it is illegal to acquire any LockManager locks inside of this function.
If orderedCommit
is true, the storage engine can assume the input opTime
has become visible in the oplog. Otherwise the storage engine must continue to maintain its own visibility management. Calls with orderedCommit
true will not be concurrent with calls of orderedCommit
false.
Reimplemented in mongo::WiredTigerRecordStore.
|
inlinevirtual |
Return the RecordId of an oplog entry as close to startingPosition as possible without being higher.
If there are no entries <= startingPosition, return RecordId().
If you don't implement the oplogStartHack, just use the default implementation which returns boost::none.
Reimplemented in mongo::WiredTigerRecordStore, mongo::MobileRecordStore, and mongo::EphemeralForTestRecordStore.
|
inlinevirtual |
|
pure virtual |
extraInfo | - optional more debug info |
level | - optional, level of debug info to put in (higher is more) |
Implemented in mongo::RecordStoreV1Base, mongo::HeapRecordStoreBtree, mongo::WiredTigerRecordStore, mongo::MobileRecordStore, mongo::EphemeralForTestRecordStore, and mongo::DevNullRecordStore.
|
inlinevirtual |
Load all data into cache.
What cache depends on implementation.
If the underlying storage engine does not support the operation, returns ErrorCodes::CommandNotSupported
output | (optional) - where to put detailed stats |
Reimplemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::MobileRecordStore, mongo::EphemeralForTestRecordStore, and mongo::HeapRecordStoreBtree.
|
pure virtual |
removes all Records
Implemented in mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, mongo::MobileRecordStore, mongo::SimpleRecordStoreV1, and mongo::CappedRecordStoreV1.
|
inlinevirtual |
used to support online change oplog size.
Reimplemented in mongo::WiredTigerRecordStore, and mongo::MobileRecordStore.
|
pure virtual |
notifier | - Only used by record stores which do not support doc-locking. Called only in the case of an in-place update. Called just before the in-place write occurs. |
For capped record stores, the record size will never change.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, and mongo::MobileRecordStore.
|
pure virtual |
Called after a repair operation is run with the recomputed numRecords and dataSize.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::MobileRecordStore, and mongo::EphemeralForTestRecordStore.
|
pure virtual |
Updates the record positioned at 'loc' in-place using the deltas described by 'damages'.
The 'damages' vector describes contiguous ranges of 'damageSource' from which to copy and apply byte-level changes to the data.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, and mongo::MobileRecordStore.
|
pure virtual |
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::EphemeralForTestRecordStore, and mongo::MobileRecordStore.
|
pure virtual |
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::MobileRecordStore, and mongo::EphemeralForTestRecordStore.
|
pure virtual |
Waits for all writes that completed before this call to be visible to forward scans.
See the comment on RecordCursor for more details about the visibility rules.
It is only legal to call this on an oplog. It is illegal to call this inside a WriteUnitOfWork.
Implemented in mongo::RecordStoreV1Base, mongo::WiredTigerRecordStore, mongo::DevNullRecordStore, mongo::HeapRecordStoreBtree, mongo::MobileRecordStore, and mongo::EphemeralForTestRecordStore.
|
protected |