org.apache.hadoop.hbase
Class HRegionInfo

java.lang.Object
  extended by org.apache.hadoop.hbase.HRegionInfo
All Implemented Interfaces:
Comparable<HRegionInfo>

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class HRegionInfo
extends Object
implements Comparable<HRegionInfo>

HRegion information. Contains HRegion id, start and end keys, a reference to this HRegions' table descriptor, etc. On a big cluster, each client will have thousands of instances of this object, often 100 000 of them if not million. It's important to keep the object size as small as possible.


Field Summary
static String ENCODED_REGION_NAME_REGEX
          A non-capture group so that this can be embedded.
static HRegionInfo FIRST_META_REGIONINFO
          HRegionInfo for first meta region
static int MD5_HEX_LENGTH
           
static String NO_HASH
           
static byte VERSION
          Deprecated. 
 
Constructor Summary
HRegionInfo()
          Deprecated. Used by Writables and Writables are going away.
HRegionInfo(HRegionInfo other)
          Costruct a copy of another HRegionInfo
HRegionInfo(TableName tableName)
           
HRegionInfo(TableName tableName, byte[] startKey, byte[] endKey)
          Construct HRegionInfo with explicit parameters
HRegionInfo(TableName tableName, byte[] startKey, byte[] endKey, boolean split)
          Construct HRegionInfo with explicit parameters
HRegionInfo(TableName tableName, byte[] startKey, byte[] endKey, boolean split, long regionid)
          Construct HRegionInfo with explicit parameters
 
Method Summary
static boolean areAdjacent(HRegionInfo regionA, HRegionInfo regionB)
          Check whether two regions are adjacent
 int compareTo(HRegionInfo o)
           
 boolean containsRange(byte[] rangeStartKey, byte[] rangeEndKey)
          Returns true if the given inclusive range of rows is fully contained by this region.
 boolean containsRow(byte[] row)
          Return true if the given row falls in this region.
static HRegionInfo convert(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo proto)
          Convert a RegionInfo to a HRegionInfo
static org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo convert(HRegionInfo info)
          Convert a HRegionInfo to a RegionInfo
static byte[] createRegionName(TableName tableName, byte[] startKey, byte[] id, boolean newFormat)
          Make a region name of passed parameters.
static byte[] createRegionName(TableName tableName, byte[] startKey, long regionid, boolean newFormat)
          Make a region name of passed parameters.
static byte[] createRegionName(TableName tableName, byte[] startKey, String id, boolean newFormat)
          Make a region name of passed parameters.
static String encodeRegionName(byte[] regionName)
           
 boolean equals(Object o)
           
 KeyValue.KVComparator getComparator()
           
static PairOfSameType<HRegionInfo> getDaughterRegions(Result data)
          Returns the daughter regions by reading the corresponding columns of the catalog table Result.
 String getEncodedName()
           
 byte[] getEncodedNameAsBytes()
           
 byte[] getEndKey()
           
static HRegionInfo getHRegionInfo(Result data)
          Returns HRegionInfo object from the column HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog table Result.
static HRegionInfo getHRegionInfo(Result r, byte[] qualifier)
          Returns the HRegionInfo object from the column HConstants.CATALOG_FAMILY and qualifier of the catalog table result.
static Pair<HRegionInfo,ServerName> getHRegionInfoAndServerName(Result r)
          Extract a HRegionInfo and ServerName from catalog table Result.
static PairOfSameType<HRegionInfo> getMergeRegions(Result data)
          Returns the merge regions by reading the corresponding columns of the catalog table Result.
 long getRegionId()
           
 byte[] getRegionName()
           
 String getRegionNameAsString()
           
static long getSeqNumDuringOpen(Result r)
          The latest seqnum that the server writing to meta observed when opening the region.
static ServerName getServerName(Result r)
          Returns a ServerName from catalog table Result.
 String getShortNameToLog()
           
 byte[] getStartKey()
           
static byte[] getStartKey(byte[] regionName)
          Gets the start key from the specified region name.
 TableName getTable()
          Get current table name of the region
static TableName getTable(byte[] regionName)
          Gets the table name from the specified region name.
 byte[] getTableName()
          Deprecated. Since 0.96.0; use #getTable()
static byte[] getTableName(byte[] regionName)
          Deprecated. Since 0.96.0; use #getTable(byte[])
 byte getVersion()
          Deprecated. HRI is no longer a VersionedWritable
 int hashCode()
           
 boolean isMetaRegion()
           
 boolean isMetaTable()
           
 boolean isOffline()
           
 boolean isSplit()
           
 boolean isSplitParent()
           
