diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2020-12-09 19:35:14 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-09 22:18:59 +0000 |
commit | c8520d84cc7356d1a30858092ee79de4dd6dc163 (patch) | |
tree | 84217bf67d7fa39a030866c9c32e08118158431c | |
parent | c7692fcb55476c5b7d1f17f10662935255637012 (diff) | |
download | mongo-c8520d84cc7356d1a30858092ee79de4dd6dc163.tar.gz |
SERVER-53305 Control AsyncRequestExecutor via ConstructorDestructorActions
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 5 | ||||
-rw-r--r-- | src/mongo/executor/async_request_executor.cpp | 5 | ||||
-rw-r--r-- | src/mongo/executor/async_request_executor.h | 10 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_build_info.cpp | 5 |
4 files changed, 22 insertions, 3 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 45374194a62..16db3845ebb 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -867,6 +867,11 @@ BuildInfoExecutor* BuildInfoExecutor::get(ServiceContext* svc) { return const_cast<BuildInfoExecutor*>(&getBuildInfoExecutor(svc)); } +const auto buildInfoExecutorRegisterer = ServiceContext::ConstructorActionRegisterer{ + "BuildInfoExecutor", + [](ServiceContext* ctx) { getBuildInfoExecutor(ctx).start(); }, + [](ServiceContext* ctx) { getBuildInfoExecutor(ctx).stop(); }}; + class CmdBuildInfo : public BasicCommand { public: CmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {} diff --git a/src/mongo/executor/async_request_executor.cpp b/src/mongo/executor/async_request_executor.cpp index cf535e864f6..93b7867f262 100644 --- a/src/mongo/executor/async_request_executor.cpp +++ b/src/mongo/executor/async_request_executor.cpp @@ -46,12 +46,15 @@ AsyncRequestExecutor::AsyncRequestExecutor(std::string name) : _name(std::move(n options.minThreads = 0; options.maxThreads = 1; _pool = std::make_unique<ThreadPool>(std::move(options)); +} + +void AsyncRequestExecutor::start() { _pool->startup(); LOGV2_DEBUG( 4910801, kDiagnosticLogLevel, "Started asynchronous request executor", "name"_attr = _name); } -AsyncRequestExecutor::~AsyncRequestExecutor() { +void AsyncRequestExecutor::stop() { _pool->shutdown(); _pool->join(); LOGV2_DEBUG( diff --git a/src/mongo/executor/async_request_executor.h b/src/mongo/executor/async_request_executor.h index a54e7848392..7a7f2f62cac 100644 --- a/src/mongo/executor/async_request_executor.h +++ b/src/mongo/executor/async_request_executor.h @@ -49,7 +49,13 @@ public: AsyncRequestExecutor(const AsyncRequestExecutor&) = delete; explicit AsyncRequestExecutor(std::string name); - ~AsyncRequestExecutor(); + + /** + * Wrap the startup and shutdown interfaces provided by `_pool` and delegate the concurrency + * control to corresponding member functions of `ThreadPool`. + */ + void start(); + void stop(); /** * Runs the command-specific code to handle the request. @@ -59,7 +65,7 @@ public: /** * Schedules the request on a thread pool (i.e., `_pool`) and calls into `handleRequest` to - * asynchronously execute the command. + * asynchronously execute the command. Note that the scheduled tasks run inline during shutdown. */ Future<void> schedule(std::shared_ptr<RequestExecutionContext> rec); diff --git a/src/mongo/s/commands/cluster_build_info.cpp b/src/mongo/s/commands/cluster_build_info.cpp index f5878c1bed6..0cf74905f7b 100644 --- a/src/mongo/s/commands/cluster_build_info.cpp +++ b/src/mongo/s/commands/cluster_build_info.cpp @@ -59,6 +59,11 @@ ClusterBuildInfoExecutor* ClusterBuildInfoExecutor::get(ServiceContext* svc) { return const_cast<ClusterBuildInfoExecutor*>(&getClusterBuildInfoExecutor(svc)); } +const auto clusterBuildInfoExecutorRegisterer = ServiceContext::ConstructorActionRegisterer{ + "ClusterBuildInfoExecutor", + [](ServiceContext* ctx) { getClusterBuildInfoExecutor(ctx).start(); }, + [](ServiceContext* ctx) { getClusterBuildInfoExecutor(ctx).stop(); }}; + class ClusterCmdBuildInfo : public BasicCommand { public: ClusterCmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {} |