Skip to content

Commit cdde342

Browse files
Xiaofei Hufacebook-github-bot
Xiaofei Hu
authored andcommittedFeb 25, 2025·
Make RouteHandleFactoryFuncForWrapper more general so we can use it to create refill RH
Summary: We are moving McRefillRoute.h to facebook/ so it can depend on UcacheRouterInfo. With that, the provider can not directly depend on McRefillRoute.h, we need to use the RouteHandleFactoryFuncForWrapper to pass in the factory function. This diff is to extend the RouteHandleFactoryFuncForWrapper to support McRefillRoute construction. Reviewed By: disylh Differential Revision: D68187767 fbshipit-source-id: c8bca9668cd66b99f20b87bd72b1a80daa4a4242
1 parent f6209b0 commit cdde342

9 files changed

+36
-18
lines changed
 

‎mcrouter/lib/carbon/example/gen/HelloGoodbyeRouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ struct HelloGoodbyeRouterInfo {
107107
std::function<RouteHandlePtr(
108108
RouteHandlePtr,
109109
facebook::memcache::mcrouter::ProxyBase&,
110-
const folly::dynamic&)>,
110+
const folly::dynamic&,
111+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
111112
folly::Hash>;
112113

113114
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/lib/carbon/test/gen/ARouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ struct ARouterInfo {
110110
std::function<RouteHandlePtr(
111111
RouteHandlePtr,
112112
facebook::memcache::mcrouter::ProxyBase&,
113-
const folly::dynamic&)>,
113+
const folly::dynamic&,
114+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
114115
folly::Hash>;
115116

116117
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/lib/carbon/test/gen/BRouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ struct BRouterInfo {
110110
std::function<RouteHandlePtr(
111111
RouteHandlePtr,
112112
facebook::memcache::mcrouter::ProxyBase&,
113-
const folly::dynamic&)>,
113+
const folly::dynamic&,
114+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
114115
folly::Hash>;
115116

116117
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/lib/carbon/test/gen/CarbonTestRouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ struct CarbonTestRouterInfo {
110110
std::function<RouteHandlePtr(
111111
RouteHandlePtr,
112112
facebook::memcache::mcrouter::ProxyBase&,
113-
const folly::dynamic&)>,
113+
const folly::dynamic&,
114+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
114115
folly::Hash>;
115116

116117
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/lib/carbon/test/gen/CarbonThriftTestRouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ struct CarbonThriftTestRouterInfo {
113113
std::function<RouteHandlePtr(
114114
RouteHandlePtr,
115115
facebook::memcache::mcrouter::ProxyBase&,
116-
const folly::dynamic&)>,
116+
const folly::dynamic&,
117+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
117118
folly::Hash>;
118119

119120
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/lib/network/gen/MemcacheRouterInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ struct MemcacheRouterInfo {
169169
std::function<RouteHandlePtr(
170170
RouteHandlePtr,
171171
facebook::memcache::mcrouter::ProxyBase&,
172-
const folly::dynamic&)>,
172+
const folly::dynamic&,
173+
facebook::memcache::RouteHandleFactory<RouteHandleIf>&)>,
173174
folly::Hash>;
174175

175176
static RouteHandleFactoryMap buildRouteMap();

‎mcrouter/routes/McRouteHandleProvider-inl.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ std::shared_ptr<typename RouterInfo::RouteHandleIf>
133133
McRouteHandleProvider<RouterInfo>::wrapAxonLogRoute(
134134
RouteHandlePtr route,
135135
ProxyBase& proxy,
136-
const folly::dynamic& json) {
136+
const folly::dynamic& json,
137+
RouteHandleFactory<RouteHandleIf>& factory) {
137138
bool needAxonlog = false;
138139
if (auto* jNeedAxonlog = json.get_ptr("axonlog")) {
139140
needAxonlog = parseBool(*jNeedAxonlog, "axonlog");
@@ -143,7 +144,7 @@ McRouteHandleProvider<RouterInfo>::wrapAxonLogRoute(
143144
checkLogic(
144145
it != routeMapForWrapper_.end(),
145146
"AxonLogRoute is not implemented for this router");
146-
return it->second(std::move(route), proxy, json);
147+
return it->second(std::move(route), proxy, json, factory);
147148
}
148149
return route;
149150
}
@@ -557,7 +558,7 @@ McRouteHandleProvider<RouterInfo>::createSRRoute(
557558
route = createAsynclogRoute(std::move(route), asynclogName.toString());
558559
}
559560

560-
route = wrapAxonLogRoute(std::move(route), proxy_, json);
561+
route = wrapAxonLogRoute(std::move(route), proxy_, json, factory);
561562

562563
if (json.count("shadows")) {
563564
route = std::move(makeShadowRoutes(
@@ -731,7 +732,7 @@ McRouteHandleProvider<RouterInfo>::makePoolRoute(
731732
}
732733
if (json.isObject()) {
733734
// Wrap AxonLogRoute if configured
734-
route = wrapAxonLogRoute(std::move(route), proxy_, json);
735+
route = wrapAxonLogRoute(std::move(route), proxy_, json, factory);
735736
route = bucketize(std::move(route), json);
736737

737738
if (auto jPoolId = json.get_ptr("pool_id")) {
@@ -844,9 +845,12 @@ McRouteHandleProvider<RouterInfo>::buildCheckedRouteMapForWrapper() {
844845
checkedRouteMapForWrapper.emplace(
845846
it.first,
846847
[factoryFunc = std::move(it.second), rhName = it.first](
847-
RouteHandlePtr rh, ProxyBase& proxy, const folly::dynamic& json) {
848+
RouteHandlePtr rh,
849+
ProxyBase& proxy,
850+
const folly::dynamic& json,
851+
RouteHandleFactory<RouteHandleIf>& factory) {
848852
try {
849-
auto ret = factoryFunc(std::move(rh), proxy, json);
853+
auto ret = factoryFunc(std::move(rh), proxy, json, factory);
850854
checkLogic(ret != nullptr, "make{} returned nullptr", rhName);
851855
return ret;
852856
} catch (const std::exception& e) {

‎mcrouter/routes/McRouteHandleProvider.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,11 @@ typename McRouteHandleProvider<
329329
McRouteHandleProvider<MemcacheRouterInfo>::buildRouteMapForWrapper() {
330330
RouteHandleFactoryMapForWrapper map{
331331
{"AxonLogRoute",
332-
[](RouteHandlePtr rh, ProxyBase& proxy, const folly::dynamic& json) {
333-
return makeAxonLogRoute(std::move(rh), proxy, json);
332+
[](RouteHandlePtr rh,
333+
ProxyBase& proxy,
334+
const folly::dynamic& json,
335+
RouteHandleFactory<RouteHandleIf>& factory) {
336+
return makeAxonLogRoute(std::move(rh), proxy, json, factory);
334337
}}};
335338
return map;
336339
}

‎mcrouter/routes/McRouteHandleProvider.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ FOLLY_ATTR_WEAK MemcacheRouterInfo::RouteHandlePtr makeSRRoute(
4040
FOLLY_ATTR_WEAK MemcacheRouterInfo::RouteHandlePtr makeAxonLogRoute(
4141
MemcacheRouterInfo::RouteHandlePtr rh,
4242
ProxyBase& proxy,
43-
const folly::dynamic& json);
43+
const folly::dynamic& json,
44+
RouteHandleFactory<MemcacheRouterInfo::RouteHandleIf>& factory);
4445

4546
template <class RouteHandleIf>
4647
class ExtraRouteHandleProviderIf;
@@ -107,8 +108,11 @@ class McRouteHandleProvider
107108
folly::StringPiece,
108109
RouteHandleFactoryFuncWithProxy,
109110
folly::Hash>;
110-
using RouteHandleFactoryFuncForWrapper = std::function<
111-
RouteHandlePtr(RouteHandlePtr, ProxyBase&, const folly::dynamic&)>;
111+
using RouteHandleFactoryFuncForWrapper = std::function<RouteHandlePtr(
112+
RouteHandlePtr,
113+
ProxyBase&,
114+
const folly::dynamic&,
115+
RouteHandleFactory<RouteHandleIf>&)>;
112116
using RouteHandleFactoryMapForWrapper = std::unordered_map<
113117
folly::StringPiece,
114118
RouteHandleFactoryFuncForWrapper,
@@ -212,7 +216,8 @@ class McRouteHandleProvider
212216
RouteHandlePtr wrapAxonLogRoute(
213217
RouteHandlePtr route,
214218
ProxyBase& proxy,
215-
const folly::dynamic& json);
219+
const folly::dynamic& json,
220+
RouteHandleFactory<RouteHandleIf>& factory);
216221

217222
template <class Transport>
218223
std::pair<RouteHandlePtr, std::shared_ptr<const AccessPoint>>

0 commit comments

Comments
 (0)