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:
162  enum ValidationAction { WARN, ERROR_V };
163  enum ValidationLevel { OFF, MODERATE, STRICT_V };
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 
188  virtual CollectionCatalogEntry* getCatalogEntry() = 0;
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 void refreshUUID(OperationContext* opCtx) = 0;
198 
199  virtual const IndexCatalog* getIndexCatalog() const = 0;
200  virtual IndexCatalog* getIndexCatalog() = 0;
201 
202  virtual const RecordStore* getRecordStore() const = 0;
203  virtual RecordStore* getRecordStore() = 0;
204 
205  virtual CursorManager* getCursorManager() const = 0;
206 
207  virtual bool requiresIdIndex() const = 0;
208 
209  virtual Snapshotted<BSONObj> docFor(OperationContext* opCtx, const RecordId& loc) const = 0;
210 
211  virtual bool findDoc(OperationContext* opCtx,
212  const RecordId& loc,
213  Snapshotted<BSONObj>* out) const = 0;
214 
215  virtual std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
216  bool forward) const = 0;
217 
218  virtual std::vector<std::unique_ptr<RecordCursor>> getManyCursors(
219  OperationContext* opCtx) const = 0;
220 
221  virtual void deleteDocument(OperationContext* opCtx,
222  StmtId stmtId,
223  const RecordId& loc,
224  OpDebug* opDebug,
225  bool fromMigrate,
226  bool noWarn,
227  StoreDeletedDoc storeDeletedDoc) = 0;
228 
229  virtual Status insertDocuments(OperationContext* opCtx,
230  std::vector<InsertStatement>::const_iterator begin,
231  std::vector<InsertStatement>::const_iterator end,
232  OpDebug* opDebug,
233  bool enforceQuota,
234  bool fromMigrate) = 0;
235 
236  virtual Status insertDocument(OperationContext* opCtx,
237  const InsertStatement& doc,
238  OpDebug* opDebug,
239  bool enforceQuota,
240  bool fromMigrate) = 0;
241 
242  virtual Status insertDocumentsForOplog(OperationContext* opCtx,
243  const DocWriter* const* docs,
244  Timestamp* timestamps,
245  size_t nDocs) = 0;
246 
247  virtual Status insertDocument(OperationContext* opCtx,
248  const BSONObj& doc,
249  const std::vector<MultiIndexBlock*>& indexBlocks,
250  bool enforceQuota) = 0;
251 
252  virtual RecordId updateDocument(OperationContext* opCtx,
253  const RecordId& oldLocation,
254  const Snapshotted<BSONObj>& oldDoc,
255  const BSONObj& newDoc,
256  bool enforceQuota,
257  bool indexesAffected,
258  OpDebug* opDebug,
259  OplogUpdateEntryArgs* args) = 0;
260 
261  virtual bool updateWithDamagesSupported() const = 0;
262 
263  virtual StatusWith<RecordData> updateDocumentWithDamages(
264  OperationContext* opCtx,
265  const RecordId& loc,
266  const Snapshotted<RecordData>& oldRec,
267  const char* damageSource,
268  const mutablebson::DamageVector& damages,
269  OplogUpdateEntryArgs* args) = 0;
270 
271  virtual StatusWith<CompactStats> compact(OperationContext* opCtx,
272  const CompactOptions* options) = 0;
273 
274  virtual Status truncate(OperationContext* opCtx) = 0;
275 
276  virtual Status validate(OperationContext* opCtx,
277  ValidateCmdLevel level,
278  bool background,
279  std::unique_ptr<Lock::CollectionLock> collLk,
280  ValidateResults* results,
281  BSONObjBuilder* output) = 0;
282 
283  virtual Status touch(OperationContext* opCtx,
284  bool touchData,
285  bool touchIndexes,
286  BSONObjBuilder* output) const = 0;
287 
288  virtual void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive) = 0;
289 
290  virtual StatusWithMatchExpression parseValidator(
291  OperationContext* opCtx,
292  const BSONObj& validator,
293  MatchExpressionParser::AllowedFeatureSet allowedFeatures,
294  boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
295  maxFeatureCompatibilityVersion = boost::none) const = 0;
296 
297  virtual Status setValidator(OperationContext* opCtx, BSONObj validator) = 0;
298 
299  virtual Status setValidationLevel(OperationContext* opCtx, StringData newLevel) = 0;
300  virtual Status setValidationAction(OperationContext* opCtx, StringData newAction) = 0;
301 
302  virtual StringData getValidationLevel() const = 0;
303  virtual StringData getValidationAction() const = 0;
304 
305  virtual Status updateValidator(OperationContext* opCtx,
306  BSONObj newValidator,
307  StringData newLevel,
308  StringData newAction) = 0;
309 
310  virtual bool isCapped() const = 0;
311 
312  virtual std::shared_ptr<CappedInsertNotifier> getCappedInsertNotifier() const = 0;
313 
314  virtual uint64_t numRecords(OperationContext* opCtx) const = 0;
315 
316  virtual uint64_t dataSize(OperationContext* opCtx) const = 0;
317 
318  virtual uint64_t getIndexSize(OperationContext* opCtx,
319  BSONObjBuilder* details,
320  int scale) = 0;
321 
322  virtual boost::optional<Timestamp> getMinimumVisibleSnapshot() = 0;
323 
324  virtual void setMinimumVisibleSnapshot(Timestamp name) = 0;
325 
326  virtual bool haveCappedWaiters() = 0;
327 
328  virtual void notifyCappedWaitersIfNeeded() = 0;
329 
330  virtual const CollatorInterface* getDefaultCollator() const = 0;
331  };
332 
333 public:
334  static MONGO_DECLARE_SHIM((Collection * _this,
335  OperationContext* opCtx,
336  StringData fullNS,
341  PrivateTo<Collection>)
342  ->std::unique_ptr<Impl>) makeImpl;
343 
344  explicit inline Collection(OperationContext* const opCtx,
345  const StringData fullNS,
347  CollectionCatalogEntry* const details, // does not own
348  RecordStore* const recordStore, // does not own
349  DatabaseCatalogEntry* const dbce) // does not own
350  : _pimpl(makeImpl(
351  this, opCtx, fullNS, uuid, details, recordStore, dbce, PrivateCall<Collection>{})) {
352  this->_impl().init(opCtx);
353  }
354 
355  // Use this constructor only for testing/mocks
356  explicit inline Collection(std::unique_ptr<Impl> mock) : _pimpl(std::move(mock)) {}
357 
358  inline ~Collection() = default;
359 
360  inline bool ok() const {
361  return this->_impl().ok();
362  }
363 
365  return this->_impl().getCatalogEntry();
366  }
367 
368  inline const CollectionCatalogEntry* getCatalogEntry() const {
369  return this->_impl().getCatalogEntry();
370  }
371 
373  return this->_impl().infoCache();
374  }
375 
376  inline const CollectionInfoCache* infoCache() const {
377  return this->_impl().infoCache();
378  }
379 
380  inline const NamespaceString& ns() const {
381  return this->_impl().ns();
382  }
383 
384  inline OptionalCollectionUUID uuid() const {
385  return this->_impl().uuid();
386  }
387 
388  inline void refreshUUID(OperationContext* opCtx) {
389  return this->_impl().refreshUUID(opCtx);
390  }
391 
392  inline const IndexCatalog* getIndexCatalog() const {
393  return this->_impl().getIndexCatalog();
394  }
396  return this->_impl().getIndexCatalog();
397  }
398 
399  inline const RecordStore* getRecordStore() const {
400  return this->_impl().getRecordStore();
401  }
403  return this->_impl().getRecordStore();
404  }
405 
406  inline CursorManager* getCursorManager() const {
407  return this->_impl().getCursorManager();
408  }
409 
410  inline bool requiresIdIndex() const {
411  return this->_impl().requiresIdIndex();
412  }
413 
414  inline Snapshotted<BSONObj> docFor(OperationContext* const opCtx, const RecordId& loc) const {
415  return Snapshotted<BSONObj>(opCtx->recoveryUnit()->getSnapshotId(),
416  this->getRecordStore()->dataFor(opCtx, loc).releaseToBson());
417  }
418 
423  inline bool findDoc(OperationContext* const opCtx,
424  const RecordId& loc,
425  Snapshotted<BSONObj>* const out) const {
426  return this->_impl().findDoc(opCtx, loc, out);
427  }
428 
429  inline std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* const opCtx,
430  const bool forward = true) const {
431  return this->_impl().getCursor(opCtx, forward);
432  }
433 
438  inline std::vector<std::unique_ptr<RecordCursor>> getManyCursors(
439  OperationContext* const opCtx) const {
440  return this->_impl().getManyCursors(opCtx);
441  }
442 
455  inline void deleteDocument(OperationContext* const opCtx,
456  StmtId stmtId,
457  const RecordId& loc,
458  OpDebug* const opDebug,
459  const bool fromMigrate = false,
460  const bool noWarn = false,
461  StoreDeletedDoc storeDeletedDoc = StoreDeletedDoc::Off) {
462  return this->_impl().deleteDocument(
463  opCtx, stmtId, loc, opDebug, fromMigrate, noWarn, storeDeletedDoc);
464  }
465 
466  /*
467  * Inserts all documents inside one WUOW.
468  * Caller should ensure vector is appropriately sized for this.
469  * If any errors occur (including WCE), caller should retry documents individually.
470  *
471  * 'opDebug' Optional argument. When not null, will be used to record operation statistics.
472  */
473  inline Status insertDocuments(OperationContext* const opCtx,
474  const std::vector<InsertStatement>::const_iterator begin,
475  const std::vector<InsertStatement>::const_iterator end,
476  OpDebug* const opDebug,
477  const bool enforceQuota,
478  const bool fromMigrate = false) {
479  return this->_impl().insertDocuments(opCtx, begin, end, opDebug, enforceQuota, fromMigrate);
480  }
481 
489  inline Status insertDocument(OperationContext* const opCtx,
490  const InsertStatement& doc,
491  OpDebug* const opDebug,
492  const bool enforceQuota,
493  const bool fromMigrate = false) {
494  return this->_impl().insertDocument(opCtx, doc, opDebug, enforceQuota, fromMigrate);
495  }
496 
501  inline Status insertDocumentsForOplog(OperationContext* const opCtx,
502  const DocWriter* const* const docs,
503  Timestamp* timestamps,
504  const size_t nDocs) {
505  return this->_impl().insertDocumentsForOplog(opCtx, docs, timestamps, nDocs);
506  }
507 
513  inline Status insertDocument(OperationContext* const opCtx,
514  const BSONObj& doc,
515  const std::vector<MultiIndexBlock*>& indexBlocks,
516  const bool enforceQuota) {
517  return this->_impl().insertDocument(opCtx, doc, indexBlocks, enforceQuota);
518  }
519 
529  inline RecordId updateDocument(OperationContext* const opCtx,
530  const RecordId& oldLocation,
531  const Snapshotted<BSONObj>& oldDoc,
532  const BSONObj& newDoc,
533  const bool enforceQuota,
534  const bool indexesAffected,
535  OpDebug* const opDebug,
536  OplogUpdateEntryArgs* const args) {
537  return this->_impl().updateDocument(
538  opCtx, oldLocation, oldDoc, newDoc, enforceQuota, indexesAffected, opDebug, args);
539  }
540 
541  inline bool updateWithDamagesSupported() const {
542  return this->_impl().updateWithDamagesSupported();
543  }
544 
553  OperationContext* const opCtx,
554  const RecordId& loc,
555  const Snapshotted<RecordData>& oldRec,
556  const char* const damageSource,
557  const mutablebson::DamageVector& damages,
558  OplogUpdateEntryArgs* const args) {
559  return this->_impl().updateDocumentWithDamages(
560  opCtx, loc, oldRec, damageSource, damages, args);
561  }
562 
563  // -----------
564 
565  inline StatusWith<CompactStats> compact(OperationContext* const opCtx,
566  const CompactOptions* const options) {
567  return this->_impl().compact(opCtx, options);
568  }
569 
575  inline Status truncate(OperationContext* const opCtx) {
576  return this->_impl().truncate(opCtx);
577  }
578 
584  inline Status validate(OperationContext* const opCtx,
585  const ValidateCmdLevel level,
586  bool background,
587  std::unique_ptr<Lock::CollectionLock> collLk,
588  ValidateResults* const results,
589  BSONObjBuilder* const output) {
590  return this->_impl().validate(opCtx, level, background, std::move(collLk), results, output);
591  }
592 
596  inline Status touch(OperationContext* const opCtx,
597  const bool touchData,
598  const bool touchIndexes,
599  BSONObjBuilder* const output) const {
600  return this->_impl().touch(opCtx, touchData, touchIndexes, output);
601  }
602 
609  inline void cappedTruncateAfter(OperationContext* const opCtx,
610  const RecordId end,
611  const bool inclusive) {
612  return this->_impl().cappedTruncateAfter(opCtx, end, inclusive);
613  }
614 
618  inline StatusWithMatchExpression parseValidator(
619  OperationContext* opCtx,
620  const BSONObj& validator,
621  MatchExpressionParser::AllowedFeatureSet allowedFeatures,
622  boost::optional<ServerGlobalParams::FeatureCompatibility::Version>
623  maxFeatureCompatibilityVersion) const {
624  return this->_impl().parseValidator(
625  opCtx, validator, allowedFeatures, maxFeatureCompatibilityVersion);
626  }
627 
628  static MONGO_DECLARE_SHIM((StringData)->StatusWith<ValidationLevel>) parseValidationLevel;
629  static MONGO_DECLARE_SHIM((StringData)->StatusWith<ValidationAction>) parseValidationAction;
630 
637  inline Status setValidator(OperationContext* const opCtx, const BSONObj validator) {
638  return this->_impl().setValidator(opCtx, validator);
639  }
640 
641  inline Status setValidationLevel(OperationContext* const opCtx, const StringData newLevel) {
642  return this->_impl().setValidationLevel(opCtx, newLevel);
643  }
644  inline Status setValidationAction(OperationContext* const opCtx, const StringData newAction) {
645  return this->_impl().setValidationAction(opCtx, newAction);
646  }
647 
648  inline StringData getValidationLevel() const {
649  return this->_impl().getValidationLevel();
650  }
651  inline StringData getValidationAction() const {
652  return this->_impl().getValidationAction();
653  }
654 
655  inline Status updateValidator(OperationContext* opCtx,
656  BSONObj newValidator,
657  StringData newLevel,
658  StringData newAction) {
659  return this->_impl().updateValidator(opCtx, newValidator, newLevel, newAction);
660  }
661 
662  // -----------
663 
664  //
665  // Stats
666  //
667 
668  inline bool isCapped() const {
669  return this->_impl().isCapped();
670  }
671 
678  inline std::shared_ptr<CappedInsertNotifier> getCappedInsertNotifier() const {
679  return this->_impl().getCappedInsertNotifier();
680  }
681 
682  inline uint64_t numRecords(OperationContext* const opCtx) const {
683  return this->_impl().numRecords(opCtx);
684  }
685 
686  inline uint64_t dataSize(OperationContext* const opCtx) const {
687  return this->_impl().dataSize(opCtx);
688  }
689 
690  inline int averageObjectSize(OperationContext* const opCtx) const {
691  uint64_t n = this->numRecords(opCtx);
692 
693  if (n == 0)
694  return 5;
695  return static_cast<int>(this->dataSize(opCtx) / n);
696  }
697 
698  inline uint64_t getIndexSize(OperationContext* const opCtx,
699  BSONObjBuilder* const details = nullptr,
700  const int scale = 1) {
701  return this->_impl().getIndexSize(opCtx, details, scale);
702  }
703 
708  inline boost::optional<Timestamp> getMinimumVisibleSnapshot() {
709  return this->_impl().getMinimumVisibleSnapshot();
710  }
711 
712  inline void setMinimumVisibleSnapshot(const Timestamp name) {
713  return this->_impl().setMinimumVisibleSnapshot(name);
714  }
715 
716  inline bool haveCappedWaiters() {
717  return this->_impl().haveCappedWaiters();
718  }
719 
724  return this->_impl().notifyCappedWaitersIfNeeded();
725  }
726 
731  inline const CollatorInterface* getDefaultCollator() const {
732  return this->_impl().getDefaultCollator();
733  }
734 
735 
736 private:
737  inline DatabaseCatalogEntry* dbce() const {
738  return this->_impl().dbce();
739  }
740 
741  inline CollectionCatalogEntry* details() const {
742  return this->_impl().details();
743  }
744 
745  inline Status aboutToDeleteCapped(OperationContext* const opCtx,
746  const RecordId& loc,
747  const RecordData data) final {
748  return this->_impl().aboutToDeleteCapped(opCtx, loc, data);
749  }
750 
751  inline Status recordStoreGoingToUpdateInPlace(OperationContext* const opCtx,
752  const RecordId& loc) final {
753  return this->_impl().recordStoreGoingToUpdateInPlace(opCtx, loc);
754  }
755 
756  // This structure exists to give us a customization point to decide how to force users of this
757  // class to depend upon the corresponding `collection.cpp` Translation Unit (TU). All public
758  // forwarding functions call `_impl(), and `_impl` creates an instance of this structure.
759  struct TUHook {
760  static void hook() noexcept;
761 
762  explicit inline TUHook() noexcept {
763  if (kDebugBuild)
764  this->hook();
765  }
766  };
767 
768  inline const Impl& _impl() const {
769  TUHook{};
770  return *this->_pimpl;
771  }
772 
773  inline Impl& _impl() {
774  TUHook{};
775  return *this->_pimpl;
776  }
777 
778  std::unique_ptr<Impl> _pimpl;
779 
780  friend class DatabaseImpl;
781  friend class IndexCatalogImpl;
782 };
783 } // namespace mongo
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:489
Queries with the awaitData option use this notifier object to wait for more data to be inserted into ...
Definition: collection.h:105
IndexCatalogEntry *const OperationContext *const const StringData CollectionCatalogEntry *const std::unique_ptr< IndexDescriptor > CollectionInfoCache *const infoCache
Definition: index_catalog_entry_impl.cpp:58
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:698
std::shared_ptr< CappedInsertNotifier > getCappedInsertNotifier() const
Get a pointer to a capped insert notifier object.
Definition: collection.h:678
Status setValidationAction(OperationContext *const opCtx, const StringData newAction)
Definition: collection.h:644
Impl & _impl()
Definition: collection.h:773
Definition: snapshot.h:69
Collection *const OperationContext *const const StringData OptionalCollectionUUID CollectionCatalogEntry *const details
Definition: collection_impl.cpp:80
Definition: record_store.h:671
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
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:438
bool ok() const
Definition: collection.h:360
Definition: collection.h:79
int paddingBytes
Definition: collection.h:83
uint64_t dataSize(OperationContext *const opCtx) const
Definition: collection.h:686
Definition: collection.h:759
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Status recordStoreGoingToUpdateInPlace(OperationContext *const opCtx, const RecordId &loc) final
Definition: collection.h:751
void setMinimumVisibleSnapshot(const Timestamp name)
Definition: collection.h:712
int averageObjectSize(OperationContext *const opCtx) const
Definition: collection.h:690
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:344
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:552
CollectionCatalogEntry * details() const
Definition: collection.h:741
Collection *const _this
Definition: collection_impl.cpp:80
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *const opCtx, const bool forward=true) const
Definition: collection.h:429
A replacement for the Record class.
Definition: record_data.h:43
friend Collection
Definition: collection.h:173
Represents a logical database containing Collections.
Definition: database_impl.h:61
how many: 1 per Collection.
Definition: index_catalog_impl.h:56
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:584
IndexCatalog * getIndexCatalog()
Definition: collection.h:395
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:473
Definition: collection.h:166
TUHook() noexcept
Definition: collection.h:762
Definition: record_store.h:78
double paddingFactor
Definition: collection.h:82
Definition: collection.h:162
void cappedTruncateAfter(OperationContext *const opCtx, const RecordId end, const bool inclusive)
Truncate documents newer than the document at &#39;end&#39; from the capped collection.
Definition: collection.h:609
Collection *const OperationContext *const const StringData OptionalCollectionUUID CollectionCatalogEntry *const RecordStore *const DatabaseCatalogEntry *const dbce
Definition: collection_impl.cpp:80
bool inclusive
Definition: btree_interface.cpp:335
DatabaseCatalogEntry * dbce() const
Definition: collection.h:737
StatusWith< CompactStats > compact(OperationContext *const opCtx, const CompactOptions *const options)
Definition: collection.h:565
Definition: collection.h:79
this is NOT safe through a yield right now.
Definition: collection.h:160
OptionalCollectionUUID uuid() const
Definition: collection.h:384
CollectionInfoCache * infoCache()
Definition: collection.h:372
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
bool updateWithDamagesSupported() const
Definition: collection.h:541
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:501
how many: 1 per Collection.
Definition: index_catalog.h:62
RecordStore * getRecordStore()
Definition: collection.h:402
Collection *const OperationContext *const const StringData OptionalCollectionUUID CollectionCatalogEntry *const RecordStore *const recordStore
Definition: collection_impl.cpp:80
bool validateDocuments
Definition: collection.h:86
boost::optional< CollectionUUID > OptionalCollectionUUID
Definition: collection_options.h:55
std::unique_ptr< Impl > _pimpl
Definition: collection.h:778
void refreshUUID(OperationContext *opCtx)
Definition: collection.h:388
const CollectionInfoCache * infoCache() const
Definition: collection.h:376
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:708
Definition: collection.h:79
Collection(std::unique_ptr< Impl > mock)
Definition: collection.h:356
Definition: index_key_validate.h:40
Collection *const OperationContext *const const StringData OptionalCollectionUUID uuid
Definition: collection_impl.cpp:80
Snapshotted< BSONObj > docFor(OperationContext *const opCtx, const RecordId &loc) const
Definition: collection.h:414
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:513
StringData getValidationAction() const
Definition: collection.h:651
Status updateValidator(OperationContext *opCtx, BSONObj newValidator, StringData newLevel, StringData newAction)
Definition: collection.h:655
uint64_t getVersion() const
Returns the version for use as an additional wake condition when used above.
Definition: collection.h:125
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:618
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:529
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:364
const Impl & _impl() const
Definition: collection.h:768
const IndexCatalog * getIndexCatalog() const
Definition: collection.h:392
bool requiresIdIndex() const
Definition: collection.h:410
Status touch(OperationContext *const opCtx, const bool touchData, const bool touchIndexes, BSONObjBuilder *const output) const
forces data into cache.
Definition: collection.h:596
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:423
stdx::condition_variable _notifier
Definition: collection.h:141
bool haveCappedWaiters()
Returns true if there may be waiters.
Definition: collection.h:716
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:455
OperationContext Database StringData BSONObj options
Definition: database_impl.cpp:949
const CollatorInterface * getDefaultCollator() const
Get a pointer to the collection&#39;s default collator.
Definition: collection.h:731
Status setValidationLevel(OperationContext *const opCtx, const StringData newLevel)
Definition: collection.h:641
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:745
Definition: collection.h:97
void notifyCappedWaitersIfNeeded()
Notify (capped collection) waiters of data changes, like an insert.
Definition: collection.h:723
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:575
ValidationLevel
Definition: collection.h:163
Database *const OperationContext *const const StringData name
Definition: database_impl.cpp:82
bool isCapped() const
Definition: collection.h:668
const NamespaceString & ns() const
Definition: collection.h:380
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
const CollectionCatalogEntry * getCatalogEntry() const
Definition: collection.h:368
CursorManager * getCursorManager() const
Definition: collection.h:406
const RecordStore * getRecordStore() const
Definition: collection.h:399
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
StringData getValidationLevel() const
Definition: collection.h:648
uint64_t numRecords(OperationContext *const opCtx) const
Definition: collection.h:682
Status setValidator(OperationContext *const opCtx, const BSONObj validator)
Sets the validator for this collection.
Definition: collection.h:637
enum mongo::CompactOptions::PaddingMode paddingMode
uint64_t _version
Definition: collection.h:150
PaddingMode
Definition: collection.h:79
bool _dead
Definition: collection.h:153