hbck源码系列(四)--表的完整性检查和修复

一,完整性检查

  1检查表在HDFS的完整性

hbck源码系列(四)--表的完整性检查和修复_第1张图片

 hbck源码系列(四)--表的完整性检查和修复_第2张图片

hbck源码系列(四)--表的完整性检查和修复_第3张图片

二.checkRegionChain方法

     完整性检查,主要检查工作在checkRegionChain方法,该方法主要两个作用:

   1.根据检查条件检查异常

   2.根据检查条件修复异常

    检查条件和异常都指什么?

    2.1  异常

  @Override
  public void handleRegionStartKeyNotEmpty(HbckInfo hi) throws IOException{
    errors.reportError(ERROR_CODE.FIRST_REGION_STARTKEY_NOT_EMPTY,
        "First region should start with an empty key.  You need to "
        + " create a new region and regioninfo in HDFS to plug the hole.",
        getTableInfo(), hi);
  }

  @Override
  public void handleRegionEndKeyNotEmpty(byte[] curEndKey) throws IOException {
    errors.reportError(ERROR_CODE.LAST_REGION_ENDKEY_NOT_EMPTY,
        "Last region should end with an empty key. You need to "
            + "create a new region and regioninfo in HDFS to plug the hole.", getTableInfo());
  }

  @Override
  public void handleDegenerateRegion(HbckInfo hi) throws IOException{
    errors.reportError(ERROR_CODE.DEGENERATE_REGION,
        "Region has the same start and end key.", getTableInfo(), hi);
  }

  @Override
  public void handleDuplicateStartKeys(HbckInfo r1, HbckInfo r2) throws IOException{
    byte[] key = r1.getStartKey();
    // dup start key
    errors.reportError(ERROR_CODE.DUPE_STARTKEYS,
        "Multiple regions have the same startkey: "
        + Bytes.toStringBinary(key), getTableInfo(), r1);
    errors.reportError(ERROR_CODE.DUPE_STARTKEYS,
        "Multiple regions have the same startkey: "
        + Bytes.toStringBinary(key), getTableInfo(), r2);
  }

  @Override
  public void handleSplit(HbckInfo r1, HbckInfo r2) throws IOException{
    byte[] key = r1.getStartKey();
    // dup start key
    errors.reportError(ERROR_CODE.DUPE_ENDKEYS,
      "Multiple regions have the same regionID: "
        + Bytes.toStringBinary(key), getTableInfo(), r1);
    errors.reportError(ERROR_CODE.DUPE_ENDKEYS,
      "Multiple regions have the same regionID: "
        + Bytes.toStringBinary(key), getTableInfo(), r2);
  }

  @Override
  public void handleOverlapInRegionChain(HbckInfo hi1, HbckInfo hi2) throws IOException{
    errors.reportError(ERROR_CODE.OVERLAP_IN_REGION_CHAIN,
        "There is an overlap in the region chain.",
        getTableInfo(), hi1, hi2);
  }

  @Override
  public void handleHoleInRegionChain(byte[] holeStart, byte[] holeStop) throws IOException{
    errors.reportError(
        ERROR_CODE.HOLE_IN_REGION_CHAIN,
        "There is a hole in the region chain between "
            + Bytes.toStringBinary(holeStart) + " and "
            + Bytes.toStringBinary(holeStop)
            + ".  You need to create a new .regioninfo and region "
            + "dir in hdfs to plug the hole.");
  }
};

2.2检查条件

     之前说过表的完整性检查主要是检查表的hole、overlap和orphan等情况,检查条件是判断上述异常的依据,在源码中的判断依据是什么,这里根据不同的情况,描述不同的检查条件,详见各个章节。

  •    hole
  •   orphan
  •   overlap
  •   others

你可能感兴趣的:(Hbase)