35 #include "mongo/base/status.h" 36 #include "mongo/base/status_with.h" 37 #include "mongo/base/string_data.h" 38 #include "mongo/bson/mutable/damage_vector.h" 39 #include "mongo/bson/timestamp.h" 45 #include "mongo/db/cursor_manager.h" 46 #include "mongo/db/exec/collection_scan_common.h" 47 #include "mongo/db/logical_session_id.h" 48 #include "mongo/db/namespace_string.h" 49 #include "mongo/db/op_observer.h" 50 #include "mongo/db/query/collation/collator_interface.h" 51 #include "mongo/db/record_id.h" 52 #include "mongo/db/repl/oplog.h" 56 #include "mongo/stdx/condition_variable.h" 57 #include "mongo/stdx/functional.h" 58 #include "mongo/stdx/mutex.h" 61 class CollectionCatalogEntry;
62 class DatabaseCatalogEntry;
65 class IndexDescriptor;
67 class MatchExpression;
68 class MultiIndexBlock;
70 class OperationContext;
71 struct OplogUpdateEntryArgs;
91 recordSize = static_cast<unsigned>(
paddingFactor * recordSize);
120 void waitUntil(uint64_t prevVersion, Date_t deadline)
const;
170 virtual void init(OperationContext*
opCtx) = 0;
183 const RecordId& loc) = 0;
186 virtual bool ok()
const = 0;
194 virtual const NamespaceString&
ns()
const = 0;
213 virtual std::unique_ptr<SeekableRecordCursor>
getCursor(OperationContext*
opCtx,
214 bool forward)
const = 0;
216 virtual std::vector<std::unique_ptr<RecordCursor>>
getManyCursors(
217 OperationContext*
opCtx)
const = 0;
228 std::vector<InsertStatement>::const_iterator begin,
229 std::vector<InsertStatement>::const_iterator end,
232 bool fromMigrate) = 0;
235 const InsertStatement& doc,
238 bool fromMigrate) = 0;
242 Timestamp* timestamps,
247 const std::vector<MultiIndexBlock*>& indexBlocks,
248 bool enforceQuota) = 0;
251 const RecordId& oldLocation,
253 const BSONObj& newDoc,
255 bool indexesAffected,
257 OplogUpdateEntryArgs* args) = 0;
262 OperationContext*
opCtx,
265 const char* damageSource,
266 const mutablebson::DamageVector& damages,
267 OplogUpdateEntryArgs* args) = 0;
277 std::unique_ptr<Lock::CollectionLock> collLk,
279 BSONObjBuilder* output) = 0;
284 BSONObjBuilder* output)
const = 0;
289 OperationContext*
opCtx,
290 const BSONObj& validator,
291 MatchExpressionParser::AllowedFeatureSet allowedFeatures,
292 boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
293 maxFeatureCompatibilityVersion = boost::none)
const = 0;
304 BSONObj newValidator,
306 StringData newAction) = 0;
314 virtual uint64_t
dataSize(OperationContext*
opCtx)
const = 0;
333 OperationContext*
opCtx,
339 PrivateTo<Collection>)
340 ->std::unique_ptr<Impl>) makeImpl;
358 inline bool ok()
const {
378 inline const NamespaceString&
ns()
const {
423 inline std::unique_ptr<SeekableRecordCursor>
getCursor(OperationContext*
const opCtx,
424 const bool forward =
true)
const {
433 OperationContext*
const opCtx)
const {
452 OpDebug*
const opDebug,
453 const bool fromMigrate =
false,
454 const bool noWarn =
false,
457 opCtx, stmtId, loc, opDebug, fromMigrate, noWarn, storeDeletedDoc);
468 const std::vector<InsertStatement>::const_iterator begin,
469 const std::vector<InsertStatement>::const_iterator end,
470 OpDebug*
const opDebug,
471 const bool enforceQuota,
472 const bool fromMigrate =
false) {
484 const InsertStatement& doc,
485 OpDebug*
const opDebug,
486 const bool enforceQuota,
487 const bool fromMigrate =
false) {
497 Timestamp* timestamps,
498 const size_t nDocs) {
509 const std::vector<MultiIndexBlock*>& indexBlocks,
510 const bool enforceQuota) {
524 const RecordId& oldLocation,
526 const BSONObj& newDoc,
527 const bool enforceQuota,
528 const bool indexesAffected,
529 OpDebug*
const opDebug,
530 OplogUpdateEntryArgs*
const args) {
532 opCtx, oldLocation, oldDoc, newDoc, enforceQuota, indexesAffected, opDebug, args);
547 OperationContext*
const opCtx,
550 const char*
const damageSource,
551 const mutablebson::DamageVector& damages,
552 OplogUpdateEntryArgs*
const args) {
554 opCtx, loc, oldRec, damageSource, damages, args);
581 std::unique_ptr<Lock::CollectionLock> collLk,
583 BSONObjBuilder*
const output) {
584 return this->
_impl().
validate(opCtx, level, background, std::move(collLk), results, output);
591 const bool touchData,
592 const bool touchIndexes,
593 BSONObjBuilder*
const output)
const {
594 return this->
_impl().
touch(opCtx, touchData, touchIndexes, output);
613 OperationContext*
opCtx,
614 const BSONObj& validator,
615 MatchExpressionParser::AllowedFeatureSet allowedFeatures,
616 boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
617 maxFeatureCompatibilityVersion)
const {
619 opCtx, validator, allowedFeatures, maxFeatureCompatibilityVersion);
650 BSONObj newValidator,
652 StringData newAction) {
689 return static_cast<int>(this->
dataSize(opCtx) / n);
693 BSONObjBuilder*
const details =
nullptr,
694 const int scale = 1) {
746 const RecordId& loc)
final {
754 static void hook() noexcept;
virtual Status insertDocument(OperationContext *opCtx, const InsertStatement &doc, OpDebug *opDebug, bool enforceQuota, bool fromMigrate)=0
bool isDead()
Returns true if no new insert notification will occur.
Definition: collection.cpp:127
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
Definition: collection.h:163
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.
Definition: collection.h:483
virtual void notifyCappedWaitersIfNeeded()=0
Used to notify any waiters when new documents may be visible in the capped collection.
Queries with the awaitData option use this notifier object to wait for more data to be inserted into ...
Definition: collection.h:105
virtual uint64_t dataSize(OperationContext *opCtx) const =0
ValidateCmdLevel
Definition: record_store.h:93
StoreDeletedDoc
Definition: collection.h:164
uint64_t getIndexSize(OperationContext *const opCtx, BSONObjBuilder *const details=nullptr, const int scale=1)
Definition: collection.h:692
std::shared_ptr< CappedInsertNotifier > getCappedInsertNotifier() const
Get a pointer to a capped insert notifier object.
Definition: collection.h:672
virtual std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *opCtx, bool forward) const =0
Status setValidationAction(OperationContext *const opCtx, const StringData newAction)
Definition: collection.h:638
virtual CollectionCatalogEntry * details() const =0
virtual StatusWithMatchExpression parseValidator(OperationContext *opCtx, const BSONObj &validator, MatchExpressionParser::AllowedFeatureSet allowedFeatures, boost::optional< ServerGlobalParams::FeatureCompatibility::Version > maxFeatureCompatibilityVersion=boost::none) const =0
virtual bool updateWithDamagesSupported() const =0
Impl & _impl()
Definition: collection.h:767
Definition: snapshot.h:69
void waitUntil(uint64_t prevVersion, Date_t deadline) const
Waits until 'deadline', or until notifyAll() is called to indicate that new data is available in the ...
Definition: collection.cpp:112
virtual StatusWith< CompactStats > compact(OperationContext *opCtx, const CompactOptions *options)=0
Definition: record_store.h:673
std::vector< std::unique_ptr< RecordCursor > > getManyCursors(OperationContext *const opCtx) const
Returns many cursors that partition the Collection into many disjoint sets.
Definition: collection.h:432
bool ok() const
Definition: collection.h:358
Definition: collection.h:79
int paddingBytes
Definition: collection.h:83
uint64_t dataSize(OperationContext *const opCtx) const
Definition: collection.h:680
virtual void cappedTruncateAfter(OperationContext *opCtx, RecordId end, bool inclusive)=0
Definition: collection.h:753
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Status recordStoreGoingToUpdateInPlace(OperationContext *const opCtx, const RecordId &loc) final
Definition: collection.h:745
void setMinimumVisibleSnapshot(const Timestamp name)
Definition: collection.h:706
int averageObjectSize(OperationContext *const opCtx) const
Definition: collection.h:684
Definition: collection_catalog_entry.h:47
Collection(OperationContext *const opCtx, const StringData fullNS, OptionalCollectionUUID uuid, CollectionCatalogEntry *const details, RecordStore *const recordStore, DatabaseCatalogEntry *const dbce)
Definition: collection.h:342
std::string toString() const
Definition: collection.cpp:81
stdx::mutex _mutex
Definition: collection.h:144
StatusWith< RecordData > updateDocumentWithDamages(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.
Definition: collection.h:546
virtual Status insertDocumentsForOplog(OperationContext *opCtx, const DocWriter *const *docs, Timestamp *timestamps, size_t nDocs)=0
virtual Status setValidationAction(OperationContext *opCtx, StringData newAction)=0
CollectionCatalogEntry * details() const
Definition: collection.h:735
Collection *const _this
Definition: collection_impl.cpp:80
virtual const IndexCatalog * getIndexCatalog() const =0
std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *const opCtx, const bool forward=true) const
Definition: collection.h:423
A replacement for the Record class.
Definition: record_data.h:43
virtual Status setValidationLevel(OperationContext *opCtx, StringData newLevel)=0
virtual Status truncate(OperationContext *opCtx)=0
void kill()
Cancels the notifier if the collection is dropped/invalidated, and wakes all waiting.
Definition: collection.cpp:121
friend Collection
Definition: collection.h:173
virtual uint64_t numRecords(OperationContext *opCtx) const =0
Represents a logical database containing Collections.
Definition: database_impl.h:61
CappedInsertNotifier()
Definition: collection.cpp:104
virtual const NamespaceString & ns() const =0
how many: 1 per Collection.
Definition: index_catalog_impl.h:56
virtual std::shared_ptr< CappedInsertNotifier > getCappedInsertNotifier() const =0
Status validate(OperationContext *const opCtx, const ValidateCmdLevel level, bool background, std::unique_ptr< Lock::CollectionLock > collLk, ValidateResults *const results, BSONObjBuilder *const output)
Definition: collection.h:578
virtual RecordId updateDocument(OperationContext *opCtx, const RecordId &oldLocation, const Snapshotted< BSONObj > &oldDoc, const BSONObj &newDoc, bool enforceQuota, bool indexesAffected, OpDebug *opDebug, OplogUpdateEntryArgs *args)=0
IndexCatalog * getIndexCatalog()
Definition: collection.h:389
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)
Definition: collection.h:467
virtual bool haveCappedWaiters()=0
Returns true if there may be waiters.
Definition: collection.h:166
TUHook() noexcept
Definition: collection.h:756
Definition: collection.h:162
Definition: record_store.h:78
virtual StringData getValidationLevel() const =0
long long corruptDocuments
Definition: collection.h:98
virtual CursorManager * getCursorManager() const =0
double paddingFactor
Definition: collection.h:82
virtual DatabaseCatalogEntry * dbce() const =0
Definition: collection.h:162
void cappedTruncateAfter(OperationContext *const opCtx, const RecordId end, const bool inclusive)
Truncate documents newer than the document at 'end' from the capped collection.
Definition: collection.h:603
virtual Status aboutToDeleteCapped(OperationContext *opCtx, const RecordId &loc, RecordData data)=0
This will be called right before loc is deleted when wrapping.
bool inclusive
Definition: btree_interface.cpp:335
DatabaseCatalogEntry * dbce() const
Definition: collection.h:731
StatusWith< CompactStats > compact(OperationContext *const opCtx, const CompactOptions *const options)
Definition: collection.h:559
Definition: collection.h:79
this is NOT safe through a yield right now.
Definition: collection.h:160
OptionalCollectionUUID uuid() const
Definition: collection.h:382
CollectionInfoCache * infoCache()
Definition: collection.h:370
Definition: collection.h:77
Allows inserting a Record "in-place" without creating a copy ahead of time.
Definition: record_store.h:62
ValidationAction
Definition: collection.h:162
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
virtual bool isCapped() const =0
bool updateWithDamagesSupported() const
Definition: collection.h:535
virtual StringData getValidationAction() const =0
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.
Definition: collection.h:495
how many: 1 per Collection.
Definition: index_catalog.h:62
virtual bool ok() const =0
RecordStore * getRecordStore()
Definition: collection.h:396
virtual StatusWith< RecordData > updateDocumentWithDamages(OperationContext *opCtx, const RecordId &loc, const Snapshotted< RecordData > &oldRec, const char *damageSource, const mutablebson::DamageVector &damages, OplogUpdateEntryArgs *args)=0
Collection *const OperationContext *const const StringData OptionalCollectionUUID CollectionCatalogEntry *const RecordStore *const recordStore
Definition: collection_impl.cpp:80
bool validateDocuments
Definition: collection.h:86
OperationContext Database StringData CollectionOptions bool const BSONObj &idIndex Status
Definition: database_impl.cpp:955
boost::optional< CollectionUUID > OptionalCollectionUUID
Definition: collection_options.h:55
static void hook() noexcept
Definition: collection.cpp:79
std::unique_ptr< Impl > _pimpl
Definition: collection.h:772
Definition: collection.h:163
const CollectionInfoCache * infoCache() const
Definition: collection.h:374
boost::optional< Timestamp > getMinimumVisibleSnapshot()
If return value is not boost::none, reads with majority read concern using an older snapshot must err...
Definition: collection.h:702
Definition: collection.h:79
virtual const RecordStore * getRecordStore() const =0
Collection(std::unique_ptr< Impl > mock)
Definition: collection.h:354
Definition: index_key_validate.h:40
virtual Snapshotted< BSONObj > docFor(OperationContext *opCtx, const RecordId &loc) const =0
Snapshotted< BSONObj > docFor(OperationContext *const opCtx, const RecordId &loc) const
Definition: collection.h:408
virtual Status updateValidator(OperationContext *opCtx, BSONObj newValidator, StringData newLevel, StringData newAction)=0
virtual void init(OperationContext *opCtx)=0
virtual Status recordStoreGoingToUpdateInPlace(OperationContext *opCtx, const RecordId &loc)=0
virtual CollectionInfoCache * infoCache()=0
StringData getValidationAction() const
Definition: collection.h:645
Status updateValidator(OperationContext *opCtx, BSONObj newValidator, StringData newLevel, StringData newAction)
Definition: collection.h:649
uint64_t getVersion() const
Returns the version for use as an additional wake condition when used above.
Definition: collection.h:125
virtual std::vector< std::unique_ptr< RecordCursor > > getManyCursors(OperationContext *opCtx) const =0
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.
Definition: collection.h:612
virtual RecordData dataFor(OperationContext *opCtx, const RecordId &loc) const
Get the RecordData at loc, which must exist.
Definition: record_store.h:339
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.
Definition: collection.h:523
An abstraction used for storing documents in a collection or entries in an index.
Definition: record_store.h:282
unsigned computeRecordSize(unsigned recordSize) const
Definition: collection.h:90
When a capped collection is modified (delete/insert/etc) then certain notifications need to be made,...
Definition: capped_callback.h:44
CollectionCatalogEntry * getCatalogEntry()
Definition: collection.h:362
const Impl & _impl() const
Definition: collection.h:762
virtual void deleteDocument(OperationContext *opCtx, StmtId stmtId, const RecordId &loc, OpDebug *opDebug, bool fromMigrate, bool noWarn, StoreDeletedDoc storeDeletedDoc)=0
virtual CollectionCatalogEntry * getCatalogEntry()=0
BSONObj releaseToBson()
Definition: record_data.h:74
const IndexCatalog * getIndexCatalog() const
Definition: collection.h:386
bool requiresIdIndex() const
Definition: collection.h:404
Status touch(OperationContext *const opCtx, const bool touchData, const bool touchIndexes, BSONObjBuilder *const output) const
forces data into cache.
Definition: collection.h:590
virtual void setMinimumVisibleSnapshot(Timestamp name)=0
Definition: database_catalog_entry.h:50
Collection *const OperationContext *const const StringData fullNS
Definition: collection_impl.cpp:80
bool findDoc(OperationContext *const opCtx, const RecordId &loc, Snapshotted< BSONObj > *const out) const
Definition: collection.h:417
stdx::condition_variable _notifier
Definition: collection.h:141
bool haveCappedWaiters()
Returns true if there may be waiters.
Definition: collection.h:710
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.
Definition: collection.h:449
virtual bool requiresIdIndex() const =0
const CollatorInterface * getDefaultCollator() const
Get a pointer to the collection's default collator.
Definition: collection.h:725
virtual Status touch(OperationContext *opCtx, bool touchData, bool touchIndexes, BSONObjBuilder *output) const =0
Status setValidationLevel(OperationContext *const opCtx, const StringData newLevel)
Definition: collection.h:635
Status aboutToDeleteCapped(OperationContext *const opCtx, const RecordId &loc, const RecordData data) final
This will be called right before loc is deleted when wrapping.
Definition: collection.h:739
virtual boost::optional< Timestamp > getMinimumVisibleSnapshot()=0
Definition: collection.h:97
void notifyCappedWaitersIfNeeded()
Notify (capped collection) waiters of data changes, like an insert.
Definition: collection.h:717
void notifyAll()
Wakes up all threads waiting.
Definition: collection.cpp:106
virtual const CollatorInterface * getDefaultCollator() const =0
Status truncate(OperationContext *const opCtx)
removes all documents as fast as possible indexes before and after will be the same as will other cha...
Definition: collection.h:569
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.
Definition: collection.h:507
ValidationLevel
Definition: collection.h:163
Database *const OperationContext *const const StringData name
Definition: database_impl.cpp:82
bool isCapped() const
Definition: collection.h:662
virtual Status setValidator(OperationContext *opCtx, BSONObj validator)=0
const NamespaceString & ns() const
Definition: collection.h:378
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
virtual OptionalCollectionUUID uuid() const =0
const CollectionCatalogEntry * getCatalogEntry() const
Definition: collection.h:366
CursorManager * getCursorManager() const
Definition: collection.h:400
Definition: collection.h:163
const RecordStore * getRecordStore() const
Definition: collection.h:393
this is for storing things that you want to cache about a single collection life cycle is managed for...
Definition: collection_info_cache.h:47
virtual uint64_t getIndexSize(OperationContext *opCtx, BSONObjBuilder *details, int scale)=0
virtual Status insertDocuments(OperationContext *opCtx, std::vector< InsertStatement >::const_iterator begin, std::vector< InsertStatement >::const_iterator end, OpDebug *opDebug, bool enforceQuota, bool fromMigrate)=0
StringData getValidationLevel() const
Definition: collection.h:642
uint64_t numRecords(OperationContext *const opCtx) const
Definition: collection.h:676
virtual Status validate(OperationContext *opCtx, ValidateCmdLevel level, bool background, std::unique_ptr< Lock::CollectionLock > collLk, ValidateResults *results, BSONObjBuilder *output)=0
Status setValidator(OperationContext *const opCtx, const BSONObj validator)
Sets the validator for this collection.
Definition: collection.h:631
enum mongo::CompactOptions::PaddingMode paddingMode
uint64_t _version
Definition: collection.h:150
PaddingMode
Definition: collection.h:79
virtual bool findDoc(OperationContext *opCtx, const RecordId &loc, Snapshotted< BSONObj > *out) const =0
bool _dead
Definition: collection.h:153