Storage Engine API
mongo::IndexCatalog Class Reference

how many: 1 per Collection. More...

#include <index_catalog.h>

Detailed Description

how many: 1 per Collection.

lifecycle: attached to a Collection.

Classes

class  Impl
 
class  IndexIterator
 
struct  TUHook
 

Public Member Functions

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

Static Public Member Functions

static MONGO_DECLARE_SHIM ((IndexCatalog *this_, Collection *collection, int maxNumIndexesAllowed, PrivateTo< IndexCatalog >) ->std::unique_ptr< Impl >) makeImpl
 
static MONGO_DECLARE_SHIM ((const BSONObj &key) ->BSONObj) fixIndexKey
 
static MONGO_DECLARE_SHIM ((OperationContext *opCtx, const IndexDescriptor *desc, InsertDeleteOptions *options) ->void) prepareInsertDeleteOptions
 Fills out 'options' in order to indicate whether to allow dups or relax index constraints, as needed by replication. More...
 

Private Member Functions

const Collection_getCollection () const
 
Collection_getCollection ()
 
IndexCatalogEntry_setupInMemoryStructures (OperationContext *opCtx, std::unique_ptr< IndexDescriptor > descriptor, bool initFromDisk)
 
Status _dropIndex (OperationContext *const opCtx, IndexCatalogEntry *const desc)
 
Status _upgradeDatabaseMinorVersionIfNeeded (OperationContext *const opCtx, const std::string &newPluginName)
 
const IndexCatalogEntryContainer_getEntries () const
 
IndexCatalogEntryContainer_getEntries ()
 
void _deleteIndexFromDisk (OperationContext *const opCtx, const std::string &indexName, const std::string &indexNamespace)
 
const Impl_impl () const
 
Impl_impl ()
 

Static Private Member Functions

static IndexCatalogEntryContainer_getEntries (IndexCatalog *const this_)
 
static const IndexCatalogEntryContainer_getEntries (const IndexCatalog *const this_)
 
static void _deleteIndexFromDisk (IndexCatalog *const this_, OperationContext *const opCtx, const std::string &indexName, const std::string &indexNamespace)
 

Private Attributes

std::unique_ptr< Impl_pimpl
 
friend IndexCatalogEntry
 

Friends

class IndexCatalogImpl
 
class MultiIndexBlockImpl
 

Constructor & Destructor Documentation

◆ ~IndexCatalog()

mongo::IndexCatalog::~IndexCatalog ( )
inlinedefault

◆ IndexCatalog() [1/2]

mongo::IndexCatalog::IndexCatalog ( Collection *const  collection,
const int  maxNumIndexesAllowed 
)
inlineexplicit

◆ IndexCatalog() [2/2]

mongo::IndexCatalog::IndexCatalog ( IndexCatalog &&  )
inlinedelete

Member Function Documentation

◆ _deleteIndexFromDisk() [1/2]

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

◆ _deleteIndexFromDisk() [2/2]

static void mongo::IndexCatalog::_deleteIndexFromDisk ( IndexCatalog *const  this_,
OperationContext *const  opCtx,
const std::string &  indexName,
const std::string &  indexNamespace 
)
inlinestaticprivate

◆ _dropIndex()

Status mongo::IndexCatalog::_dropIndex ( OperationContext *const  opCtx,
IndexCatalogEntry *const  desc 
)
inlineprivate

◆ _getCollection() [1/2]

const Collection* mongo::IndexCatalog::_getCollection ( ) const
inlineprivate

◆ _getCollection() [2/2]

Collection* mongo::IndexCatalog::_getCollection ( )
inlineprivate

◆ _getEntries() [1/4]

const IndexCatalogEntryContainer& mongo::IndexCatalog::_getEntries ( ) const
inlineprivate

◆ _getEntries() [2/4]

IndexCatalogEntryContainer& mongo::IndexCatalog::_getEntries ( )
inlineprivate

◆ _getEntries() [3/4]

static IndexCatalogEntryContainer& mongo::IndexCatalog::_getEntries ( IndexCatalog *const  this_)
inlinestaticprivate

◆ _getEntries() [4/4]

static const IndexCatalogEntryContainer& mongo::IndexCatalog::_getEntries ( const IndexCatalog *const  this_)
inlinestaticprivate

◆ _impl() [1/2]

const Impl& mongo::IndexCatalog::_impl ( ) const
inlineprivate

◆ _impl() [2/2]

Impl& mongo::IndexCatalog::_impl ( )
inlineprivate

◆ _setupInMemoryStructures()

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

◆ _upgradeDatabaseMinorVersionIfNeeded()

Status mongo::IndexCatalog::_upgradeDatabaseMinorVersionIfNeeded ( OperationContext *const  opCtx,
const std::string &  newPluginName 
)
inlineprivate

◆ checkUnfinished()

Status mongo::IndexCatalog::checkUnfinished ( ) const
inline

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

No new indexes should be built when in this state.

◆ createIndexOnEmptyCollection()

