Search in sources :

Example 1 with RegionInfoBuilder

use of org.apache.hadoop.hbase.client.RegionInfoBuilder in project hbase by apache.

the class ProtobufUtil method toRegionInfo.

/**
 * Convert HBaseProto.RegionInfo to a RegionInfo
 *
 * @param proto the RegionInfo to convert
 * @return the converted RegionInfo
 */
public static org.apache.hadoop.hbase.client.RegionInfo toRegionInfo(final HBaseProtos.RegionInfo proto) {
    if (proto == null) {
        return null;
    }
    TableName tableName = ProtobufUtil.toTableName(proto.getTableName());
    long regionId = proto.getRegionId();
    int defaultReplicaId = org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID;
    int replicaId = proto.hasReplicaId() ? proto.getReplicaId() : defaultReplicaId;
    if (tableName.equals(TableName.META_TABLE_NAME) && replicaId == defaultReplicaId) {
        return RegionInfoBuilder.FIRST_META_REGIONINFO;
    }
    byte[] startKey = null;
    byte[] endKey = null;
    if (proto.hasStartKey()) {
        startKey = proto.getStartKey().toByteArray();
    }
    if (proto.hasEndKey()) {
        endKey = proto.getEndKey().toByteArray();
    }
    boolean split = false;
    if (proto.hasSplit()) {
        split = proto.getSplit();
    }
    RegionInfoBuilder rib = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(endKey).setRegionId(regionId).setReplicaId(replicaId).setSplit(split);
    if (proto.hasOffline()) {
        rib.setOffline(proto.getOffline());
    }
    return rib.build();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionInfoBuilder(org.apache.hadoop.hbase.client.RegionInfoBuilder)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1 RegionInfoBuilder (org.apache.hadoop.hbase.client.RegionInfoBuilder)1