Storage Engine API
collection.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <cstdint>
32 #include <memory>
33 #include <string>
34 
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"
59 
60 namespace mongo {
61 class CollectionCatalogEntry;
62 class DatabaseCatalogEntry;
63 class ExtentManager;
64 class IndexCatalog;
65 class IndexDescriptor;
66 class DatabaseImpl;
67 class MatchExpression;
68 class MultiIndexBlock;
69 class OpDebug;
70 class OperationContext;
71 struct OplogUpdateEntryArgs;
72 class RecordCursor;
73 class RecordFetcher;
74 class UpdateDriver;
75 class UpdateRequest;
76 
78  // padding
80 
81  // only used if _paddingMode == MANUAL
82  double paddingFactor = 1; // what to multiple document size by
83  int paddingBytes = 0; // what to add to ducment size after multiplication
84 
85  // other
86  bool validateDocuments = true;
87 
88  std::string toString() const;
89 
90  unsigned computeRecordSize(unsigned recordSize) const {
91  recordSize = static_cast<unsigned>(paddingFactor * recordSize);
92  recordSize += paddingBytes;
93  return recordSize;
94  }
95 };
96 
97 struct CompactStats {
98  long long corruptDocuments = 0;
99 };
100 
106 public:
108 
112  void notifyAll();
113 
120  void waitUntil(uint64_t prevVersion, Date_t deadline) const;
121 
125  uint64_t getVersion() const {
126  return _version;
127  }
128 
132  void kill();
133 
137  bool isDead();
138 
139 private:
140  // Signalled when a successful insert is made into a capped collection.
141  mutable stdx::condition_variable _notifier;
142 
143  // Mutex used with '_notifier'. Protects access to '_version'.
144  mutable stdx::mutex _mutex;
145 
146  // A counter, incremented on insertion of new data into the capped collection.
147  //
148  // The condition which '_cappedNewDataNotifier' is being notified of is an increment of this
149  // counter. Access to this counter is synchronized with '_mutex'.
150  uint64_t _version;
151 
152  // True once the notifier is dead.
153  bool _dead;
154 };
155 
161 public:
164  enum class StoreDeletedDoc { Off, On };
165 
166  class Impl : virtual CappedCallback, virtual UpdateNotifier {
167  public:
168  virtual ~Impl() = 0;
169 
170  virtual void init(OperationContext* opCtx) = 0;
171 
172  private:
173  friend Collection;
174  virtual DatabaseCatalogEntry* dbce() const = 0;
175 
176  virtual CollectionCatalogEntry* details() const = 0;
177 
178  virtual Status aboutToDeleteCapped(OperationContext* opCtx,
179  const RecordId& loc,
180  RecordData data) = 0;
181 
182  virtual Status recordStoreGoingToUpdateInPlace(OperationContext* opCtx,
183  const RecordId& loc) = 0;
184 
185  public:
186  virtual bool ok() const = 0;
187 
189  virtual const CollectionCatalogEntry* getCatalogEntry() const = 0;
190 
191  virtual CollectionInfoCache* infoCache() = 0;
192  virtual const CollectionInfoCache* infoCache() const = 0;
193 
194  virtual const NamespaceString& ns() const = 0;
195  virtual OptionalCollectionUUID uuid() const = 0;
196 
197  virtual const IndexCatalog* getIndexCatalog() const = 0;
198  virtual IndexCatalog* getIndexCatalog() = 0;
199 
200  virtual const RecordStore* getRecordStore() const = 0;
201  virtual RecordStore* getRecordStore() = 0;
202 
203  virtual CursorManager* getCursorManager() const = 0;
204 
205  virtual bool requiresIdIndex() const = 0;
206 
207  virtual Snapshotted<BSONObj> docFor(OperationContext* opCtx, const RecordId& loc) const = 0;
208 
209  virtual bool findDoc(OperationContext* opCtx,
210  const RecordId& loc,
211  Snapshotted<BSONObj>* out) const = 0;
212 
213  virtual std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
214  bool forward) const = 0;
215 
216  virtual std::vector<std::unique_ptr<RecordCursor>> getManyCursors(
217  OperationContext* opCtx) const = 0;
218 
219  virtual void deleteDocument(OperationContext* opCtx,
220  StmtId stmtId,
221  const RecordId& loc,
222  OpDebug* opDebug,
223  bool fromMigrate,
224  bool noWarn,
225  StoreDeletedDoc storeDeletedDoc) = 0;
226 
227  virtual Status insertDocuments(OperationContext* opCtx,
228  std::vector<InsertStatement>::const_iterator begin,
229  std::vector<InsertStatement>::const_iterator end,
230  OpDebug* opDebug,
231  bool enforceQuota,
232  bool fromMigrate) = 0;
233 
234  virtual Status insertDocument(OperationContext* opCtx,
235  const InsertStatement& doc,
236  OpDebug* opDebug,
237  bool enforceQuota,
238  bool fromMigrate) = 0;
239 
240  virtual Status insertDocumentsForOplog(OperationContext* opCtx,
241  const DocWriter* const* docs,
242  Timestamp* timestamps,
243  size_t nDocs) = 0;
244 
245  virtual Status insertDocument(OperationContext* opCtx,
246  const BSONObj& doc,
247  const std::vector<MultiIndexBlock*>& indexBlocks,
248  bool enforceQuota) = 0;
249 
250  virtual RecordId updateDocument(OperationContext* opCtx,
251  const RecordId& oldLocation,
252  const Snapshotted<BSONObj>& oldDoc,
253  const BSONObj& newDoc,
254  bool enforceQuota,
255  bool indexesAffected,
256  OpDebug* opDebug,
257  OplogUpdateEntryArgs* args) = 0;
258 
259  virtual bool updateWithDamagesSupported() const = 0;
260 
262  OperationContext* opCtx,
263  const RecordId& loc,
264  const Snapshotted<RecordData>& oldRec,
265  const char* damageSource,
266  const mutablebson::DamageVector& damages,
267  OplogUpdateEntryArgs* args) = 0;
268 
269  virtual StatusWith<CompactStats> compact(OperationContext* opCtx,
270  const CompactOptions* options) = 0;
271 
272  virtual Status truncate(OperationContext* opCtx) = 0;
273 
274  virtual Status validate(OperationContext* opCtx,
275  ValidateCmdLevel level,
276  bool background,
277  std::unique_ptr<Lock::CollectionLock> collLk,
278  ValidateResults* results,
279  BSONObjBuilder* output) = 0;
280 
281  virtual Status touch(OperationContext* opCtx,
282  bool touchData,
283  bool touchIndexes,
284  BSONObjBuilder* output) const = 0;
285 
286  virtual void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive) = 0;
287 
288  virtual StatusWithMatchExpression parseValidator(
289  OperationContext* opCtx,
290  const BSONObj& validator,
291  MatchExpressionParser::AllowedFeatureSet allowedFeatures,
292  boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
293  maxFeatureCompatibilityVersion = boost::none) const = 0;
294 
295  virtual Status setValidator(OperationContext* opCtx, BSONObj validator) = 0;
296 
297  virtual Status setValidationLevel(OperationContext* opCtx, StringData newLevel) = 0;
298  virtual Status setValidationAction(OperationContext* opCtx, StringData newAction) = 0;
299 
300  virtual StringData getValidationLevel() const = 0;
301  virtual StringData getValidationAction() const = 0;
302 
303  virtual Status updateValidator(OperationContext* opCtx,
304  BSONObj newValidator,
305  StringData newLevel,
306  StringData newAction) = 0;
307 
308  virtual bool isCapped() const = 0;
309 
310  virtual std::shared_ptr<CappedInsertNotifier> getCappedInsertNotifier() const = 0;
311 
312  virtual uint64_t numRecords(OperationContext* opCtx) const = 0;
313 
314  virtual uint64_t dataSize(OperationContext* opCtx) const = 0;
315 
316  virtual uint64_t getIndexSize(OperationContext* opCtx,
317  BSONObjBuilder* details,
318  int scale) = 0;
319 
320  virtual boost::optional<Timestamp> getMinimumVisibleSnapshot() = 0;
321 
322  virtual void setMinimumVisibleSnapshot(Timestamp name) = 0;
323 
324  virtual bool haveCappedWaiters() = 0;
325 
326  virtual void notifyCappedWaitersIfNeeded() = 0;
327 
328  virtual const CollatorInterface* getDefaultCollator() const = 0;
329  };
330 
331 public:
333  OperationContext* opCtx,
334  StringData fullNS,
339  PrivateTo<Collection>)
340  ->std::unique_ptr<Impl>) makeImpl;
341 
342  explicit inline Collection(OperationContext* const opCtx,
343  const StringData fullNS,
345  CollectionCatalogEntry* const details, // does not own
346  RecordStore* const recordStore, // does not own
347  DatabaseCatalogEntry* const dbce) // does not own
348  : _pimpl(makeImpl(
349  this, opCtx, fullNS, uuid, details, recordStore, dbce, PrivateCall<Collection>{})) {
350  this->_impl().init(opCtx);
351  }
352 
353  // Use this constructor only for testing/mocks
354  explicit inline Collection(std::unique_ptr<Impl> mock) : _pimpl(std::move(mock)) {}
355 
356  inline ~Collection() = default;
357 
358  inline bool ok() const {
359  return this->_impl().ok();
360  }
361 
363  return this->_impl().getCatalogEntry();
364  }
365 
366  inline const CollectionCatalogEntry* getCatalogEntry() const {
367  return this->_impl().getCatalogEntry();
368  }
369 
371  return this->_impl().infoCache();
372  }
373 
374  inline const CollectionInfoCache* infoCache() const {
375  return this->_impl().infoCache();
376  }
377 
378  inline const NamespaceString& ns() const {
379  return this->_impl().ns();
380  }
381 
382  inline OptionalCollectionUUID uuid() const {
383  return this->_impl().uuid();
384  }
385 
386  inline const IndexCatalog* getIndexCatalog() const {
387  return this->_impl().getIndexCatalog();
388  }
390  return this->_impl().getIndexCatalog();
391  }
392 
393  inline const RecordStore* getRecordStore() const {
394  return this->_impl().getRecordStore();
395  }
397  return this->_impl().getRecordStore();
398  }
399 
400  inline CursorManager* getCursorManager() const {
401  return this->_impl().getCursorManager();
402  }
403 
404  inline bool requiresIdIndex() const {
405  return this->_impl().requiresIdIndex();
406  }
407 
408  inline Snapshotted<BSONObj> docFor(OperationContext* const opCtx, const RecordId& loc) const {
409  return Snapshotted<BSONObj>(opCtx->recoveryUnit()->getSnapshotId(),
410  this->getRecordStore()->dataFor(opCtx, loc).releaseToBson());
411  }
412 
417  inline bool findDoc(OperationContext* const opCtx,
418  const RecordId& loc,
419  Snapshotted<BSONObj>* const out) const {
420  return this->_impl().findDoc(opCtx, loc, out);
421  }
422 
423  inline std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* const opCtx,
424  const bool forward = true) const {
425  return this->_impl().getCursor(opCtx, forward);
426  }
427 
432  inline std::vector<std::unique_ptr<RecordCursor>> getManyCursors(
433  OperationContext* const opCtx) const {
434  return this->_impl().getManyCursors(opCtx);
435  }
436 
449  inline void deleteDocument(OperationContext* const opCtx,
450  StmtId stmtId,
451  const RecordId& loc,
452  OpDebug* const opDebug,
453  const bool fromMigrate = false,
454  const bool noWarn = false,
455  StoreDeletedDoc storeDeletedDoc = StoreDeletedDoc::Off) {
456  return this->_impl().deleteDocument(
457  opCtx, stmtId, loc, opDebug, fromMigrate, noWarn, storeDeletedDoc);
458  }
459 
460  /*
461  * Inserts all documents inside one WUOW.
462  * Caller should ensure vector is appropriately sized for this.
463  * If any errors occur (including WCE), caller should retry documents individually.
464  *
465  * 'opDebug' Optional argument. When not null, will be used to record operation statistics.
466  */
467  inline Status insertDocuments(OperationContext* const opCtx,
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) {
473  return this->_impl().insertDocuments(opCtx, begin, end, opDebug, enforceQuota, fromMigrate);
474  }
475 
483  inline Status insertDocument(OperationContext* const opCtx,
484  const InsertStatement& doc,
485  OpDebug* const opDebug,
486  const bool enforceQuota,
487  const bool fromMigrate = false) {
488  return this->_impl().insertDocument(opCtx, doc, opDebug, enforceQuota, fromMigrate);
489  }
490 
495  inline Status insertDocumentsForOplog(OperationContext* const opCtx,
496  const DocWriter* const* const docs,
497  Timestamp* timestamps,
498  const size_t nDocs) {
499  return this->_impl().insertDocumentsForOplog(opCtx, docs, timestamps, nDocs);
500  }
501 
507  inline Status insertDocument(OperationContext* const opCtx,
508  const BSONObj& doc,
509  const std::vector<MultiIndexBlock*>& indexBlocks,
510  const bool enforceQuota) {
511  return this->_impl().insertDocument(opCtx, doc, indexBlocks, enforceQuota);
512  }
513 
523  inline RecordId updateDocument(OperationContext* const opCtx,
524  const RecordId& oldLocation,
525  const Snapshotted<BSONObj>& oldDoc,
526  const BSONObj& newDoc,
527  const bool enforceQuota,
528  const bool indexesAffected,
529  OpDebug* const opDebug,
530  OplogUpdateEntryArgs* const args) {
531  return this->_impl().updateDocument(
532  opCtx, oldLocation, oldDoc, newDoc, enforceQuota, indexesAffected, opDebug, args);
533  }
534 
535  inline bool updateWithDamagesSupported() const {
536  return this->_impl().updateWithDamagesSupported();
537  }
538 
547  OperationContext* const opCtx,
548  const RecordId& loc,
549  const Snapshotted<RecordData>& oldRec,
550  const char* const damageSource,
551  const mutablebson::DamageVector& damages,
552  OplogUpdateEntryArgs* const args) {
553  return this->_impl().updateDocumentWithDamages(
554  opCtx, loc, oldRec, damageSource, damages, args);
555  }
556 
557  // -----------
558 
559  inline StatusWith<CompactStats> compact(OperationContext* const opCtx,
560  const CompactOptions* const options) {
561  return this->_impl().compact(opCtx, options);
562  }
563 
569  inline Status truncate(OperationContext* const opCtx) {
570  return this->_impl().truncate(opCtx);
571  }
572 
578  inline Status validate(OperationContext* const opCtx,
579  const ValidateCmdLevel level,
580  bool background,
581  std::unique_ptr<Lock::CollectionLock> collLk,
582  ValidateResults* const results,
583  BSONObjBuilder* const output) {
584  return this->_impl().validate(opCtx, level, background, std::move(collLk), results, output);
585  }
586 
590  inline Status touch(OperationContext* const opCtx,
591  const bool touchData,
592  const bool touchIndexes,
593  BSONObjBuilder* const output) const {
594  return this->_impl().touch(opCtx, touchData, touchIndexes, output);
595  }
596 
603  inline void cappedTruncateAfter(OperationContext* const opCtx,
604  const RecordId end,
605  const bool inclusive) {
606  return this->_impl().cappedTruncateAfter(opCtx, end, inclusive);
607  }
608 
612  inline StatusWithMatchExpression parseValidator(
613  OperationContext* opCtx,
614  const BSONObj& validator,
615  MatchExpressionParser::AllowedFeatureSet allowedFeatures,
616  boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
617  maxFeatureCompatibilityVersion) const {
618  return this->_impl().parseValidator(
619  opCtx, validator, allowedFeatures, maxFeatureCompatibilityVersion);
620  }
621 
622  static MONGO_DECLARE_SHIM((StringData)->StatusWith<ValidationLevel>) parseValidationLevel;
623  static MONGO_DECLARE_SHIM((StringData)->StatusWith<ValidationAction>) parseValidationAction;
624 
631  inline Status setValidator(OperationContext* const opCtx, const BSONObj validator) {
632  return this->_impl().setValidator(opCtx, validator);
633  }
634 
635  inline Status setValidationLevel(OperationContext* const opCtx, const StringData newLevel) {
636  return this->_impl().setValidationLevel(opCtx, newLevel);
637  }
638  inline Status setValidationAction(OperationContext* const opCtx, const StringData newAction) {
639  return this->_impl().setValidationAction(opCtx, newAction);
640  }
641 
642  inline StringData getValidationLevel() const {
643  return this->_impl().getValidationLevel();
644  }
645  inline StringData getValidationAction() const {
646  return this->_impl().getValidationAction();
647  }
648 
649  inline Status updateValidator(OperationContext* opCtx,
650  BSONObj newValidator,
651  StringData newLevel,
652  StringData newAction) {
653  return this->_impl().updateValidator(opCtx, newValidator, newLevel, newAction);
654  }
655 
656  // -----------
657 
658  //
659  // Stats
660  //
661 
662  inline bool isCapped() const {
663  return this->_impl().isCapped();
664  }
665 
672  inline std::shared_ptr<CappedInsertNotifier> getCappedInsertNotifier() const {
673  return this->_impl().getCappedInsertNotifier();
674  }
675 
676  inline uint64_t numRecords(OperationContext* const opCtx) const {
677  return this->_impl().numRecords(opCtx);
678  }
679 
680  inline uint64_t dataSize(OperationContext* const opCtx) const {
681  return this->_impl().dataSize(opCtx);
682  }
683 
684  inline int averageObjectSize(OperationContext* const opCtx) const {
685  uint64_t n = this->numRecords(opCtx);
686 
687  if (n == 0)
688  return 5;
689  return static_cast<int>(this->dataSize(opCtx) / n);
690  }
691 
692  inline uint64_t getIndexSize(OperationContext* const opCtx,
693  BSONObjBuilder* const details = nullptr,
694  const int scale = 1) {
695  return this->_impl().getIndexSize(opCtx, details, scale);
696  }
697 
702  inline boost::optional<Timestamp> getMinimumVisibleSnapshot() {
703  return this->_impl().getMinimumVisibleSnapshot();
704  }
705 
706  inline void setMinimumVisibleSnapshot(const Timestamp name) {
707  return this->_impl().setMinimumVisibleSnapshot(name);
708  }
709 
710  inline bool haveCappedWaiters() {
711  return this->_impl().haveCappedWaiters();
712  }
713 
718  return this->_impl().notifyCappedWaitersIfNeeded();
719  }
720 
725  inline const CollatorInterface* getDefaultCollator() const {
726  return this->_impl().getDefaultCollator();
727  }
728 
729 
730 private:
731  inline DatabaseCatalogEntry* dbce() const {
732  return this->_impl().dbce();
733  }
734 
735  inline CollectionCatalogEntry* details() const {
736  return this->_impl().details();
737  }
738 
739  inline Status aboutToDeleteCapped(OperationContext* const opCtx,
740  const RecordId& loc,
741  const RecordData data) final {
742  return this->_impl().aboutToDeleteCapped(opCtx, loc, data);
743  }
744 
745  inline Status recordStoreGoingToUpdateInPlace(OperationContext* const opCtx,
746  const RecordId& loc) final {
747  return this->_impl().recordStoreGoingToUpdateInPlace(opCtx, loc);
748  }
749 
750  // This structure exists to give us a customization point to decide how to force users of this
751  // class to depend upon the corresponding `collection.cpp` Translation Unit (TU). All public
752  // forwarding functions call `_impl(), and `_impl` creates an instance of this structure.
753  struct TUHook {
754  static void hook() noexcept;
755 
756  explicit inline TUHook() noexcept {
757  if (kDebugBuild)
758  this->hook();
759  }
760  };
761 
762  inline const Impl& _impl() const {
763  TUHook{};
764  return *this->_pimpl;
765  }
766 
767  inline Impl& _impl() {
768  TUHook{};
769  return *this->_pimpl;
770  }
771 
772  std::unique_ptr<Impl> _pimpl;
773 
774  friend class DatabaseImpl;
775  friend class IndexCatalogImpl;
776 };
777 } // namespace mongo
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
~Collection()=default
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