Storage Engine API
mongo::MobileRecordStore Class Reference

A RecordStore that stores all data in SQLite. More...

#include <mobile_record_store.h>

Inheritance diagram for mongo::MobileRecordStore:
mongo::RecordStore

Detailed Description

A RecordStore that stores all data in SQLite.

Classes

class  Cursor
 
class  DataSizeChange
 Keeps track of the total data size. More...
 
class  NumRecsChange
 Keeps track of the changes to the number of records. More...
 

Public Member Functions

 MobileRecordStore (OperationContext *opCtx, StringData ns, const std::string &path, const std::string &ident, const CollectionOptions &options)
 
const char * name () const override
 
RecordData dataFor (OperationContext *opCtx, const RecordId &recId) const override
 Get the RecordData at loc, which must exist. More...
 
bool findRecord (OperationContext *opCtx, const RecordId &recId, RecordData *rd) const override
 
void deleteRecord (OperationContext *opCtx, const RecordId &dl) override
 
StatusWith< RecordId > insertRecord (OperationContext *opCtx, const char *data, int len, Timestamp timestamp, bool enforceQuota) override
 
Status insertRecordsWithDocWriter (OperationContext *opCtx, const DocWriter *const *docs, const Timestamp *timestamps, size_t nDocs, RecordId *idsOut) override
 Inserts nDocs documents into this RecordStore using the DocWriter interface. More...
 
Status updateRecord (OperationContext *opCtx, const RecordId &oldLocation, const char *data, int len, bool enforceQuota, UpdateNotifier *notifier) override
 
bool updateWithDamagesSupported () const override
 
StatusWith< RecordDataupdateWithDamages (OperationContext *opCtx, const RecordId &recId, const RecordData &oldRec, const char *damageSource, const mutablebson::DamageVector &damages) override
 Updates the record positioned at 'loc' in-place using the deltas described by 'damages'. More...
 
std::unique_ptr< SeekableRecordCursorgetCursor (OperationContext *opCtx, bool forward) const override
 Returns a new cursor over this record store. More...
 
Status truncate (OperationContext *opCtx) override
 SQLite does not directly support truncate. More...
 
void cappedTruncateAfter (OperationContext *opCtx, RecordId end, bool inclusive) override
 The method throws an assertion if the capped truncate results in an emptied table. More...
 
bool compactSupported () const override
 does this RecordStore support the compact operation? More...
 
bool compactsInPlace () const override
 Does compact() leave RecordIds alone or can they change. More...
 
Status compact (OperationContext *opCtx, RecordStoreCompactAdaptor *adaptor, const CompactOptions *options, CompactStats *stats) override
 Attempt to reduce the storage space used by this RecordStore. More...
 
Status validate (OperationContext *opCtx, ValidateCmdLevel level, ValidateAdaptor *adaptor, ValidateResults *results, BSONObjBuilder *output) override
 Note: on full validation, this validates the entire database file, not just the table used by this record store. More...
 
void appendCustomStats (OperationContext *opCtx, BSONObjBuilder *result, double scale) const override
 
Status touch (OperationContext *opCtx, BSONObjBuilder *output) const override
 Load all data into cache. More...
 
int64_t storageSize (OperationContext *opCtx, BSONObjBuilder *extraInfo=NULL, int infoLevel=0) const override
 Note: does not accurately return the size of the table on disk. More...
 
long long dataSize (OperationContext *opCtx) const override
 The dataSize is an approximation of the sum of the sizes (in bytes) of the documents or entries in the recordStore. More...
 
long long numRecords (OperationContext *opCtx) const override
 Total number of record in the RecordStore. More...
 
boost::optional< RecordId > oplogStartHack (OperationContext *opCtx, const RecordId &startingPosition) const override
 Return the RecordId of an oplog entry as close to startingPosition as possible without being higher. More...
 
void waitForAllEarlierOplogWritesToBeVisible (OperationContext *opCtx) const override
 Waits for all writes that completed before this call to be visible to forward scans. More...
 
void updateStatsAfterRepair (OperationContext *opCtx, long long numRecords, long long dataSize) override
 Called after a repair operation is run with the recomputed numRecords and dataSize. More...
 
bool isCapped () const override
 
void setCappedCallback (CappedCallback *cb) override
 
Status updateCappedSize (OperationContext *opCtx, long long cappedSize) override
 used to support online change oplog size. More...
 
