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-10-10 21:37:56 +0000
commit949beadb40c670e6b7d1ac66dcac17916e51725a (patch)
treeed23c2449c07a8e3d65a1c839c2d760d3419eeee
parentba31c2d4c78fe0f0261b0b82c259e511dce9447c (diff)
downloadmongo-949beadb40c670e6b7d1ac66dcac17916e51725a.tar.gz
SERVER-68477 add TTLMonitor::onStepUp()
(cherry picked from commit 3b17e5f7916fdf1a21dd162a079aeb9d06ca9425) (cherry picked from commit 02a6f50be29f295d36a8c86f1e3f6c21587bb04d)
-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 415d6edeabf..b56f2898980 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1144,6 +1144,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/idl/server_parameter',
'catalog/database_holder',
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index 241c9b5002e..c682282100f 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -50,6 +50,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/service_context.h"
@@ -171,6 +172,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.
@@ -535,4 +541,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