Storage Engine API
mongo::Collection Class Referencefinal

this is NOT safe through a yield right now. More...

#include <collection.h>

Inheritance diagram for mongo::Collection:
mongo::CappedCallback mongo::UpdateNotifier

Detailed Description

this is NOT safe through a yield right now.

not sure if it will be, or what yet.

Classes

class  Impl
 
struct  TUHook
 

Public Types

enum  ValidationAction { WARN, ERROR_V }
 
enum  ValidationLevel { OFF, MODERATE, STRICT_V }
 
enum  StoreDeletedDoc { StoreDeletedDoc::Off, StoreDeletedDoc::On }
 

Public Member Functions

 Collection (OperationContext *const opCtx, const StringData fullNS, OptionalCollectionUUID uuid, CollectionCatalogEntry *const details, RecordStore *const recordStore, DatabaseCatalogEntry *const dbce)
 
 Collection (std::unique_ptr< Impl > mock)
 
 ~Collection ()=default
 
bool ok () const
 
CollectionCatalogEntrygetCatalogEntry ()
 
const CollectionCatalogEntrygetCatalogEntry () const
 
CollectionInfoCacheinfoCache ()
 
const CollectionInfoCacheinfoCache () const
 
const NamespaceString & ns () const
 
OptionalCollectionUUID uuid () const
 
void refreshUUID (OperationContext *opCtx)
 
const IndexCataloggetIndexCatalog () const
 
IndexCataloggetIndexCatalog ()
 
const RecordStoregetRecordStore () const
 
RecordStoregetRecordStore ()
 
CursorManager * getCursorManager () const
 
bool requiresIdIndex () const
 
Snapshotted< BSONObj > docFor (OperationContext *const opCtx, const RecordId &loc) const
 
bool findDoc (OperationContext *const opCtx, const RecordId &loc, Snapshotted< BSONObj > *const out) const
 
std::unique_ptr< SeekableRecordCursorgetCursor (OperationContext *const opCtx, const bool forward=true) const
 
std::vector< std::unique_ptr< RecordCursor > > getManyCursors (OperationContext *const opCtx) const
 Returns many cursors that partition the Collection into many disjoint sets. More...
 
void deleteDocument (OperationContext *const opCtx, StmtId stmtId, const RecordId &loc, OpDebug *const opDebug, const bool fromMigrate=false, const bool noWarn=false, StoreDeletedDoc storeDeletedDoc=StoreDeletedDoc::Off)
 Deletes the document with the given RecordId from the collection. More...
 
Status insertDocuments (OperationContext *const opCtx, const std::vector< InsertStatement >::const_iterator begin, const std::vector< InsertStatement >::const_iterator end, OpDebug *const opDebug, const bool enforceQuota, const bool fromMigrate=false)
 
Status insertDocument (OperationContext *const opCtx, const InsertStatement &doc, OpDebug *const opDebug, const bool enforceQuota, const bool fromMigrate=false)
 this does NOT modify the doc before inserting i.e. More...
 
Status insertDocumentsForOplog (OperationContext *const opCtx, const DocWriter *const *const docs, Timestamp *timestamps, const size_t nDocs)
 Callers must ensure no document validation is performed for this collection when calling this method. More...
 
Status insertDocument (OperationContext *const opCtx, const BSONObj &doc, const std::vector< MultiIndexBlock *> &indexBlocks, const bool enforceQuota)
 Inserts a document into the record store and adds it to the MultiIndexBlocks passed in. More...
 
RecordId updateDocument (OperationContext *const opCtx, const RecordId &oldLocation, const Snapshotted< BSONObj > &oldDoc, const BSONObj &newDoc, const bool enforceQuota, const bool indexesAffected, OpDebug *const opDebug, OplogUpdateEntryArgs *const args)
 Updates the document @ oldLocation with newDoc. More...
 
bool updateWithDamagesSupported () const
 
StatusWith< RecordDataupdateDocumentWithDamages (OperationContext *const opCtx, const RecordId &loc, const Snapshotted< RecordData > &oldRec, const char *const damageSource, const mutablebson::DamageVector &damages, OplogUpdateEntryArgs *const args)
 Not allowed to modify indexes. More...
 
StatusWith< CompactStatscompact (OperationContext *const opCtx, const CompactOptions *const options)
 
Status truncate (OperationContext *const opCtx)
 removes all documents as fast as possible indexes before and after will be the same as will other characteristics. More...
 
