Skip to content

Commit

Permalink
Make request to PoolRoute with empty SMC tier return error
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: stuclar

Differential Revision: D44887555

fbshipit-source-id: fd8f595fc3532b969df4681be35b96dc5999681a
  • Loading branch information
disylh authored and facebook-github-bot committed May 3, 2023
1 parent 035dfed commit 0a402a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mcrouter/routes/HashRouteFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ std::shared_ptr<typename RouterInfo::RouteHandleIf> createHashRoute(

auto n = rh.size();
if (n == 0) {
return createNullRoute<typename RouterInfo::RouteHandleIf>();
auto errorOnEmpty = true;
folly::StringPiece name{nullptr, nullptr};
if (json.isObject()) {
if (auto* jErrorOnEmpty = json.get_ptr("error_on_empty")) {
errorOnEmpty = parseBool(*jErrorOnEmpty, "error_on_empty");
}
if (auto* jName = json.get_ptr("name")) {
name = jName->stringPiece();
}
}
return errorOnEmpty ? createErrorRoute<RouterInfo>(folly::sformat(
"HashRoute with empty children, name: {}", name))
: createNullRoute<typename RouterInfo::RouteHandleIf>();
}
if (n == 1) {
return std::move(rh[0]);
Expand Down
9 changes: 9 additions & 0 deletions mcrouter/routes/McRouteHandleProvider-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,15 @@ McRouteHandleProvider<RouterInfo>::makePoolRoute(
}
}
}

if (poolJson.json.isObject()) {
if (auto* jErrorOnEmpty = poolJson.json.get_ptr("error_on_empty")) {
jhashWithWeights["error_on_empty"] =
parseBool(*jErrorOnEmpty, "error_on_empty");
}
}
jhashWithWeights["name"] = poolJson.name;

auto route = createHashRoute<RouterInfo>(
jhashWithWeights, std::move(destinations), factory.getThreadId());

Expand Down
1 change: 1 addition & 0 deletions mcrouter/routes/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mcrouter_routes_test_SOURCES = \
ConstShardHashFuncTest.cpp \
FailoverWithExptimeRouteTest.cpp \
Main.cpp \
PoolRouteTest.cpp \
RateLimitRouteTest.cpp \
RouteHandleTestUtil.h \
ShadowRouteTest.cpp \
Expand Down

0 comments on commit 0a402a5

Please sign in to comment.