Class RegionLocations

java.lang.Object
org.apache.hadoop.hbase.RegionLocations
All Implemented Interfaces:
Iterable<HRegionLocation>

@Private public class RegionLocations extends Object implements Iterable<HRegionLocation>
Container for holding a list of HRegionLocation's that correspond to the same range. The list is indexed by the replicaId. This is an immutable list, however mutation operations are provided which returns a new List via copy-on-write (assuming small number of locations)
  • Field Details

  • Constructor Details

    • RegionLocations

      public RegionLocations(HRegionLocation... locations)
      Constructs the region location list. The locations array should contain all the locations for known replicas for the region, and should be sorted in replicaId ascending order, although it can contain nulls indicating replicaIds that the locations of which are not known.
      Parameters:
      locations - an array of HRegionLocations for the same region range
    • RegionLocations

  • Method Details

    • size

      public int size()
      Returns the size of the list even if some of the elements might be null.
      Returns:
      the size of the list (corresponding to the max replicaId)
    • numNonNullElements

      public int numNonNullElements()
      Returns the size of not-null locations
      Returns:
      the size of not-null locations
    • isEmpty

      public boolean isEmpty()
      Returns whether there are non-null elements in the list
      Returns:
      whether there are non-null elements in the list
    • removeByServer

      Returns a new RegionLocations with the locations removed (set to null) which have the destination server as given.
      Parameters:
      serverName - the serverName to remove locations of
      Returns:
      an RegionLocations object with removed locations or the same object if nothing is removed
    • remove

      Removes the given location from the list
      Parameters:
      location - the location to remove
      Returns:
      an RegionLocations object with removed locations or the same object if nothing is removed
    • remove

      public RegionLocations remove(int replicaId)
      Removes location of the given replicaId from the list
      Parameters:
      replicaId - the replicaId of the location to remove
      Returns:
      an RegionLocations object with removed locations or the same object if nothing is removed
    • removeElementsWithNullLocation

      Set the element to null if its getServerName method returns null. Returns null if all the elements are removed.
    • mergeLocations

      Merges this RegionLocations list with the given list assuming same range, and keeping the most up to date version of the HRegionLocation entries from either list according to seqNum. If seqNums are equal, the location from the argument (other) is taken.
      Parameters:
      other - the locations to merge with
      Returns:
      an RegionLocations object with merged locations or the same object if nothing is merged
    • selectRegionLocation

      private HRegionLocation selectRegionLocation(HRegionLocation oldLocation, HRegionLocation location, boolean checkForEquals, boolean force)
    • updateLocation

      public RegionLocations updateLocation(HRegionLocation location, boolean checkForEquals, boolean force)
      Updates the location with new only if the new location has a higher seqNum than the old one or force is true.
      Parameters:
      location - the location to add or update
      checkForEquals - whether to update the location if seqNums for the HRegionLocations for the old and new location are the same
      force - whether to force update
      Returns:
      an RegionLocations object with updated locations or the same object if nothing is updated
    • isGreaterThan

      private boolean isGreaterThan(long a, long b, boolean checkForEquals)
    • getRegionLocation

      public HRegionLocation getRegionLocation(int replicaId)
    • getRegionLocationByRegionName

      public HRegionLocation getRegionLocationByRegionName(byte[] regionName)
      Returns the region location from the list for matching regionName, which can be regionName or encodedRegionName
      Parameters:
      regionName - regionName or encodedRegionName
      Returns:
      HRegionLocation found or null
    • getRegionLocations

    • getDefaultRegionLocation

    • getRegionLocation

      Returns the first not-null region location in the list
    • iterator

      Specified by:
      iterator in interface Iterable<HRegionLocation>
    • toString

      public String toString()
      Overrides:
      toString in class Object