summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-12-22 00:36:00 -0500
committerBenety Goh <benety@mongodb.com>2018-12-22 07:04:32 -0500
commit402ea2b4d8e616878c2e14a5fb6f2f86faaaada0 (patch)
treef52a6aa0a4d0eb2cbcea622685de6803fb108358 /src/mongo/db/storage
parent7f70c1213b2cc79591ea1d11f9724d057886a0fd (diff)
downloadmongo-402ea2b4d8e616878c2e14a5fb6f2f86faaaada0.tar.gz
SERVER-38603 KVStorageEngine removes drop-pending idents when the oldest timestamp advances.hdbefg
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.cpp24
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.h8
2 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.cpp b/src/mongo/db/storage/kv/kv_storage_engine.cpp
index 7b47c069a21..80290716266 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.cpp
+++ b/src/mongo/db/storage/kv/kv_storage_engine.cpp
@@ -37,6 +37,7 @@
#include <algorithm>
#include "mongo/db/catalog/catalog_control.h"
+#include "mongo/db/client.h"
#include "mongo/db/logical_clock.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/storage/kv/kv_catalog_feature_tracker.h"
@@ -88,6 +89,9 @@ KVStorageEngine::KVStorageEngine(
_options(std::move(options)),
_databaseCatalogEntryFactory(std::move(databaseCatalogEntryFactory)),
_dropPendingIdentReaper(engine),
+ _oldestTimestampListener(
+ TimestampMonitor::TimestampType::kOldest,
+ [this](Timestamp timestamp) { _onOldestTimestampChanged(timestamp); }),
_supportsDocLocking(_engine->supportsDocLocking()),
_supportsDBLocking(_engine->supportsDBLocking()),
_supportsCappedCollections(_engine->supportsCappedCollections()) {
@@ -472,6 +476,10 @@ std::string KVStorageEngine::getFilesystemPathForDb(const std::string& dbName) c
}
void KVStorageEngine::cleanShutdown() {
+ if (_timestampMonitor) {
+ _timestampMonitor->removeListener(&_oldestTimestampListener);
+ }
+
for (DBMap::const_iterator it = _dbs.begin(); it != _dbs.end(); ++it) {
delete it->second;
}
@@ -493,6 +501,7 @@ void KVStorageEngine::finishInit() {
_timestampMonitor = std::make_unique<TimestampMonitor>(
_engine.get(), getGlobalServiceContext()->getPeriodicRunner());
_timestampMonitor->startup();
+ _timestampMonitor->addListener(&_oldestTimestampListener);
}
}
@@ -780,6 +789,21 @@ void KVStorageEngine::_dumpCatalog(OperationContext* opCtx) {
opCtx->recoveryUnit()->abandonSnapshot();
}
+void KVStorageEngine::_onOldestTimestampChanged(const Timestamp& oldestTimestamp) {
+ if (oldestTimestamp.isNull()) {
+ return;
+ }
+ // No drop-pending idents present if getEarliestDropTimestamp() returns boost::none.
+ if (auto earliestDropTimestamp = _dropPendingIdentReaper.getEarliestDropTimestamp()) {
+ if (oldestTimestamp > *earliestDropTimestamp) {
+ log() << "Removing drop-pending idents with drop timestamps before: "
+ << oldestTimestamp;
+ auto opCtx = cc().makeOperationContext();
+ _dropPendingIdentReaper.dropIdentsOlderThan(opCtx.get(), oldestTimestamp);
+ }
+ }
+}
+
KVStorageEngine::TimestampMonitor::TimestampMonitor(KVEngine* engine, PeriodicRunner* runner)
: _engine(engine), _running(false), _periodicRunner(runner) {
_currentTimestamps.checkpoint = _engine->getCheckpointTimestamp();
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.h b/src/mongo/db/storage/kv/kv_storage_engine.h
index 45196ebecea..d04d8d41679 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.h
+++ b/src/mongo/db/storage/kv/kv_storage_engine.h
@@ -364,6 +364,11 @@ private:
void _dumpCatalog(OperationContext* opCtx);
+ /**
+ * Called when the oldest timestamp advances in the KVEngine.
+ */
+ void _onOldestTimestampChanged(const Timestamp& oldestTimestamp);
+
class RemoveDBChange;
// This must be the first member so it is destroyed last.
@@ -376,6 +381,9 @@ private:
// Manages drop-pending idents. Requires access to '_engine'.
KVDropPendingIdentReaper _dropPendingIdentReaper;
+ // Listener for oldest timestamp changes.
+ TimestampMonitor::TimestampListener _oldestTimestampListener;
+
const bool _supportsDocLocking;
const bool _supportsDBLocking;
const bool _supportsCappedCollections;