Skip to content

Commit

Permalink
Add option to wrap srroute with refill route
Browse files Browse the repository at this point in the history
Summary: as title

Reviewed By: disylh, stuclar

Differential Revision: D61394564

fbshipit-source-id: 3c9d95a47667a532b4a262b32c119ba85e2adb2c
  • Loading branch information
Xiaofei Hu authored and facebook-github-bot committed Aug 23, 2024
1 parent 7f5c691 commit b4818bf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mcrouter/routes/McRefillRoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ typename RouterInfo::RouteHandlePtr makeMcRefillRoute(
factory.create(json["primary"]), factory.create(json["refill"]));
}

template <class RouterInfo>
typename RouterInfo::RouteHandlePtr makeMcRefillRouteUsePrimaryAndRefill(
typename RouterInfo::RouteHandlePtr primary,
typename RouterInfo::RouteHandlePtr refill) {
return makeRouteHandleWithInfo<RouterInfo, McRefillRoute>(
std::move(primary), std::move(refill));
}

} // namespace mcrouter
} // namespace memcache
} // namespace facebook
21 changes: 21 additions & 0 deletions mcrouter/routes/McRouteHandleProvider-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mcrouter/routes/FailoverRoute.h"
#include "mcrouter/routes/HashRouteFactory.h"
#include "mcrouter/routes/McBucketRoute.h"
#include "mcrouter/routes/McRefillRoute.h"
#include "mcrouter/routes/PoolRouteUtils.h"
#include "mcrouter/routes/RateLimitRoute.h"
#include "mcrouter/routes/RateLimiter.h"
Expand Down Expand Up @@ -581,6 +582,26 @@ McRouteHandleProvider<RouterInfo>::createSRRoute(
route = std::move(makeShadowRoutes(
factory, json, {std::move(route)}, proxy_, *extraProvider_)[0]);
}

if constexpr (RouterInfo::hasMcRefillRoute) {
bool refillOnMiss = false;
if (auto* jRefillOnMiss = json.get_ptr("refill_on_miss")) {
refillOnMiss = parseBool(*jRefillOnMiss, "refill_on_miss");
}
if (refillOnMiss) {
auto jRefillFromTier = json.get_ptr("refill_from_tier");
checkLogic(
jRefillFromTier != nullptr,
"SRroute: 'refill_from_tier' property is missing");
folly::dynamic refillJson = json;
refillJson["service_name"] = *jRefillFromTier;
refillJson["type"] = "SRRoute";

route = makeMcRefillRouteUsePrimaryAndRefill<RouterInfo>(
route, factoryFunc(factory, refillJson, proxy_));
}
}

route = bucketize(std::move(route), json);

if (needAsynclog) {
Expand Down
23 changes: 23 additions & 0 deletions mcrouter/test/cpp_unit_tests/mc_route_handle_provider_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ const char* const kBucketizedPoolRoute =
"bucketization_keyspace": "tst"
})";

const char* const kRefillOnMissSRRoute =
R"({
"type": "SRRoute",
"service_name": "twmemcache.shadow.bucketization-test",
"server_timeout": 200,
"asynclog_name": "test.asynclog",
"axonlog": false,
"bucketize": true,
"total_buckets": 1000,
"bucketization_keyspace": "tst",
"refill_on_miss": true,
"refill_from_tier": "twmemcache.shadow.mcrouter-rc"
})";

struct TestSetup {
public:
TestSetup()
Expand Down Expand Up @@ -176,3 +190,12 @@ TEST(McRouteHandleProvider, bucketized_pool_route_and_mcreplay_asynclogRoutes) {
"bucketize|total_buckets=1000|bucketization_keyspace=tst|prefix_map_enabled=false",
asynclogRoutes["test.asynclog"]->routeName());
}

TEST(McRouteHandleProvider, bucketized_sr_route_with_refill_on_miss) {
TestSetup setup;
auto rh = setup.getRoute(kRefillOnMissSRRoute);
EXPECT_TRUE(rh != nullptr);
EXPECT_EQ(
"bucketize|total_buckets=1000|bucketization_keyspace=tst|prefix_map_enabled=false",
rh->routeName());
}

0 comments on commit b4818bf

Please sign in to comment.