Storage Engine API
mongo::SortedDataInterface Class Referenceabstract

This interface is a work in progress. More...

#include <sorted_data_interface.h>

Inheritance diagram for mongo::SortedDataInterface:
mongo::DevNullSortedDataInterface mongo::MobileIndex mongo::WiredTigerIndex mongo::MobileIndexStandard mongo::MobileIndexUnique mongo::WiredTigerIndexStandard mongo::WiredTigerIndexUnique

Detailed Description

This interface is a work in progress.

Notes below:

This interface began as the SortedDataInterface, a way to hide the fact that there were two on-disk formats for the btree. With the introduction of other storage engines, this interface was generalized to provide access to sorted data. Specifically:

  1. Many other storage engines provide different Btree(-ish) implementations. This interface could allow those interfaces to avoid storing btree buckets in an already sorted structure.

TODO: See if there is actually a performance gain.

  1. The existing btree implementation is written to assume that if it modifies a record it is modifying the underlying record. This interface is an attempt to work around that.

TODO: See if this actually works.

Classes

class  Cursor
 Navigates over the sorted data. More...
 

Public Member Functions

virtual ~SortedDataInterface ()
 
virtual SortedDataBuilderInterfacegetBulkBuilder (OperationContext *opCtx, bool dupsAllowed)=0
 Return a bulk builder for 'this' index. More...
 
virtual Status insert (OperationContext *opCtx, const BSONObj &key, const RecordId &loc, bool dupsAllowed)=0
 Insert an entry into the index with the specified key and RecordId. More...
 
virtual void unindex (OperationContext *opCtx, const BSONObj &key, const RecordId &loc, bool dupsAllowed)=0
 Remove the entry from the index with the specified key and RecordId. More...
 
virtual Status dupKeyCheck (OperationContext *opCtx, const BSONObj &key, const RecordId &loc)=0
 Return ErrorCodes::DuplicateKey if 'key' already exists in 'this' index at a RecordId other than 'loc', and Status::OK() otherwise. More...
 
virtual Status compact (OperationContext *opCtx)
 Attempt to reduce the storage space used by this index via compaction. More...
 
virtual void fullValidate (OperationContext *opCtx, long long *numKeysOut, ValidateResults *fullResults) const =0
 TODO: expose full set of args for testing? More...
 
virtual bool appendCustomStats (OperationContext *opCtx, BSONObjBuilder *output, double scale) const =0
 
virtual long long getSpaceUsedBytes (OperationContext *opCtx) const =0
 Return the number of bytes consumed by 'this' index. More...
 
virtual bool isEmpty (OperationContext *opCtx)=0
 Return true if 'this' index is empty, and false otherwise. More...
 
virtual Status touch (OperationContext *opCtx) const
 Attempt to bring the entirety of 'this' index into memory. More...
 
virtual long long numEntries (OperationContext *opCtx) const
 Return the number of entries in 'this' index. More...
 
virtual std::unique_ptr< CursornewCursor (OperationContext *opCtx, bool isForward=true) const =0
 Returns an unpositioned cursor over 'this' index. More...
 
virtual std::unique_ptr< CursornewRandomCursor (OperationContext *opCtx) const
 Constructs a cursor over an index that returns entries in a randomized order, and allows storage engines to provide a more efficient way to randomly sample a collection than MongoDB's default sampling methods, which are used when this method returns {}. More...
 
virtual Status initAsEmpty (OperationContext *opCtx)=0
 

Constructor & Destructor Documentation

◆ ~SortedDataInterface()

virtual mongo::SortedDataInterface::~SortedDataInterface ( )
inlinevirtual

Member Function Documentation

◆ appendCustomStats()

virtual bool mongo::SortedDataInterface::appendCustomStats ( OperationContext *  opCtx,
BSONObjBuilder *  output,
double  scale 
) const
pure virtual

◆ compact()

virtual Status mongo::SortedDataInterface::compact ( OperationContext *  opCtx)
inlinevirtual

Attempt to reduce the storage space used by this index via compaction.

Only called if the indexed record store supports compaction-in-place.

Reimplemented in mongo::WiredTigerIndex.

◆ dupKeyCheck()

virtual Status mongo::SortedDataInterface::dupKeyCheck ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc 
)
pure virtual

Return ErrorCodes::DuplicateKey if 'key' already exists in 'this' index at a RecordId other than 'loc', and Status::OK() otherwise.

Parameters
opCtxthe transaction under which this operation takes place

TODO: Hide this by exposing an update method?

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.