Status validate (OperationContext *const opCtx, const ValidateCmdLevel level, bool background, std::unique_ptr< Lock::CollectionLock > collLk, ValidateResults *const results, BSONObjBuilder *const output)
 
Status touch (OperationContext *const opCtx, const bool touchData, const bool touchIndexes, BSONObjBuilder *const output) const
 forces data into cache. More...
 
void cappedTruncateAfter (OperationContext *const opCtx, const RecordId end, const bool inclusive)
 Truncate documents newer than the document at 'end' from the capped collection. More...
 
StatusWithMatchExpression parseValidator (OperationContext *opCtx, const BSONObj &validator, MatchExpressionParser::AllowedFeatureSet allowedFeatures, boost::optional< ServerGlobalParams::FeatureCompatibility::Version > maxFeatureCompatibilityVersion) const
 Returns a non-ok Status if validator is not legal for this collection. More...
 
Status setValidator (OperationContext *const opCtx, const BSONObj validator)
 Sets the validator for this collection. More...
 
Status setValidationLevel (OperationContext *const opCtx, const StringData newLevel)
 
Status setValidationAction (OperationContext *const opCtx, const StringData newAction)
 
StringData getValidationLevel () const
 
StringData getValidationAction () const
 
Status updateValidator (OperationContext *opCtx, BSONObj newValidator, StringData newLevel, StringData newAction)
 
bool isCapped () const
 
std::shared_ptr< CappedInsertNotifiergetCappedInsertNotifier () const
 Get a pointer to a capped insert notifier object. More...
 
uint64_t numRecords (OperationContext *const opCtx) const
 
uint64_t dataSize (OperationContext *const opCtx) const
 
int averageObjectSize (OperationContext *const opCtx) const
 
uint64_t getIndexSize (OperationContext *const opCtx, BSONObjBuilder *const details=nullptr, const int scale=1)
 
boost::optional< Timestamp > getMinimumVisibleSnapshot ()
 If return value is not boost::none, reads with majority read concern using an older snapshot must error. More...
 
void setMinimumVisibleSnapshot (const Timestamp name)
 
bool haveCappedWaiters ()
 Returns true if there may be waiters. More...
 
void notifyCappedWaitersIfNeeded ()
 Notify (capped collection) waiters of data changes, like an insert. More...
 
const CollatorInterface * getDefaultCollator () const
 Get a pointer to the collection's default collator. More...
 

Static Public Member Functions

static MONGO_DECLARE_SHIM ((Collection *_this, OperationContext *opCtx, StringData fullNS, OptionalCollectionUUID uuid, CollectionCatalogEntry *details, RecordStore *recordStore, DatabaseCatalogEntry *dbce, PrivateTo< Collection >) ->std::unique_ptr< Impl >) makeImpl
 
static MONGO_DECLARE_SHIM ((StringData) ->StatusWith< ValidationLevel >) parseValidationLevel
 
static MONGO_DECLARE_SHIM ((StringData) ->StatusWith< ValidationAction >) parseValidationAction
 

Private Member Functions

DatabaseCatalogEntrydbce () const
 
CollectionCatalogEntrydetails () const
 
Status aboutToDeleteCapped (OperationContext *const opCtx, const RecordId &loc, const RecordData data) final
 This will be called right before loc is deleted when wrapping. More...
 
Status recordStoreGoingToUpdateInPlace (OperationContext *const opCtx, const RecordId &loc) final
 
const Impl_impl () const
 
Impl_impl ()
 
- Private Member Functions inherited from mongo::CappedCallback
virtual ~CappedCallback ()
 
- Private Member Functions inherited from mongo::UpdateNotifier
virtual ~UpdateNotifier ()
 

Private Attributes

std::unique_ptr< Impl_pimpl
 

Friends

class DatabaseImpl
 
class IndexCatalogImpl
 

Member Enumeration Documentation

◆ StoreDeletedDoc

Enumerator
Off 
On 

◆ ValidationAction

Enumerator
WARN 
ERROR_V 

◆ ValidationLevel

Enumerator
OFF 
MODERATE 
STRICT_V 

Constructor & Destructor Documentation

◆ Collection() [1/2]

mongo::Collection::Collection ( OperationContext *const  opCtx,
const StringData  fullNS,
OptionalCollectionUUID  uuid,
CollectionCatalogEntry *const  details,
RecordStore *const  recordStore,
DatabaseCatalogEntry *const  dbce 
)
inlineexplicit