static List<HRegionInfo> parseDelimitedFrom(byte[] bytes, int offset, int length)
          Parses all the HRegionInfo instances from the passed in stream until EOF.
static HRegionInfo parseFrom(byte[] bytes)
           
static HRegionInfo parseFrom(byte[] bytes, int offset, int len)
           
static HRegionInfo parseFrom(DataInputStream in)
          Parses an HRegionInfo instance from the passed in stream.
static HRegionInfo parseFromOrNull(byte[] bytes)
           
static HRegionInfo parseFromOrNull(byte[] bytes, int offset, int len)
           
static byte[][] parseRegionName(byte[] regionName)
          Separate elements of a regionName.
static String prettyPrint(String encodedRegionName)
          Use logging.
 void readFields(DataInput in)
          Deprecated. Use protobuf deserialization instead.
 void setOffline(boolean offLine)
          The parent of a region split is offline while split daughters hold references to the parent.
 void setSplit(boolean split)
           
 byte[] toByteArray()
           
 byte[] toDelimitedByteArray()
          Use this instead of toByteArray() 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).
static byte[] toDelimitedByteArray(HRegionInfo... infos)
          Serializes given HRegionInfo's as a byte array.
 String toString()
           
 void write(DataOutput out)
          Deprecated. Use protobuf serialization instead. See toByteArray() and toDelimitedByteArray()
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

@Deprecated
public static final byte VERSION
Deprecated. 
See Also:
Constant Field Values

MD5_HEX_LENGTH

public static final int MD5_HEX_LENGTH
See Also:
Constant Field Values

ENCODED_REGION_NAME_REGEX

public static final String ENCODED_REGION_NAME_REGEX
A non-capture group so that this can be embedded.

See Also:
Constant Field Values

NO_HASH

public static final String NO_HASH

FIRST_META_REGIONINFO

public static final HRegionInfo FIRST_META_REGIONINFO
HRegionInfo for first meta region

Constructor Detail

HRegionInfo

@Deprecated
public HRegionInfo()
Deprecated. Used by Writables and Writables are going away.

Default constructor - creates empty object


HRegionInfo

public HRegionInfo(TableName tableName)

HRegionInfo

public HRegionInfo(TableName tableName,
                   byte[] startKey,
                   byte[] endKey)
            throws IllegalArgumentException
Construct HRegionInfo with explicit parameters

Parameters:
tableName - the table name
startKey - first key in region
endKey - end of key range
Throws:
IllegalArgumentException

HRegionInfo

public HRegionInfo(TableName tableName,
                   byte[] startKey,
                   byte[] endKey,
                   boolean split)
            throws IllegalArgumentException
Construct HRegionInfo with explicit parameters

Parameters:
tableName - the table descriptor
startKey - first key in region
endKey - end of key range
split - true if this region has split and we have daughter regions regions that may or may not hold references to this region.
Throws:
IllegalArgumentException

HRegionInfo

public HRegionInfo(TableName tableName,
                   byte[] startKey,
                   byte[] endKey,
                   boolean split,
                   long regionid)
            throws IllegalArgumentException
Construct HRegionInfo with explicit parameters

Parameters:
tableName - the table descriptor
startKey - first key in region
endKey - end of key range
split - true if this region has split and we have daughter regions regions that may or may not hold references to this region.
regionid - Region id to use.
Throws:
IllegalArgumentException

HRegionInfo

public HRegionInfo(HRegionInfo other)
Costruct a copy of another HRegionInfo

Parameters:
other -
Method Detail

encodeRegionName

public static String encodeRegionName(byte[] regionName)
Parameters:
regionName -
Returns:
the encodedName

getShortNameToLog

public String getShortNameToLog()
Returns:
Return a short, printable name for this region (usually encoded name) for us logging.

prettyPrint

public static String prettyPrint(String encodedRegionName)
Use logging.

Parameters:
encodedRegionName - The encoded regionname.
Returns:
hbase:meta if passed 1028785192 else returns encodedRegionName

createRegionName

public static byte[] createRegionName(TableName tableName,
                                      byte[] startKey,
                                      long regionid,
                                      boolean newFormat)
Make a region name of passed parameters.

Parameters:
tableName -
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

public static byte[] createRegionName(TableName tableName,
                                      byte[] startKey,
                                      String id,
                                      boolean newFormat)
