Storage Engine API
mongo::IndexCatalogImpl Class Reference

how many: 1 per Collection. More...

#include <index_catalog_impl.h>

Inheritance diagram for mongo::IndexCatalogImpl:
mongo::IndexCatalog::Impl

Detailed Description

how many: 1 per Collection.

lifecycle: attached to a Collection.

Classes

class  IndexBuildBlock
 disk creation order 1) system.indexes entry 2) collection's NamespaceDetails a) info + head b) _indexBuildsInProgress++ 3) indexes entry in .ns file 4) system.namespaces entry for index ns More...
 
class  IndexIteratorImpl
 
struct  IndexKillCriteria
 

Public Types

using IndexIterator = IndexCatalog::IndexIterator
 

Public Member Functions

 IndexCatalogImpl (IndexCatalog *this_, Collection *collection, int maxNumIndexesAllowed)
 
 ~IndexCatalogImpl () override
 
Status init (OperationContext *opCtx) override
 
bool ok () const override
 
bool haveAnyIndexes () const override
 
int numIndexesTotal (OperationContext *opCtx) const override
 
int numIndexesReady (OperationContext *opCtx) const override
 
int numIndexesInProgress (OperationContext *opCtx) const
 
bool haveIdIndex (OperationContext *opCtx) const override
 this is in "alive" until the Collection goes away in which case everything from this tree has to go away. More...
 
BSONObj getDefaultIdIndexSpec () const override
 Returns the spec for the id index to create by default for this collection. More...
 
IndexDescriptor * findIdIndex (OperationContext *opCtx) const override
 
IndexDescriptor * findIndexByName (OperationContext *opCtx, StringData name, bool includeUnfinishedIndexes=false) const override
 Find index by name. More...
 
IndexDescriptor * findIndexByKeyPatternAndCollationSpec (OperationContext *opCtx, const BSONObj &key, const BSONObj &collationSpec, bool includeUnfinishedIndexes=false) const override
 Find index by matching key pattern and collation spec. More...
 
void findIndexesByKeyPattern (OperationContext *opCtx, const BSONObj &key, bool includeUnfinishedIndexes, std::vector< IndexDescriptor *> *matches) const override
 Find indexes with a matching key pattern, putting them into the vector 'matches'. More...
 
IndexDescriptor * findShardKeyPrefixedIndex (OperationContext *opCtx, const BSONObj &shardKey, bool requireSingleKey) const override
 Returns an index suitable for shard key range scans. More...
 
void findIndexByType (OperationContext *opCtx, const std::string &type, std::vector< IndexDescriptor *> &matches, bool includeUnfinishedIndexes=false) const override
 
const IndexDescriptor * refreshEntry (OperationContext *opCtx, const IndexDescriptor *oldDesc) override
 Reload the index definition for 'oldDesc' from the CollectionCatalogEntry. More...
 
const IndexCatalogEntrygetEntry (const IndexDescriptor *desc) const override
 
IndexAccessMethod * getIndex (const IndexDescriptor *desc) override
 
const IndexAccessMethod * getIndex (const IndexDescriptor *desc) const override
 
Status checkUnfinished () const override
 Returns a not-ok Status if there are any unfinished index builds. More...
 
StatusWith< BSONObj > createIndexOnEmptyCollection (OperationContext *opCtx, BSONObj spec) override
 Call this only on an empty collection from inside a WriteUnitOfWork. More...
 
StatusWith< BSONObj > prepareSpecForCreate (OperationContext *opCtx, const BSONObj &original) const override
 
void dropAllIndexes (OperationContext *opCtx, bool includingIdIndex, stdx::function< void(const IndexDescriptor *)> onDropFn=nullptr) override
 Drops all indexes in the index catalog, optionally dropping the id index depending on the 'includingIdIndex' parameter value. More...
 
Status dropIndex (OperationContext *opCtx, IndexDescriptor *desc) override
 