◆ Collection() [2/2]

mongo::Collection::Collection ( std::unique_ptr< Impl mock)
inlineexplicit

◆ ~Collection()

mongo::Collection::~Collection ( )
inlinedefault

Member Function Documentation

◆ _impl() [1/2]

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

◆ _impl() [2/2]

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

◆ aboutToDeleteCapped()

Status mongo::Collection::aboutToDeleteCapped ( OperationContext *const  opCtx,
const RecordId &  loc,
const RecordData  data 
)
inlinefinalprivatevirtual

This will be called right before loc is deleted when wrapping.

If data is unowned, it is only valid inside of this call. If implementations wish to stash a pointer, they must copy it.

Implements mongo::CappedCallback.

◆ averageObjectSize()

int mongo::Collection::averageObjectSize ( OperationContext *const  opCtx) const
inline

◆ cappedTruncateAfter()

void mongo::Collection::cappedTruncateAfter ( OperationContext *const  opCtx,
const RecordId  end,
const bool  inclusive 
)
inline

Truncate documents newer than the document at 'end' from the capped collection.

The collection cannot be completely emptied using this function. An assertion will be thrown if that is attempted.

Parameters
inclusive- Truncate 'end' as well iff true

◆ compact()

StatusWith<CompactStats> mongo::Collection::compact ( OperationContext *const  opCtx,
const CompactOptions *const  options 
)
inline

◆ dataSize()

uint64_t mongo::Collection::dataSize ( OperationContext *const  opCtx) const
inline

◆ dbce()

DatabaseCatalogEntry* mongo::Collection::dbce ( ) const
inlineprivate

◆ deleteDocument()

void mongo::Collection::deleteDocument ( OperationContext *const  opCtx,
StmtId  stmtId,
const RecordId &  loc,
OpDebug *const  opDebug,
const bool  fromMigrate = false,
const bool  noWarn = false,
StoreDeletedDoc  storeDeletedDoc = StoreDeletedDoc::Off 
)
inline

Deletes the document with the given RecordId from the collection.

'fromMigrate' indicates whether the delete was induced by a chunk migration, and so should be ignored by the user as an internal maintenance operation and not a real delete. 'loc' key to uniquely identify a record in a collection. 'opDebug' Optional argument. When not null, will be used to record operation statistics. 'cappedOK' if true, allows deletes on capped collections (Cloner::copyDB uses this). 'noWarn' if unindexing the record causes an error, if noWarn is true the error will not be logged.

◆ details()

CollectionCatalogEntry* mongo::Collection::details ( ) const
inlineprivate

◆ docFor()

Snapshotted<BSONObj> mongo::Collection::docFor ( OperationContext *const  opCtx,
const RecordId &  loc 
) const
inline

◆ findDoc()

bool mongo::Collection::findDoc ( OperationContext *const  opCtx,
const RecordId &  loc,
Snapshotted< BSONObj > *const  out 
) const
inline
Parameters
out- contents set to the right docs if exists, or nothing.
Returns
true iff loc exists

◆ getCappedInsertNotifier()

std::shared_ptr<CappedInsertNotifier> mongo::Collection::getCappedInsertNotifier ( ) const
inline

Get a pointer to a capped insert notifier object.

The caller can wait on this object until it is notified of a new insert into the capped collection.

It is invalid to call this method unless the collection is capped.

◆ getCatalogEntry() [1/2]

CollectionCatalogEntry* mongo::Collection::getCatalogEntry ( )
inline

◆ getCatalogEntry() [2/2]

const CollectionCatalogEntry* mongo::Collection::getCatalogEntry ( ) const
inline

◆ getCursor()

std::unique_ptr<SeekableRecordCursor> mongo::Collection::getCursor ( OperationContext *const  opCtx,
const bool  forward = true 
) const
inline

◆ getCursorManager()

CursorManager* mongo::Collection::getCursorManager ( ) const
inline

◆ getDefaultCollator()

const CollatorInterface* mongo::Collection::getDefaultCollator ( ) const
inline

Get a pointer to the collection's default collator.

The pointer must not be used after this Collection is destroyed.

◆ getIndexCatalog() [1/2]

const IndexCatalog* mongo::Collection::getIndexCatalog ( ) const
inline

◆ getIndexCatalog() [2/2]

