Storage Engine API
mongo::WiredTigerIndex Class Referenceabstract

#include <wiredtiger_index.h>

Inheritance diagram for mongo::WiredTigerIndex:
mongo::SortedDataInterface mongo::WiredTigerIndexStandard mongo::WiredTigerIndexUnique

Classes

class  BulkBuilder
 Base class for WiredTigerIndex bulk builders. More...
 
class  StandardBulkBuilder
 Bulk builds a non-unique index. More...
 
class  UniqueBulkBuilder
 Bulk builds a unique index. More...
 

Public Member Functions

 WiredTigerIndex (OperationContext *ctx, const std::string &uri, const IndexDescriptor *desc, KVPrefix prefix, bool readOnly)
 
virtual Status insert (OperationContext *opCtx, const BSONObj &key, const RecordId &id, bool dupsAllowed)
 Insert an entry into the index with the specified key and RecordId. More...
 
virtual void unindex (OperationContext *opCtx, const BSONObj &key, const RecordId &id, bool dupsAllowed)
 Remove the entry from the index with the specified key and RecordId. More...
 
virtual void fullValidate (OperationContext *opCtx, long long *numKeysOut, ValidateResults *fullResults) const
 TODO: expose full set of args for testing? More...
 
virtual bool appendCustomStats (OperationContext *opCtx, BSONObjBuilder *output, double scale) const
 
virtual Status dupKeyCheck (OperationContext *opCtx, const BSONObj &key, const RecordId &id)
 Return ErrorCodes::DuplicateKey if 'key' already exists in 'this' index at a RecordId other than 'loc', and Status::OK() otherwise. More...
 
virtual bool isEmpty (OperationContext *opCtx)
 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 getSpaceUsedBytes (OperationContext *opCtx) const
 Return the number of bytes consumed by 'this' index. More...
 
virtual Status initAsEmpty (OperationContext *opCtx)
 
virtual Status compact (OperationContext *opCtx)
 Attempt to reduce the storage space used by this index via compaction. More...
 
const std::string & uri () const
 
virtual bool isDup (OperationContext *opCtx, WT_CURSOR *c, const BSONObj &key, const RecordId &id)
 
uint64_t tableId () const
 
Ordering ordering () const
 
KeyString::Version keyStringVersion () const
 
std::string collectionNamespace () const
 
std::string indexName () const
 
bool isIdIndex () const
 
virtual bool unique () const =0
 
virtual bool isTimestampSafeUniqueIdx () const =0
 
Status dupKeyError (const BSONObj &key)
 
- Public Member Functions inherited from mongo::SortedDataInterface
virtual ~SortedDataInterface ()
 
virtual SortedDataBuilderInterfacegetBulkBuilder (OperationContext *opCtx, bool dupsAllowed)=0
 Return a bulk builder for 'this' index. 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...
 

Static Public Member Functions

static StatusWith< std::string > parseIndexOptions (const BSONObj &options)
 Parses index options for wired tiger configuration string suitable for table creation. More...
 
static std::string generateAppMetadataString (const IndexDescriptor &desc)
 Creates the "app_metadata" string for the index from the index descriptor, to be stored in WiredTiger's metadata. More...
 
static StatusWith< std::string > generateCreateString (const std::string &engineName, const std::string &sysIndexConfig, const std::string &collIndexConfig, const IndexDescriptor &desc, bool isPrefixed)
 Creates a configuration string suitable for 'config' parameter in WT_SESSION::create(). More...
 
static int Create (OperationContext *opCtx, const std::string &uri, const std::string &config)
 Creates a WiredTiger table suitable for implementing a MongoDB index. More...
 

Protected Member Functions

virtual Status _insert (OperationContext *opCtx, WT_CURSOR *c, const BSONObj &key, const RecordId &id, bool dupsAllowed)=0
 
virtual void _unindex (OperationContext *opCtx, WT_CURSOR *c, const BSONObj &key, const RecordId &id, bool dupsAllowed)=0
 
void setKey (WT_CURSOR *cursor, const WT_ITEM *item)
 

Protected Attributes

const Ordering _ordering
 
KeyString::Version _keyStringVersion
 
int _dataFormatVersion
 
std::string _uri
 
uint64_t _tableId
 
std::string _collectionNamespace
 
std::string _indexName
 
KVPrefix _prefix
 
bool _isIdIndex
 

Constructor & Destructor Documentation

◆ WiredTigerIndex()

mongo::WiredTigerIndex::WiredTigerIndex ( OperationContext *  ctx,
const std::string &  uri,
const IndexDescriptor *  desc,
KVPrefix  prefix,
bool  readOnly 
)

Member Function Documentation

◆ _insert()

virtual Status mongo::WiredTigerIndex::_insert ( OperationContext *  opCtx,
WT_CURSOR *  c,
const BSONObj &  key,
const RecordId &  id,
bool  dupsAllowed 
)
protectedpure virtual

◆ _unindex()

virtual void mongo::WiredTigerIndex::_unindex ( OperationContext *  opCtx,
WT_CURSOR *  c,
const BSONObj &  key,
const RecordId &  id,
bool  dupsAllowed 
)
protectedpure virtual

◆ appendCustomStats()

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

◆ collectionNamespace()

std::string mongo::WiredTigerIndex::collectionNamespace ( ) const
inline

◆ compact()