std::vector< BSONObj > getAndClearUnfinishedIndexes (OperationContext *opCtx) override
 will drop all incompleted indexes and return specs after this, the indexes can be rebuilt More...
 
bool isMultikey (OperationContext *opCtx, const IndexDescriptor *idx) override
 Returns true if the index 'idx' is multikey, and returns false otherwise. More...
 
MultikeyPaths getMultikeyPaths (OperationContext *opCtx, const IndexDescriptor *idx) override
 Returns the path components that cause the index 'idx' to be multikey if the index supports path-level multikey tracking, and returns an empty vector if path-level multikey tracking isn't supported. More...
 
Status indexRecords (OperationContext *opCtx, const std::vector< BsonRecord > &bsonRecords, int64_t *keysInsertedOut) override
 When 'keysInsertedOut' is not null, it will be set to the number of index keys inserted by this operation. More...
 
void unindexRecord (OperationContext *opCtx, const BSONObj &obj, const RecordId &loc, bool noWarn, int64_t *keysDeletedOut) override
 When 'keysDeletedOut' is not null, it will be set to the number of index keys removed by this operation. More...
 
std::string getAccessMethodName (OperationContext *opCtx, const BSONObj &keyPattern) override
 
Status _upgradeDatabaseMinorVersionIfNeeded (OperationContext *opCtx, const std::string &newPluginName) override
 
- Public Member Functions inherited from mongo::IndexCatalog::Impl
virtual ~Impl ()=0
 

Static Public Member Functions

static BSONObj fixIndexKey (const BSONObj &key)
 
static void prepareInsertDeleteOptions (OperationContext *opCtx, const IndexDescriptor *desc, InsertDeleteOptions *options)
 Fills out 'options' in order to indicate whether to allow dups or relax index constraints, as needed by replication. More...
 

Private Member Functions

bool _shouldOverridePlugin (OperationContext *opCtx, const BSONObj &keyPattern) const
 
std::string _getAccessMethodName (OperationContext *opCtx, const BSONObj &keyPattern) const
 This differs from IndexNames::findPluginName in that returns the plugin name we should use, not the plugin name inside of the provided key pattern. More...
 
void _checkMagic () const
 
Status _indexFilteredRecords (OperationContext *opCtx, IndexCatalogEntry *index, const std::vector< BsonRecord > &bsonRecords, int64_t *keysInsertedOut)
 
Status _indexRecords (OperationContext *opCtx, IndexCatalogEntry *index, const std::vector< BsonRecord > &bsonRecords, int64_t *keysInsertedOut)
 
Status _unindexRecord (OperationContext *opCtx, IndexCatalogEntry *index, const BSONObj &obj, const RecordId &loc, bool logIfError, int64_t *keysDeletedOut)
 
const IndexCatalogEntryContainer_getEntries () const override
 
IndexCatalogEntryContainer_getEntries () override
 
Status _dropIndex (OperationContext *opCtx, IndexCatalogEntry *entry) override
 this does no sanity checks More...
 
void _deleteIndexFromDisk (OperationContext *opCtx, const std::string &indexName, const std::string &indexNamespace)
 
IndexCatalogEntry_setupInMemoryStructures (OperationContext *opCtx, std::unique_ptr< IndexDescriptor > descriptor, bool initFromDisk)
 
Status _isSpecOk (OperationContext *opCtx, const BSONObj &spec) const
 
Status _doesSpecConflictWithExisting (OperationContext *opCtx, const BSONObj &spec) const
 
const Collection_getCollection () const override
 
Collection_getCollection () override
 

Static Private Member Functions

static StatusWith< BSONObj > _fixIndexSpec (OperationContext *opCtx, Collection *collection, const BSONObj &spec)
 
static IndexCatalogEntry_setupInMemoryStructures (IndexCatalog *const this_, OperationContext *const opCtx, std::unique_ptr< IndexDescriptor > descriptor, const bool initFromDisk)
 
