Class AsyncRegionLocationCache

java.lang.Object
org.apache.hadoop.hbase.client.AsyncRegionLocationCache

final class AsyncRegionLocationCache extends Object
Cache of RegionLocations for use by AsyncNonMetaRegionLocator. Wrapper around ConcurrentSkipListMap ensuring proper access to cached items. Updates are synchronized, but reads are not.
  • Field Details

  • Constructor Details

  • Method Details

    • add

      Add the given locations to the cache, merging with existing if necessary. Also cleans out any previously cached locations which may have been superseded by this one (i.e. in case of merged regions). See cleanProblematicOverlappedRegions(RegionLocations)
      Parameters:
      locs - the locations to cache
      Returns:
      the final location (possibly merged) that was added to the cache
    • cleanProblematicOverlappedRegions

      When caching a location, the region may have been the result of a merge. Check to see if the region's boundaries overlap any other cached locations in a problematic way. Those would have been merge parents which no longer exist. We need to proactively clear them out to avoid a case where a merged region which receives no requests never gets cleared. This causes requests to other merged regions after it to see the wrong cached location.

      For example, if we have Start_New < Start_Old < End_Old < End_New, then if we only access within range [End_Old, End_New], then it will always return the old region but it will then find out the row is not in the range, and try to get the new region, and then we get [Start_New, End_New), still fall into the same situation.

      If Start_Old is less than Start_New, even if we have overlap, it is not a problem, as when the row is greater than Start_New, we will locate to the new region, and if the row is less than Start_New, it will fall into the old region's range and we will try to access the region and get a NotServing exception, and then we will clean the cache.

      See HBASE-27650

      Parameters:
      locations - the new location that was just cached
    • isEqual

      private boolean isEqual(RegionLocations locs1, RegionLocations locs2)
    • getAll

      Returns all cached RegionLocations
    • get

      public RegionLocations get(byte[] startKey)
      Gets the RegionLocations for a given region's startKey. This is a direct lookup, if the key does not exist in the cache it will return null.
      Parameters:
      startKey - region start key to directly look up
    • findForRow

      public RegionLocations findForRow(byte[] row, int replicaId)
      Finds the RegionLocations for the region with the greatest startKey less than or equal to the given row
      Parameters:
      row - row to find locations
    • findForBeforeRow

      public RegionLocations findForBeforeRow(byte[] row, int replicaId)
      Finds the RegionLocations for the region with the greatest startKey strictly less than the given row
      Parameters:
      row - row to find locations
    • remove

      public boolean remove(HRegionLocation loc)
      Removes the location from the cache if it exists and can be removed.
      Returns:
      true if entry was removed
    • size

      public int size()
      Returns the size of the region locations cache
    • removeForServer

      public void removeForServer(ServerName serverName)
      Removes serverName from all locations in the cache, fully removing any RegionLocations which are empty after removing the server from it.
      Parameters:
      serverName - server to remove from locations