1. 程式人生 > >HBase 0.94.3的HRegion名字

HBase 0.94.3的HRegion名字

2013-01-10

周海漢

2013.1.10

HBase 可以通過Region server的60030埠看到各區域的資訊。

Region Name Start Key End Key Metrics
-ROOT-,,0.70236052 numberOfStores=1, numberOfStorefiles=1, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=456675, writeRequestsCount=1, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=10, currentCompactedKVs=10, compactionProgressPct=1.0, coprocessors=[]
award_1209,2012-09-01 18:29:11:106558138,1356603311407.ece53b830498cf7e0462332056b436f9. 2012-09-01 18:29:11:106558138 2012-09-01 20:13:38:162325277 numberOfStores=1, numberOfStorefiles=1, storefileUncompressedSizeMB=133, storefileSizeMB=133, compressionRatio=1.0000, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=188270, writeRequestsCount=0, rootIndexSizeKB=0, totalStaticIndexSizeKB=140, totalStaticBloomSizeKB=0, totalCompactingKVs=4515962, currentCompactedKVs=1998451, compactionProgressPct=0.0, coprocessors=[]

新版的區域名字包含了尾巴上的encodeName,即用JenkinsHash計算後生成整形值轉成的10進位制字串,32位。其組成為“表名,起始行鍵,regionid.encodeName.”。ROOT表和第一個META表,及老版HRegion(0.20以前),使用老的區域名。

原始碼如下:

HRegionInfo.java (srcmainjavaorgapachehadoophbase) 25868 2012/11/15

/**
   * Make a region name of passed parameters.
   * @param tableName
   * @param startKey Can be null
   * @param id Region id (Usually timestamp from when region was created).
   * @param newFormat should we create the region name in the new format
   *                  (such that it contains its encoded name?).
   * @return Region name made of passed tableName, startKey and id
   */
  public static byte [] createRegionName(final byte [] tableName,
      final byte [] startKey, final byte [] id, boolean newFormat) {
    byte [] b = new byte [tableName.length + 2 + id.length +
       (startKey == null? 0: startKey.length) +
       (newFormat ? (MD5_HEX_LENGTH + 2) : 0)];

    int offset = tableName.length;
    System.arraycopy(tableName, 0, b, 0, offset);
    b[offset++] = DELIMITER;
    if (startKey != null && startKey.length > 0) {
      System.arraycopy(startKey, 0, b, offset, startKey.length);
      offset += startKey.length;
    }
    b[offset++] = DELIMITER;
    System.arraycopy(id, 0, b, offset, id.length);
    offset += id.length;
//新版增加一個Hash值
    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;
    }

如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源