static Status _dropIndex (IndexCatalog *const this_, OperationContext *const opCtx, IndexCatalogEntry *const desc)
 

Private Attributes

int _magic
 
Collection *const _collection
 
const int _maxNumIndexesAllowed
 
IndexCatalogEntryContainer _entries
 
std::vector< BSONObj > _unfinishedIndexes
 
IndexCatalog *const _this
 

Static Private Attributes

static const BSONObj _idObj = BSON("_id" << 1)
 

Member Typedef Documentation

◆ IndexIterator

Constructor & Destructor Documentation

◆ IndexCatalogImpl()

mongo::IndexCatalogImpl::IndexCatalogImpl ( IndexCatalog this_,
Collection collection,
int  maxNumIndexesAllowed 
)
explicit

◆ ~IndexCatalogImpl()

mongo::IndexCatalogImpl::~IndexCatalogImpl ( )
override

Member Function Documentation

◆ _checkMagic()

void mongo::IndexCatalogImpl::_checkMagic ( ) const
private

◆ _deleteIndexFromDisk()

void mongo::IndexCatalogImpl::_deleteIndexFromDisk ( OperationContext *  opCtx,
const std::string &  indexName,
const std::string &  indexNamespace 
)
privatevirtual

◆ _doesSpecConflictWithExisting()

Status mongo::IndexCatalogImpl::_doesSpecConflictWithExisting ( OperationContext *  opCtx,
const BSONObj &  spec 
) const
private

◆ _dropIndex() [1/2]

Status mongo::IndexCatalogImpl::_dropIndex ( OperationContext *  opCtx,
IndexCatalogEntry entry 
)
overrideprivatevirtual

this does no sanity checks

IndexState in order <db>.system.indexes NamespaceDetails <db>.system.ns

Implements mongo::IndexCatalog::Impl.

◆ _dropIndex() [2/2]

static Status mongo::IndexCatalogImpl::_dropIndex ( IndexCatalog *const  this_,
OperationContext *const  opCtx,
IndexCatalogEntry *const  desc 
)
inlinestaticprivate

◆ _fixIndexSpec()

StatusWith< BSONObj > mongo::IndexCatalogImpl::_fixIndexSpec ( OperationContext *  opCtx,
Collection collection,
const BSONObj &  spec 
)
staticprivate

◆ _getAccessMethodName()

string mongo::IndexCatalogImpl::_getAccessMethodName ( OperationContext *  opCtx,
const BSONObj &  keyPattern 
) const
private

This differs from IndexNames::findPluginName in that returns the plugin name we should use, not the plugin name inside of the provided key pattern.

To understand when these differ, see shouldOverridePlugin.

◆ _getCollection() [1/2]

const Collection* mongo::IndexCatalogImpl::_getCollection ( ) const
inlineoverrideprivatevirtual

◆ _getCollection() [2/2]

Collection* mongo::IndexCatalogImpl::_getCollection ( )
inlineoverrideprivatevirtual

◆ _getEntries() [1/2]

const IndexCatalogEntryContainer& mongo::IndexCatalogImpl::_getEntries ( ) const
inlineoverrideprivatevirtual

◆ _getEntries() [2/2]

IndexCatalogEntryContainer& mongo::IndexCatalogImpl::_getEntries ( )
inlineoverrideprivatevirtual

◆ _indexFilteredRecords()

Status mongo::IndexCatalogImpl::_indexFilteredRecords ( OperationContext *  opCtx,
IndexCatalogEntry index,
const std::vector< BsonRecord > &  bsonRecords,
int64_t *  keysInsertedOut 
)
private

◆ _indexRecords()

Status mongo::IndexCatalogImpl::_indexRecords ( OperationContext *  opCtx,
IndexCatalogEntry index,
const std::vector< BsonRecord > &  bsonRecords,
int64_t *  keysInsertedOut 
)
private

◆ _isSpecOk()

