diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-10-22 14:43:51 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2018-10-29 18:20:36 -0400 |
commit | 51ba5067d70313de211d22c1d7378024987c7908 (patch) | |
tree | 6a7c205f2f170e5bf31d4842b2e0b5cd7be9b732 | |
parent | 556d4f8b0fabeaac4958c8f6d319367c1a10b543 (diff) | |
download | mongo-51ba5067d70313de211d22c1d7378024987c7908.tar.gz |
SERVER-37496 Register balancer shutdown task when MongoD is single-threaded
(cherry picked from commit 871f1234c72f3f390f81dc31fd8a95d8bc69cf91)
-rw-r--r-- | src/mongo/db/db.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 9 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index c3721fb7413..a7ab9db34a8 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -869,6 +869,12 @@ void shutdownTask() { auto const client = Client::getCurrent(); auto const serviceContext = client->getServiceContext(); + // Terminate the balancer thread so it doesn't leak memory. + if (auto balancer = Balancer::get(serviceContext)) { + balancer->interruptBalancer(); + balancer->waitForBalancerToStop(); + } + // Shutdown the TransportLayer so that new connections aren't accepted if (auto tl = serviceContext->getTransportLayer()) { log(LogComponent::kNetwork) << "shutdown: going to close listening sockets..."; diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 4e53cf06962..d027601f284 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -168,15 +168,6 @@ Balancer::~Balancer() { void Balancer::create(ServiceContext* serviceContext) { invariant(!getBalancer(serviceContext)); getBalancer(serviceContext) = stdx::make_unique<Balancer>(serviceContext); - - // Register a shutdown task to terminate the balancer thread so that it doesn't leak memory. - registerShutdownTask([serviceContext] { - auto balancer = Balancer::get(serviceContext); - // Make sure that the balancer thread has been interrupted. - balancer->interruptBalancer(); - // Make sure the balancer thread has terminated. - balancer->waitForBalancerToStop(); - }); } Balancer* Balancer::get(ServiceContext* serviceContext) { |