McrouterRouteHandlePtr makeHashRoute( const folly::dynamic& json, std::vector<McrouterRouteHandlePtr> 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(); } } if (funcType == Ch3HashFunc::type()) { return makeHashRouteCh3(std::move(rh), std::move(salt)); } else if (funcType == Crc32HashFunc::type()) { return makeHashRouteCrc32(std::move(rh), std::move(salt)); } else if (funcType == WeightedCh3HashFunc::type()) { WeightedCh3HashFunc func{json, rh.size()}; return makeHashRouteWeightedCh3(std::move(rh), std::move(salt), std::move(func)); } else if (funcType == ConstShardHashFunc::type()) { return makeHashRouteConstShard(std::move(rh), std::move(salt)); } else if (funcType == "Latest") { return makeLatestRoute(json, std::move(rh), threadId); } throwLogic("Unknown hash function: {}", funcType); }
McrouterRouteHandlePtr makeLatestRoute( RouteHandleFactory<McrouterRouteHandleIf>& factory, const folly::dynamic& json) { std::vector<McrouterRouteHandlePtr> children; if (json.isObject()) { if (auto jchildren = json.get_ptr("children")) { children = factory.createList(*jchildren); } } else { children = factory.createList(json); } return makeLatestRoute(json, std::move(children)); }
McrouterRouteHandlePtr makeLatestRoute( const folly::dynamic& json, std::vector<McrouterRouteHandlePtr> targets) { size_t failoverCount = 5; FailoverErrorsSettings failoverErrors; if (json.isObject()) { if (auto jfailoverCount = json.get_ptr("failover_count")) { checkLogic(jfailoverCount->isInt(), "LatestRoute: failover_count is not an integer"); failoverCount = jfailoverCount->getInt(); } if (auto jFailoverErrors = json.get_ptr("failover_errors")) { failoverErrors = FailoverErrorsSettings(*jFailoverErrors); } } return makeLatestRoute(std::move(targets), failoverCount, std::move(failoverErrors)); }