Skip to content

Commit 03b667a

Browse files
Lenar Fatikhovfacebook-github-bot
authored andcommitted
remove bucketize_until parameter
Summary: This param was intended for rollout of the bucketization. Now that it is everywhere, there's no need for it. Furthermore, we want to change the bucket id to be string literals not always convertible to integers, so we won't be able to do math on them. Reviewed By: stuclar Differential Revision: D52550763 fbshipit-source-id: 0a70fa3f69a3285c0e0a1b1d41db977a7365a38c
1 parent 11e526d commit 03b667a

File tree

8 files changed

+23
-106
lines changed

8 files changed

+23
-106
lines changed

third-party/mcrouter/src/mcrouter/routes/McBucketRoute-inl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace facebook::memcache::mcrouter {
1717
* McBucketRoute Config:
1818
* - bucketize(bool) - enable the bucketization
1919
* - total_buckets(int) - total number of buckets
20-
* - bucketize_until(int) - enable the handle for buckets until (exclusive)
21-
* this number. Must be less than total_buckets.
22-
* Needed for gradual migration.
2320
* - bucketization_keyspace - can be used to separate into multiple
2421
* bucketization domains decoupled from each other,
2522
* e.g. one keyspace for each Memache pool.

third-party/mcrouter/src/mcrouter/routes/McBucketRoute.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ McBucketRouteSettings parseMcBucketRouteSettings(const folly::dynamic& json) {
2020
1,
2121
std::numeric_limits<int64_t>::max());
2222

23-
auto bucketizeUntil = 0;
24-
if (json.count("bucketize_until")) {
25-
bucketizeUntil = parseInt(
26-
*json.get_ptr("bucketize_until"), "bucketize_until", 0, totalBuckets);
27-
}
28-
2923
auto* bucketizationKeyspacePtr = json.get_ptr("bucketization_keyspace");
3024
checkLogic(
3125
bucketizationKeyspacePtr && bucketizationKeyspacePtr->isString(),
@@ -38,7 +32,6 @@ McBucketRouteSettings parseMcBucketRouteSettings(const folly::dynamic& json) {
3832
}
3933

4034
settings.totalBuckets = totalBuckets;
41-
settings.bucketizeUntil = bucketizeUntil;
4235
return settings;
4336
}
4437
} // namespace mcrouter

third-party/mcrouter/src/mcrouter/routes/McBucketRoute.h

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace facebook::memcache::mcrouter {
1919

2020
struct McBucketRouteSettings {
2121
size_t totalBuckets;
22-
size_t bucketizeUntil;
2322
std::string salt;
2423
std::string bucketizationKeyspace;
2524
};
@@ -52,16 +51,14 @@ class McBucketRoute {
5251
McBucketRoute(RouteHandlePtr rh, McBucketRouteSettings& settings)
5352
: rh_(std::move(rh)),
5453
totalBuckets_(settings.totalBuckets),
55-
bucketizeUntil_(settings.bucketizeUntil),
5654
salt_(settings.salt),
5755
ch3_(totalBuckets_),
5856
bucketizationKeyspace_(settings.bucketizationKeyspace) {}
5957

6058
std::string routeName() const {
6159
return fmt::format(
62-
"bucketize|total_buckets={}|bucketize_until={}|salt={}|bucketization_keyspace={}",
60+
"bucketize|total_buckets={}|salt={}|bucketization_keyspace={}",
6361
totalBuckets_,
64-
bucketizeUntil_,
6562
salt_,
6663
bucketizationKeyspace_);
6764
}
@@ -82,20 +79,16 @@ class McBucketRoute {
8279
return ch3_(getRoutingKey<Request>(req, this->salt_));
8380
}
8481
});
85-
if (bucketId < bucketizeUntil_) {
86-
if (auto* ctx = fiber_local<RouterInfo>::getTraverseCtx()) {
87-
ctx->recordBucketizationData(
88-
req.key_ref()->keyWithoutRoute().str(),
89-
bucketId,
90-
bucketizationKeyspace_);
91-
}
92-
return fiber_local<RouterInfo>::runWithLocals(
93-
[this, &req, &t, bucketId]() {
94-
fiber_local<RouterInfo>::setBucketId(bucketId);
95-
return t(*rh_, req);
96-
});
82+
if (auto* ctx = fiber_local<RouterInfo>::getTraverseCtx()) {
83+
ctx->recordBucketizationData(
84+
req.key_ref()->keyWithoutRoute().str(),
85+
bucketId,
86+
bucketizationKeyspace_);
9787
}
98-
return t(*rh_, req);
88+
return fiber_local<RouterInfo>::runWithLocals([this, &req, &t, bucketId]() {
89+
fiber_local<RouterInfo>::setBucketId(bucketId);
90+
return t(*rh_, req);
91+
});
9992
}
10093

