Interface RegionInfo

All Superinterfaces:
Comparable<RegionInfo>
All Known Implementing Classes:
MutableRegionInfo

@Public public interface RegionInfo extends Comparable<RegionInfo>
Information about a region. A region is a range of keys in the whole keyspace of a table, an identifier (a timestamp) for differentiating between subset ranges (after region split) and a replicaId for differentiating the instance for the same range and some status information about the region. The region has a unique name which consists of the following fields:
  • tableName : The name of the table
  • startKey : The startKey for the region.
  • regionId : A timestamp when the region is created.
  • replicaId : An id starting from 0 to differentiate replicas of the same region range but hosted in separated servers. The same region range can be hosted in multiple locations.
  • encodedName : An MD5 encoded string for the region name.

Other than the fields in the region name, region info contains:
  • endKey : the endKey for the region (exclusive)
  • split : Whether the region is split
  • offline : Whether the region is offline
  • Field Details

  • Method Details

    • getShortNameToLog

      Returns Return a short, printable name for this region (usually encoded name) for us logging.
    • getRegionId

      long getRegionId()
      Returns the regionId.
    • getRegionName

      byte[] getRegionName()
      Returns the regionName as an array of bytes.
      See Also:
    • getRegionNameAsString

      Returns Region name as a String for use in logging, etc.
    • getEncodedName

      Returns the encoded region name.
    • getEncodedNameAsBytes

      Returns the encoded region name as an array of bytes.
    • getStartKey

      byte[] getStartKey()
      Returns the startKey.
    • getEndKey

      byte[] getEndKey()
      Returns the endKey.
    • getTable

      Returns current table name of the region
    • getReplicaId

      Returns returns region replica id
    • isSplit

      boolean isSplit()
      Returns True if has been split and has daughters.
    • isOffline

      Deprecated.
      since 3.0.0 and will be removed in 4.0.0
      Returns True if this region is offline.
      See Also:
    • isSplitParent

      Deprecated.
      since 3.0.0 and will be removed in 4.0.0, Use isSplit() instead.
      Returns True if this is a split parent region.
      See Also:
    • isMetaRegion

      boolean isMetaRegion()
      Returns true if this region is a meta region.
    • containsRange

      boolean containsRange(byte[] rangeStartKey, byte[] rangeEndKey)
      Returns true if the given inclusive range of rows is fully contained by this region. For example, if the region is foo,a,g and this is passed ["b","c"] or ["a","c"] it will return true, but if this is passed ["b","z"] it will return false.
      Throws:
      IllegalArgumentException - if the range passed is invalid (ie. end < start)
    • containsRow

      boolean containsRow(byte[] row)
      Returns true if the given row falls in this region.
    • hasEncodedName

      @Private static boolean hasEncodedName(byte[] regionName)
      Does region name contain its encoded name?
      Parameters:
      regionName - region name
      Returns:
      boolean indicating if this a new format region name which contains its encoded name.
    • encodeRegionName

      @Private static String encodeRegionName(byte[] regionName)
      Returns the encodedName
    • getRegionNameAsString

      @Private static String getRegionNameAsString(byte[] regionName)
    • getRegionNameAsString

      @Private static String getRegionNameAsString(@CheckForNull RegionInfo ri, byte[] regionName)
    • getShortNameToLog

      Returns a String of short, printable names for hris (usually encoded name) for us logging.
    • getShortNameToLog

      Returns a String of short, printable names for hris (usually encoded name) for us logging.
    • getTable

      @Private static TableName getTable(byte[] regionName)
      Gets the table name from the specified region name.
      Parameters:
      regionName - to extract the table name from
      Returns:
      Table name
    • getStartKey

      static byte[] getStartKey(byte[] regionName) throws IOException
      Gets the start key from the specified region name.
      Returns:
      Start key.
      Throws:
      IOException
    • isEncodedRegionName

      @Private static boolean isEncodedRegionName(byte[] regionName)
      Figure if the passed bytes represent an encoded region name or not.
      Parameters:
      regionName - A Region name either encoded or not.
      Returns:
      True if regionName represents an encoded name.
    • parseFromOrNull

      @Private static RegionInfo parseFromOrNull(byte[] bytes)
      Returns A deserialized RegionInfo or null if we failed deserialize or passed bytes null
    • parseFromOrNull

      @Private static RegionInfo parseFromOrNull(byte[] bytes, int offset, int len)
      Returns A deserialized RegionInfo or null if we failed deserialize or passed bytes null
    • parseFrom

      @Private static RegionInfo parseFrom(byte[] bytes) throws DeserializationException
      Returns A deserialized RegionInfo
      Throws:
      DeserializationException
    • parseFrom

      @Private static RegionInfo parseFrom(byte[] bytes, int offset, int len) throws DeserializationException
      Parse a serialized representation of RegionInfo
      Parameters:
      bytes - A pb RegionInfo serialized with a pb magic prefix.
      offset - starting point in the byte array
      len - length to read on the byte array
      Returns:
      A deserialized RegionInfo
      Throws:
      DeserializationException
    • areAdjacent

      static boolean areAdjacent(RegionInfo regionA, RegionInfo regionB)
      Check whether two regions are adjacent; i.e. lies just before or just after in a table.
      Returns:
      true if two regions are adjacent
    • toByteArray

      static byte[] toByteArray(RegionInfo ri)
      Returns This instance serialized as protobuf w/ a magic pb prefix.
      See Also:
    • prettyPrint

      static String prettyPrint(String encodedRegionName)
      Use logging.
      Parameters:
      encodedRegionName - The encoded regionname.
      Returns:
      hbase:meta if passed 1028785192 else returns encodedRegionName
    • createRegionName

      static byte[] createRegionName(TableName tableName, byte[] startKey, long regionid, boolean newFormat)
      Make a region name of passed parameters.
      Parameters:
      startKey - Can be null
      regionid - Region id (Usually timestamp from when region was created).
      newFormat - should we create the region name in the new format (such that it contains its encoded name?).
      Returns:
      Region name made of passed tableName, startKey and id
    • createRegionName

      static byte[] createRegionName(TableName tableName, byte[] startKey, String id, boolean newFormat)
      Make a region name of passed parameters.
      Parameters:
      startKey - Can be null
      id - Region id (Usually timestamp from when region was created).
      newFormat - should we create the region name in the new format (such that it contains its encoded name?).
      Returns:
      Region name made of passed tableName, startKey and id
    • createRegionName

      static byte[] createRegionName(TableName tableName, byte[] startKey, long regionid, int replicaId, boolean newFormat)
      Make a region name of passed parameters.
      Parameters:
      startKey - Can be null
      regionid - Region id (Usually timestamp from when region was created).
      newFormat - should we create the region name in the new format (such that it contains its encoded name?).
      Returns:
      Region name made of passed tableName, startKey, id and replicaId
    • createRegionName

      static byte[] createRegionName(TableName tableName, byte[] startKey, byte[] id, boolean newFormat)
      Make a region name of passed parameters.
      Parameters:
      startKey - Can be null
      id - Region id (Usually timestamp from when region was created).
      newFormat - should we create the region name in the new format (such that it contains its encoded name?).
      Returns:
      Region name made of passed tableName, startKey and id
    • createRegionName

      static byte[] createRegionName(TableName tableName, byte[] startKey, byte[] id, int replicaId, boolean newFormat)
      Make a region name of passed parameters.
      Parameters:
      startKey - Can be null
      id - Region id (Usually timestamp from when region was created).
      newFormat - should we create the region name in the new format
      Returns:
      Region name made of passed tableName, startKey, id and replicaId
    • createMobRegionInfo

      Creates a RegionInfo object for MOB data.
      Parameters:
      tableName - the name of the table
      Returns:
      the MOB RegionInfo.
    • parseRegionName

      static byte[][] parseRegionName(byte[] regionName) throws IOException
      Separate elements of a regionName.
      Returns:
      Array of byte[] containing tableName, startKey and id OR null if not parseable as a region name.
      Throws:
      IOException - if not parseable as regionName.
    • parseRegionNameOrReturnNull

      static byte[][] parseRegionNameOrReturnNull(byte[] regionName)
      Separate elements of a regionName. Region name is of the format: tablename,startkey,regionIdTimestamp[_replicaId][.encodedName.]. Startkey can contain the delimiter (',') so we parse from the start and then parse from the end.
      Returns:
      Array of byte[] containing tableName, startKey and id OR null if not parseable as a region name.
    • toDelimitedByteArray

      static byte[] toDelimitedByteArray(RegionInfo... infos) throws IOException
      Serializes given RegionInfo's as a byte array. Use this instead of toByteArray(RegionInfo) when writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads to EOF which may not be what you want). parseDelimitedFrom(byte[], int, int) can be used to read back the instances.
      Parameters:
      infos - RegionInfo objects to serialize
      Returns:
      This instance serialized as a delimited protobuf w/ a magic pb prefix.
      Throws:
      IOException
    • toDelimitedByteArray

      static byte[] toDelimitedByteArray(RegionInfo ri) throws IOException
      Use this instead of toByteArray(RegionInfo) when writing to a stream and you want to use the pb mergeDelimitedFrom (w/o the delimiter, pb reads to EOF which may not be what you want).
      Returns:
      This instance serialized as a delimied protobuf w/ a magic pb prefix.
      Throws:
      IOException
    • parseFrom

      Parses an RegionInfo instance from the passed in stream. Presumes the RegionInfo was serialized to the stream with toDelimitedByteArray(RegionInfo).
      Returns:
      An instance of RegionInfo.
      Throws:
      IOException
    • parseDelimitedFrom

      static List<RegionInfo> parseDelimitedFrom(byte[] bytes, int offset, int length) throws IOException
      Parses all the RegionInfo instances from the passed in stream until EOF. Presumes the RegionInfo's were serialized to the stream with oDelimitedByteArray()
      Parameters:
      bytes - serialized bytes
      offset - the start offset into the byte[] buffer
      length - how far we should read into the byte[] buffer
      Returns:
      All the RegionInfos that are in the byte array. Keeps reading till we hit the end.
      Throws:
      IOException
    • isFirst

      default boolean isFirst()
      Returns True if this is first Region in Table
    • isLast

      default boolean isLast()
      Returns True if this is last Region in Table
    • isNext

      default boolean isNext(RegionInfo after)
      Returns True if region is next, adjacent but 'after' this one.
      See Also:
    • isAdjacent

      default boolean isAdjacent(RegionInfo other)
      Returns True if region is adjacent, either just before or just after this one.
      See Also:
    • isDegenerate

      default boolean isDegenerate()
      Returns True if RegionInfo is degenerate... if startKey > endKey.
    • isOverlap

      default boolean isOverlap(RegionInfo other)
      Returns True if an overlap in region range.
      See Also:
    • compareTo

      default int compareTo(RegionInfo other)
      Specified by:
      compareTo in interface Comparable<RegionInfo>