Java Code Examples for org.apache.hadoop.hbase.MetaTableAccessor#getMergeRegions()

The following examples show how to use org.apache.hadoop.hbase.MetaTableAccessor#getMergeRegions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogJanitor.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the specified region has merge qualifiers, if so, try to clean them.
 * @return true if no info:merge* columns; i.e. the specified region doesn't have
 *   any merge qualifiers.
 */
public boolean cleanMergeQualifier(final RegionInfo region) throws IOException {
  // Get merge regions if it is a merged region and already has merge qualifier
  List<RegionInfo> parents = MetaTableAccessor.getMergeRegions(this.services.getConnection(),
      region.getRegionName());
  if (parents == null || parents.isEmpty()) {
    // It doesn't have merge qualifier, no need to clean
    return true;
  }

  // If a parent region is a merged child region and GC has not kicked in/finish its work yet,
  // return false in this case to avoid kicking in a merge, trying later.
  cleanMergeRegion(region, parents);
  return false;
}
 
Example 2
Source File: GCMultipleMergedRegionsProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected Flow executeFromState(MasterProcedureEnv env, GCMergedRegionsState state)
    throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + " execute state=" + state);
  }
  try {
    switch (state) {
      case GC_MERGED_REGIONS_PREPARE:
        // If GCMultipleMergedRegionsProcedure processing is slower than the CatalogJanitor's scan
        // interval, it will end resubmitting GCMultipleMergedRegionsProcedure for the same
        // region. We can skip duplicate GCMultipleMergedRegionsProcedure while previous finished
        List<RegionInfo> parents = MetaTableAccessor.getMergeRegions(
          env.getMasterServices().getConnection(), mergedChild.getRegionName());
        if (parents == null || parents.isEmpty()) {
          LOG.info("{} mergeXXX qualifiers have ALL been deleted", mergedChild.getShortNameToLog());
          return Flow.NO_MORE_STATE;
        }
        setNextState(GCMergedRegionsState.GC_MERGED_REGIONS_PURGE);
        break;
      case GC_MERGED_REGIONS_PURGE:
        addChildProcedure(createGCRegionProcedures(env));
        setNextState(GCMergedRegionsState.GC_REGION_EDIT_METADATA);
        break;
      case GC_REGION_EDIT_METADATA:
        MetaTableAccessor.deleteMergeQualifiers(env.getMasterServices().getConnection(),
            mergedChild);
        return Flow.NO_MORE_STATE;
      default:
        throw new UnsupportedOperationException(this + " unhandled state=" + state);
    }
  } catch (IOException ioe) {
    // TODO: This is going to spew log?
    LOG.warn("Error trying to GC merged regions {}; retrying...",
        this.parents.stream().map(r -> RegionInfo.getShortNameToLog(r)).
            collect(Collectors.joining(", ")),
        ioe);
  }
  return Flow.HAS_MORE_STATE;
}
 
Example 3
Source File: HBaseFsck.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Scan hbase:meta, adding all regions found to the regionInfo map.
 * @throws IOException if an error is encountered
 */
boolean loadMetaEntries() throws IOException {
  ClientMetaTableAccessor.Visitor visitor = new ClientMetaTableAccessor.Visitor() {
    int countRecord = 1;

    // comparator to sort KeyValues with latest modtime
    final Comparator<Cell> comp = new Comparator<Cell>() {
      @Override
      public int compare(Cell k1, Cell k2) {
        return Long.compare(k1.getTimestamp(), k2.getTimestamp());
      }
    };

    @Override
    public boolean visit(Result result) throws IOException {
      try {

        // record the latest modification of this META record
        long ts =  Collections.max(result.listCells(), comp).getTimestamp();
        RegionLocations rl = CatalogFamilyFormat.getRegionLocations(result);
        if (rl == null) {
          emptyRegionInfoQualifiers.add(result);
          errors.reportError(ERROR_CODE.EMPTY_META_CELL,
            "Empty REGIONINFO_QUALIFIER found in hbase:meta");
          return true;
        }
        ServerName sn = null;
        if (rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID) == null ||
            rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion() == null) {
          emptyRegionInfoQualifiers.add(result);
          errors.reportError(ERROR_CODE.EMPTY_META_CELL,
            "Empty REGIONINFO_QUALIFIER found in hbase:meta");
          return true;
        }
        RegionInfo hri = rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion();
        if (!(isTableIncluded(hri.getTable())
            || hri.isMetaRegion())) {
          return true;
        }
        PairOfSameType<RegionInfo> daughters = MetaTableAccessor.getDaughterRegions(result);
        for (HRegionLocation h : rl.getRegionLocations()) {
          if (h == null || h.getRegion() == null) {
            continue;
          }
          sn = h.getServerName();
          hri = h.getRegion();

          HbckRegionInfo.MetaEntry m = null;
          if (hri.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) {
            m = new HbckRegionInfo.MetaEntry(hri, sn, ts, daughters.getFirst(),
                daughters.getSecond());
          } else {
            m = new HbckRegionInfo.MetaEntry(hri, sn, ts, null, null);
          }
          HbckRegionInfo previous = regionInfoMap.get(hri.getEncodedName());
          if (previous == null) {
            regionInfoMap.put(hri.getEncodedName(), new HbckRegionInfo(m));
          } else if (previous.getMetaEntry() == null) {
            previous.setMetaEntry(m);
          } else {
            throw new IOException("Two entries in hbase:meta are same " + previous);
          }
        }
        List<RegionInfo> mergeParents = MetaTableAccessor.getMergeRegions(result.rawCells());
        if (mergeParents != null) {
          for (RegionInfo mergeRegion : mergeParents) {
            if (mergeRegion != null) {
              // This region is already being merged
              HbckRegionInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName());
              hbInfo.setMerged(true);
            }
          }
        }

        // show proof of progress to the user, once for every 100 records.
        if (countRecord % 100 == 0) {
          errors.progress();
        }
        countRecord++;
        return true;
      } catch (RuntimeException e) {
        LOG.error("Result=" + result);
        throw e;
      }
    }
  };
  if (!checkMetaOnly) {
    // Scan hbase:meta to pick up user regions
    MetaTableAccessor.fullScanRegions(connection, visitor);
  }

  errors.print("");
  return true;
}
 
Example 4
Source File: TestMergeTableRegionsProcedure.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void testMerge(TableName tableName, int mergeCount) throws IOException {
  List<RegionInfo> ris = MetaTableAccessor.getTableRegions(UTIL.getConnection(), tableName);
  int originalRegionCount = ris.size();
  assertTrue(originalRegionCount > mergeCount);
  RegionInfo[] regionsToMerge = ris.subList(0, mergeCount).toArray(new RegionInfo [] {});
  int countOfRowsLoaded = 0;
  try (Table table = UTIL.getConnection().getTable(tableName)) {
    countOfRowsLoaded = loadARowPerRegion(table, ris);
  }
  assertEquals(countOfRowsLoaded, UTIL.countRows(tableName));

  // collect AM metrics before test
  collectAssignmentManagerMetrics();
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
  MergeTableRegionsProcedure proc =
      new MergeTableRegionsProcedure(procExec.getEnvironment(), regionsToMerge, true);
  long procId = procExec.submitProcedure(proc);
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
  MetaTableAccessor.fullScanMetaAndPrint(UTIL.getConnection());
  assertEquals(originalRegionCount - mergeCount + 1,
      MetaTableAccessor.getTableRegions(UTIL.getConnection(), tableName).size());

  assertEquals(mergeSubmittedCount + 1, mergeProcMetrics.getSubmittedCounter().getCount());
  assertEquals(mergeFailedCount, mergeProcMetrics.getFailedCounter().getCount());
  assertEquals(assignSubmittedCount + 1, assignProcMetrics.getSubmittedCounter().getCount());
  assertEquals(assignFailedCount, assignProcMetrics.getFailedCounter().getCount());
  assertEquals(unassignSubmittedCount + mergeCount,
      unassignProcMetrics.getSubmittedCounter().getCount());
  assertEquals(unassignFailedCount, unassignProcMetrics.getFailedCounter().getCount());

  // Need to get the references cleaned out. Close of region will move them
  // to archive so disable and reopen just to get rid of references to later
  // when the catalogjanitor runs, it can do merged region cleanup.
  admin.disableTable(tableName);
  admin.enableTable(tableName);

  // Can I purge the merged regions from hbase:meta? Check that all went
  // well by looking at the merged row up in hbase:meta. It should have no
  // more mention of the merged regions; they are purged as last step in
  // the merged regions cleanup.
  UTIL.getHBaseCluster().getMaster().setCatalogJanitorEnabled(true);
  UTIL.getHBaseCluster().getMaster().getCatalogJanitor().triggerNow();
  byte [] mergedRegion = proc.getMergedRegion().getRegionName();
  while (ris != null && ris.get(0) != null && ris.get(1) != null) {
    ris = MetaTableAccessor.getMergeRegions(UTIL.getConnection(), mergedRegion);
    LOG.info("{} {}", Bytes.toStringBinary(mergedRegion), ris);
    Threads.sleep(1000);
  }
  assertEquals(countOfRowsLoaded, UTIL.countRows(tableName));
}
 
Example 5
Source File: CompatUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static List<RegionInfo> getMergeRegions(Connection conn, byte[] regionName)
        throws IOException {
    return MetaTableAccessor.getMergeRegions(conn, regionName);
}
 
Example 6
Source File: CompatUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static List<RegionInfo> getMergeRegions(Connection conn, byte[] regionName) 
        throws IOException {
    return MetaTableAccessor.getMergeRegions(conn, regionName);
}