Status mongo::WiredTigerIndex::compact ( OperationContext *  opCtx)
virtual

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

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

Reimplemented from mongo::SortedDataInterface.

◆ Create()

int mongo::WiredTigerIndex::Create ( OperationContext *  opCtx,
const std::string &  uri,
const std::string &  config 
)
static

Creates a WiredTiger table suitable for implementing a MongoDB index.

'config' should be created with generateCreateString().

◆ dupKeyCheck()

Status mongo::WiredTigerIndex::dupKeyCheck ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc 
)
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?

Implements mongo::SortedDataInterface.

◆ dupKeyError()

Status mongo::WiredTigerIndex::dupKeyError ( const BSONObj &  key)

◆ fullValidate()

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

TODO: expose full set of args for testing?

Implements mongo::SortedDataInterface.

◆ generateAppMetadataString()

std::string mongo::WiredTigerIndex::generateAppMetadataString ( const IndexDescriptor &  desc)
static

Creates the "app_metadata" string for the index from the index descriptor, to be stored in WiredTiger's metadata.

The output string is of the form: ",app_metadata=(...)," and can be appended to the config strings for WiredTiger's API calls.

◆ generateCreateString()

StatusWith< std::string > mongo::WiredTigerIndex::generateCreateString ( const std::string &  engineName,
const std::string &  sysIndexConfig,
const std::string &  collIndexConfig,
const IndexDescriptor &  desc,
bool  isPrefixed 
)
static

Creates a configuration string suitable for 'config' parameter in WT_SESSION::create().

Configuration string is constructed from: built-in defaults 'sysIndexConfig' 'collIndexConfig' storageEngine.wiredTiger.configString in index descriptor's info object. Performs simple validation on the supplied parameters. Returns error status if validation fails. Note that even if this function returns an OK status, WT_SESSION:create() may still fail with the constructed configuration string.

◆ getSpaceUsedBytes()

long long mongo::WiredTigerIndex::getSpaceUsedBytes ( OperationContext *  opCtx) const
virtual

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

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

Implements mongo::SortedDataInterface.

◆ indexName()

std::string mongo::WiredTigerIndex::indexName ( ) const
inline

◆ initAsEmpty()

Status mongo::WiredTigerIndex::initAsEmpty ( OperationContext *  opCtx)
virtual

◆ insert()

Status mongo::WiredTigerIndex::insert ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc,
bool  dupsAllowed 
)
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

Implements mongo::SortedDataInterface.

◆ isDup()

bool mongo::WiredTigerIndex::isDup ( OperationContext *  opCtx,
WT_CURSOR *  c,
const BSONObj &  key,
const RecordId &  id 
)
virtual

Reimplemented in mongo::WiredTigerIndexUnique.

◆ isEmpty()

bool mongo::WiredTigerIndex::isEmpty ( OperationContext *  opCtx)
virtual

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

Implements mongo::SortedDataInterface.

◆ isIdIndex()

bool mongo::WiredTigerIndex::isIdIndex ( ) const
inline

◆ isTimestampSafeUniqueIdx()

virtual bool mongo::WiredTigerIndex::isTimestampSafeUniqueIdx ( ) const
pure virtual

◆ keyStringVersion()

KeyString::Version mongo::WiredTigerIndex::keyStringVersion ( ) const
inline

◆ ordering()

Ordering mongo::WiredTigerIndex::ordering ( ) const
inline

◆ parseIndexOptions()

StatusWith< std::string > mongo::WiredTigerIndex::parseIndexOptions ( const BSONObj &  options)
static

Parses index options for wired tiger configuration string suitable for table creation.

The document 'options' is typically obtained from the 'storageEngine.wiredTiger' field of an IndexDescriptor's info object.

◆ setKey()

void mongo::WiredTigerIndex::setKey ( WT_CURSOR *  cursor,
const WT_ITEM *  item 
)
protected

◆ tableId()

uint64_t mongo::WiredTigerIndex::tableId ( ) const
inline

◆ touch()

Status mongo::WiredTigerIndex::touch ( OperationContext *  opCtx) const
virtual

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

◆ unindex()

void mongo::WiredTigerIndex::unindex ( OperationContext *  opCtx,
const BSONObj &  key,
const RecordId &  loc,
bool  dupsAllowed 
)
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

Implements mongo::SortedDataInterface.

◆ unique()

virtual bool mongo::WiredTigerIndex::unique ( ) const
pure virtual

◆ uri()

const std::string& mongo::WiredTigerIndex::uri ( ) const
inline

Member Data Documentation

◆ _collectionNamespace

std::string mongo::WiredTigerIndex::_collectionNamespace
protected

◆ _dataFormatVersion

int mongo::WiredTigerIndex::_dataFormatVersion
protected

◆ _indexName

std::string mongo::WiredTigerIndex::_indexName
protected

◆ _isIdIndex

bool mongo::WiredTigerIndex::_isIdIndex
protected

◆ _keyStringVersion

KeyString::Version mongo::WiredTigerIndex::_keyStringVersion
protected

◆ _ordering

const Ordering mongo::WiredTigerIndex::_ordering
protected

◆ _prefix

KVPrefix mongo::WiredTigerIndex::_prefix
protected

◆ _tableId

uint64_t mongo::WiredTigerIndex::_tableId
protected

◆ _uri

std::string mongo::WiredTigerIndex::_uri
protected

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