◆ fullValidate()

virtual void mongo::SortedDataInterface::fullValidate ( OperationContext *  opCtx,
long long *  numKeysOut,
ValidateResults fullResults 
) const
pure virtual

TODO: expose full set of args for testing?

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.

◆ getBulkBuilder()

virtual SortedDataBuilderInterface* mongo::SortedDataInterface::getBulkBuilder ( OperationContext *  opCtx,
bool  dupsAllowed 
)
pure virtual

Return a bulk builder for 'this' index.

Implementations can assume that 'this' index outlives its bulk builder.

Parameters
opCtxthe transaction under which keys are added to 'this' index
dupsAllowedtrue if duplicate keys are allowed, and false otherwise
Returns
caller takes ownership

Implemented in mongo::WiredTigerIndexStandard, mongo::WiredTigerIndexUnique, mongo::DevNullSortedDataInterface, mongo::MobileIndexUnique, and mongo::MobileIndexStandard.

◆ getSpaceUsedBytes()

virtual long long mongo::SortedDataInterface::getSpaceUsedBytes ( OperationContext *  opCtx) const
pure virtual

Return the number of bytes consumed by 'this' index.

Parameters
opCtxthe transaction under which this operation takes place
See also
IndexAccessMethod::getSpaceUsedBytes

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.

◆ initAsEmpty()

virtual Status mongo::SortedDataInterface::initAsEmpty ( OperationContext *  opCtx)
pure virtual

◆ insert()

virtual Status mongo::SortedDataInterface::insert ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc,
bool  dupsAllowed 
)
pure virtual

Insert an entry into the index with the specified key and RecordId.

Parameters
opCtxthe transaction under which the insert takes place
dupsAllowedtrue if duplicate keys are allowed, and false otherwise
Returns
Status::OK() if the insert succeeded,
    ErrorCodes::DuplicateKey if 'key' already exists in 'this' index
    at a RecordId other than 'loc' and duplicates were not allowed

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.

◆ isEmpty()

virtual bool mongo::SortedDataInterface::isEmpty ( OperationContext *  opCtx)
pure virtual

Return true if 'this' index is empty, and false otherwise.

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.

◆ newCursor()

virtual std::unique_ptr<Cursor> mongo::SortedDataInterface::newCursor ( OperationContext *  opCtx,
bool  isForward = true 
) const
pure virtual

Returns an unpositioned cursor over 'this' index.

Implementations can assume that 'this' index outlives all cursors it produces.

Implemented in mongo::WiredTigerIndexStandard, mongo::DevNullSortedDataInterface, mongo::WiredTigerIndexUnique, mongo::MobileIndexUnique, and mongo::MobileIndexStandard.

◆ newRandomCursor()

virtual std::unique_ptr<Cursor> mongo::SortedDataInterface::newRandomCursor ( OperationContext *  opCtx) const
inlinevirtual

Constructs a cursor over an index that returns entries in a randomized order, and allows storage engines to provide a more efficient way to randomly sample a collection than MongoDB's default sampling methods, which are used when this method returns {}.

Note if it is possible to implement RecordStore::getRandomCursor(), that method is preferred, as it will return the entire document, whereas this method will only return the index key and the RecordId, requiring an extra lookup.

This method may be implemented using a pseudo-random walk over B-trees or a similar approach. Different cursors should return entries in a different order. Random cursors may return the same entry more than once and, as a result, may return more entries than exist in the index. Implementations should avoid obvious biases toward older, newer, larger smaller or other specific classes of entries.

◆ numEntries()

virtual long long mongo::SortedDataInterface::numEntries ( OperationContext *  opCtx) const
inlinevirtual

Return the number of entries in 'this' index.

The default implementation should be overridden with a more efficient one if at all possible.

Reimplemented in mongo::MobileIndex.

◆ touch()

virtual Status mongo::SortedDataInterface::touch ( OperationContext *  opCtx) const
inlinevirtual

Attempt to bring the entirety of 'this' index into memory.

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

Returns
Status::OK()

Reimplemented in mongo::WiredTigerIndex.

◆ unindex()

virtual void mongo::SortedDataInterface::unindex ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc,
bool  dupsAllowed 
)
pure virtual

Remove the entry from the index with the specified key and RecordId.

Parameters
opCtxthe transaction under which the remove takes place
dupsAllowedtrue if duplicate keys are allowed, and false otherwise

Implemented in mongo::DevNullSortedDataInterface, mongo::WiredTigerIndex, and mongo::MobileIndex.


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