- Public Member Functions inherited from mongo::RecordStore
 RecordStore (StringData ns)
 
virtual ~RecordStore ()
 
virtual const std::string & ns () const
 
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< RecordCursorgetCursorForRepair (OperationContext *opCtx) const
 Constructs a cursor over a potentially corrupted store, which can be used to salvage damaged records. 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 bool isInRecordIdOrder () const
 Does the RecordStore cursor retrieve its document in RecordId Order? 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...
 

Static Public Member Functions

static void create (OperationContext *opCtx, const std::string &ident)
 Creates a new record store inside SQLite. More...
 

Private Member Functions

RecordId _nextId ()
 
bool _isCappedAndNeedsDelete (int64_t numRecs, int64_t numBytes)
 Returns true if the collection is capped and exceeds the size or document cap. More...
 
void _notifyCappedCallbackIfNeeded_inlock (OperationContext *opCtx, RecordId recId, const RecordData &recData)
 Notifies the capped callback that a capped collection is about to delete a record. More...
 
void _doCappedDelete (OperationContext *opCtx, SqliteStatement &stmt, const std::string &direction, int64_t startRecId=0)
 Performs the capped deletion. More...
 
void _cappedDeleteIfNeeded (OperationContext *opCtx)
 Deletes records from a capped database if the cap is exceeded. More...
 
void _initNumRecsIfNeeded_inlock (OperationContext *opCtx) const
 Fetches the number of records from the database. More...
 
void _changeNumRecs (OperationContext *opCtx, int64_t diff)
 Updates _numRecords. More...
 
bool _resetNumRecsIfNeeded (OperationContext *opCtx, int64_t newNumRecs)
 Resets _numRecords to the new value. More...
 
void _initDataSizeIfNeeded_inlock (OperationContext *opCtx) const
 Fetches the data size from the database. More...
 
void _changeDataSize (OperationContext *opCtx, int64_t diff)
 Updates _dataSize. More...
 
bool _resetDataSizeIfNeeded (OperationContext *opCtx, int64_t newDataSize)
 Resets _dataSize to the new value. More...
 

Private Attributes

const std::string _path
 
const std::string _ident
 
const bool _isOplog
 
const bool _isCapped
 
int64_t _cappedMaxSize
 
const int64_t _cappedMaxDocs
 
stdx::mutex _cappedCallbackMutex
 
CappedCallback_cappedCallback = nullptr
 
AtomicInt64 _nextIdNum
 
int64_t _numRecs
 
stdx::mutex _numRecsMutex
 
bool _isNumRecsInitialized = false
 
int64_t _dataSize
 
stdx::mutex _dataSizeMutex
 
bool _isDataSizeInitialized = false
 

Additional Inherited Members

- Protected Attributes inherited from mongo::RecordStore
std::string _ns
 

Constructor & Destructor Documentation

◆ MobileRecordStore()

mongo::MobileRecordStore::MobileRecordStore ( OperationContext *  opCtx,
StringData  ns,
const std::string &  path,
const std::string &  ident,
const CollectionOptions options 
)
explicit

Member Function Documentation

◆ _cappedDeleteIfNeeded()

void mongo::MobileRecordStore::_cappedDeleteIfNeeded ( OperationContext *  opCtx)
private

Deletes records from a capped database if the cap is exceeded.

◆ _changeDataSize()

void mongo::MobileRecordStore::_changeDataSize ( OperationContext *  opCtx,
int64_t  diff 
)
private

Updates _dataSize.

This must be called before the actual change is made to the database.

◆ _changeNumRecs()

void mongo::MobileRecordStore::_changeNumRecs ( OperationContext *  opCtx,
int64_t  diff 
)
private

Updates _numRecords.

This must be called before the actual change is made to the database.

◆ _doCappedDelete()

void mongo::MobileRecordStore::_doCappedDelete ( OperationContext *  opCtx,
SqliteStatement stmt,
const std::string &  direction,
int64_t  startRecId = 0 
)
private

Performs the capped deletion.

Deletes all records in the specified direction beginning at startRecId.

◆ _initDataSizeIfNeeded_inlock()

void mongo::MobileRecordStore::_initDataSizeIfNeeded_inlock ( OperationContext *  opCtx) const
private

Fetches the data size from the database.

_dataSizeMutex should be locked before this is called.

◆ _initNumRecsIfNeeded_inlock()

