std::shared_ptr LocationCache::GetCachedLocation()

in src/hbase/client/location-cache.cc [214:246]


std::shared_ptr<RegionLocation> LocationCache::GetCachedLocation(const hbase::pb::TableName &tn,
                                                                 const std::string &row) {
  auto t_locs = this->GetTableLocations(tn);
  std::shared_lock<folly::SharedMutexWritePriority> lock(locations_lock_);

  // looking for the "floor" key as a start key
  auto possible_region = t_locs->upper_bound(row);

  if (t_locs->empty()) {
    VLOG(5) << "Could not find region in cache, table map is empty";
    return nullptr;
  }

  if (possible_region == t_locs->begin()) {
    VLOG(5) << "Could not find region in cache, all keys are greater, row:" << row
            << " ,possible_region:" << possible_region->second->DebugString();
    return nullptr;
  }
  --possible_region;

  VLOG(5) << "Found possible region in cache for row:" << row
          << " ,possible_region:" << possible_region->second->DebugString();

  // found possible start key, now need to check end key
  if (possible_region->second->region_info().end_key() == "" ||
      possible_region->second->region_info().end_key() > row) {
    VLOG(2) << "Found region in cache for row:" << row
            << " ,region:" << possible_region->second->DebugString();
    return possible_region->second;
  } else {
    return nullptr;
  }
}