summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-26 09:36:42 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-10 18:02:42 +0000
commit02a6f50be29f295d36a8c86f1e3f6c21587bb04d (patch)
tree8aebd4bf9a421515e3431c1e4c39c07b852cfb75
parent2a53498a27cb9665dd7b50843b0c43c1232f30a6 (diff)
downloadmongo-02a6f50be29f295d36a8c86f1e3f6c21587bb04d.tar.gz
SERVER-68477 add TTLMonitor::onStepUp()
(cherry picked from commit 3b17e5f7916fdf1a21dd162a079aeb9d06ca9425)
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/ttl.cpp47
2 files changed, 48 insertions, 0 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 1046dc4d45a..215dd5f2748 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1415,6 +1415,7 @@ env.Library(
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/commands/fsync_locked',
'$BUILD_DIR/mongo/db/record_id_helpers',
+ '$BUILD_DIR/mongo/db/repl/replica_set_aware_service',
'$BUILD_DIR/mongo/db/repl/tenant_migration_access_blocker',
'$BUILD_DIR/mongo/db/s/sharding_runtime_d',
'$BUILD_DIR/mongo/idl/server_parameter',
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index 32ec347d525..3c729cadcc6 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/ops/insert.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/record_id_helpers.h"
+#include "mongo/db/repl/replica_set_aware_service.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/tenant_migration_access_blocker_registry.h"
#include "mongo/db/s/operation_sharding_state.h"
@@ -175,6 +176,11 @@ public:
LOGV2(3684101, "Finished shutting down TTL collection monitor thread");
}
+ /**
+ * Invoked when the node enters the primary state.
+ */
+ void onStepUp(OperationContext* opCtx);
+
private:
/**
* Gets all TTL specifications for every collection and deletes expired documents.
@@ -600,4 +606,45 @@ void shutdownTTLMonitor(ServiceContext* serviceContext) {
}
}
+void TTLMonitor::onStepUp(OperationContext* opCtx) {}
+
+namespace {
+
+/**
+ * Runs on primaries and secondaries. Forwards replica set events to the TTLMonitor.
+ */
+class TTLMonitorService : public ReplicaSetAwareService<TTLMonitorService> {
+public:
+ static TTLMonitorService* get(ServiceContext* serviceContext);
+ TTLMonitorService() = default;
+
+private:
+ void onStartup(OperationContext* opCtx) override {}
+ void onInitialDataAvailable(OperationContext* opCtx, bool isMajorityDataAvailable) override {}
+ void onShutdown() override {}
+ void onStepUpBegin(OperationContext* opCtx, long long term) override {}
+ void onStepUpComplete(OperationContext* opCtx, long long term) override {
+ auto ttlMonitor = TTLMonitor::get(opCtx->getServiceContext());
+ if (!ttlMonitor) {
+ // Some test fixtures might not install the TTLMonitor.
+ return;
+ }
+ ttlMonitor->onStepUp(opCtx);
+ }
+ void onStepDown() override {}
+ void onBecomeArbiter() override {}
+};
+
+const auto _ttlMonitorService = ServiceContext::declareDecoration<TTLMonitorService>();
+
+const ReplicaSetAwareServiceRegistry::Registerer<TTLMonitorService> _ttlMonitorServiceRegisterer(
+ "TTLMonitorService");
+
+// static
+TTLMonitorService* TTLMonitorService::get(ServiceContext* serviceContext) {
+ return &_ttlMonitorService(serviceContext);
+}
+
+} // namespace
+
} // namespace mongo