in mcrouter/routes/HashRouteFactory.h [49:112]
std::shared_ptr<typename RouterInfo::RouteHandleIf> createHashRoute(
const folly::dynamic& json,
std::vector<std::shared_ptr<typename RouterInfo::RouteHandleIf>> rh,
size_t threadId) {
std::string salt;
folly::StringPiece funcType = Ch3HashFunc::type();
if (json.isObject()) {
if (auto jsalt = json.get_ptr("salt")) {
checkLogic(jsalt->isString(), "HashRoute: salt is not a string");
salt = jsalt->getString();
}
if (auto jhashFunc = json.get_ptr("hash_func")) {
checkLogic(jhashFunc->isString(), "HashRoute: hash_func is not a string");
funcType = jhashFunc->stringPiece();
}
}
auto n = rh.size();
if (n == 0) {
return createNullRoute<typename RouterInfo::RouteHandleIf>();
}
if (n == 1) {
return std::move(rh[0]);
}
if (funcType == Ch3HashFunc::type()) {
return createHashRoute<RouterInfo, Ch3HashFunc>(
std::move(rh), std::move(salt), Ch3HashFunc(n));
} else if (funcType == Crc32HashFunc::type()) {
return createHashRoute<RouterInfo, Crc32HashFunc>(
std::move(rh), std::move(salt), Crc32HashFunc(n));
} else if (funcType == WeightedCh3HashFunc::type()) {
WeightedCh3HashFunc func{json, n};
return createHashRoute<RouterInfo, WeightedCh3HashFunc>(
std::move(rh), std::move(salt), std::move(func));
} else if (funcType == WeightedCh4HashFunc::type()) {
WeightedCh4HashFunc func{json, n};
return createHashRoute<RouterInfo, WeightedCh4HashFunc>(
std::move(rh), std::move(salt), std::move(func));
} else if (funcType == ConstShardHashFunc::type()) {
return createHashRoute<RouterInfo, ConstShardHashFunc>(
std::move(rh), std::move(salt), ConstShardHashFunc(n));
} else if (
funcType == RendezvousHashFunc::type() ||
funcType == WeightedRendezvousHashFunc::type()) {
auto endpoints = getTags(json, rh.size(), "HashRoute");
if (funcType == RendezvousHashFunc::type()) {
return createHashRoute<RouterInfo, RendezvousHashFunc>(
std::move(rh),
std::move(salt),
RendezvousHashFunc(std::move(endpoints), json));
} else {
return createHashRoute<RouterInfo, WeightedRendezvousHashFunc>(
std::move(rh),
std::move(salt),
WeightedRendezvousHashFunc(std::move(endpoints), json));
}
} else if (funcType == "Latest") {
return createLatestRoute<RouterInfo>(json, std::move(rh), threadId);
} else if (funcType == "LoadBalancer") {
return createLoadBalancerRoute<RouterInfo>(json, std::move(rh));
}
throwLogic("Unknown hash function: {}", funcType);
}