Skip to content

Commit

Permalink
add bucket route and axon routes to asyncLogRoutes
Browse files Browse the repository at this point in the history
Summary: Mcreplay needs a whole chain of `bucketRoute->axon route->pool route` in order to work correctly.

Reviewed By: stuclar

Differential Revision: D49698867

fbshipit-source-id: 2bc42ddb089b14af16ebee9229c488a4730c367a
  • Loading branch information
Lenar Fatikhov authored and facebook-github-bot committed Sep 28, 2023
1 parent 99fbb26 commit 04b479a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mcrouter/routes/McRouteHandleProvider-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ McRouteHandleProvider<RouterInfo>::createAsynclogRoute(
if (!proxy_.router().opts().asynclog_disable) {
target = makeAsynclogRoute<RouterInfo>(std::move(target), asynclogName);
}
asyncLogRoutes_.emplace(std::move(asynclogName), target);
return target;
}

Expand Down Expand Up @@ -552,8 +551,8 @@ McRouteHandleProvider<RouterInfo>::createSRRoute(
if (auto* jNeedAsynclog = json.get_ptr("asynclog")) {
needAsynclog = parseBool(*jNeedAsynclog, "asynclog");
}
folly::StringPiece asynclogName;
if (needAsynclog) {
folly::StringPiece asynclogName;
if (auto jAsynclogName = json.get_ptr("asynclog_name")) {
asynclogName = parseString(*jAsynclogName, "asynclog_name");
} else if (auto jServiceName = json.get_ptr("service_name")) {
Expand All @@ -573,6 +572,10 @@ McRouteHandleProvider<RouterInfo>::createSRRoute(
}
route = bucketize(std::move(route), json);

if (needAsynclog) {
asyncLogRoutes_.emplace(asynclogName.toString(), route);
}

if (auto jSRRouteName = json.get_ptr("service_name")) {
auto srRouteName = parseString(*jSRRouteName, "service_name");
tierRoutes_.emplace(srRouteName, srRoute);
Expand Down Expand Up @@ -711,6 +714,9 @@ McRouteHandleProvider<RouterInfo>::makePoolRoute(
tierRoutes_.emplace(poolId, poolRoute);
}
}
if (needAsynclog) {
asyncLogRoutes_.emplace(asynclogName.toString(), route);
}
return route;
} catch (const std::exception& e) {
throwLogic("PoolRoute {}: {}", poolJson.name, e.what());
Expand Down
56 changes: 56 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 @@ -56,6 +56,33 @@ const char* const kPoolRoute =
"hash": { "hash_func": "Crc32" }
})";

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

const char* const kBucketizedPoolRoute =
R"({
"type": "PoolRoute",
"pool": { "name": "mock", "servers": [ ] },
"pool_id": "twmemcache.shadow.bucketization-test",
"hash": "WeightedCh3",
"asynclog_name": "test.asynclog",
"axonlog": false,
"bucketize": true,
"total_buckets": 1000,
"bucketize_until": 1000,
"bucketization_keyspace": "tst"
})";

struct TestSetup {
public:
TestSetup()
Expand Down Expand Up @@ -85,6 +112,7 @@ struct TestSetup {

static McrouterOptions getOpts() {
auto opts = defaultTestOptions();
opts.enable_service_router = true;
opts.config = std::string("file:") + kMemcacheConfig;
return opts;
}
Expand Down Expand Up @@ -122,3 +150,31 @@ TEST(McRouteHandleProvider, pool_route) {
EXPECT_EQ(1, asynclogRoutes.size());
EXPECT_EQ("asynclog:mock", asynclogRoutes["mock"]->routeName());
}

TEST(McRouteHandleProvider, bucketized_sr_route_and_mcreplay_asynclogRoutes) {
TestSetup setup;
auto rh = setup.getRoute(kBucketizedSRRoute);
EXPECT_TRUE(rh != nullptr);
EXPECT_EQ(
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
rh->routeName());
auto asynclogRoutes = setup.provider().releaseAsyncLogRoutes();
EXPECT_EQ(1, asynclogRoutes.size());
EXPECT_EQ(
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
asynclogRoutes["test.asynclog"]->routeName());
}

TEST(McRouteHandleProvider, bucketized_pool_route_and_mcreplay_asynclogRoutes) {
TestSetup setup;
auto rh = setup.getRoute(kBucketizedPoolRoute);
EXPECT_TRUE(rh != nullptr);
EXPECT_EQ(
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
rh->routeName());
auto asynclogRoutes = setup.provider().releaseAsyncLogRoutes();
EXPECT_EQ(1, asynclogRoutes.size());
EXPECT_EQ(
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
asynclogRoutes["test.asynclog"]->routeName());
}

0 comments on commit 04b479a

Please sign in to comment.