IndexCatalog* mongo::Collection::getIndexCatalog ( )
inline

◆ getIndexSize()

uint64_t mongo::Collection::getIndexSize ( OperationContext *const  opCtx,
BSONObjBuilder *const  details = nullptr,
const int  scale = 1 
)
inline

◆ getManyCursors()

std::vector<std::unique_ptr<RecordCursor> > mongo::Collection::getManyCursors ( OperationContext *const  opCtx) const
inline

Returns many cursors that partition the Collection into many disjoint sets.

Iterating all returned cursors is equivalent to iterating the full collection.

◆ getMinimumVisibleSnapshot()

boost::optional<Timestamp> mongo::Collection::getMinimumVisibleSnapshot ( )
inline

If return value is not boost::none, reads with majority read concern using an older snapshot must error.

◆ getRecordStore() [1/2]

const RecordStore* mongo::Collection::getRecordStore ( ) const
inline

◆ getRecordStore() [2/2]

RecordStore* mongo::Collection::getRecordStore ( )
inline

◆ getValidationAction()

StringData mongo::Collection::getValidationAction ( ) const
inline

◆ getValidationLevel()

StringData mongo::Collection::getValidationLevel ( ) const
inline

◆ haveCappedWaiters()

bool mongo::Collection::haveCappedWaiters ( )
inlinevirtual

Returns true if there may be waiters.

Implements mongo::CappedCallback.

◆ infoCache() [1/2]

CollectionInfoCache* mongo::Collection::infoCache ( )
inline

◆ infoCache() [2/2]

const CollectionInfoCache* mongo::Collection::infoCache ( ) const
inline

◆ insertDocument() [1/2]

Status mongo::Collection::insertDocument ( OperationContext *const  opCtx,
const InsertStatement &  doc,
OpDebug *const  opDebug,
const bool  enforceQuota,
const bool  fromMigrate = false 
)
inline

this does NOT modify the doc before inserting i.e.

will not add an _id field for documents that are missing it

'opDebug' Optional argument. When not null, will be used to record operation statistics. 'enforceQuota' If false, quotas will be ignored.

◆ insertDocument() [2/2]

Status mongo::Collection::insertDocument ( OperationContext *const  opCtx,
const BSONObj &  doc,
const std::vector< MultiIndexBlock *> &  indexBlocks,
const bool  enforceQuota 
)
inline

Inserts a document into the record store and adds it to the MultiIndexBlocks passed in.

NOTE: It is up to caller to commit the indexes.

◆ insertDocuments()

Status mongo::Collection::insertDocuments ( OperationContext *const  opCtx,
const std::vector< InsertStatement >::const_iterator  begin,
const std::vector< InsertStatement >::const_iterator  end,
OpDebug *const  opDebug,
const bool  enforceQuota,
const bool  fromMigrate = false 
)
inline

◆ insertDocumentsForOplog()

Status mongo::Collection::insertDocumentsForOplog ( OperationContext *const  opCtx,
const DocWriter *const *const  docs,
Timestamp *  timestamps,
const size_t  nDocs 
)
inline

Callers must ensure no document validation is performed for this collection when calling this method.

◆ isCapped()

bool mongo::Collection::isCapped ( ) const
inline

◆ MONGO_DECLARE_SHIM() [1/3]

static mongo::Collection::MONGO_DECLARE_SHIM ( (Collection *_this, OperationContext *opCtx, StringData fullNS, OptionalCollectionUUID uuid, CollectionCatalogEntry *details, RecordStore *recordStore, DatabaseCatalogEntry *dbce, PrivateTo< Collection >) ->std::unique_ptr< Impl )
static

◆ MONGO_DECLARE_SHIM() [2/3]

static mongo::Collection::MONGO_DECLARE_SHIM ( (StringData) ->StatusWith< ValidationLevel )
static

◆ MONGO_DECLARE_SHIM() [3/3]

static mongo::Collection::MONGO_DECLARE_SHIM ( (StringData) ->StatusWith< ValidationAction )
static

◆ notifyCappedWaitersIfNeeded()

void mongo::Collection::notifyCappedWaitersIfNeeded ( )
inlinevirtual

Notify (capped collection) waiters of data changes, like an insert.

Implements mongo::CappedCallback.

◆ ns()

const NamespaceString& mongo::Collection::ns ( ) const
inline

◆ numRecords()