Status mongo::IndexCatalogImpl::_isSpecOk ( OperationContext *  opCtx,
const BSONObj &  spec 
) const
private

◆ _setupInMemoryStructures() [1/2]

IndexCatalogEntry * mongo::IndexCatalogImpl::_setupInMemoryStructures ( OperationContext *  opCtx,
std::unique_ptr< IndexDescriptor >  descriptor,
bool  initFromDisk 
)
privatevirtual

◆ _setupInMemoryStructures() [2/2]

static IndexCatalogEntry* mongo::IndexCatalogImpl::_setupInMemoryStructures ( IndexCatalog *const  this_,
OperationContext *const  opCtx,
std::unique_ptr< IndexDescriptor >  descriptor,
const bool  initFromDisk 
)
inlinestaticprivate

◆ _shouldOverridePlugin()

bool mongo::IndexCatalogImpl::_shouldOverridePlugin ( OperationContext *  opCtx,
const BSONObj &  keyPattern 
) const
private

◆ _unindexRecord()

Status mongo::IndexCatalogImpl::_unindexRecord ( OperationContext *  opCtx,
IndexCatalogEntry index,
const BSONObj &  obj,
const RecordId &  loc,
bool  logIfError,
int64_t *  keysDeletedOut 
)
private

◆ _upgradeDatabaseMinorVersionIfNeeded()

Status mongo::IndexCatalogImpl::_upgradeDatabaseMinorVersionIfNeeded ( OperationContext *  opCtx,
const std::string &  newPluginName 
)
overridevirtual

◆ checkUnfinished()

Status mongo::IndexCatalogImpl::checkUnfinished ( ) const
overridevirtual

Returns a not-ok Status if there are any unfinished index builds.

No new indexes should be built when in this state.

Implements mongo::IndexCatalog::Impl.

◆ createIndexOnEmptyCollection()

StatusWith< BSONObj > mongo::IndexCatalogImpl::createIndexOnEmptyCollection ( OperationContext *  opCtx,
BSONObj  spec 
)
overridevirtual

Call this only on an empty collection from inside a WriteUnitOfWork.

Index creation on an empty collection can be rolled back as part of a larger WUOW. Returns the full specification of the created index, as it is stored in this index catalog.

Implements mongo::IndexCatalog::Impl.

◆ dropAllIndexes()

void mongo::IndexCatalogImpl::dropAllIndexes ( OperationContext *  opCtx,
bool  includingIdIndex,
stdx::function< void(const IndexDescriptor *)>  onDropFn = nullptr 
)
overridevirtual

Drops all indexes in the index catalog, optionally dropping the id index depending on the 'includingIdIndex' parameter value.

If the 'droppedIndexes' parameter is not null, it is filled with the names and index info of the dropped indexes.

Implements mongo::IndexCatalog::Impl.

◆ dropIndex()

Status mongo::IndexCatalogImpl::dropIndex ( OperationContext *  opCtx,
IndexDescriptor *  desc 
)
overridevirtual

◆ findIdIndex()

IndexDescriptor * mongo::IndexCatalogImpl::findIdIndex ( OperationContext *  opCtx) const
overridevirtual

◆ findIndexByKeyPatternAndCollationSpec()

IndexDescriptor * mongo::IndexCatalogImpl::findIndexByKeyPatternAndCollationSpec ( OperationContext *  opCtx,
const BSONObj &  key,
const BSONObj &  collationSpec,
bool  includeUnfinishedIndexes = false 
) const
overridevirtual

Find index by matching key pattern and collation spec.

The key pattern and collation spec uniquely identify an index.

Collation is specified as a normalized collation spec as returned by CollationInterface::getSpec. An empty object indicates the simple collation.

Returns
null if cannot find index, otherwise the index with a matching key pattern and collation.

Implements mongo::IndexCatalog::Impl.

◆ findIndexByName()

IndexDescriptor * mongo::IndexCatalogImpl::findIndexByName ( OperationContext *  opCtx,
StringData  name,
bool  includeUnfinishedIndexes = false 
) const
overridevirtual

