Skip to content

Commit 0276874

Browse files
Will Wangmeta-codesync[bot]
authored andcommitted
Register RateLimitRoute
Summary: `RateLimitRoute` already existed and worked as an mcrouter route handle; the capability was simply missing from the Carbon-generated `BigCacheRouterInfo` route-handle map. BigCache therefore could not construct a config that named it: parsing threw `Unknown RouteHandle: RateLimitRoute`, and the uncaught exception in `createRaw()` could crash RevProxy workers. This diff plugs that registration gap through constrained factory overloads, the `BigCache.idl` opt-in, and regenerated Carbon output. It changes no routing or wire semantics and follows code-before-config ordering, so it is inert on land until a BigCache config activates the route. `IsRouterInfo<T>` detects at compile time whether `T` exposes `RouteHandleIf`, `RouteHandlePtr`, and `RoutableRequests`. This change implements concept, which allows the new `RouterInfo` overload, constrained to `IsRouterInfo<T>`, only unwraps `RouterInfo::RouteHandleIf` and delegates to that implementation without duplicating logic. Reviewed By: lenar-f Differential Revision: D114367253 fbshipit-source-id: 3a6cf45696a638fc2cce059392418438f20f1dd5
1 parent 5a73a9b commit 0276874

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

mcrouter/routes/RateLimitRoute.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ class RouteHandleFactory;
2727

2828
namespace mcrouter {
2929

30+
namespace detail {
31+
32+
template <class T>
33+
concept RouterInfoLike = requires {
34+
typename T::RouteHandleIf;
35+
typename T::RouteHandlePtr;
36+
typename T::RoutableRequests;
37+
};
38+
39+
} // namespace detail
40+
3041
/**
3142
* Requests sent through this route will be rate limited according
3243
* to settings in the RateLimiter passed to the constructor.
@@ -87,6 +98,7 @@ std::shared_ptr<RouteHandleIf> createRateLimitRoute(
8798
}
8899

89100
template <class RouteHandleIf>
101+
requires(!detail::RouterInfoLike<RouteHandleIf>)
90102
std::shared_ptr<RouteHandleIf> makeRateLimitRoute(
91103
RouteHandleFactory<RouteHandleIf>& factory,
92104
const folly::dynamic& json) {
@@ -107,6 +119,13 @@ std::shared_ptr<RouteHandleIf> makeRateLimitRoute(
107119
std::move(target), RateLimiter(*jrates), std::move(fallback));
108120
}
109121

122+
template <detail::RouterInfoLike RouterInfo>
123+
typename RouterInfo::RouteHandlePtr makeRateLimitRoute(
124+
RouteHandleFactory<typename RouterInfo::RouteHandleIf>& factory,
125+
const folly::dynamic& json) {
126+
return makeRateLimitRoute<typename RouterInfo::RouteHandleIf>(factory, json);
127+
}
128+
110129
} // namespace mcrouter
111130
} // namespace memcache
112131
} // namespace facebook

0 commit comments

Comments
 (0)