void mongo::MobileRecordStore::_initNumRecsIfNeeded_inlock ( OperationContext *  opCtx) const
private

Fetches the number of records from the database.

_numRecsMutex should be locked before this is called.

◆ _isCappedAndNeedsDelete()

bool mongo::MobileRecordStore::_isCappedAndNeedsDelete ( int64_t  numRecs,
int64_t  numBytes 
)
private

Returns true if the collection is capped and exceeds the size or document cap.

◆ _nextId()

RecordId mongo::MobileRecordStore::_nextId ( )
private

◆ _notifyCappedCallbackIfNeeded_inlock()

void mongo::MobileRecordStore::_notifyCappedCallbackIfNeeded_inlock ( OperationContext *  opCtx,
RecordId  recId,
const RecordData recData 
)
private

Notifies the capped callback that a capped collection is about to delete a record.

_cappedCallbackMutex should be locked before this is called.

◆ _resetDataSizeIfNeeded()

bool mongo::MobileRecordStore::_resetDataSizeIfNeeded ( OperationContext *  opCtx,
int64_t  newDataSize 
)
private

Resets _dataSize to the new value.

Returns true if _dataSize was reset; returns false otherwise.

◆ _resetNumRecsIfNeeded()

bool mongo::MobileRecordStore::_resetNumRecsIfNeeded ( OperationContext *  opCtx,
int64_t  newNumRecs 
)
private

Resets _numRecords to the new value.

Returns true if _numRecs was reset; returns false otherwise.

◆ appendCustomStats()

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

Implements mongo::RecordStore.

◆ cappedTruncateAfter()

void mongo::MobileRecordStore::cappedTruncateAfter ( OperationContext *  opCtx,
RecordId  end,
bool  inclusive 
)
overridevirtual

The method throws an assertion if the capped truncate results in an emptied table.

Implements mongo::RecordStore.

◆ compact()

Status mongo::MobileRecordStore::compact ( OperationContext *  opCtx,
RecordStoreCompactAdaptor adaptor,
const CompactOptions options,
CompactStats stats 
)
overridevirtual

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

◆ compactsInPlace()

bool mongo::MobileRecordStore::compactsInPlace ( ) const
inlineoverridevirtual

Does compact() leave RecordIds alone or can they change.

Only called if compactSupported() returns true.

Reimplemented from mongo::RecordStore.

◆ compactSupported()

bool mongo::MobileRecordStore::compactSupported ( ) const
inlineoverridevirtual

does this RecordStore support the compact operation?

If you return true, you must provide implementations of all compact methods.

Reimplemented from mongo::RecordStore.

◆ create()

void mongo::MobileRecordStore::create ( OperationContext *  opCtx,
const std::string &  ident 
)
static

Creates a new record store inside SQLite.

Creates a new record store within SQLite.

Transational semantics are handled by the caller.

The method is not transactional. Callers are responsible for handling transactional semantics.

◆ dataFor()

RecordData mongo::MobileRecordStore::dataFor ( OperationContext *  opCtx,
const RecordId &  loc 
) const
overridevirtual

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()

long long mongo::MobileRecordStore::dataSize ( OperationContext *  opCtx) const
overridevirtual

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

Implements mongo::RecordStore.

◆ deleteRecord()

void mongo::MobileRecordStore::deleteRecord ( OperationContext *  opCtx,
const RecordId &  dl 
)
overridevirtual

Implements mongo::RecordStore.

◆ findRecord()

bool mongo::MobileRecordStore::findRecord ( OperationContext *  opCtx,
const RecordId &  loc,
RecordData out 
) const
overridevirtual
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.

◆ getCursor()

std::unique_ptr< SeekableRecordCursor > mongo::MobileRecordStore::getCursor ( OperationContext *  opCtx,
bool  forward 
) const
overridevirtual

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.

Implements mongo::RecordStore.

◆ insertRecord()

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

Implements mongo::RecordStore.

◆ insertRecordsWithDocWriter()

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

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()

bool mongo::MobileRecordStore::isCapped ( ) const
inlineoverridevirtual

Implements mongo::RecordStore.

◆ name()

const char * mongo::MobileRecordStore::name ( ) const
overridevirtual

Implements mongo::RecordStore.

◆ numRecords()

long long mongo::MobileRecordStore::numRecords ( OperationContext *  opCtx) const
overridevirtual

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.