Make a region name of passed parameters.

Parameters:
tableName -
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

public static byte[] createRegionName(TableName tableName,
                                      byte[] startKey,
                                      byte[] id,
                                      boolean newFormat)
Make a region name of passed parameters.

Parameters:
tableName -
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

getTableName

@Deprecated
public static byte[] getTableName(byte[] regionName)
Deprecated. Since 0.96.0; use #getTable(byte[])

Gets the table name from the specified region name.

Parameters:
regionName -
Returns:
Table name.

getTable

public static TableName getTable(byte[] regionName)
Gets the table name from the specified region name. Like getTableName(byte[]) only returns a TableName rather than a byte array.

Parameters:
regionName -
Returns:
Table name
See Also:
getTableName(byte[])

getStartKey

public static byte[] getStartKey(byte[] regionName)
                          throws IOException
Gets the start key from the specified region name.

Parameters:
regionName -
Returns:
Start key.
Throws:
IOException

parseRegionName

public static byte[][] parseRegionName(byte[] regionName)
                                throws IOException
Separate elements of a regionName.

Parameters:
regionName -
Returns:
Array of byte[] containing tableName, startKey and id
Throws:
IOException

getRegionId

public long getRegionId()
Returns:
the regionId

getRegionName

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

getRegionNameAsString

public String getRegionNameAsString()
Returns:
Region name as a String for use in logging, etc.

getEncodedName

public String getEncodedName()
Returns:
the encoded region name

getEncodedNameAsBytes

public byte[] getEncodedNameAsBytes()

getStartKey

public byte[] getStartKey()
Returns:
the startKey

getEndKey

public byte[] getEndKey()
Returns:
the endKey

getTableName

@Deprecated
public byte[] getTableName()
Deprecated. Since 0.96.0; use #getTable()

Get current table name of the region

Returns:
byte array of table name

getTable

public TableName getTable()
Get current table name of the region

Returns:
TableName
See Also:
getTableName()

containsRange

public 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

public boolean containsRow(byte[] row)
Return true if the given row falls in this region.


isMetaTable

public boolean isMetaTable()
Returns:
true if this region is from hbase:meta

isMetaRegion

public boolean isMetaRegion()
Returns:
true if this region is a meta region

isSplit

public boolean isSplit()
Returns:
True if has been split and has daughters.

setSplit

public void setSplit(boolean split)
Parameters:
split - set split status

isOffline

public boolean isOffline()
Returns:
True if this region is offline.

setOffline

public void setOffline(boolean offLine)
The parent of a region split is offline while split daughters hold references to the parent. Offlined regions are closed.

Parameters:
offLine - Set online/offline status.

isSplitParent

public boolean isSplitParent()
Returns:
True if this is a split parent region.

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

equals

public boolean equals(Object o)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

getVersion

@Deprecated
public byte getVersion()
Deprecated. HRI is no longer a VersionedWritable

Returns:
the object version number

write

@Deprecated
public void write(DataOutput out)
           throws IOException
Deprecated. Use protobuf serialization instead. See toByteArray() and toDelimitedByteArray()

Throws:
IOException

readFields

@Deprecated
public void readFields(DataInput in)
                throws IOException
Deprecated. Use protobuf deserialization instead.

Throws:
IOException
See Also:
parseFrom(byte[])

compareTo

public int compareTo(HRegionInfo o)
Specified by:
compareTo in interface Comparable<HRegionInfo>

getComparator

public KeyValue.KVComparator getComparator()
Returns:
Comparator to use comparing KeyValues.

convert

public static org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo convert(HRegionInfo info)
Convert a HRegionInfo to a RegionInfo

Parameters:
info - the HRegionInfo to convert
Returns:
the converted RegionInfo

convert

public static HRegionInfo convert(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo proto)
Convert a RegionInfo to a HRegionInfo

Parameters:
proto - the RegionInfo to convert
Returns:
the converted HRegionInfho

toByteArray

public byte[] toByteArray()
Returns:
This instance serialized as protobuf w/ a magic pb prefix.
See Also:
parseFrom(byte[])

parseFromOrNull

public static HRegionInfo parseFromOrNull(byte[] bytes)
Returns:
A deserialized HRegionInfo or null if we failed deserialize or passed bytes null
See Also:
toByteArray()

parseFromOrNull

public static HRegionInfo parseFromOrNull(byte[] bytes,
                                          int offset,
                                          int len)
