HBase meta表介绍

在网上较多的文章都会介绍hbase的两个关键表ROOT表与meta表。其实在hbase0.98之后,hbase就废弃了ROOT表,仅保留meta表(还有namespace表,该表只与hbase命名空间有关,这里不做介绍),并且该表不允许split。

meta split

在0.98后,meta被禁止进行split操作。要知道meta表的一条记录包含了一个region的位置、起始key,创建时间等信息。那万一region数量过大怎么办?查看了公司集群一共1091个region,meta表的大小如图所示:

image

假定集群有十万个region,meta表也就400多M。在生产环境下,hbase.hregion.max.filesize配置为10G,如果按照这个大小来看,meta可支持的region的数据是一个很可观的数量。

meta位置

meta表location info以非临时znode的方式注册到zk上,如下图,可知meta region位置为centos063机器。

HBase meta表介绍_第1张图片
image

meta rowkey

meta表的rowkey信息在HRegionInfo类的createRegionName方法中构建,代码如下:

public static byte [] createRegionName(final TableName tableName,
      final byte [] startKey, final byte [] id, final int replicaId, boolean newFormat) {
    int len = tableName.getName().length + 2 + id.length +
        (startKey == null? 0: startKey.length);
    if (newFormat) {
      len += MD5_HEX_LENGTH + 2;
    }
    byte[] replicaIdBytes = null;
    // Special casing: replicaId is only appended if replicaId is greater than
    // 0. This is because all regions in meta would have to be migrated to the new
    // name otherwise
    if (replicaId > 0) {
      // use string representation for replica id
      replicaIdBytes = Bytes.toBytes(String.format(REPLICA_ID_FORMAT, replicaId));
      len += 1 + replicaIdBytes.length;
    }

    byte [] b = new byte [len];

    int offset = tableName.getName().length;
    System.arraycopy(tableName.getName(), 0, b, 0, offset);
    b[offset++] = HConstants.DELIMITER;
    if (startKey != null && startKey.length > 0) {
      System.arraycopy(startKey, 0, b, offset, startKey.length);
      offset += startKey.length;
    }
    b[offset++] = HConstants.DELIMITER;
    System.arraycopy(id, 0, b, offset, id.length);
    offset += id.length;

    if (replicaIdBytes != null) {
      b[offset++] = REPLICA_ID_DELIMITER;
      System.arraycopy(replicaIdBytes, 0, b, offset, replicaIdBytes.length);
      offset += replicaIdBytes.length;
    }

    if (newFormat) {
      //
      // Encoded name should be built into the region name.
      //
      // Use the region name thus far (namely, ,,_)
      // to compute a MD5 hash to be used as the encoded name, and append
      // it to the byte buffer.
      //
      String md5Hash = MD5Hash.getMD5AsHex(b, 0, offset);
      byte [] md5HashBytes = Bytes.toBytes(md5Hash);

      if (md5HashBytes.length != MD5_HEX_LENGTH) {
        LOG.error("MD5-hash length mismatch: Expected=" + MD5_HEX_LENGTH +
                  "; Got=" + md5HashBytes.length);
      }

      // now append the bytes '..' to the end
      b[offset++] = ENC_SEPARATOR;
      System.arraycopy(md5HashBytes, 0, b, offset, MD5_HEX_LENGTH);
      offset += MD5_HEX_LENGTH;
      b[offset++] = ENC_SEPARATOR;
    }

    return b;
  }

根据上图源码,再通过hbase shell查询mate表信息如下图:

HBase meta表介绍_第2张图片
image

可知,hash值=MD5Hash.getMD5AsHex(byte(表名,region startKey,创建时间)),meta表的rowkey组成为: 表名,region startKey,创建时间.hash值。如果当前region为table的第一个region时(第一个region无start key)时,region startKey=null。

mete info

meta表只有一个列簇info,并且包含四列:
1、regioninfo :当前region的startKey与endKey,name等消息
2、seqnumDuringOpen:
3、server:region所在服务器及端口
4、serverstartcode:服务开始的时候的timestamp

你可能感兴趣的:(HBase meta表介绍)