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:29:44 -0400 |
commit | 98c2b9e9c05e18c3417dbfd882d7f32b81ec558e (patch) | |
tree | 3de834c7ebee867d12177d541830540002ad28d8 | |
parent | 8b07e3e7242c5048eb847105fe30a9e3ef2bb88c (diff) | |
download | mongo-98c2b9e9c05e18c3417dbfd882d7f32b81ec558e.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 0f4e332bc6f..635f13bbd19 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -1267,6 +1267,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 6622a04ad47..30d766726bf 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -170,15 +170,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) { |