Package org.apache.hadoop.hbase.client
Interface RegionInfo
- All Superinterfaces:
Comparable<RegionInfo>
- All Known Implementing Classes:
MutableRegionInfo
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:
Other than the fields in the region name, region info contains:
- 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 Summary
Modifier and TypeFieldDescriptionstatic final Comparator<RegionInfo>
static final int
static final int
Separator used to demarcate the encodedName in a region name in the new format.static final String
static final int
static final byte
static final String
to keep appended int's sorted in string format. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAdjacent
(RegionInfo regionA, RegionInfo regionB) Check whether two regions are adjacent; i.e.default int
compareTo
(RegionInfo other) 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) Returns true if the given row falls in this region.static RegionInfo
createMobRegionInfo
(TableName tableName) Creates a RegionInfo object for MOB data.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, byte[] id, int replicaId, 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, long regionid, int replicaId, 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) Returns the encodedNameReturns the encoded region name.byte[]
Returns the encoded region name as an array of bytes.byte[]
Returns the endKey.long
Returns the regionId.byte[]
Returns the regionName as an array of bytes.Returns Region name as a String for use in logging, etc.static String
getRegionNameAsString
(byte[] regionName) static String
getRegionNameAsString
(RegionInfo ri, byte[] regionName) int
Returns returns region replica idReturns Return a short, printable name for this region (usually encoded name) for us logging.static String
getShortNameToLog
(List<RegionInfo> ris) Returns a String of short, printable names forhris
(usually encoded name) for us logging.static String
getShortNameToLog
(RegionInfo... hris) Returns a String of short, printable names forhris
(usually encoded name) for us logging.byte[]
Returns the startKey.static byte[]
getStartKey
(byte[] regionName) Gets the start key from the specified region name.getTable()
Returns current table name of the regionstatic TableName
getTable
(byte[] regionName) Gets the table name from the specified region name.static boolean
hasEncodedName
(byte[] regionName) Does region name contain its encoded name?default boolean
isAdjacent
(RegionInfo other) Returns True if region is adjacent, either just before or just after this one.default boolean
Returns True if RegionInfo is degenerate...static boolean
isEncodedRegionName
(byte[] regionName) Figure if the passed bytes represent an encoded region name or not.default boolean
isFirst()
Returns True if this is first Region in Tabledefault boolean
isLast()
Returns True if this is last Region in Tableboolean
Returns true if this region is a meta region.default boolean
isNext
(RegionInfo after) Returns True if region is next, adjacent but 'after' this one.boolean
Deprecated.since 3.0.0 and will be removed in 4.0.0default boolean
isOverlap
(RegionInfo other) Returns True if an overlap in region range.boolean
isSplit()
Returns True if has been split and has daughters.boolean
Deprecated.since 3.0.0 and will be removed in 4.0.0, UseisSplit()
instead.static List<RegionInfo>
parseDelimitedFrom
(byte[] bytes, int offset, int length) Parses all the RegionInfo instances from the passed in stream until EOF.static RegionInfo
parseFrom
(byte[] bytes) Returns A deserializedRegionInfo
static RegionInfo
parseFrom
(byte[] bytes, int offset, int len) Parse a serialized representation ofRegionInfo
static RegionInfo
Parses an RegionInfo instance from the passed in stream.static RegionInfo
parseFromOrNull
(byte[] bytes) Returns A deserializedRegionInfo
or null if we failed deserialize or passed bytes nullstatic RegionInfo
parseFromOrNull
(byte[] bytes, int offset, int len) Returns A deserializedRegionInfo
or null if we failed deserialize or passed bytes nullstatic byte[][]
parseRegionName
(byte[] regionName) Separate elements of a regionName.static byte[][]
parseRegionNameOrReturnNull
(byte[] regionName) Separate elements of a regionName.static String
prettyPrint
(String encodedRegionName) Use logging.static byte[]
Returns This instance serialized as protobuf w/ a magic pb prefix.static byte[]
Use this instead oftoByteArray(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).static byte[]
toDelimitedByteArray
(RegionInfo... infos) Serializes given RegionInfo's as a byte array.
-
Field Details
-
ENC_SEPARATOR
Separator used to demarcate the encodedName in a region name in the new format. See description on new format above.- See Also:
-
MD5_HEX_LENGTH
- See Also:
-
DEFAULT_REPLICA_ID
- See Also:
-
REPLICA_ID_FORMAT
to keep appended int's sorted in string format. Only allows 2 bytes to be sorted for replicaId.- See Also:
-
REPLICA_ID_DELIMITER
- See Also:
-
INVALID_REGION_NAME_FORMAT_MESSAGE
- See Also:
-
COMPARATOR
-
-
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
byte[] 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
int 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.0Returns True if this region is offline.- See Also:
-
isSplitParent
Deprecated.since 3.0.0 and will be removed in 4.0.0, UseisSplit()
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
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
Returns true if the given row falls in this region. -
hasEncodedName
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
Returns the encodedName -
getRegionNameAsString
-
getRegionNameAsString
-
getShortNameToLog
Returns a String of short, printable names forhris
(usually encoded name) for us logging. -
getShortNameToLog
Returns a String of short, printable names forhris
(usually encoded name) for us logging. -
getTable
Gets the table name from the specified region name.- Parameters:
regionName
- to extract the table name from- Returns:
- Table name
-
getStartKey
Gets the start key from the specified region name.- Returns:
- Start key.
- Throws:
IOException
-
isEncodedRegionName
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
Returns A deserializedRegionInfo
or null if we failed deserialize or passed bytes null -
parseFromOrNull
Returns A deserializedRegionInfo
or null if we failed deserialize or passed bytes null -
parseFrom
Returns A deserializedRegionInfo
- Throws:
DeserializationException
-
parseFrom
@Private static RegionInfo parseFrom(byte[] bytes, int offset, int len) throws DeserializationException Parse a serialized representation ofRegionInfo
- Parameters:
bytes
- A pb RegionInfo serialized with a pb magic prefix.offset
- starting point in the byte arraylen
- length to read on the byte array- Returns:
- A deserialized
RegionInfo
- Throws:
DeserializationException
-
areAdjacent
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
Returns This instance serialized as protobuf w/ a magic pb prefix.- See Also:
-
prettyPrint
Use logging.- Parameters:
encodedRegionName
- The encoded regionname.- Returns:
hbase:meta
if passed1028785192
else returnsencodedRegionName
-
createRegionName
static byte[] createRegionName(TableName tableName, byte[] startKey, long regionid, boolean newFormat) Make a region name of passed parameters.- Parameters:
startKey
- Can be nullregionid
- 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
Make a region name of passed parameters.- Parameters:
startKey
- Can be nullid
- 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 nullregionid
- 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
Make a region name of passed parameters.- Parameters:
startKey
- Can be nullid
- 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 nullid
- 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
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
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
Serializes given RegionInfo's as a byte array. Use this instead oftoByteArray(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
Use this instead oftoByteArray(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 withtoDelimitedByteArray(RegionInfo)
.- Returns:
- An instance of RegionInfo.
- Throws:
IOException
-
parseDelimitedFrom
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 bytesoffset
- the start offset into the byte[] bufferlength
- 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
Returns True if this is first Region in Table -
isLast
Returns True if this is last Region in Table -
isNext
Returns True if region is next, adjacent but 'after' this one. -
isAdjacent
Returns True if region is adjacent, either just before or just after this one.- See Also:
-
isDegenerate
Returns True if RegionInfo is degenerate... if startKey > endKey. -
isOverlap
Returns True if an overlap in region range.- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<RegionInfo>
-