Skip to content

Commit

Permalink
add dynamic config to disable broadcast delete rpc
Browse files Browse the repository at this point in the history
Summary: design & discussion doc: https://fburl.com/gdoc/xyjcaj9x

Reviewed By: stuclar

Differential Revision: D49361955

fbshipit-source-id: 1fb370ba2f415c2caecc28b3d247ce3e7b583897
  • Loading branch information
Lenar Fatikhov authored and facebook-github-bot committed Sep 21, 2023
1 parent c25ff7f commit 73f1918
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
10 changes: 9 additions & 1 deletion mcrouter/ProxyConfig-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ ProxyConfig<RouterInfo>::ProxyConfig(
partialConfigs_ = provider.releasePartialConfigs();
}
accessPoints_ = provider.releaseAccessPoints();
proxyRoute_ = std::make_shared<ProxyRoute<RouterInfo>>(proxy, routeSelectors);
bool disableBroadcastDeleteRpc = false;
if (auto* jDisableBroadcastDeleteRpc =
json.get_ptr("disable_broadcast_delete_rpc")) {
disableBroadcastDeleteRpc =
parseBool(*jDisableBroadcastDeleteRpc, "disable_broadcast_delete_rpc");
}

proxyRoute_ = std::make_shared<ProxyRoute<RouterInfo>>(
proxy, routeSelectors, disableBroadcastDeleteRpc);
serviceInfo_ = std::make_shared<ServiceInfo<RouterInfo>>(proxy, *this);
}

Expand Down
6 changes: 4 additions & 2 deletions mcrouter/routes/ProxyRoute-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ typename RouterInfo::RouteHandlePtr wrapWithBigValueRoute(
template <class RouterInfo>
ProxyRoute<RouterInfo>::ProxyRoute(
Proxy<RouterInfo>& proxy,
const RouteSelectorMap<typename RouterInfo::RouteHandleIf>& routeSelectors)
const RouteSelectorMap<typename RouterInfo::RouteHandleIf>& routeSelectors,
bool disableBroadcastDeleteRpc)
: proxy_(proxy),
root_(makeRouteHandle<typename RouterInfo::RouteHandleIf, RootRoute>(
proxy_,
routeSelectors)) {
routeSelectors,
disableBroadcastDeleteRpc)) {
if (proxy_.getRouterOptions().big_value_split_threshold != 0) {
root_ = detail::wrapWithBigValueRoute<RouterInfo>(
std::move(root_), proxy_.getRouterOptions());
Expand Down
3 changes: 2 additions & 1 deletion mcrouter/routes/ProxyRoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ProxyRoute {
ProxyRoute(
Proxy<RouterInfo>& proxy,
const RouteSelectorMap<typename RouterInfo::RouteHandleIf>&
routeSelectors);
routeSelectors,
bool disableBroadcastDeleteRpc = false);

template <class Request>
bool traverse(
Expand Down
18 changes: 15 additions & 3 deletions mcrouter/routes/RootRoute.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class RootRoute {

RootRoute(
ProxyBase& proxy,
const RouteSelectorMap<RouteHandleIf>& routeSelectors)
const RouteSelectorMap<RouteHandleIf>& routeSelectors,
bool disableBroadcastDeleteRpc = false)
: opts_(proxy.getRouterOptions()),
rhMap_(
routeSelectors,
opts_.default_route,
opts_.send_invalid_route_to_default) {}
opts_.send_invalid_route_to_default),
disableBroadcastDeleteRpc_(disableBroadcastDeleteRpc) {}

template <class Request>
bool traverse(
Expand Down Expand Up @@ -93,6 +95,7 @@ class RootRoute {
private:
const McrouterOptions& opts_;
RouteHandleMap<RouteHandleIf> rhMap_;
bool disableBroadcastDeleteRpc_;

template <class Request>
ReplyT<Request> routeImpl(
Expand Down Expand Up @@ -148,10 +151,19 @@ class RootRoute {
ReplyT<Request> doRoute(
const std::vector<std::shared_ptr<RouteHandleIf>>& rh,
const Request& req) const {
if (LIKELY(rh.size() == 1)) {
if (FOLLY_LIKELY(rh.size() == 1)) {
return rh[0]->route(req);
}
if (!rh.empty()) {
// Broadcast delete via Distribution, route only
// to the first (local) route handle
if constexpr (folly::IsOneOf<Request, McDeleteRequest>::value) {
if (disableBroadcastDeleteRpc_ &&
req.key_ref()->routingPrefix() == kBroadcastPrefix) {
return rh[0]->route(req);
}
}

auto reqCopy = std::make_shared<const Request>(req);
for (size_t i = 1, e = rh.size(); i < e; ++i) {
auto r = rh[i];
Expand Down
5 changes: 3 additions & 2 deletions mcrouter/routes/RouteHandleMap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace facebook {
namespace memcache {
namespace mcrouter {

constexpr std::string_view kBroadcastPrefix = "/*/*/";
constexpr const char* kFallbackCluster = "fallback";

namespace detail {
Expand Down Expand Up @@ -140,7 +141,7 @@ void RouteHandleMap<RouteHandleIf>::foreachRoutePolicy(
return;
}

bool selectAll = (prefix == "/*/*/");
bool selectAll = (prefix == kBroadcastPrefix);
for (const auto& it : byRoute_) {
if (it.first != defaultRoute_.str() &&
(selectAll || match_pattern_route(prefix, it.first))) {
Expand Down Expand Up @@ -204,7 +205,7 @@ RouteHandleMap<RouteHandleIf>::getTargetsForKeyFast(
if (LIKELY(prefix.empty())) {
// empty prefix => route to default route
result = &defaultRouteMap_->getTargetsForKey(key);
} else if (prefix == "/*/*/") {
} else if (prefix == kBroadcastPrefix) {
// route to all routes
result = &allRoutes_->getTargetsForKey(key);
} else {
Expand Down

0 comments on commit 73f1918

Please sign in to comment.