StatusWith<BSONObj> mongo::IndexCatalog::createIndexOnEmptyCollection ( OperationContext *const  opCtx,
const BSONObj  spec 
)
inline

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.

◆ dropAllIndexes()

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

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

If 'onDropFn' is provided, it will be called before each index is dropped to allow timestamping each individual drop.

◆ dropIndex()

Status mongo::IndexCatalog::dropIndex ( OperationContext *const  opCtx,
IndexDescriptor *const  desc 
)
inline

◆ findIdIndex()

IndexDescriptor* mongo::IndexCatalog::findIdIndex ( OperationContext *const  opCtx) const
inline

◆ findIndexByKeyPatternAndCollationSpec()

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

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.

◆ findIndexByName()

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

Find index by name.

The index name uniquely identifies an index.

Returns
null if cannot find

◆ findIndexByType()

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

◆ findIndexesByKeyPattern()

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

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.

◆ findShardKeyPrefixedIndex()

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

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.

◆ getAccessMethodName()

std::string mongo::IndexCatalog::getAccessMethodName ( OperationContext *const  opCtx,
const BSONObj &  keyPattern 
)
inline

◆ getAndClearUnfinishedIndexes()

std::vector<BSONObj> mongo::IndexCatalog::getAndClearUnfinishedIndexes ( OperationContext *const  opCtx)
inline

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

◆ getDefaultIdIndexSpec()

BSONObj mongo::IndexCatalog::getDefaultIdIndexSpec ( ) const
inline

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

◆ getEntry()

const IndexCatalogEntry* mongo::IndexCatalog::getEntry ( const IndexDescriptor *const  desc) const
inline

◆ getIndex() [1/2]

IndexAccessMethod* mongo::IndexCatalog::getIndex ( const IndexDescriptor *const  desc)
inline

◆ getIndex() [2/2]

const IndexAccessMethod* mongo::IndexCatalog::getIndex ( const IndexDescriptor *const  desc) const
inline

◆ getIndexIterator()

IndexIterator mongo::IndexCatalog::getIndexIterator ( OperationContext *const  opCtx,
const bool  includeUnfinishedIndexes 
) const
inline

◆ getLongestIndexNameLength()

std::string::size_type mongo::IndexCatalog::getLongestIndexNameLength ( OperationContext *  opCtx) const

Returns length of longest index name.

This includes unfinished indexes.

◆ getMultikeyPaths()

MultikeyPaths mongo::IndexCatalog::getMultikeyPaths ( OperationContext *const  opCtx,
const IndexDescriptor *const  idx 
)
inline

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.

◆ haveAnyIndexes()

bool mongo::IndexCatalog::haveAnyIndexes ( ) const
inline

◆ haveIdIndex()

bool mongo::IndexCatalog::haveIdIndex ( OperationContext *const  opCtx) const
inline

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

◆ indexRecords()

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

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

This method may throw.

◆ init()

Status mongo::IndexCatalog::init ( OperationContext *const  opCtx)
inline

◆ isMultikey()

bool mongo::IndexCatalog::isMultikey ( OperationContext *const  opCtx,
const IndexDescriptor *const  idx 
)
inline

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

◆ MONGO_DECLARE_SHIM() [1/3]

static mongo::IndexCatalog::MONGO_DECLARE_SHIM ( (IndexCatalog *this_, Collection *collection, int maxNumIndexesAllowed, PrivateTo< IndexCatalog >) ->std::unique_ptr< Impl )
static

◆ MONGO_DECLARE_SHIM() [2/3]

static mongo::IndexCatalog::MONGO_DECLARE_SHIM ( (const BSONObj &key) ->  BSONObj)
static

◆ MONGO_DECLARE_SHIM() [3/3]

static mongo::IndexCatalog::MONGO_DECLARE_SHIM ( (OperationContext *opCtx, const IndexDescriptor *desc, InsertDeleteOptions *options) ->  void)
static

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

◆ numIndexesInProgress()

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

◆ numIndexesReady()

int mongo::IndexCatalog::numIndexesReady ( OperationContext *const  opCtx) const
inline

◆ numIndexesTotal()

int mongo::IndexCatalog::numIndexesTotal ( OperationContext *const  opCtx) const
inline

◆ ok()

bool mongo::IndexCatalog::ok ( ) const
inline

◆ operator=()

IndexCatalog& mongo::IndexCatalog::operator= ( IndexCatalog &&  )
inlinedelete

◆ prepareSpecForCreate()

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

◆ refreshEntry()

const IndexDescriptor* mongo::IndexCatalog::refreshEntry ( OperationContext *const  opCtx,
const IndexDescriptor *const  oldDesc 
)
inline

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.

◆ unindexRecord()

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

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

Friends And Related Function Documentation

◆ IndexCatalogImpl

friend class IndexCatalogImpl
friend

◆ MultiIndexBlockImpl

friend class MultiIndexBlockImpl
friend

Member Data Documentation

◆ _pimpl

std::unique_ptr<Impl> mongo::IndexCatalog::_pimpl
private

◆ IndexCatalogEntry

friend mongo::IndexCatalog::IndexCatalogEntry
private

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