std::shared_ptr makeL1L2SizeSplitRoute()

in mcrouter/routes/L1L2SizeSplitRoute.cpp [236:301]


std::shared_ptr<MemcacheRouteHandleIf> makeL1L2SizeSplitRoute(
    RouteHandleFactory<MemcacheRouteHandleIf>& factory,
    const folly::dynamic& json) {
  checkLogic(json.isObject(), "L1L2SizeSplitRoute should be an object");
  checkLogic(json.count("l1"), "L1L2SizeSplitRoute: no l1 route");
  checkLogic(json.count("l2"), "L1L2SizeSplitRoute: no l2 route");
  checkLogic(json.count("threshold"), "L1L2SizeSplitRoute: no threshold");
  checkLogic(
      json["threshold"].isInt(),
      "L1L2SizeSplitRoute: threshold is not an integer");
  size_t threshold = json["threshold"].getInt();

  int32_t ttlThreshold = 0;
  if (json.count("ttl_threshold")) {
    checkLogic(
        json["ttl_threshold"].isInt(),
        "L1L2SizeSplitRoute: ttl_threshold is not an integer");
    ttlThreshold = json["ttl_threshold"].getInt();
    checkLogic(
        ttlThreshold >= 0,
        "L1L2SizeSplitRoute: ttl_threshold must be nonnegative");
  }

  int32_t failureTtl = 60;
  if (json.count("failure_ttl")) {
    checkLogic(
        json["failure_ttl"].isInt(),
        "L1L2SizeSplitRoute: failure_ttl is not an integer");
    failureTtl = json["failure_ttl"].getInt();
    checkLogic(
        failureTtl >= 0, "L1L2SizeSplitRoute: failure_ttl must be nonnegative");
    checkLogic(
        failureTtl != 0, "L1L2SizeSplitRoute: failure_ttl must not be zero");
  }

  bool bothFullSet = false;
  if (json.count("both_full_set")) {
    checkLogic(
        json["both_full_set"].isBool(),
        "L1L2SizeSplitRoute: both_full_set is not a boolean");
    bothFullSet = json["both_full_set"].getBool();
  }

  uint32_t numRetries = L1L2SizeSplitRoute::kDefaultNumRetries;
  if (json.count("retries")) {
    checkLogic(
        json["retries"].isInt(),
        "L1L2SizeSplitRoute: number of retries is not an integer");
    numRetries = json["retries"].getInt();
    checkLogic(
        numRetries > 0, "L1L2SizeSplitRoute: number of retries must be > 0");
    checkLogic(
        numRetries <= L1L2SizeSplitRoute::kMaxNumRetries,
        "L1L2SizeSplitRoute: maximum number of retries is " +
            std::to_string(L1L2SizeSplitRoute::kMaxNumRetries));
  }

  return std::make_shared<MemcacheRouteHandle<L1L2SizeSplitRoute>>(
      factory.create(json["l1"]),
      factory.create(json["l2"]),
      threshold,
      ttlThreshold,
      failureTtl,
      bothFullSet,
      numRetries);
}