HBase meta表介紹

在網(wǎng)上較多的文章都會介紹hbase的兩個關鍵表ROOT表與meta表。其實在hbase0.98之后,hbase就廢棄了ROOT表,僅保留meta表(還有namespace表,該表只與hbase命名空間有關,這里不做介紹),并且該表不允許split。

meta split

在0.98后,meta被禁止進行split操作。要知道m(xù)eta表的一條記錄包含了一個region的位置、起始key,創(chuàng)建時間等信息。那萬一region數(shù)量過大怎么辦?查看了公司集群一共1091個region,meta表的大小如圖所示:

image

假定集群有十萬個region,meta表也就400多M。在生產(chǎn)環(huán)境下,hbase.hregion.max.filesize配置為10G,如果按照這個大小來看,meta可支持的region的數(shù)據(jù)是一個很可觀的數(shù)量。

meta位置

meta表location info以非臨時znode的方式注冊到zk上,如下圖,可知meta region位置為centos063機器。

image

meta rowkey

meta表的rowkey信息在HRegionInfo類的createRegionName方法中構(gòu)建,代碼如下:

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, <tablename>,<startKey>,<id>_<replicaId>)
      // 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 '.<encodedName>.' 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;
  }

根據(jù)上圖源碼,再通過hbase shell查詢mate表信息如下圖:

image

可知,hash值=MD5Hash.getMD5AsHex(byte(表名,region startKey,創(chuàng)建時間)),meta表的rowkey組成為:表名,region startKey,創(chuàng)建時間.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

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 參考:http://m.itdecent.cn/p/569106a3008f 最近在逐步跟進Hbase的相關...
    博弈史密斯閱讀 935評論 1 1
  • 最近在逐步跟進Hbase的相關工作,由于之前對Hbase并不怎么了解,因此系統(tǒng)地學習了下Hbase,為了加深對Hb...
    飛鴻無痕閱讀 50,609評論 19 272
  • 比特科技: 存儲、數(shù)據(jù)庫、大數(shù)據(jù)技術 ? HBase原理和設計 http://www.bitstech.net/...
    葡萄喃喃囈語閱讀 767評論 0 11
  • 本文首先簡單介紹了HBase,然后重點講述了HBase的高并發(fā)和實時處理數(shù)據(jù) 、HBase數(shù)據(jù)模型、HBase物理...
    達微閱讀 2,854評論 1 13
  • 簡介 HBase —— Hadoop Database的簡稱,Google BigTable的另一種開源實現(xiàn)方式,...
    尼小摩閱讀 587評論 0 3

友情鏈接更多精彩內(nèi)容