Storage Engine API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mongo::RecordStoreV1Base Class Referenceabstract

#include <record_store_v1_base.h>

Inheritance diagram for mongo::RecordStoreV1Base:
mongo::RecordStore mongo::CappedRecordStoreV1 mongo::SimpleRecordStoreV1

Classes

class  IntraExtentIterator
 Iterates over all records within a single extent. More...
 

Public Member Functions

 RecordStoreV1Base (StringData ns, RecordStoreV1MetaData *details, ExtentManager *em, bool isSystemIndexes)
 
virtual ~RecordStoreV1Base ()
 
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 the recordStore. More...
 
virtual long long numRecords (OperationContext *opCtx) const
 Total number of record in the RecordStore. More...
 
virtual int64_t storageSize (OperationContext *opCtx, BSONObjBuilder *extraInfo=NULL, int level=0) const
 
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 *rd) const
 
void deleteRecord (OperationContext *opCtx, const RecordId &dl)
 
StatusWith< RecordId > insertRecord (OperationContext *opCtx, const char *data, int len, Timestamp, bool enforceQuota)
 
Status insertRecordsWithDocWriter (OperationContext *opCtx, const DocWriter *const *docs, const Timestamp *, size_t nDocs, RecordId *idsOut) final
 Inserts nDocs documents into this RecordStore using the DocWriter interface. More...
 
virtual Status updateRecord (OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier)
 
virtual bool updateWithDamagesSupported () const
 
