Skip to content

Commit

Permalink
Accept IOThreadPoolExecutorBase
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ot authored and facebook-github-bot committed Dec 19, 2023
1 parent fbe8b8d commit 665e318
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions mcrouter/CarbonRouterInstance-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ template <class RouterInfo>
CarbonRouterInstance<RouterInfo>::init(
folly::StringPiece persistenceId,
const McrouterOptions& options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool) {
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool) {
if (auto manager = detail::McrouterManager::getSingletonInstance()) {
return manager->mcrouterGetCreate<RouterInfo>(
persistenceId, options, ioThreadPool);
Expand Down Expand Up @@ -90,7 +90,7 @@ bool CarbonRouterInstance<RouterInfo>::hasInstance(
template <class RouterInfo>
CarbonRouterInstance<RouterInfo>* CarbonRouterInstance<RouterInfo>::createRaw(
McrouterOptions input_options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool) {
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool) {
extraValidateOptions(input_options);
folly::Executor::KeepAlive<> auxThreadPool;
if (auto threadPool = AuxiliaryCPUThreadPoolSingleton::try_get()) {
Expand Down Expand Up @@ -170,7 +170,7 @@ template <class RouterInfo>
std::shared_ptr<CarbonRouterInstance<RouterInfo>>
CarbonRouterInstance<RouterInfo>::create(
McrouterOptions input_options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool) {
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool) {
return folly::fibers::runInMainContext([&]() mutable {
return std::shared_ptr<CarbonRouterInstance<RouterInfo>>(
createRaw(std::move(input_options), std::move(ioThreadPool)),
Expand Down
12 changes: 6 additions & 6 deletions mcrouter/CarbonRouterInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CarbonRouterInstance
static CarbonRouterInstance<RouterInfo>* init(
folly::StringPiece persistenceId,
const McrouterOptions& options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool);
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool);

/**
* If an instance with the given persistenceId already exists,
Expand All @@ -106,7 +106,7 @@ class CarbonRouterInstance
*/
static std::shared_ptr<CarbonRouterInstance<RouterInfo>> create(
McrouterOptions input_options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool = nullptr);
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool = nullptr);

/**
* Destroys ALL active instances for ALL RouterInfos.
Expand Down Expand Up @@ -157,11 +157,11 @@ class CarbonRouterInstance
}

void setIOThreadPool(
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool) {
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool) {
proxyThreads_ = std::move(ioThreadPool);
}

const folly::IOThreadPoolExecutor& getIOThreadPool() const {
const folly::IOThreadPoolExecutorBase& getIOThreadPool() const {
return *proxyThreads_;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class CarbonRouterInstance
*/
std::vector<Proxy<RouterInfo>*> proxies_;
std::vector<std::unique_ptr<folly::VirtualEventBase>> proxyEvbs_;
std::shared_ptr<folly::IOThreadPoolExecutor> proxyThreads_;
std::shared_ptr<folly::IOThreadPoolExecutorBase> proxyThreads_;

/**
* Indicates if evbs/IOThreadPoolExecutor has been created by McRouter or
Expand All @@ -211,7 +211,7 @@ class CarbonRouterInstance
*/
static CarbonRouterInstance<RouterInfo>* createRaw(
McrouterOptions input_options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool = nullptr);
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool = nullptr);

explicit CarbonRouterInstance(McrouterOptions input_options);

Expand Down
2 changes: 1 addition & 1 deletion mcrouter/McrouterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class McrouterManager {
CarbonRouterInstance<RouterInfo>* mcrouterGetCreate(
folly::StringPiece persistenceId,
const McrouterOptions& options,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool = nullptr) {
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool = nullptr) {
std::shared_ptr<CarbonRouterInstanceBase> mcrouterBase;

{
Expand Down
4 changes: 2 additions & 2 deletions mcrouter/Server-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ bool runServerDual(
const McrouterStandaloneOptions& standaloneOpts,
StandalonePreRunCb preRunCb) {
using RequestHandlerType = RequestHandler<ServerOnRequest<RouterInfo>>;
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool;
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool;
CarbonRouterInstance<RouterInfo>* router;
std::shared_ptr<AsyncMcServer> asyncMcServer;
std::shared_ptr<apache::thrift::ThriftServer> thriftServer;
Expand Down Expand Up @@ -496,7 +496,7 @@ bool runServer(
AsyncMcServer::Options opts =
detail::createAsyncMcServerOptions(mcrouterOpts, standaloneOpts);

std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool;
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool;
CarbonRouterInstance<RouterInfo>* router = nullptr;
std::shared_ptr<AsyncMcServer> asyncMcServer;
try {
Expand Down
4 changes: 2 additions & 2 deletions mcrouter/TargetHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ namespace mcrouter {
* SR factory init hook
*/
FOLLY_ATTR_WEAK std::shared_ptr<void> gSRInitHook(
std::shared_ptr<folly::IOThreadPoolExecutor>,
std::shared_ptr<folly::IOThreadPoolExecutorBase>,
const std::string& /* threadPrefix */,
const McrouterOptions&);

FOLLY_ATTR_WEAK void gAxonInitHook(
CarbonRouterInstanceBase& router,
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool,
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool,
const std::string& threadPrefix);

} // namespace mcrouter
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/lib/AuxiliaryIOThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace {
folly::Singleton<AuxiliaryIOThreadPool> gAuxiliaryIOThreadPool;
} // namespace

folly::IOThreadPoolExecutor& AuxiliaryIOThreadPool::getThreadPool() {
folly::IOThreadPoolExecutorBase& AuxiliaryIOThreadPool::getThreadPool() {
folly::call_once(initFlag_, [&] {
threadPool_ = std::make_unique<folly::IOThreadPoolExecutor>(
kNumIOThreads,
Expand Down
4 changes: 2 additions & 2 deletions mcrouter/lib/AuxiliaryIOThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace mcrouter {
*/
class AuxiliaryIOThreadPool {
public:
folly::IOThreadPoolExecutor& getThreadPool();
folly::IOThreadPoolExecutorBase& getThreadPool();

private:
std::unique_ptr<folly::IOThreadPoolExecutor> threadPool_;
std::unique_ptr<folly::IOThreadPoolExecutorBase> threadPool_;
folly::once_flag initFlag_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct InternalCarbonConnectionOptions {
InternalCarbonConnectionOptions() = default;
size_t maxOutstanding{1024};
size_t maxOutstandingError{false};
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreads{nullptr};
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreads{nullptr};
};

template <class If>
Expand Down
2 changes: 1 addition & 1 deletion mcrouter/lib/network/test/MockMcServerDual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char** argv) {

try {
// Create IOThreadPoolExecutor and extract event bases
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool =
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool =
std::make_shared<folly::IOThreadPoolExecutor>(numThreads);
auto ioThreads = mcrouter::extractEvbs(*ioThreadPool);

Expand Down
2 changes: 1 addition & 1 deletion mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<folly::IOThreadPoolExecutor> ioThreadPool =
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool =
std::make_shared<folly::IOThreadPoolExecutor>(
opts.num_proxies, opts.num_proxies);
auto router = CarbonRouterInstance<MemcacheRouterInfo>::init(
Expand Down

0 comments on commit 665e318

Please sign in to comment.