Storage Engine API
record_store_v1_capped.h
Go to the documentation of this file.
1 // record_store_v1_capped.h
2 
31 #pragma once
32 
33 #include "mongo/base/owned_pointer_vector.h"
38 
39 namespace mongo {
40 
41 class CappedRecordStoreV1 final : public RecordStoreV1Base {
42 public:
43  CappedRecordStoreV1(OperationContext* opCtx,
45  StringData ns,
47  ExtentManager* em,
48  bool isSystemIndexes);
49 
50  ~CappedRecordStoreV1() final;
51 
52  const char* name() const final {
53  return "CappedRecordStoreV1";
54  }
55 
56  Status truncate(OperationContext* opCtx) final;
57 
64  void cappedTruncateAfter(OperationContext* opCtx, RecordId end, bool inclusive) final;
65 
66  std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx,
67  bool forward) const final;
68 
69  std::vector<std::unique_ptr<RecordCursor>> getManyCursors(OperationContext* opCtx) const final;
70 
71  // Start from firstExtent by default.
72  DiskLoc firstRecord(OperationContext* opCtx, const DiskLoc& startExtent = DiskLoc()) const;
73  // Start from lastExtent by default.
74  DiskLoc lastRecord(OperationContext* opCtx, const DiskLoc& startExtent = DiskLoc()) const;
75 
76 protected:
77  bool isCapped() const final {
78  return true;
79  }
80  bool shouldPadInserts() const final {
81  return false;
82  }
83 
85  _cappedCallback = cb;
86  }
87 
88  StatusWith<DiskLoc> allocRecord(OperationContext* opCtx,
89  int lengthWithHeaders,
90  bool enforceQuota) final;
91 
92  void addDeletedRec(OperationContext* opCtx, const DiskLoc& dloc) final;
93 
94 private:
95  // -- start copy from cap.cpp --
96  void _compact(OperationContext* opCtx);
98  void setFirstDeletedInCurExtent(OperationContext* opCtx, const DiskLoc& loc);
99  void cappedCheckMigrate(OperationContext* opCtx);
100  DiskLoc __capAlloc(OperationContext* opCtx, int len);
101  bool inCapExtent(const DiskLoc& dl) const;
104  void setListOfAllDeletedRecords(OperationContext* opCtx, const DiskLoc& loc);
105  void setLastDelRecLastExtent(OperationContext* opCtx, const DiskLoc& loc);
106  Extent* theCapExtent() const;
107  bool nextIsInCapExtent(const DiskLoc& dl) const;
108  void advanceCapExtent(OperationContext* opCtx, StringData ns);
109  void cappedTruncateLastDelUpdate(OperationContext* opCtx);
110 
117  void cappedTruncateAfter(OperationContext* opCtx, const char* ns, DiskLoc end, bool inclusive);
118 
119  void _maybeComplain(OperationContext* opCtx, int len) const;
120 
121  // -- end copy from cap.cpp --
122 
124 
125  OwnedPointerVector<ExtentManager::CacheHint> _extentAdvice;
126 
128 };
129 }
Extent * theCapExtent() const
Definition: record_store_v1_capped.cpp:564
DiskLoc __capAlloc(OperationContext *opCtx, int len)
Definition: record_store_v1_capped.cpp:396
void setListOfAllDeletedRecords(OperationContext *opCtx, const DiskLoc &loc)
Definition: record_store_v1_capped.cpp:552
void cappedTruncateAfter(OperationContext *opCtx, RecordId end, bool inclusive) final
Truncate documents newer than the document at &#39;end&#39; from the capped collection.
Definition: record_store_v1_capped.cpp:254
Definition: extent.h:50
bool isCapped() const final
Definition: record_store_v1_capped.h:77
void addDeletedRec(OperationContext *opCtx, const DiskLoc &dloc) final
Definition: record_store_v1_capped.cpp:568
bool inCapExtent(const DiskLoc &dl) const
Definition: record_store_v1_capped.cpp:351
bool shouldPadInserts() const final
Definition: record_store_v1_capped.h:80
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
std::unique_ptr< SeekableRecordCursor > getCursor(OperationContext *opCtx, bool forward) const final
Returns a new cursor over this record store.
Definition: record_store_v1_capped.cpp:589
void cappedTruncateLastDelUpdate(OperationContext *opCtx)
Definition: record_store_v1_capped.cpp:423
OwnedPointerVector< ExtentManager::CacheHint > _extentAdvice
Definition: record_store_v1_capped.h:125
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
Definition: record_store_v1_base.h:152
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
void setCappedCallback(CappedCallback *cb) final
Definition: record_store_v1_capped.h:84
void advanceCapExtent(OperationContext *opCtx, StringData ns)
Definition: record_store_v1_capped.cpp:373
represents a disk location/offset on disk in a database.
Definition: diskloc.h:53
bool inclusive
Definition: btree_interface.cpp:335
DiskLoc lastRecord(OperationContext *opCtx, const DiskLoc &startExtent=DiskLoc()) const
Definition: record_store_v1_capped.cpp:687
DiskLoc cappedFirstDeletedInCurExtent() const
Definition: record_store_v1_capped.cpp:311
DiskLoc cappedLastDelRecLastExtent() const
Definition: record_store_v1_capped.cpp:556
void setFirstDeletedInCurExtent(OperationContext *opCtx, const DiskLoc &loc)
Definition: record_store_v1_capped.cpp:318
void cappedCheckMigrate(OperationContext *opCtx)
Definition: record_store_v1_capped.cpp:325
This class iterates over a capped collection identified by &#39;ns&#39;.
Definition: record_store_v1_capped_iterator.h:44
Definition: index_key_validate.h:40
DiskLoc firstRecord(OperationContext *opCtx, const DiskLoc &startExtent=DiskLoc()) const
Definition: record_store_v1_capped.cpp:675
CappedRecordStoreV1(OperationContext *opCtx, CappedCallback *collection, StringData ns, RecordStoreV1MetaData *details, ExtentManager *em, bool isSystemIndexes)
Definition: record_store_v1_capped.cpp:71
When a capped collection is modified (delete/insert/etc) then certain notifications need to be made...
Definition: capped_callback.h:44
virtual const std::string & ns() const
Definition: record_store.h:295
StatusWith< DiskLoc > allocRecord(OperationContext *opCtx, int lengthWithHeaders, bool enforceQuota) final
Definition: record_store_v1_capped.cpp:91
void setLastDelRecLastExtent(OperationContext *opCtx, const DiskLoc &loc)
Definition: record_store_v1_capped.cpp:560
Definition: record_store_v1_capped.h:41
const RecordStoreV1MetaData * details() const
Definition: record_store_v1_base.h:231
bool nextIsInCapExtent(const DiskLoc &dl) const
Definition: record_store_v1_capped.cpp:365
ExtentManager basics.
Definition: extent_manager.h:64
Definition: record_store_v1_base.h:46
CappedCallback * _cappedCallback
Definition: record_store_v1_capped.h:123
void _compact(OperationContext *opCtx)
Definition: record_store_v1_capped.cpp:265
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
Status truncate(OperationContext *opCtx) final
removes all Records
Definition: record_store_v1_capped.cpp:223
DiskLoc cappedListOfAllDeletedRecords() const
Definition: record_store_v1_capped.cpp:548
const char * name() const final
Definition: record_store_v1_capped.h:52
~CappedRecordStoreV1() final
Definition: record_store_v1_capped.cpp:89
std::vector< std::unique_ptr< RecordCursor > > getManyCursors(OperationContext *opCtx) const final
Returns many RecordCursors that partition the RecordStore into many disjoint sets.
Definition: record_store_v1_capped.cpp:594
void _maybeComplain(OperationContext *opCtx, int len) const
Definition: record_store_v1_capped.cpp:647