diff options
author | Suganthi Mani <suganthi.mani@mongodb.com> | 2020-09-08 23:51:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-09 05:12:40 +0000 |
commit | 36618db78d1d919595ed15493592019f89ae7920 (patch) | |
tree | d5160d70002785ed967c7f3e24413b932eebf4c9 /src/mongo | |
parent | 2bcab5793e96a6b8466b1cf8a3d7289ec4263b8d (diff) | |
download | mongo-36618db78d1d919595ed15493592019f89ae7920.tar.gz |
SERVER-50740 Add onShutdown() method to ReplicaSetAwareInterface class.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/primary_only_service.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/repl/primary_only_service.h | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/primary_only_service_test.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/replica_set_aware_service.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/replica_set_aware_service.h | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/replica_set_aware_service_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer.h | 1 | ||||
-rw-r--r-- | src/mongo/db/vector_clock_mongod.cpp | 1 |
11 files changed, 34 insertions, 18 deletions
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index 093bb83eb18..8e69eea713a 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -1111,10 +1111,6 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { LOGV2_OPTIONS(4784902, {LogComponent::kSharding}, "Shutting down the WaitForMajorityService"); WaitForMajorityService::get(serviceContext).shutDown(); - LOGV2_OPTIONS( - 5006600, {LogComponent::kReplication}, "Shutting down the PrimaryOnlyServiceRegistry"); - repl::PrimaryOnlyServiceRegistry::get(serviceContext)->shutdown(); - // Join the logical session cache before the transport layer. if (auto lsc = LogicalSessionCache::get(serviceContext)) { LOGV2(4784903, "Shutting down the LogicalSessionCache"); diff --git a/src/mongo/db/repl/primary_only_service.cpp b/src/mongo/db/repl/primary_only_service.cpp index 4be2ac36730..acf79190d1b 100644 --- a/src/mongo/db/repl/primary_only_service.cpp +++ b/src/mongo/db/repl/primary_only_service.cpp @@ -36,7 +36,9 @@ #include <utility> #include "mongo/db/auth/authorization_session.h" +#include "mongo/db/catalog_raii.h" #include "mongo/db/client.h" +#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/logical_time_metadata_hook.h" #include "mongo/db/ops/write_ops.h" @@ -195,6 +197,12 @@ void PrimaryOnlyServiceRegistry::onStartup(OperationContext* opCtx) { } } +void PrimaryOnlyServiceRegistry::onShutdown() { + for (auto& service : _servicesByName) { + service.second->shutdown(); + } +} + void PrimaryOnlyServiceRegistry::onStepUpComplete(OperationContext* opCtx, long long term) { auto replCoord = ReplicationCoordinator::get(opCtx); @@ -219,12 +227,6 @@ void PrimaryOnlyServiceRegistry::onStepDown() { } } -void PrimaryOnlyServiceRegistry::shutdown() { - for (auto& service : _servicesByName) { - service.second->shutdown(); - } -} - PrimaryOnlyService::PrimaryOnlyService(ServiceContext* serviceContext) : _serviceContext(serviceContext) {} diff --git a/src/mongo/db/repl/primary_only_service.h b/src/mongo/db/repl/primary_only_service.h index 791426a432f..0d57cf96d9b 100644 --- a/src/mongo/db/repl/primary_only_service.h +++ b/src/mongo/db/repl/primary_only_service.h @@ -328,12 +328,8 @@ public: */ PrimaryOnlyService* lookupServiceByNamespace(const NamespaceString& ns); - /** - * Shuts down all registered services. - */ - void shutdown(); - void onStartup(OperationContext*) final; + void onShutdown() final; void onStepUpBegin(OperationContext*, long long term) final {} void onBecomeArbiter() final {} void onStepUpComplete(OperationContext*, long long term) final; diff --git a/src/mongo/db/repl/primary_only_service_test.cpp b/src/mongo/db/repl/primary_only_service_test.cpp index bb75b4f8ba1..d89005e8b1d 100644 --- a/src/mongo/db/repl/primary_only_service_test.cpp +++ b/src/mongo/db/repl/primary_only_service_test.cpp @@ -248,7 +248,7 @@ public: _testExecutor->join(); _testExecutor.reset(); - _registry->shutdown(); + _registry->onShutdown(); _service = nullptr; ServiceContextMongoDTest::tearDown(); @@ -310,7 +310,7 @@ DEATH_TEST_F(PrimaryOnlyServiceTest, } TEST_F(PrimaryOnlyServiceTest, StepUpAfterShutdown) { - _registry->shutdown(); + _registry->onShutdown(); stepUp(); } diff --git a/src/mongo/db/repl/replica_set_aware_service.cpp b/src/mongo/db/repl/replica_set_aware_service.cpp index 056ec48d1b4..cb925e58ced 100644 --- a/src/mongo/db/repl/replica_set_aware_service.cpp +++ b/src/mongo/db/repl/replica_set_aware_service.cpp @@ -56,6 +56,12 @@ void ReplicaSetAwareServiceRegistry::onStartup(OperationContext* opCtx) { }); } +void ReplicaSetAwareServiceRegistry::onShutdown() { + std::for_each(_services.begin(), _services.end(), [&](ReplicaSetAwareInterface* service) { + service->onShutdown(); + }); +} + void ReplicaSetAwareServiceRegistry::onStepUpBegin(OperationContext* opCtx, long long term) { std::for_each(_services.begin(), _services.end(), [&](ReplicaSetAwareInterface* service) { service->onStepUpBegin(opCtx, term); diff --git a/src/mongo/db/repl/replica_set_aware_service.h b/src/mongo/db/repl/replica_set_aware_service.h index df0ad747296..eb38cac0252 100644 --- a/src/mongo/db/repl/replica_set_aware_service.h +++ b/src/mongo/db/repl/replica_set_aware_service.h @@ -75,6 +75,9 @@ namespace mongo { * void onStartup(OperationContext* opCtx) final { * // ... * } + * void onShutdown() final { + * // ... + * } * void onStepUpBegin(OperationContext* opCtx) final { * // ... * } @@ -115,6 +118,11 @@ public: virtual void onStartup(OperationContext* opCtx) = 0; /** + * Called as part of ReplicationCoordinator shutdown. + */ + virtual void onShutdown() = 0; + + /** * Called prior to stepping up as PRIMARY, i.e. after drain mode has completed. */ virtual void onStepUpBegin(OperationContext* opCtx, long long term) = 0; @@ -182,6 +190,7 @@ public: static ReplicaSetAwareServiceRegistry& get(ServiceContext* serviceContext); void onStartup(OperationContext* opCtx) final; + void onShutdown() final; void onStepUpBegin(OperationContext* opCtx, long long term) final; void onStepUpComplete(OperationContext* opCtx, long long term) final; void onStepDown() final; diff --git a/src/mongo/db/repl/replica_set_aware_service_test.cpp b/src/mongo/db/repl/replica_set_aware_service_test.cpp index f6c5d6bfeca..cd4e6697835 100644 --- a/src/mongo/db/repl/replica_set_aware_service_test.cpp +++ b/src/mongo/db/repl/replica_set_aware_service_test.cpp @@ -68,6 +68,8 @@ protected: void onBecomeArbiter() override { numCallsOnBecomeArbiter++; } + + void onShutdown() override {} }; /** diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 0d715d6a0e5..72fe1b45797 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -938,6 +938,9 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) { return; } + LOGV2_DEBUG(5074000, 1, "Shutting down the replica set aware services."); + ReplicaSetAwareServiceRegistry::get(_service).onShutdown(); + LOGV2(21328, "Shutting down replication subsystems"); // Used to shut down outside of the lock. diff --git a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp index 874f1a11a02..8e9994bd16a 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service_test.cpp @@ -92,7 +92,7 @@ public: void tearDown() override { WaitForMajorityService::get(getServiceContext()).shutDown(); - _registry->shutdown(); + _registry->onShutdown(); _service = nullptr; ServiceContextMongoDTest::tearDown(); diff --git a/src/mongo/db/s/balancer/balancer.h b/src/mongo/db/s/balancer/balancer.h index d781ae661bd..ebe79363caa 100644 --- a/src/mongo/db/s/balancer/balancer.h +++ b/src/mongo/db/s/balancer/balancer.h @@ -168,6 +168,7 @@ private: * ReplicaSetAwareService entry points. */ void onStartup(OperationContext* opCtx) final {} + void onShutdown() final {} void onStepUpBegin(OperationContext* opCtx, long long term) final; void onStepUpComplete(OperationContext* opCtx, long long term) final; void onStepDown() final; diff --git a/src/mongo/db/vector_clock_mongod.cpp b/src/mongo/db/vector_clock_mongod.cpp index b9d2d7b9ca2..7d66266aa42 100644 --- a/src/mongo/db/vector_clock_mongod.cpp +++ b/src/mongo/db/vector_clock_mongod.cpp @@ -79,6 +79,7 @@ private: // ReplicaSetAwareService methods implementation void onStartup(OperationContext* opCtx) override {} + void onShutdown() override {} void onStepUpBegin(OperationContext* opCtx, long long term) override; void onStepUpComplete(OperationContext* opCtx, long long term) override {} void onStepDown() override; |