std::shared_ptr MetaUtil::CreateLocation()

in src/hbase/client/meta-utils.cc [99:120]


std::shared_ptr<RegionLocation> MetaUtil::CreateLocation(const Response &resp,
                                                         const TableName &tn) {
  std::vector<std::shared_ptr<Result>> results = ResponseConverter::FromScanResponse(resp);
  if (results.size() == 0) {
    throw TableNotFoundException(folly::to<std::string>(tn));
  }
  if (results.size() != 1) {
    throw std::runtime_error("Was expecting exactly 1 result in meta scan response, got:" +
                             std::to_string(results.size()));
  }
  auto result = *results[0];

  auto region_info_str = result.Value(MetaUtil::kCatalogFamily, MetaUtil::kRegionInfoColumn);
  auto server_str = result.Value(MetaUtil::kCatalogFamily, MetaUtil::kServerColumn);
  CHECK(region_info_str);
  CHECK(server_str);

  auto row = result.Row();
  auto region_info = folly::to<RegionInfo>(*region_info_str);
  auto server_name = folly::to<ServerName>(*server_str);
  return std::make_shared<RegionLocation>(row, std::move(region_info), server_name);
}