◆ oplogStartHack()

boost::optional< RecordId > mongo::MobileRecordStore::oplogStartHack ( OperationContext *  opCtx,
const RecordId &  startingPosition 
) const
overridevirtual

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

◆ setCappedCallback()

void mongo::MobileRecordStore::setCappedCallback ( CappedCallback cb)
inlineoverridevirtual

Reimplemented from mongo::RecordStore.

◆ storageSize()

int64_t mongo::MobileRecordStore::storageSize ( OperationContext *  opCtx,
BSONObjBuilder *  extraInfo = NULL,
int  infoLevel = 0 
) const
overridevirtual

Note: does not accurately return the size of the table on disk.

Instead, it returns the number of bytes used to store the BSON documents.

Implements mongo::RecordStore.

◆ touch()

Status mongo::MobileRecordStore::touch ( OperationContext *  opCtx,
BSONObjBuilder *  output 
) const
overridevirtual

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.

◆ truncate()

Status mongo::MobileRecordStore::truncate ( OperationContext *  opCtx)
overridevirtual

SQLite does not directly support truncate.

The SQLite documentation recommends dropping then recreating the table rather than deleting all the contents of a table.

Implements mongo::RecordStore.

◆ updateCappedSize()

Status mongo::MobileRecordStore::updateCappedSize ( OperationContext *  opCtx,
long long  cappedSize 
)
overridevirtual

used to support online change oplog size.

Reimplemented from mongo::RecordStore.

◆ updateRecord()

Status mongo::MobileRecordStore::updateRecord ( OperationContext *  opCtx,
const RecordId &  oldLocation,
const char *  data,
int  len,
bool  enforceQuota,
UpdateNotifier notifier 
)
overridevirtual
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()

void mongo::MobileRecordStore::updateStatsAfterRepair ( OperationContext *  opCtx,
long long  numRecords,
long long  dataSize 
)
inlineoverridevirtual

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

Implements mongo::RecordStore.

◆ updateWithDamages()

StatusWith< RecordData > mongo::MobileRecordStore::updateWithDamages ( OperationContext *  opCtx,
const RecordId &  loc,
const RecordData oldRec,
const char *  damageSource,
const mutablebson::DamageVector &  damages 
)
overridevirtual

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::MobileRecordStore::updateWithDamagesSupported ( ) const
overridevirtual
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::MobileRecordStore::validate ( OperationContext *  opCtx,
ValidateCmdLevel  level,
ValidateAdaptor adaptor,
ValidateResults results,
BSONObjBuilder *  output 
)
overridevirtual

Note: on full validation, this validates the entire database file, not just the table used by this record store.

Implements mongo::RecordStore.

◆ waitForAllEarlierOplogWritesToBeVisible()

void mongo::MobileRecordStore::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.

Member Data Documentation

◆ _cappedCallback

CappedCallback* mongo::MobileRecordStore::_cappedCallback = nullptr
private

◆ _cappedCallbackMutex

stdx::mutex mongo::MobileRecordStore::_cappedCallbackMutex
private

◆ _cappedMaxDocs

const int64_t mongo::MobileRecordStore::_cappedMaxDocs
private

◆ _cappedMaxSize

int64_t mongo::MobileRecordStore::_cappedMaxSize
private

◆ _dataSize

int64_t mongo::MobileRecordStore::_dataSize
mutableprivate

◆ _dataSizeMutex

stdx::mutex mongo::MobileRecordStore::_dataSizeMutex
mutableprivate

◆ _ident

const std::string mongo::MobileRecordStore::_ident
private

◆ _isCapped

const bool mongo::MobileRecordStore::_isCapped
private

◆ _isDataSizeInitialized

bool mongo::MobileRecordStore::_isDataSizeInitialized = false
mutableprivate

◆ _isNumRecsInitialized

bool mongo::MobileRecordStore::_isNumRecsInitialized = false
mutableprivate

◆ _isOplog

const bool mongo::MobileRecordStore::_isOplog
private

◆ _nextIdNum

AtomicInt64 mongo::MobileRecordStore::_nextIdNum
private

◆ _numRecs

int64_t mongo::MobileRecordStore::_numRecs
mutableprivate

◆ _numRecsMutex

stdx::mutex mongo::MobileRecordStore::_numRecsMutex
mutableprivate

◆ _path

const std::string mongo::MobileRecordStore::_path
private

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