Find index by name.

The index name uniquely identifies an index.

Returns
null if cannot find

Implements mongo::IndexCatalog::Impl.

◆ findIndexByType()

void mongo::IndexCatalogImpl::findIndexByType ( OperationContext *  opCtx,
const std::string &  type,
std::vector< IndexDescriptor *> &  matches,
bool  includeUnfinishedIndexes = false 
) const
overridevirtual

◆ findIndexesByKeyPattern()

void mongo::IndexCatalogImpl::findIndexesByKeyPattern ( OperationContext *  opCtx,
const BSONObj &  key,
bool  includeUnfinishedIndexes,
std::vector< IndexDescriptor *> *  matches 
) const
overridevirtual

Find indexes with a matching key pattern, putting them into the vector 'matches'.

The key pattern alone does not uniquely identify an index.

Consider using 'findIndexByName' if expecting to match one index.

Implements mongo::IndexCatalog::Impl.

◆ findShardKeyPrefixedIndex()

IndexDescriptor * mongo::IndexCatalogImpl::findShardKeyPrefixedIndex ( OperationContext *  opCtx,
const BSONObj &  shardKey,
bool  requireSingleKey 
) const
overridevirtual

Returns an index suitable for shard key range scans.

This index:

  • must be prefixed by 'shardKey', and
  • must not be a partial index.
  • must have the simple collation.

If the parameter 'requireSingleKey' is true, then this index additionally must not be multi-key.

If no such index exists, returns NULL.

Implements mongo::IndexCatalog::Impl.

◆ fixIndexKey()

BSONObj mongo::IndexCatalogImpl::fixIndexKey ( const BSONObj &  key)
static

◆ getAccessMethodName()

std::string mongo::IndexCatalogImpl::getAccessMethodName ( OperationContext *  opCtx,
const BSONObj &  keyPattern 
)
inlineoverridevirtual

◆ getAndClearUnfinishedIndexes()

vector< BSONObj > mongo::IndexCatalogImpl::getAndClearUnfinishedIndexes ( OperationContext *  opCtx)
overridevirtual

will drop all incompleted indexes and return specs after this, the indexes can be rebuilt

Implements mongo::IndexCatalog::Impl.

◆ getDefaultIdIndexSpec()

BSONObj mongo::IndexCatalogImpl::getDefaultIdIndexSpec ( ) const
overridevirtual

Returns the spec for the id index to create by default for this collection.

Implements mongo::IndexCatalog::Impl.

◆ getEntry()

const IndexCatalogEntry * mongo::IndexCatalogImpl::getEntry ( const IndexDescriptor *  desc) const
overridevirtual

◆ getIndex() [1/2]

IndexAccessMethod * mongo::IndexCatalogImpl::getIndex ( const IndexDescriptor *  desc)
overridevirtual

◆ getIndex() [2/2]

const IndexAccessMethod * mongo::IndexCatalogImpl::getIndex ( const IndexDescriptor *  desc) const
overridevirtual

◆ getMultikeyPaths()

MultikeyPaths mongo::IndexCatalogImpl::getMultikeyPaths ( OperationContext *  opCtx,
const IndexDescriptor *  idx 
)
overridevirtual

Returns the path components that cause the index 'idx' to be multikey if the index supports path-level multikey tracking, and returns an empty vector if path-level multikey tracking isn't supported.

If the index supports path-level multikey tracking but isn't multikey, then this function returns a vector with size equal to the number of elements in the index key pattern where each element in the vector is an empty set.

Implements mongo::IndexCatalog::Impl.

◆ haveAnyIndexes()

bool mongo::IndexCatalogImpl::haveAnyIndexes ( ) const
overridevirtual

◆ haveIdIndex()

bool mongo::IndexCatalogImpl::haveIdIndex ( OperationContext *  opCtx) const
overridevirtual