10194
template <class Request>
@@ -121,21 +114,17 @@ class McBucketRoute {
121114

122115
template <class Request>
123116
ReplyT<Request> routeImpl(const Request& req, const size_t bucketId) const {
124-
if (bucketId < bucketizeUntil_) {
125-
auto proxy = &fiber_local<RouterInfo>::getSharedCtx()->proxy();
126-
proxy->stats().increment(bucketized_routing_stat);
127-
return fiber_local<RouterInfo>::runWithLocals([this, &req, bucketId]() {
128-
fiber_local<RouterInfo>::setBucketId(bucketId);
129-
return rh_->route(req);
130-
});
131-
}
132-
return rh_->route(req);
117+
auto proxy = &fiber_local<RouterInfo>::getSharedCtx()->proxy();
118+
proxy->stats().increment(bucketized_routing_stat);
119+
return fiber_local<RouterInfo>::runWithLocals([this, &req, bucketId]() {
120+
fiber_local<RouterInfo>::setBucketId(bucketId);
121+
return rh_->route(req);
122+
});
133123
}
134124

135125
private:
136126
const RouteHandlePtr rh_;
137127
const size_t totalBuckets_{0};
138-
const size_t bucketizeUntil_{0};
139128
const std::string salt_;
140129
const Ch3HashFunc ch3_;
141130
const std::string bucketizationKeyspace_;

third-party/mcrouter/src/mcrouter/routes/test/McBucketRouteTest.cpp

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ TEST(McBucketRouteTest, bucketIdShouldPropagate) {
3535
{
3636
"bucketize": true,
3737
"total_buckets": 100,
38-
"bucketize_until": 29,
3938
"bucketization_keyspace": "testRegion:testPool"
4039
}
4140
)";
@@ -51,32 +50,6 @@ TEST(McBucketRouteTest, bucketIdShouldPropagate) {
5150
EXPECT_EQ(28, srHandleVec[0]->sawBucketIds[0]);
5251
}
5352

54-
TEST(McBucketRouteTest, bucketIdShouldNotPropagate) {
55-
std::vector<std::shared_ptr<TestHandle>> srHandleVec{
56-
std::make_shared<TestHandle>(
57-
GetRouteTestData(carbon::Result::FOUND, "a")),
58-
};
59-
auto mockSrHandle = get_route_handles(srHandleVec)[0];
60-
61-
constexpr folly::StringPiece kMcBucketRouteConfig = R"(
62-
{
63-
"bucketize": true,
64-
"total_buckets": 100,
65-
"bucketize_until": 27,
66-
"bucketization_keyspace": "testRegion:testPool"
67-
}
68-
)";
69-
70-
auto rh = makeMcBucketRoute<MemcacheRouterInfo>(
71-
mockSrHandle, folly::parseJson(kMcBucketRouteConfig));
72-
ASSERT_TRUE(rh);
73-
mockFiberContext();
74-
rh->route(McGetRequest("getReq")); // bucketId == 28
75-
auto proxy = &fiber_local<MemcacheRouterInfo>::getSharedCtx()->proxy();
76-
EXPECT_EQ(0, proxy->stats().getValue(bucketized_routing_stat));
77-
EXPECT_TRUE(srHandleVec[0]->sawBucketIds.empty());
78-
}
79-
8053
TEST(McBucketRouteTest, bucketIdShouldPropagateInTraverse) {
8154
std::vector<std::shared_ptr<TestHandle>> srHandleVec{
8255
std::make_shared<TestHandle>(
@@ -88,7 +61,6 @@ TEST(McBucketRouteTest, bucketIdShouldPropagateInTraverse) {
8861
{
8962
"bucketize": true,
9063
"total_buckets": 100,
91-
"bucketize_until": 29,
9264
"bucketization_keyspace": "testRegion:testPool"
9365
}
9466
)";
@@ -102,51 +74,24 @@ TEST(McBucketRouteTest, bucketIdShouldPropagateInTraverse) {
10274
EXPECT_EQ(28, srHandleVec[0]->sawBucketIds[0]);
10375
}
10476

105-
TEST(McBucketRouteTest, bucketIdShouldNotPropagateInTraverse) {
106-
std::vector<std::shared_ptr<TestHandle>> srHandleVec{
107-
std::make_shared<TestHandle>(
108-
GetRouteTestData(carbon::Result::FOUND, "a")),
109-
};
110-
auto mockSrHandle = get_route_handles(srHandleVec)[0];
111-
112-
constexpr folly::StringPiece kMcBucketRouteConfig = R"(
113-
{
114-
"bucketize": true,
115-
"total_buckets": 100,
116-
"bucketize_until": 28,
117-
"bucketization_keyspace": "testRegion:testPool"
118-
}
119-
)";
120-
121-
auto rh = makeMcBucketRoute<MemcacheRouterInfo>(
122-
mockSrHandle, folly::parseJson(kMcBucketRouteConfig));
123-
mockFiberContext();
124-
RouteHandleTraverser<MemcacheRouterInfo::RouteHandleIf> t{};
125-
rh->traverse(McGetRequest("getReq"), t); // bucketId == 28
126-
EXPECT_TRUE(srHandleVec[0]->sawBucketIds.empty());
127-
}
128-
12977
TEST(McBucketRouteTest, checkParams) {
13078
std::vector<std::shared_ptr<TestHandle>> srHandleVec{
13179
std::make_shared<TestHandle>(
13280
GetRouteTestData(carbon::Result::FOUND, "a")),
13381
};
13482
auto mockSrHandle = get_route_handles(srHandleVec)[0];
13583
std::string_view total = "100";
136-
std::string_view until = "29";
13784
std::string_view keyspace = "testReg:testPool";
13885

13986
std::string kMcBucketRouteConfig = folly::sformat(
14087
R"(
14188
{{
14289
"bucketize": true,
14390
"total_buckets": {},
144-
"bucketize_until": {},
14591
"bucketization_keyspace": "{}"
14692
}}
14793
)",
14894
total,
149-
until,
15095
keyspace);
15196

15297
auto rh = makeMcBucketRoute<MemcacheRouterInfo>(
@@ -155,13 +100,12 @@ TEST(McBucketRouteTest, checkParams) {
155100
auto name = rh->routeName();
156101
std::vector<std::string> params;
157102
folly::split('|', name, params, true);
158-
EXPECT_TRUE(params.size() == 5);
103+
EXPECT_TRUE(params.size() == 4);
159104
EXPECT_EQ(params[0], "bucketize");
160105
EXPECT_EQ(params[1], folly::to<std::string>("total_buckets=", total));
161-
EXPECT_EQ(params[2], folly::to<std::string>("bucketize_until=", until));
162-
EXPECT_EQ(params[3], folly::to<std::string>("salt="));
106+
EXPECT_EQ(params[2], folly::to<std::string>("salt="));
163107
EXPECT_EQ(
164-
params[4], folly::to<std::string>("bucketization_keyspace=", keyspace));
108+
params[3], folly::to<std::string>("bucketization_keyspace=", keyspace));
165109
}
166110

167111
TEST(McBucketRouteTest, recordBucketizationData) {
@@ -175,7 +119,6 @@ TEST(McBucketRouteTest, recordBucketizationData) {
175119
{
176120
"bucketize": true,
177121
"total_buckets": 100,
178-
"bucketize_until": 100,
179122
"bucketization_keyspace": "testRegionBucketKeyspace"
180123
}
181124
)";

third-party/mcrouter/src/mcrouter/test/cpp_unit_tests/mc_route_handle_provider_test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const char* const kBucketizedSRRoute =
6565
"axonlog": false,
6666
"bucketize": true,
6767
"total_buckets": 1000,
68-
"bucketize_until": 1000,
6968
"bucketization_keyspace": "tst"
7069
})";
7170

@@ -79,7 +78,6 @@ const char* const kBucketizedPoolRoute =
7978
"axonlog": false,
8079
"bucketize": true,
8180
"total_buckets": 1000,
82-
"bucketize_until": 1000,
8381
"bucketization_keyspace": "tst"
8482
})";
8583

