Skip to content

Commit

Permalink
Split McRouteHandleProvider.cpp to speed up compile time
Browse files Browse the repository at this point in the history
Summary: Split McRouteHandleProvider.cpp to speed up compile time

Reviewed By: danobi

Differential Revision: D26886048

fbshipit-source-id: 8af5f4196f5e178c7145d530f1a9832e534770f6
  • Loading branch information
dmm-fb authored and facebook-github-bot committed Mar 15, 2021
1 parent 99133d2 commit a3d9640
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 126 deletions.
4 changes: 4 additions & 0 deletions mcrouter/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ libmcroutercore_a_SOURCES = \
routes/McExtraRouteHandleProvider.h \
routes/McImportResolver.cpp \
routes/McImportResolver.h \
routes/McRouteBuildRouteMap0.cpp \
routes/McRouteBuildRouteMap1.cpp \
routes/McRouteBuildRouteMap2.cpp \
routes/McRouteBuildRouteMap3.cpp \
routes/McRouteHandleBuilder.h \
routes/McRouteHandleProvider-inl.h \
routes/McRouteHandleProvider.cpp \
Expand Down
86 changes: 86 additions & 0 deletions mcrouter/routes/McRouteBuildRouteMap0.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "mcrouter/routes/McRouteHandleProvider.h"

#include "mcrouter/routes/AllAsyncRouteFactory.h"
#include "mcrouter/routes/AllFastestRouteFactory.h"
#include "mcrouter/routes/AllInitialRouteFactory.h"
#include "mcrouter/routes/AllMajorityRouteFactory.h"
#include "mcrouter/routes/AllSyncRouteFactory.h"
#include "mcrouter/routes/BlackholeRoute.h"
#include "mcrouter/routes/CarbonLookasideRoute.h"

namespace facebook {
namespace memcache {
namespace mcrouter {

using McRouteHandleFactory = RouteHandleFactory<McrouterRouteHandleIf>;
using MemcacheRouterInfo = facebook::memcache::MemcacheRouterInfo;

/**
* This implementation is only for test purposes. Typically the users of
* CarbonLookaside will be services other than memcache.
*/
class MemcacheCarbonLookasideHelper {
public:
MemcacheCarbonLookasideHelper(const folly::dynamic* /* jsonConfig */) {}

static std::string name() {
return "MemcacheCarbonLookasideHelper";
}

template <typename Request>
bool cacheCandidate(const Request& /* unused */) const {
if (HasKeyTrait<Request>::value) {
return true;
}
return false;
}

template <typename Request>
std::string buildKey(const Request& req) const {
if (HasKeyTrait<Request>::value) {
return req.key_ref()->fullKey().str();
}
return std::string();
}

template <typename Reply>
bool shouldCacheReply(const Reply& /* unused */) const {
return true;
}

template <typename Reply>
void postProcessCachedReply(Reply& /* reply */) const {}
};

template <>
void McRouteHandleProvider<MemcacheRouterInfo>::buildRouteMap0(
RouteHandleFactoryMap& map) {
map.insert(
std::make_pair("AllAsyncRoute", &makeAllAsyncRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"AllFastestRoute", &makeAllFastestRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"AllInitialRoute", &makeAllInitialRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"AllMajorityRoute", &makeAllMajorityRoute<MemcacheRouterInfo>));
map.insert(
std::make_pair("AllSyncRoute", &makeAllSyncRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"BlackholeRoute", &makeBlackholeRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"CarbonLookasideRoute",
&createCarbonLookasideRoute<
MemcacheRouterInfo,
MemcacheCarbonLookasideHelper>));
}

} // namespace mcrouter
} // namespace memcache
} // namespace facebook
50 changes: 50 additions & 0 deletions mcrouter/routes/McRouteBuildRouteMap1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "mcrouter/routes/McRouteHandleProvider.h"

#include "mcrouter/routes/DevNullRoute.h"
#include "mcrouter/routes/ErrorRoute.h"
#include "mcrouter/routes/FailoverRoute.h"
#include "mcrouter/routes/FailoverWithExptimeRouteFactory.h"
#include "mcrouter/routes/HashRouteFactory.h"
#include "mcrouter/routes/HostIdRouteFactory.h"
#include "mcrouter/routes/L1L2CacheRouteFactory.h"
#include "mcrouter/routes/LatencyInjectionRoute.h"

namespace facebook {
namespace memcache {
namespace mcrouter {

using McRouteHandleFactory = RouteHandleFactory<McrouterRouteHandleIf>;
using MemcacheRouterInfo = facebook::memcache::MemcacheRouterInfo;

template <>
void McRouteHandleProvider<MemcacheRouterInfo>::buildRouteMap1(
RouteHandleFactoryMap& map) {
map.insert(
std::make_pair("DevNullRoute", &makeDevNullRoute<MemcacheRouterInfo>));
map.insert(std::make_pair("ErrorRoute", &makeErrorRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"FailoverWithExptimeRoute",
&makeFailoverWithExptimeRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"HashRoute",
[](McRouteHandleFactory& factory, const folly::dynamic& json) {
return makeHashRoute<McrouterRouterInfo>(factory, json);
}));
map.insert(
std::make_pair("HostIdRoute", &makeHostIdRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"LatencyInjectionRoute", &makeLatencyInjectionRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"L1L2CacheRoute", &makeL1L2CacheRoute<MemcacheRouterInfo>));
}

} // namespace mcrouter
} // namespace memcache
} // namespace facebook
44 changes: 44 additions & 0 deletions mcrouter/routes/McRouteBuildRouteMap2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "mcrouter/routes/McRouteHandleProvider.h"