Returns:
A deserialized HRegionInfo or null if we failed deserialize or passed bytes null
See Also:
toByteArray()

parseFrom

public static HRegionInfo parseFrom(byte[] bytes)
                             throws DeserializationException
Parameters:
bytes - A pb RegionInfo serialized with a pb magic prefix.
Returns:
A deserialized HRegionInfo
Throws:
DeserializationException
See Also:
toByteArray()

parseFrom

public static HRegionInfo parseFrom(byte[] bytes,
                                    int offset,
                                    int len)
                             throws DeserializationException
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 HRegionInfo
Throws:
DeserializationException
See Also:
toByteArray()

toDelimitedByteArray

public byte[] toDelimitedByteArray()
                            throws IOException
Use this instead of toByteArray() 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 delimited protobuf w/ a magic pb prefix.
Throws:
IOException
See Also:
toByteArray()

getHRegionInfoAndServerName

public static Pair<HRegionInfo,ServerName> getHRegionInfoAndServerName(Result r)
Extract a HRegionInfo and ServerName from catalog table Result.

Parameters:
r - Result to pull from
Returns:
A pair of the HRegionInfo and the ServerName (or null for server address if no address set in hbase:meta).
Throws:
IOException

getHRegionInfo

public static HRegionInfo getHRegionInfo(Result data)
Returns HRegionInfo object from the column HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog table Result.

Parameters:
data - a Result object from the catalog table scan
Returns:
HRegionInfo or null

getDaughterRegions

public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data)
                                                      throws IOException
Returns the daughter regions by reading the corresponding columns of the catalog table Result.

Parameters:
data - a Result object from the catalog table scan
Returns:
a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split parent
Throws:
IOException

getMergeRegions

public static PairOfSameType<HRegionInfo> getMergeRegions(Result data)
                                                   throws IOException
Returns the merge regions by reading the corresponding columns of the catalog table Result.

Parameters:
data - a Result object from the catalog table scan
Returns:
a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split parent
Throws:
IOException

getHRegionInfo

public static HRegionInfo getHRegionInfo(Result r,
                                         byte[] qualifier)
Returns the HRegionInfo object from the column HConstants.CATALOG_FAMILY and qualifier of the catalog table result.

Parameters:
r - a Result object from the catalog table scan
qualifier - Column family qualifier -- either HConstants.SPLITA_QUALIFIER, HConstants.SPLITB_QUALIFIER or HConstants.REGIONINFO_QUALIFIER.
Returns:
An HRegionInfo instance or null.

getServerName

public static ServerName getServerName(Result r)
Returns a ServerName from catalog table Result.

Parameters:
r - Result to pull from
Returns:
A ServerName instance or null if necessary fields not found or empty.

getSeqNumDuringOpen

public static long getSeqNumDuringOpen(Result r)
The latest seqnum that the server writing to meta observed when opening the region. E.g. the seqNum when the result of getServerName(Result) was written.

Parameters:
r - Result to pull the seqNum from
Returns:
SeqNum, or HConstants.NO_SEQNUM if there's no value written.

parseFrom

public static HRegionInfo parseFrom(DataInputStream in)
                             throws IOException
Parses an HRegionInfo instance from the passed in stream. Presumes the HRegionInfo was serialized to the stream with toDelimitedByteArray()

Parameters:
in -
Returns:
An instance of HRegionInfo.
Throws:
IOException

toDelimitedByteArray

public static byte[] toDelimitedByteArray(HRegionInfo... infos)
                                   throws IOException
Serializes given HRegionInfo's as a byte array. Use this instead of toByteArray() 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 - HRegionInfo objects to serialize
Returns:
This instance serialized as a delimited protobuf w/ a magic pb prefix.
Throws:
IOException
See Also:
toByteArray()

parseDelimitedFrom

public static List<HRegionInfo> parseDelimitedFrom(byte[] bytes,
                                                   int offset,
                                                   int length)
                                            throws IOException
Parses all the HRegionInfo instances from the passed in stream until EOF. Presumes the HRegionInfo's were serialized to the stream with toDelimitedByteArray()

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 hregioninfos that are in the byte array. Keeps reading till we hit the end.
Throws:
IOException

areAdjacent

public static boolean areAdjacent(HRegionInfo regionA,
                                  HRegionInfo regionB)
Check whether two regions are adjacent

Parameters:
regionA -
regionB -
Returns:
true if two regions are adjacent


Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.