@@ -156,12 +154,12 @@ TEST(McRouteHandleProvider, bucketized_sr_route_and_mcreplay_asynclogRoutes) {
156154
auto rh = setup.getRoute(kBucketizedSRRoute);
157155
EXPECT_TRUE(rh != nullptr);
158156
EXPECT_EQ(
159-
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
157+
"bucketize|total_buckets=1000|salt=|bucketization_keyspace=tst",
160158
rh->routeName());
161159
auto asynclogRoutes = setup.provider().releaseAsyncLogRoutes();
162160
EXPECT_EQ(1, asynclogRoutes.size());
163161
EXPECT_EQ(
164-
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
162+
"bucketize|total_buckets=1000|salt=|bucketization_keyspace=tst",
165163
asynclogRoutes["test.asynclog"]->routeName());
166164
}
167165

@@ -170,11 +168,11 @@ TEST(McRouteHandleProvider, bucketized_pool_route_and_mcreplay_asynclogRoutes) {
170168
auto rh = setup.getRoute(kBucketizedPoolRoute);
171169
EXPECT_TRUE(rh != nullptr);
172170
EXPECT_EQ(
173-
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
171+
"bucketize|total_buckets=1000|salt=|bucketization_keyspace=tst",
174172
rh->routeName());
175173
auto asynclogRoutes = setup.provider().releaseAsyncLogRoutes();
176174
EXPECT_EQ(1, asynclogRoutes.size());
177175
EXPECT_EQ(
178-
"bucketize|total_buckets=1000|bucketize_until=1000|salt=|bucketization_keyspace=tst",
176+
"bucketize|total_buckets=1000|salt=|bucketization_keyspace=tst",
179177
asynclogRoutes["test.asynclog"]->routeName());
180178
}

third-party/mcrouter/src/mcrouter/test/mcrouter_test_bucketized_poolroute_bucketized.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"pool": "foo",
1111
"bucketize": true,
1212
"total_buckets": 1000,
13-
"bucketize_until": 1000,
1413
"bucketization_keyspace": "test",
1514
"hash": "WeightedCh3"
1615
}

third-party/mcrouter/src/mcrouter/test/test_axon_log.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"pool": "A",
1111
"protocol": "thrift",
1212
"bucketize": true,
13-
"bucketize_until": 1000,
1413
"bucketization_keyspace": "test",
1514
"total_buckets": 1000,
1615
"hash": "WeightedCh3",

third-party/mcrouter/src/mcrouter/test/test_axon_log_alldelete.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"pool": "A",
1111
"protocol": "thrift",
1212
"bucketize": true,
13-
"bucketize_until": 1000,
1413
"bucketization_keyspace": "test",
1514
"total_buckets": 1000,
1615
"hash": "WeightedCh3",

0 commit comments

Comments
 (0)