#include "mcrouter/routes/KeySplitRoute.h"
#include "mcrouter/routes/L1L2SizeSplitRoute.h"
#include "mcrouter/routes/LatestRoute.h"
#include "mcrouter/routes/LoadBalancerRoute.h"
#include "mcrouter/routes/LoggingRoute.h"
#include "mcrouter/routes/MigrateRouteFactory.h"
#include "mcrouter/routes/MissFailoverRoute.h"

namespace facebook {
namespace memcache {
namespace mcrouter {

using McRouteHandleFactory = RouteHandleFactory<McrouterRouteHandleIf>;
using MemcacheRouterInfo = facebook::memcache::MemcacheRouterInfo;

template <>
void McRouteHandleProvider<MemcacheRouterInfo>::buildRouteMap2(
RouteHandleFactoryMap& map) {
map.insert(std::make_pair("L1L2SizeSplitRoute", &makeL1L2SizeSplitRoute));
map.insert(std::make_pair("KeySplitRoute", &makeKeySplitRoute));
map.insert(
std::make_pair("LatestRoute", &makeLatestRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"LoadBalancerRoute", &makeLoadBalancerRoute<MemcacheRouterInfo>));
map.insert(
std::make_pair("LoggingRoute", &makeLoggingRoute<MemcacheRouterInfo>));
map.insert(
std::make_pair("MigrateRoute", &makeMigrateRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"MissFailoverRoute", &makeMissFailoverRoute<MemcacheRouterInfo>));
}

} // namespace mcrouter
} // namespace memcache
} // namespace facebook
72 changes: 72 additions & 0 deletions mcrouter/routes/McRouteBuildRouteMap3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "mcrouter/routes/McRouteHandleProvider.h"

#include "mcrouter/routes/ModifyExptimeRoute.h"
#include "mcrouter/routes/ModifyKeyRoute.h"
#include "mcrouter/routes/OperationSelectorRoute.h"
#include "mcrouter/routes/OriginalClientHashRoute.h"
#include "mcrouter/routes/RandomRouteFactory.h"
#include "mcrouter/routes/RoutingGroupRoute.h"
#include "mcrouter/routes/ShadowRoute.h"
#include "mcrouter/routes/StagingRoute.h"

namespace facebook {
namespace memcache {
namespace mcrouter {

using McRouteHandleFactory = RouteHandleFactory<McrouterRouteHandleIf>;
using MemcacheRouterInfo = facebook::memcache::MemcacheRouterInfo;

McrouterRouteHandlePtr makeWarmUpRoute(
McRouteHandleFactory& factory,
const folly::dynamic& json);

template <>
void McRouteHandleProvider<MemcacheRouterInfo>::buildRouteMap3(
RouteHandleFactoryMap& map) {
map.insert(std::make_pair(
"ModifyKeyRoute", &makeModifyKeyRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"ModifyExptimeRoute", &makeModifyExptimeRoute<MemcacheRouterInfo>));
map.insert(
std::make_pair("NullRoute", &makeNullRoute<MemcacheRouteHandleIf>));
map.insert(std::make_pair(
"OperationSelectorRoute",
&makeOperationSelectorRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"OriginalClientHashRoute",
&makeOriginalClientHashRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"PoolRoute",
[this](McRouteHandleFactory& factory, const folly::dynamic& json) {
return makePoolRoute(factory, json);
}));
map.insert(std::make_pair(
"PrefixPolicyRoute", &makeOperationSelectorRoute<MemcacheRouterInfo>));
map.insert(
std::make_pair("RandomRoute", &makeRandomRoute<MemcacheRouterInfo>));
map.insert(std::make_pair(
"RateLimitRoute",
[](McRouteHandleFactory& factory, const folly::dynamic& json) {
return makeRateLimitRoute(factory, json);
}));
map.insert(std::make_pair(
"RoutingGroupRoute", &makeRoutingGroupRoute<MemcacheRouterInfo>));
map.insert(std::make_pair("StagingRoute", &makeStagingRoute));
map.insert(std::make_pair(
"SRRoute",
[this](McRouteHandleFactory& factory, const folly::dynamic& json) {
return createSRRoute(factory, json);
}));
map.insert(std::make_pair("WarmUpRoute", &makeWarmUpRoute));
}

} // namespace mcrouter
} // namespace memcache
} // namespace facebook
Loading

0 comments on commit a3d9640

Please sign in to comment.