uint64_t mongo::Collection::numRecords ( OperationContext *const  opCtx) const
inline

◆ ok()

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

◆ parseValidator()

StatusWithMatchExpression mongo::Collection::parseValidator ( OperationContext *  opCtx,
const BSONObj &  validator,
MatchExpressionParser::AllowedFeatureSet  allowedFeatures,
boost::optional< ServerGlobalParams::FeatureCompatibility::Version >  maxFeatureCompatibilityVersion 
) const
inline

Returns a non-ok Status if validator is not legal for this collection.

◆ recordStoreGoingToUpdateInPlace()

Status mongo::Collection::recordStoreGoingToUpdateInPlace ( OperationContext *const  opCtx,
const RecordId &  loc 
)
inlinefinalprivatevirtual

Implements mongo::UpdateNotifier.

◆ refreshUUID()

void mongo::Collection::refreshUUID ( OperationContext *  opCtx)
inline

◆ requiresIdIndex()

bool mongo::Collection::requiresIdIndex ( ) const
inline

◆ setMinimumVisibleSnapshot()

void mongo::Collection::setMinimumVisibleSnapshot ( const Timestamp  name)
inline

◆ setValidationAction()

Status mongo::Collection::setValidationAction ( OperationContext *const  opCtx,
const StringData  newAction 
)
inline

◆ setValidationLevel()

Status mongo::Collection::setValidationLevel ( OperationContext *const  opCtx,
const StringData  newLevel 
)
inline

◆ setValidator()

Status mongo::Collection::setValidator ( OperationContext *const  opCtx,
const BSONObj  validator 
)
inline

Sets the validator for this collection.

An empty validator removes all validation. Requires an exclusive lock on the collection.

◆ touch()

Status mongo::Collection::touch ( OperationContext *const  opCtx,
const bool  touchData,
const bool  touchIndexes,
BSONObjBuilder *const  output 
) const
inline

forces data into cache.

◆ truncate()

Status mongo::Collection::truncate ( OperationContext *const  opCtx)
inline

removes all documents as fast as possible indexes before and after will be the same as will other characteristics.

◆ updateDocument()

RecordId mongo::Collection::updateDocument ( OperationContext *const  opCtx,
const RecordId &  oldLocation,
const Snapshotted< BSONObj > &  oldDoc,
const BSONObj &  newDoc,
const bool  enforceQuota,
const bool  indexesAffected,
OpDebug *const  opDebug,
OplogUpdateEntryArgs *const  args 
)
inline

Updates the document @ oldLocation with newDoc.

If the document fits in the old space, it is put there; if not, it is moved. Sets 'args.updatedDoc' to the updated version of the document with damages applied, on success. 'opDebug' Optional argument. When not null, will be used to record operation statistics.

Returns
the post update location of the doc (may or may not be the same as oldLocation)

◆ updateDocumentWithDamages()

StatusWith<RecordData> mongo::Collection::updateDocumentWithDamages ( OperationContext *const  opCtx,
const RecordId &  loc,
const Snapshotted< RecordData > &  oldRec,
const char *const  damageSource,
const mutablebson::DamageVector &  damages,
OplogUpdateEntryArgs *const  args 
)
inline

Not allowed to modify indexes.

Illegal to call if updateWithDamagesSupported() returns false. Sets 'args.updatedDoc' to the updated version of the document with damages applied, on success.

Returns
the contents of the updated record.

◆ updateValidator()

Status mongo::Collection::updateValidator ( OperationContext *  opCtx,
BSONObj  newValidator,
StringData  newLevel,
StringData  newAction 
)
inline

◆ updateWithDamagesSupported()

bool mongo::Collection::updateWithDamagesSupported ( ) const
inline

◆ uuid()

OptionalCollectionUUID mongo::Collection::uuid ( ) const
inline

◆ validate()

Status mongo::Collection::validate ( OperationContext *const  opCtx,
const ValidateCmdLevel  level,
bool  background,
std::unique_ptr< Lock::CollectionLock collLk,
ValidateResults *const  results,
BSONObjBuilder *const  output 
)
inline
Returns
OK if the validate run successfully OK will be returned even if corruption is found deatils will be in result.

Friends And Related Function Documentation

◆ DatabaseImpl

friend class DatabaseImpl
friend

◆ IndexCatalogImpl

friend class IndexCatalogImpl
friend

Member Data Documentation

◆ _pimpl

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

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