virtual StatusWith< RecordDataupdateWithDamages (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'. More...
 
virtual std::unique_ptr< RecordCursorgetCursorForRepair (OperationContext *opCtx) const
 Constructs a cursor over a potentially corrupted store, which can be used to salvage damaged records. More...
 
void increaseStorageSize (OperationContext *opCtx, int size, bool enforceQuota)
 
virtual Status validate (OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output)
 
virtual void appendCustomStats (OperationContext *opCtx, BSONObjBuilder *result, double scale) const
 
virtual Status touch (OperationContext *opCtx, BSONObjBuilder *output) const
 Load all data into cache. More...
 
const RecordStoreV1MetaDatadetails () const
 
DiskLoc getExtentLocForRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc getNextRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc getPrevRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc getNextRecordInExtent (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc getPrevRecordInExtent (OperationContext *opCtx, const DiskLoc &loc) const
 
void waitForAllEarlierOplogWritesToBeVisible (OperationContext *opCtx) const override
 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)
 Called after a repair operation is run with the recomputed numRecords and dataSize. More...
 
- Public Member Functions inherited from mongo::RecordStore
 RecordStore (StringData ns)
 
virtual ~RecordStore ()
 
virtual const char * name () const =0
 
virtual const std::string & ns () const
 
virtual void setCappedCallback (CappedCallback *)
 
virtual Status insertRecords (OperationContext *opCtx, std::vector< Record > *records, std::vector< Timestamp > *timestamps, bool enforceQuota)
 
StatusWith< RecordId > insertRecordWithDocWriter (OperationContext *opCtx, const DocWriter *doc, Timestamp timestamp)
 A thin wrapper around insertRecordsWithDocWriter() to simplify handling of single DocWriters. More...
 
virtual std::unique_ptr< SeekableRecordCursorgetCursor (OperationContext *opCtx, bool forward=true) const =0
 Returns a new cursor over this record store. More...
 
virtual std::unique_ptr< RecordCursorgetRandomCursor (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 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 Status updateCappedSize (OperationContext *opCtx, long long cappedSize)
 used to support online change oplog size. More...
 

Static Public Member Functions

static int quantizeAllocationSpace (int minSize)
 Quantize 'minSize' to the nearest allocation size. More...
 
static bool isQuantized (int recordSize)
 
static int bucket (int size)
 

Public Attributes

SavedCursorRegistry savedCursors
 

Static Public Attributes

static const int Buckets = 26
 
static const int MaxAllowedAllocation = 16 * 1024 * 1024 + 512 * 1024
 
static const int bucketSizes []
 

Protected Member Functions

virtual MmapV1RecordHeaderrecordFor (const DiskLoc &loc) const
 
const DeletedRecorddeletedRecordFor (const DiskLoc &loc) const
 
virtual bool isCapped () const =0
 
virtual bool shouldPadInserts () const =0
 
virtual StatusWith< DiskLocallocRecord (OperationContext *opCtx, int lengthWithHeaders, bool enforceQuota)=0
 
virtual void addDeletedRec (OperationContext *opCtx, const DiskLoc &dloc)=0
 
virtual DeletedRecorddrec (const DiskLoc &loc) const
 
Extent_getExtent (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _getExtentLocForRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _getNextRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _getPrevRecord (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _getNextRecordInExtent (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _getPrevRecordInExtent (OperationContext *opCtx, const DiskLoc &loc) const
 
DiskLoc _findFirstSpot (OperationContext *opCtx, const DiskLoc &extDiskLoc, Extent *e)
 finds the first suitable DiskLoc for data will return the DiskLoc of a newly created DeletedRecord More...
 
void _addRecordToRecListInExtent (OperationContext *opCtx, MmapV1RecordHeader *r, DiskLoc loc)
 add a record to the end of the linked list chain within this extent. More...
 
StatusWith< RecordId > _insertRecord (OperationContext *opCtx, const char *data, int len, bool enforceQuota)
 internal doesn't check inputs or change padding More...
 

Protected Attributes

std::unique_ptr< RecordStoreV1MetaData_details
 
ExtentManager_extentManager
 
bool _isSystemIndexes
 
- Protected Attributes inherited from mongo::RecordStore
std::string _ns
 

Friends

class RecordStoreV1RepairCursor
 

Constructor & Destructor Documentation

◆ RecordStoreV1Base()

mongo::RecordStoreV1Base::RecordStoreV1Base ( StringData  ns,
RecordStoreV1MetaData details,
ExtentManager em,
bool  isSystemIndexes 
)
Parameters
details- takes ownership
em- does NOT take ownership

◆ ~RecordStoreV1Base()

mongo::RecordStoreV1Base::~RecordStoreV1Base ( )
virtual

Member Function Documentation

◆ _addRecordToRecListInExtent()

void mongo::RecordStoreV1Base::_addRecordToRecListInExtent ( OperationContext *  opCtx,
MmapV1RecordHeader r,
DiskLoc  loc 
)
protected

add a record to the end of the linked list chain within this extent.

require: you must have already declared write intent for the record header.

◆ _findFirstSpot()

DiskLoc mongo::RecordStoreV1Base::_findFirstSpot ( OperationContext *  opCtx,
const DiskLoc extDiskLoc,
Extent e 
)
protected

finds the first suitable DiskLoc for data will return the DiskLoc of a newly created DeletedRecord

◆ _getExtent()

Extent * mongo::RecordStoreV1Base::_getExtent ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _getExtentLocForRecord()

DiskLoc mongo::RecordStoreV1Base::_getExtentLocForRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _getNextRecord()

DiskLoc mongo::RecordStoreV1Base::_getNextRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _getNextRecordInExtent()

DiskLoc mongo::RecordStoreV1Base::_getNextRecordInExtent ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _getPrevRecord()

DiskLoc mongo::RecordStoreV1Base::_getPrevRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _getPrevRecordInExtent()

DiskLoc mongo::RecordStoreV1Base::_getPrevRecordInExtent ( OperationContext *  opCtx,
const DiskLoc loc 
) const
protected

◆ _insertRecord()

StatusWith< RecordId > mongo::RecordStoreV1Base::_insertRecord ( OperationContext *  opCtx,
const char *  data,
int  len,
bool  enforceQuota 
)
protected

internal doesn't check inputs or change padding

◆ addDeletedRec()

virtual void mongo::RecordStoreV1Base::addDeletedRec ( OperationContext *  opCtx,
const DiskLoc dloc 
)
protectedpure virtual

◆ allocRecord()

virtual StatusWith<DiskLoc> mongo::RecordStoreV1Base::allocRecord ( OperationContext *  opCtx,
int  lengthWithHeaders,
bool  enforceQuota 
)
protectedpure virtual

◆ appendCustomStats()

void mongo::RecordStoreV1Base::appendCustomStats ( OperationContext *  opCtx,
BSONObjBuilder *  result,
double  scale 
) const
virtual
Parameters
scaleSize- amount by which to scale size metrics appends any custom stats from the RecordStore or other unique stats

Implements mongo::RecordStore.

◆ bucket()

int mongo::RecordStoreV1Base::bucket ( int  size)
static

◆ dataFor()

RecordData mongo::RecordStoreV1Base::dataFor ( OperationContext *  opCtx,
const RecordId &  loc 
) const
virtual

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 from mongo::RecordStore.

◆ dataSize()

virtual long long mongo::RecordStoreV1Base::dataSize ( OperationContext *  opCtx) const
inlinevirtual

The dataSize is an approximation of the sum of the sizes (in bytes) of the documents or entries in the recordStore.

Implements mongo::RecordStore.

◆ deletedRecordFor()

const DeletedRecord * mongo::RecordStoreV1Base::deletedRecordFor ( const DiskLoc loc) const
protected

◆ deleteRecord()

void mongo::RecordStoreV1Base::deleteRecord ( OperationContext *  opCtx,
const RecordId &  dl 
)
virtual

Implements mongo::RecordStore.

◆ details()

const RecordStoreV1MetaData* mongo::RecordStoreV1Base::details ( ) const
inline

◆ drec()

DeletedRecord * mongo::RecordStoreV1Base::drec ( const DiskLoc loc) const
protectedvirtual

◆ findRecord()

bool mongo::RecordStoreV1Base::findRecord ( OperationContext *  opCtx,
const RecordId &  loc,
RecordData out 
) const
virtual
Parameters
out- If the record exists, the contents of this are set.
Returns
true iff there is a Record for loc

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 from mongo::RecordStore.

◆ getCursorForRepair()

std::unique_ptr< RecordCursor > mongo::RecordStoreV1Base::getCursorForRepair ( OperationContext *  opCtx) const
virtual

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 from mongo::RecordStore.

◆ getExtentLocForRecord()

DiskLoc mongo::RecordStoreV1Base::getExtentLocForRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const

◆ getNextRecord()

DiskLoc mongo::RecordStoreV1Base::getNextRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const

◆ getNextRecordInExtent()

DiskLoc mongo::RecordStoreV1Base::getNextRecordInExtent ( OperationContext *  opCtx,
const DiskLoc loc 
) const

◆ getPrevRecord()

DiskLoc mongo::RecordStoreV1Base::getPrevRecord ( OperationContext *  opCtx,
const DiskLoc loc 
) const

◆ getPrevRecordInExtent()

DiskLoc mongo::RecordStoreV1Base::getPrevRecordInExtent ( OperationContext *  opCtx,
const DiskLoc loc 
) const

◆ increaseStorageSize()

void mongo::RecordStoreV1Base::increaseStorageSize ( OperationContext *  opCtx,
int  size,
bool  enforceQuota 
)

◆ insertRecord()

StatusWith< RecordId > mongo::RecordStoreV1Base::insertRecord ( OperationContext *  opCtx,
const char *  data,
int  len,
Timestamp  ,
bool  enforceQuota 
)
virtual

Implements mongo::RecordStore.

◆ insertRecordsWithDocWriter()

Status mongo::RecordStoreV1Base::insertRecordsWithDocWriter ( OperationContext *  opCtx,
const DocWriter *const *  docs,
const Timestamp *  timestamps,
size_t  nDocs,
RecordId *  idsOut 
)
finalvirtual

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.

Implements mongo::RecordStore.

◆ isCapped()

virtual bool mongo::RecordStoreV1Base::isCapped ( ) const
protectedpure virtual

◆ isQuantized()

bool mongo::RecordStoreV1Base::isQuantized ( int  recordSize)
static

◆ numRecords()

virtual long long mongo::RecordStoreV1Base::numRecords ( OperationContext *  opCtx) const
inlinevirtual

Total number of record in the RecordStore.

You may need to cache it, so this call takes constant time, as it is called often.

Implements mongo::RecordStore.

◆ quantizeAllocationSpace()

int mongo::RecordStoreV1Base::quantizeAllocationSpace ( int  minSize)
static

Quantize 'minSize' to the nearest allocation size.

◆ recordFor()

MmapV1RecordHeader * mongo::RecordStoreV1Base::recordFor ( const DiskLoc loc) const
protectedvirtual

◆ shouldPadInserts()

virtual bool mongo::RecordStoreV1Base::shouldPadInserts ( ) const
protectedpure virtual

◆ storageSize()

int64_t mongo::RecordStoreV1Base::storageSize ( OperationContext *  opCtx,
BSONObjBuilder *  extraInfo = NULL,
int  infoLevel = 0 
) const
virtual
Parameters
extraInfo- optional more debug info
level- optional, level of debug info to put in (higher is more)
Returns
total estimate size (in bytes) on stable storage

Implements mongo::RecordStore.

◆ touch()

Status mongo::RecordStoreV1Base::touch ( OperationContext *  opCtx,
BSONObjBuilder *  output 
) const
virtual

Load all data into cache.

What cache depends on implementation.

If the underlying storage engine does not support the operation, returns ErrorCodes::CommandNotSupported

Parameters
output(optional) - where to put detailed stats

Reimplemented from mongo::RecordStore.

◆ updateRecord()

Status mongo::RecordStoreV1Base::updateRecord ( OperationContext *  opCtx,
const RecordId &  oldLocation,
const char *  data,
int  len,
bool  enforceQuota,
UpdateNotifier notifier 
)
virtual
Parameters
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.
Returns
Status - If a document move is required (MMAPv1 only) then a status of ErrorCodes::NeedsDocumentMove will be returned. On receipt of this status no update will be performed. It is the caller's responsibility to:
  1. Remove the existing document and associated index keys.
  2. Insert a new document and index keys.

For capped record stores, the record size will never change.

Implements mongo::RecordStore.

◆ updateStatsAfterRepair()

virtual void mongo::RecordStoreV1Base::updateStatsAfterRepair ( OperationContext *  opCtx,
long long  numRecords,
long long  dataSize 
)
inlinevirtual

Called after a repair operation is run with the recomputed numRecords and dataSize.

Implements mongo::RecordStore.

◆ updateWithDamages()

StatusWith< RecordData > mongo::RecordStoreV1Base::updateWithDamages ( OperationContext *  opCtx,
const RecordId &  loc,
const RecordData oldRec,
const char *  damageSource,
const mutablebson::DamageVector &  damages 
)
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.

Returns
the updated version of the record. If unowned data is returned, then it is valid until the next modification of this Record or the lock on the collection has been released.

Implements mongo::RecordStore.

◆ updateWithDamagesSupported()

bool mongo::RecordStoreV1Base::updateWithDamagesSupported ( ) const
virtual
Returns
Returns 'false' if this record store does not implement 'updatewithDamages'. If this method returns false, 'updateWithDamages' must not be called, and all updates must be routed through 'updateRecord' above. This allows the update framework to avoid doing the work of damage tracking if the underlying record store cannot utilize that information.

Implements mongo::RecordStore.

◆ validate()

Status mongo::RecordStoreV1Base::validate ( OperationContext *  opCtx,
ValidateCmdLevel  level,
ValidateAdaptor adaptor,
ValidateResults results,
BSONObjBuilder *  output 
)
virtual
Returns
OK if the validate run successfully OK will be returned even if corruption is found deatils will be in result

Implements mongo::RecordStore.

◆ waitForAllEarlierOplogWritesToBeVisible()

void mongo::RecordStoreV1Base::waitForAllEarlierOplogWritesToBeVisible ( OperationContext *  opCtx) const
inlineoverridevirtual

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.

Implements mongo::RecordStore.

Friends And Related Function Documentation

◆ RecordStoreV1RepairCursor

friend class RecordStoreV1RepairCursor
friend

Member Data Documentation

◆ _details

std::unique_ptr<RecordStoreV1MetaData> mongo::RecordStoreV1Base::_details
protected

◆ _extentManager

ExtentManager* mongo::RecordStoreV1Base::_extentManager
protected

◆ _isSystemIndexes

bool mongo::RecordStoreV1Base::_isSystemIndexes
protected

◆ Buckets

const int mongo::RecordStoreV1Base::Buckets = 26
static

◆ bucketSizes

const int mongo::RecordStoreV1Base::bucketSizes
static
Initial value:
= {
0x20,
0x40,
0x80,
0x100,
0x200,
0x400,
0x800,
0x1000,
0x2000,
0x4000,
0x8000,
0x10000,
0x20000,
0x40000,
0x80000,
0x100000,
0x200000,
0x400000,
0x600000,
0x800000,
0xA00000,
0xC00000,
0xE00000,
INT_MAX,
}

◆ MaxAllowedAllocation

const int mongo::RecordStoreV1Base::MaxAllowedAllocation = 16 * 1024 * 1024 + 512 * 1024
static

◆ savedCursors

SavedCursorRegistry mongo::RecordStoreV1Base::savedCursors

The documentation for this class was generated from the following files: