void removeParentsAndFixSplits()

in hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java [3455:3563]


      void removeParentsAndFixSplits(Collection<HbckInfo> overlap) throws IOException {
        Pair<byte[], byte[]> range = null;
        HbckInfo parent = null;
        HbckInfo daughterA = null;
        HbckInfo daughterB = null;
        Collection<HbckInfo> daughters = new ArrayList<>(overlap);

        String thread = Thread.currentThread().getName();
        LOG.info("== [" + thread + "] Attempting fix splits in overlap state.");

        // we only can handle a single split per group at the time
        if (overlap.size() > 3) {
          LOG.info("Too many overlaps were found on this group, falling back to regular merge.");
          return;
        }

        for (HbckInfo hi : overlap) {
          if (range == null) {
            range = new Pair<>(hi.getStartKey(), hi.getEndKey());
          } else {
            if (RegionSplitCalculator.BYTES_COMPARATOR
              .compare(hi.getStartKey(), range.getFirst()) < 0) {
              range.setFirst(hi.getStartKey());
            }
            if (RegionSplitCalculator.BYTES_COMPARATOR
              .compare(hi.getEndKey(), range.getSecond()) > 0) {
              range.setSecond(hi.getEndKey());
            }
          }
        }

        LOG.info("This group range is [" + Bytes.toStringBinary(range.getFirst()) + ", "
          + Bytes.toStringBinary(range.getSecond()) + "]");

        // attempt to find a possible parent for the edge case of a split
        for (HbckInfo hi : overlap) {
          if (Bytes.compareTo(hi.getHdfsHRI().getStartKey(), range.getFirst()) == 0
            && Bytes.compareTo(hi.getHdfsHRI().getEndKey(), range.getSecond()) == 0) {
            LOG.info("This is a parent for this group: " + hi.toString());
            parent = hi;
          }
        }

        // Remove parent regions from daughters collection
        if (parent != null) {
          daughters.remove(parent);
        }

        // Lets verify that daughters share the regionID at split time and they
        // were created after the parent
        for (HbckInfo hi : daughters) {
          if (Bytes.compareTo(hi.getHdfsHRI().getStartKey(), range.getFirst()) == 0) {
            if (parent.getHdfsHRI().getRegionId() < hi.getHdfsHRI().getRegionId()) {
              daughterA = hi;
            }
          }
          if (Bytes.compareTo(hi.getHdfsHRI().getEndKey(), range.getSecond()) == 0) {
            if (parent.getHdfsHRI().getRegionId() < hi.getHdfsHRI().getRegionId()) {
              daughterB = hi;
            }
          }
        }

        // daughters must share the same regionID and we should have a parent too
        if (daughterA.getHdfsHRI().getRegionId() != daughterB.getHdfsHRI().getRegionId() ||
            parent == null) {
          return;
        }

        LOG.info("Found parent: " + parent.getRegionNameAsString());
        LOG.info("Found potential daughter a: " + daughterA.getRegionNameAsString());
        LOG.info("Found potential daughter b: " + daughterB.getRegionNameAsString());
        LOG.info("Trying to fix parent in overlap by removing the parent.");
        try {
          closeRegion(parent);
        } catch (IOException | InterruptedException e) {
          LOG.warn("Parent region could not be closed, continuing with regular merge...", e);
          return;
        }

        try {
          offline(parent.getRegionName());
        } catch (IOException ioe) {
          LOG.warn("Unable to offline parent region: " + parent.getRegionNameAsString()
            + ".  Just continuing with regular merge... ", ioe);
          return;
        }

        try {
          HBaseFsckRepair.removeParentInMeta(conf, parent.getHdfsHRI());
        } catch (IOException ioe) {
          LOG.warn("Unable to remove parent region in META: " + parent.getRegionNameAsString()
            + ".  Just continuing with regular merge... ", ioe);
          return;
        }

        sidelineRegionDir(rootFs, parent);
        LOG.info("[" + thread + "] Sidelined parent region dir "+ parent.getHdfsRegionDir() +
            " into " + getSidelineDir());
        debugLsr(parent.getHdfsRegionDir());

        // Make sure we don't have the parents and daughters around
        overlap.remove(parent);
        overlap.remove(daughterA);
        overlap.remove(daughterB);

        LOG.info("Done fixing split.");

      }