this is in "alive" until the Collection goes away in which case everything from this tree has to go away.

Implements mongo::IndexCatalog::Impl.

◆ indexRecords()

Status mongo::IndexCatalogImpl::indexRecords ( OperationContext *  opCtx,
const std::vector< BsonRecord > &  bsonRecords,
int64_t *  keysInsertedOut 
)
overridevirtual

When 'keysInsertedOut' is not null, it will be set to the number of index keys inserted by this operation.

This method may throw.

Implements mongo::IndexCatalog::Impl.

◆ init()

Status mongo::IndexCatalogImpl::init ( OperationContext *  opCtx)
overridevirtual

◆ isMultikey()

bool mongo::IndexCatalogImpl::isMultikey ( OperationContext *  opCtx,
const IndexDescriptor *  idx 
)
overridevirtual

Returns true if the index 'idx' is multikey, and returns false otherwise.

Implements mongo::IndexCatalog::Impl.

◆ numIndexesInProgress()

int mongo::IndexCatalogImpl::numIndexesInProgress ( OperationContext *  opCtx) const
inline

◆ numIndexesReady()

int mongo::IndexCatalogImpl::numIndexesReady ( OperationContext *  opCtx) const
overridevirtual

◆ numIndexesTotal()

int mongo::IndexCatalogImpl::numIndexesTotal ( OperationContext *  opCtx) const
overridevirtual

◆ ok()

bool mongo::IndexCatalogImpl::ok ( ) const
overridevirtual

◆ prepareInsertDeleteOptions()

void mongo::IndexCatalogImpl::prepareInsertDeleteOptions ( OperationContext *  opCtx,
const IndexDescriptor *  desc,
InsertDeleteOptions *  options 
)
static

Fills out 'options' in order to indicate whether to allow dups or relax index constraints, as needed by replication.

◆ prepareSpecForCreate()

StatusWith< BSONObj > mongo::IndexCatalogImpl::prepareSpecForCreate ( OperationContext *  opCtx,
const BSONObj &  original 
) const
overridevirtual

◆ refreshEntry()

const IndexDescriptor * mongo::IndexCatalogImpl::refreshEntry ( OperationContext *  opCtx,
const IndexDescriptor *  oldDesc 
)
overridevirtual

Reload the index definition for 'oldDesc' from the CollectionCatalogEntry.

'oldDesc' must be a ready index that is already registered with the index catalog. Returns an unowned pointer to the descriptor for the new index definition.

Use this method to notify the IndexCatalog that the spec for this index has changed.

It is invalid to dereference 'oldDesc' after calling this method. This method broadcasts an invalidateAll() on the cursor manager to notify other users of the IndexCatalog that this descriptor is now invalid.

Implements mongo::IndexCatalog::Impl.

◆ unindexRecord()

void mongo::IndexCatalogImpl::unindexRecord ( OperationContext *  opCtx,
const BSONObj &  obj,
const RecordId &  loc,
bool  noWarn,
int64_t *  keysDeletedOut 
)
overridevirtual

When 'keysDeletedOut' is not null, it will be set to the number of index keys removed by this operation.

Implements mongo::IndexCatalog::Impl.

Member Data Documentation

◆ _collection

Collection* const mongo::IndexCatalogImpl::_collection
private

◆ _entries

IndexCatalogEntryContainer mongo::IndexCatalogImpl::_entries
private

◆ _idObj

const BSONObj mongo::IndexCatalogImpl::_idObj = BSON("_id" << 1)
staticprivate

◆ _magic

int mongo::IndexCatalogImpl::_magic
private

◆ _maxNumIndexesAllowed

const int mongo::IndexCatalogImpl::_maxNumIndexesAllowed
private

◆ _this

IndexCatalog* const mongo::IndexCatalogImpl::_this
private

◆ _unfinishedIndexes

std::vector<BSONObj> mongo::IndexCatalogImpl::_unfinishedIndexes
private

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