From 665e3182a6d616f1b54cd89766ee001294e1476d Mon Sep 17 00:00:00 2001 From: Giuseppe Ottaviano Date: Mon, 18 Dec 2023 17:10:03 -0800 Subject: [PATCH] Accept IOThreadPoolExecutorBase Summary: Accept the base class instead of IOThreadPoolExecutor so we can experiment with other implementations. Reviewed By: stuclar Differential Revision: D52163795 fbshipit-source-id: b960d44c9bbb9be848dfb975a68e49128a0d51a9 --- mcrouter/CarbonRouterInstance-inl.h | 6 +++--- mcrouter/CarbonRouterInstance.h | 12 ++++++------ mcrouter/McrouterManager.h | 2 +- mcrouter/Server-inl.h | 4 ++-- mcrouter/TargetHooks.h | 4 ++-- mcrouter/lib/AuxiliaryIOThreadPool.cpp | 2 +- mcrouter/lib/AuxiliaryIOThreadPool.h | 4 ++-- .../carbon/connection/InternalCarbonConnectionImpl.h | 2 +- mcrouter/lib/network/test/MockMcServerDual.cpp | 2 +- mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mcrouter/CarbonRouterInstance-inl.h b/mcrouter/CarbonRouterInstance-inl.h index bffa1a706..3e1f65856 100644 --- a/mcrouter/CarbonRouterInstance-inl.h +++ b/mcrouter/CarbonRouterInstance-inl.h @@ -62,7 +62,7 @@ template CarbonRouterInstance::init( folly::StringPiece persistenceId, const McrouterOptions& options, - std::shared_ptr ioThreadPool) { + std::shared_ptr ioThreadPool) { if (auto manager = detail::McrouterManager::getSingletonInstance()) { return manager->mcrouterGetCreate( persistenceId, options, ioThreadPool); @@ -90,7 +90,7 @@ bool CarbonRouterInstance::hasInstance( template CarbonRouterInstance* CarbonRouterInstance::createRaw( McrouterOptions input_options, - std::shared_ptr ioThreadPool) { + std::shared_ptr ioThreadPool) { extraValidateOptions(input_options); folly::Executor::KeepAlive<> auxThreadPool; if (auto threadPool = AuxiliaryCPUThreadPoolSingleton::try_get()) { @@ -170,7 +170,7 @@ template std::shared_ptr> CarbonRouterInstance::create( McrouterOptions input_options, - std::shared_ptr ioThreadPool) { + std::shared_ptr ioThreadPool) { return folly::fibers::runInMainContext([&]() mutable { return std::shared_ptr>( createRaw(std::move(input_options), std::move(ioThreadPool)), diff --git a/mcrouter/CarbonRouterInstance.h b/mcrouter/CarbonRouterInstance.h index fbd6facb1..50ec8f619 100644 --- a/mcrouter/CarbonRouterInstance.h +++ b/mcrouter/CarbonRouterInstance.h @@ -79,7 +79,7 @@ class CarbonRouterInstance static CarbonRouterInstance* init( folly::StringPiece persistenceId, const McrouterOptions& options, - std::shared_ptr ioThreadPool); + std::shared_ptr ioThreadPool); /** * If an instance with the given persistenceId already exists, @@ -106,7 +106,7 @@ class CarbonRouterInstance */ static std::shared_ptr> create( McrouterOptions input_options, - std::shared_ptr ioThreadPool = nullptr); + std::shared_ptr ioThreadPool = nullptr); /** * Destroys ALL active instances for ALL RouterInfos. @@ -157,11 +157,11 @@ class CarbonRouterInstance } void setIOThreadPool( - std::shared_ptr ioThreadPool) { + std::shared_ptr ioThreadPool) { proxyThreads_ = std::move(ioThreadPool); } - const folly::IOThreadPoolExecutor& getIOThreadPool() const { + const folly::IOThreadPoolExecutorBase& getIOThreadPool() const { return *proxyThreads_; } @@ -197,7 +197,7 @@ class CarbonRouterInstance */ std::vector*> proxies_; std::vector> proxyEvbs_; - std::shared_ptr proxyThreads_; + std::shared_ptr proxyThreads_; /** * Indicates if evbs/IOThreadPoolExecutor has been created by McRouter or @@ -211,7 +211,7 @@ class CarbonRouterInstance */ static CarbonRouterInstance* createRaw( McrouterOptions input_options, - std::shared_ptr ioThreadPool = nullptr); + std::shared_ptr ioThreadPool = nullptr); explicit CarbonRouterInstance(McrouterOptions input_options); diff --git a/mcrouter/McrouterManager.h b/mcrouter/McrouterManager.h index 4daed3d38..f4a75aa02 100644 --- a/mcrouter/McrouterManager.h +++ b/mcrouter/McrouterManager.h @@ -34,7 +34,7 @@ class McrouterManager { CarbonRouterInstance* mcrouterGetCreate( folly::StringPiece persistenceId, const McrouterOptions& options, - std::shared_ptr ioThreadPool = nullptr) { + std::shared_ptr ioThreadPool = nullptr) { std::shared_ptr mcrouterBase; { diff --git a/mcrouter/Server-inl.h b/mcrouter/Server-inl.h index db877d630..b686c3769 100644 --- a/mcrouter/Server-inl.h +++ b/mcrouter/Server-inl.h @@ -292,7 +292,7 @@ bool runServerDual( const McrouterStandaloneOptions& standaloneOpts, StandalonePreRunCb preRunCb) { using RequestHandlerType = RequestHandler>; - std::shared_ptr ioThreadPool; + std::shared_ptr ioThreadPool; CarbonRouterInstance* router; std::shared_ptr asyncMcServer; std::shared_ptr thriftServer; @@ -496,7 +496,7 @@ bool runServer( AsyncMcServer::Options opts = detail::createAsyncMcServerOptions(mcrouterOpts, standaloneOpts); - std::shared_ptr ioThreadPool; + std::shared_ptr ioThreadPool; CarbonRouterInstance* router = nullptr; std::shared_ptr asyncMcServer; try { diff --git a/mcrouter/TargetHooks.h b/mcrouter/TargetHooks.h index d2daa3374..396a37982 100644 --- a/mcrouter/TargetHooks.h +++ b/mcrouter/TargetHooks.h @@ -19,13 +19,13 @@ namespace mcrouter { * SR factory init hook */ FOLLY_ATTR_WEAK std::shared_ptr gSRInitHook( - std::shared_ptr, + std::shared_ptr, const std::string& /* threadPrefix */, const McrouterOptions&); FOLLY_ATTR_WEAK void gAxonInitHook( CarbonRouterInstanceBase& router, - std::shared_ptr ioThreadPool, + std::shared_ptr ioThreadPool, const std::string& threadPrefix); } // namespace mcrouter diff --git a/mcrouter/lib/AuxiliaryIOThreadPool.cpp b/mcrouter/lib/AuxiliaryIOThreadPool.cpp index 668f1b3ba..6cdbee263 100644 --- a/mcrouter/lib/AuxiliaryIOThreadPool.cpp +++ b/mcrouter/lib/AuxiliaryIOThreadPool.cpp @@ -19,7 +19,7 @@ namespace { folly::Singleton gAuxiliaryIOThreadPool; } // namespace -folly::IOThreadPoolExecutor& AuxiliaryIOThreadPool::getThreadPool() { +folly::IOThreadPoolExecutorBase& AuxiliaryIOThreadPool::getThreadPool() { folly::call_once(initFlag_, [&] { threadPool_ = std::make_unique( kNumIOThreads, diff --git a/mcrouter/lib/AuxiliaryIOThreadPool.h b/mcrouter/lib/AuxiliaryIOThreadPool.h index 23537263d..d6e9063e1 100644 --- a/mcrouter/lib/AuxiliaryIOThreadPool.h +++ b/mcrouter/lib/AuxiliaryIOThreadPool.h @@ -23,10 +23,10 @@ namespace mcrouter { */ class AuxiliaryIOThreadPool { public: - folly::IOThreadPoolExecutor& getThreadPool(); + folly::IOThreadPoolExecutorBase& getThreadPool(); private: - std::unique_ptr threadPool_; + std::unique_ptr threadPool_; folly::once_flag initFlag_; }; diff --git a/mcrouter/lib/carbon/connection/InternalCarbonConnectionImpl.h b/mcrouter/lib/carbon/connection/InternalCarbonConnectionImpl.h index 9926a0dd9..2e4835630 100644 --- a/mcrouter/lib/carbon/connection/InternalCarbonConnectionImpl.h +++ b/mcrouter/lib/carbon/connection/InternalCarbonConnectionImpl.h @@ -23,7 +23,7 @@ struct InternalCarbonConnectionOptions { InternalCarbonConnectionOptions() = default; size_t maxOutstanding{1024}; size_t maxOutstandingError{false}; - std::shared_ptr ioThreads{nullptr}; + std::shared_ptr ioThreads{nullptr}; }; template diff --git a/mcrouter/lib/network/test/MockMcServerDual.cpp b/mcrouter/lib/network/test/MockMcServerDual.cpp index 98915a521..21a2e4d03 100644 --- a/mcrouter/lib/network/test/MockMcServerDual.cpp +++ b/mcrouter/lib/network/test/MockMcServerDual.cpp @@ -138,7 +138,7 @@ int main(int argc, char** argv) { try { // Create IOThreadPoolExecutor and extract event bases - std::shared_ptr ioThreadPool = + std::shared_ptr ioThreadPool = std::make_shared(numThreads); auto ioThreads = mcrouter::extractEvbs(*ioThreadPool); diff --git a/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp b/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp index 13f2ca939..2c63b9355 100644 --- a/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp +++ b/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp @@ -67,7 +67,7 @@ TEST(CarbonRouterClient, basicUsageSameThreadClient) { // request-handling proxies, stats logging, and more. // Using createSameThreadClient() makes most sense in situations where the // user controls their own EventBases, as below. - std::shared_ptr ioThreadPool = + std::shared_ptr ioThreadPool = std::make_shared( opts.num_proxies, opts.num_proxies); auto router = CarbonRouterInstance::init(