summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/devnull
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-03-11 06:11:52 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-18 03:06:31 +0000
commit68cd2c39ff64864b533471af63450cd352c51709 (patch)
tree60cf09b8d87d0aabd8cd57a2a4621c229a44e6df /src/mongo/db/storage/devnull
parent10439de079b03a981ead7f5566e6f539a6f9becd (diff)
downloadmongo-68cd2c39ff64864b533471af63450cd352c51709.tar.gz
SERVER-55156 Move capped collection responsibilities to the collection layer
Diffstat (limited to 'src/mongo/db/storage/devnull')
-rw-r--r--src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp64
-rw-r--r--src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h9
2 files changed, 1 insertions, 72 deletions
diff --git a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp
index f39c325863d..84f67fe8f1b 100644
--- a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp
+++ b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp
@@ -279,27 +279,15 @@ EphemeralForTestRecordStore::EphemeralForTestRecordStore(StringData ns,
StringData identName,
std::shared_ptr<void>* dataInOut,
bool isCapped,
- int64_t cappedMaxSize,
- int64_t cappedMaxDocs,
CappedCallback* cappedCallback)
: RecordStore(ns, identName),
_isCapped(isCapped),
- _cappedMaxSize(cappedMaxSize),
- _cappedMaxDocs(cappedMaxDocs),
_cappedCallback(cappedCallback),
_data(*dataInOut ? static_cast<Data*>(dataInOut->get())
: new Data(ns, NamespaceString::oplog(ns))) {
if (!*dataInOut) {
dataInOut->reset(_data); // takes ownership
}
-
- if (_isCapped) {
- invariant(_cappedMaxSize > 0);
- invariant(_cappedMaxDocs == -1 || _cappedMaxDocs > 0);
- } else {
- invariant(_cappedMaxSize == -1);
- invariant(_cappedMaxDocs == -1);
- }
}
const char* EphemeralForTestRecordStore::name() const {
@@ -365,34 +353,6 @@ void EphemeralForTestRecordStore::deleteRecord(WithLock lk,
invariant(_data->records.erase(loc) == 1);
}
-bool EphemeralForTestRecordStore::cappedAndNeedDelete(WithLock, OperationContext* opCtx) const {
- if (!_isCapped)
- return false;
-
- if (_data->dataSize > _cappedMaxSize)
- return true;
-
- if ((_cappedMaxDocs != -1) && (numRecords(opCtx) > _cappedMaxDocs))
- return true;
-
- return false;
-}
-
-void EphemeralForTestRecordStore::cappedDeleteAsNeeded(WithLock lk, OperationContext* opCtx) {
- while (cappedAndNeedDelete(lk, opCtx)) {
- invariant(!_data->records.empty());
-
- Records::iterator oldest = _data->records.begin();
- RecordId id = oldest->first;
- RecordData data = oldest->second.toRecordData();
-
- if (_cappedCallback)
- uassertStatusOK(_cappedCallback->aboutToDeleteCapped(opCtx, id, data));
-
- deleteRecord(lk, opCtx, id);
- }
-}
-
StatusWith<RecordId> EphemeralForTestRecordStore::extractAndCheckLocForOplog(WithLock,
const char* data,
int len) const {
@@ -413,14 +373,6 @@ StatusWith<RecordId> EphemeralForTestRecordStore::extractAndCheckLocForOplog(Wit
Status EphemeralForTestRecordStore::insertRecords(OperationContext* opCtx,
std::vector<Record>* inOutRecords,
const std::vector<Timestamp>& timestamps) {
-
- for (auto& record : *inOutRecords) {
- if (_isCapped && record.data.size() > _cappedMaxSize) {
- // We use dataSize for capped rollover and we don't want to delete everything if we know
- // this won't fit.
- return Status(ErrorCodes::BadValue, "object to insert exceeds cappedMaxSize");
- }
- }
const auto insertSingleFn = [this, opCtx](Record* record) {
stdx::lock_guard<stdx::recursive_mutex> lock(_data->recordsMutex);
EphemeralForTestRecord rec(record->data.size());
@@ -442,8 +394,6 @@ Status EphemeralForTestRecordStore::insertRecords(OperationContext* opCtx,
record->id = loc;
opCtx->recoveryUnit()->registerChange(std::make_unique<InsertChange>(opCtx, _data, loc));
- cappedDeleteAsNeeded(lock, opCtx);
-
return Status::OK();
};
@@ -474,8 +424,6 @@ Status EphemeralForTestRecordStore::updateRecord(OperationContext* opCtx,
std::make_unique<RemoveChange>(opCtx, _data, loc, *oldRecord));
_data->dataSize += len - oldLen;
*oldRecord = newRecord;
-
- cappedDeleteAsNeeded(lock, opCtx);
return Status::OK();
}
@@ -502,8 +450,6 @@ StatusWith<RecordData> EphemeralForTestRecordStore::updateWithDamages(
std::make_unique<RemoveChange>(opCtx, _data, loc, *oldRecord));
*oldRecord = newRecord;
- cappedDeleteAsNeeded(lock, opCtx);
-
char* root = newRecord.data.get();
mutablebson::DamageVector::const_iterator where = damages.begin();
const mutablebson::DamageVector::const_iterator end = damages.end();
@@ -553,16 +499,6 @@ void EphemeralForTestRecordStore::cappedTruncateAfter(OperationContext* opCtx,
}
}
-void EphemeralForTestRecordStore::appendCustomStats(OperationContext* opCtx,
- BSONObjBuilder* result,
- double scale) const {
- result->appendBool("capped", _isCapped);
- if (_isCapped) {
- result->appendNumber("max", static_cast<long long>(_cappedMaxDocs));
- result->appendNumber("maxSize", _cappedMaxSize / scale);
- }
-}
-
int64_t EphemeralForTestRecordStore::storageSize(OperationContext* opCtx,
BSONObjBuilder* extraInfo,
int infoLevel) const {
diff --git a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
index b56fc826d3c..2945975a56f 100644
--- a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
+++ b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.h
@@ -52,8 +52,6 @@ public:
StringData identName,
std::shared_ptr<void>* dataInOut,
bool isCapped = false,
- int64_t cappedMaxSize = -1,
- int64_t cappedMaxDocs = -1,
CappedCallback* cappedCallback = nullptr);
virtual const char* name() const;
@@ -94,7 +92,7 @@ public:
virtual void appendCustomStats(OperationContext* opCtx,
BSONObjBuilder* result,
- double scale) const;
+ double scale) const {}
virtual int64_t storageSize(OperationContext* opCtx,
BSONObjBuilder* extraInfo = nullptr,
@@ -159,14 +157,9 @@ private:
StatusWith<RecordId> extractAndCheckLocForOplog(WithLock, const char* data, int len) const;
RecordId allocateLoc(WithLock);
- bool cappedAndNeedDelete(WithLock, OperationContext* opCtx) const;
- void cappedDeleteAsNeeded(WithLock lk, OperationContext* opCtx);
void deleteRecord(WithLock lk, OperationContext* opCtx, const RecordId& dl);
- // TODO figure out a proper solution to metadata
const bool _isCapped;
- const int64_t _cappedMaxSize;
- const int64_t _cappedMaxDocs;
CappedCallback* _cappedCallback;
// This is the "persistent" data.