Java Code Examples for org.apache.hadoop.hbase.client.RegionInfo#isSplit()

The following examples show how to use org.apache.hadoop.hbase.client.RegionInfo#isSplit() . 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: RegionStateNode.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void checkOnline() throws DoNotRetryRegionException {
  RegionInfo ri = getRegionInfo();
  State s = state;
  if (s != State.OPEN) {
    throw new DoNotRetryRegionException(ri.getEncodedName() + " is not OPEN; state=" + s);
  }
  if (ri.isSplitParent()) {
    throw new DoNotRetryRegionException(
      ri.getEncodedName() + " is not online (splitParent=true)");
  }
  if (ri.isSplit()) {
    throw new DoNotRetryRegionException(ri.getEncodedName() + " has split=true");
  }
  if (ri.isOffline()) {
    // RegionOfflineException is not instance of DNRIOE so wrap it.
    throw new DoNotRetryRegionException(new RegionOfflineException(ri.getEncodedName()));
  }
}
 
Example 2
Source File: RestoreSnapshotProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Add regions to in-memory states
 * @param regionInfos regions to add
 * @param env MasterProcedureEnv
 * @param regionReplication the number of region replications
 */
private void addRegionsToInMemoryStates(List<RegionInfo> regionInfos, MasterProcedureEnv env,
    int regionReplication) {
  AssignmentManager am = env.getAssignmentManager();
  for (RegionInfo regionInfo : regionInfos) {
    if (regionInfo.isSplit()) {
      am.getRegionStates().updateRegionState(regionInfo, RegionState.State.SPLIT);
    } else {
      am.getRegionStates().updateRegionState(regionInfo, RegionState.State.CLOSED);

      // For region replicas
      for (int i = 1; i < regionReplication; i++) {
        RegionInfo regionInfoForReplica =
            RegionReplicaUtil.getRegionInfoForReplica(regionInfo, i);
        am.getRegionStates().updateRegionState(regionInfoForReplica, RegionState.State.CLOSED);
      }
    }
  }
}
 
Example 3
Source File: TableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static List<RegionInfo> getRegionInfosFromManifest(SnapshotManifest manifest) {
  List<SnapshotRegionManifest> regionManifests = manifest.getRegionManifests();
  if (regionManifests == null) {
    throw new IllegalArgumentException("Snapshot seems empty");
  }

  List<RegionInfo> regionInfos = Lists.newArrayListWithCapacity(regionManifests.size());

  for (SnapshotRegionManifest regionManifest : regionManifests) {
    RegionInfo hri = ProtobufUtil.toRegionInfo(regionManifest.getRegionInfo());
    if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent())) {
      continue;
    }
    regionInfos.add(hri);
  }
  return regionInfos;
}
 
Example 4
Source File: RegionStates.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Utility. Whether to include region in list of regions. Default is to
 * weed out split and offline regions.
 * @return True if we should include the <code>node</code> (do not include
 * if split or offline unless <code>offline</code> is set to true.
 */
boolean include(final RegionStateNode node, final boolean offline) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("WORKING ON " + node + " " + node.getRegionInfo());
  }
  final RegionInfo hri = node.getRegionInfo();
  if (node.isInState(State.SPLIT) || hri.isSplit()) {
    return false;
  }
  if ((node.isInState(State.OFFLINE) || hri.isOffline()) && !offline) {
    return false;
  }
  return (!hri.isOffline() && !hri.isSplit()) ||
      ((hri.isOffline() || hri.isSplit()) && offline);
}
 
Example 5
Source File: TableSnapshotResultIterator.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Exclude offline split parent regions and
 * regions that don't intersect with provided scan
 */
private boolean isValidRegion(RegionInfo hri) {
  if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent())) {
    return false;
  }
  return PrivateCellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(),
          hri.getStartKey(), hri.getEndKey());
}
 
Example 6
Source File: RegionsMerger.java    From hbase-operator-tools with Apache License 2.0 4 votes vote down vote up
public void mergeRegions(String tblName, int targetRegions) throws Exception {
  TableName table = TableName.valueOf(tblName);
  Path tableDir = getTablePath(table);
  try(Connection conn = ConnectionFactory.createConnection(conf)) {
    Admin admin = conn.getAdmin();
    LongAdder counter = new LongAdder();
    LongAdder lastTimeProgessed = new LongAdder();
    //need to get all regions for the table, regardless of region state
    List<RegionInfo> regions = admin.getRegions(table);
    Map<Future, Pair<RegionInfo, RegionInfo>> regionsMerging = new ConcurrentHashMap<>();
    long roundsNoProgress = 0;
    while (regions.size() > targetRegions) {
      LOG.info("Iteration: {}", counter);
      RegionInfo previous = null;
      int regionSize = regions.size();
      LOG.info("Attempting to merge {} regions to reach the target {} ...", regionSize, targetRegions);
      //to request merge, regions must be OPEN, though
      regions = getOpenRegions(conn, table);
      for (RegionInfo current : regions) {
        if (!current.isSplit()) {
          if (previous != null && canMerge(tableDir, previous, current, regionsMerging.values())) {
            Future f = admin.mergeRegionsAsync(current.getEncodedNameAsBytes(),
                previous.getEncodedNameAsBytes(), true);
            Pair<RegionInfo, RegionInfo> regionPair = new Pair<>(previous, current);
            regionsMerging.put(f,regionPair);
            previous = null;
            if ((regionSize - regionsMerging.size()) <= targetRegions) {
              break;
            }
          } else {
            previous = current;
          }
        }
        else{
          LOG.debug("Skipping split region: {}", current.getEncodedName());
        }
      }
      counter.increment();
      LOG.info("Sleeping for {} seconds before next iteration...", (sleepBetweenCycles/1000));
      Thread.sleep(sleepBetweenCycles);
      regionsMerging.forEach((f, currentPair)-> {
        if (f.isDone()) {
          LOG.info("Merged regions {} and {} together.",
            currentPair.getFirst().getEncodedName(),
            currentPair.getSecond().getEncodedName());
          regionsMerging.remove(f);
          lastTimeProgessed.reset();
          lastTimeProgessed.add(counter.longValue());
        } else {
          LOG.warn("Merge of regions {} and {} isn't completed yet.",
            currentPair.getFirst(),
            currentPair.getSecond());
        }
      });
      roundsNoProgress = counter.longValue() - lastTimeProgessed.longValue();
      if(roundsNoProgress == this.maxRoundsStuck){
        LOG.warn("Reached {} iterations without progressing with new merges. Aborting...",
          roundsNoProgress);
        break;
      }

      //again, get all regions, regardless of the state,
      // in order to avoid breaking the loop prematurely
      regions = admin.getRegions(table);
    }
  }
}
 
Example 7
Source File: SnapshotOfRegionAssignmentFromMeta.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the region assignment snapshot by scanning the hbase:meta table
 * @throws IOException
 */
public void initialize() throws IOException {
  LOG.info("Start to scan the hbase:meta for the current region assignment " +
    "snappshot");
  // TODO: at some point this code could live in the MetaTableAccessor
  ClientMetaTableAccessor.Visitor v = new ClientMetaTableAccessor.Visitor() {
    @Override
    public boolean visit(Result result) throws IOException {
      try {
        if (result ==  null || result.isEmpty()) return true;
        RegionLocations rl = CatalogFamilyFormat.getRegionLocations(result);
        if (rl == null) return true;
        RegionInfo hri = rl.getRegionLocation(0).getRegion();
        if (hri == null) return true;
        if (hri.getTable() == null) return true;
        if (disabledTables.contains(hri.getTable())) {
          return true;
        }
        // Are we to include split parents in the list?
        if (excludeOfflinedSplitParents && hri.isSplit()) return true;
        HRegionLocation[] hrls = rl.getRegionLocations();

        // Add the current assignment to the snapshot for all replicas
        for (int i = 0; i < hrls.length; i++) {
          if (hrls[i] == null) continue;
          hri = hrls[i].getRegion();
          if (hri == null) continue;
          addAssignment(hri, hrls[i].getServerName());
          addRegion(hri);
        }

        hri = rl.getRegionLocation(0).getRegion();
        // the code below is to handle favored nodes
        byte[] favoredNodes = result.getValue(HConstants.CATALOG_FAMILY,
            FavoredNodeAssignmentHelper.FAVOREDNODES_QUALIFIER);
        if (favoredNodes == null) return true;
        // Add the favored nodes into assignment plan
        ServerName[] favoredServerList =
            FavoredNodeAssignmentHelper.getFavoredNodesList(favoredNodes);
        // Add the favored nodes into assignment plan
        existingAssignmentPlan.updateFavoredNodesMap(hri,
            Arrays.asList(favoredServerList));

        /*
         * Typically there should be FAVORED_NODES_NUM favored nodes for a region in meta. If
         * there is less than FAVORED_NODES_NUM, lets use as much as we can but log a warning.
         */
        if (favoredServerList.length != FavoredNodeAssignmentHelper.FAVORED_NODES_NUM) {
          LOG.warn("Insufficient favored nodes for region " + hri + " fn: " + Arrays
              .toString(favoredServerList));
        }
        for (int i = 0; i < favoredServerList.length; i++) {
          if (i == PRIMARY.ordinal()) addPrimaryAssignment(hri, favoredServerList[i]);
          if (i == SECONDARY.ordinal()) addSecondaryAssignment(hri, favoredServerList[i]);
          if (i == TERTIARY.ordinal()) addTeritiaryAssignment(hri, favoredServerList[i]);
        }
        return true;
      } catch (RuntimeException e) {
        LOG.error("Catche remote exception " + e.getMessage() +
            " when processing" + result);
        throw e;
      }
    }
  };
  // Scan hbase:meta to pick up user regions
  MetaTableAccessor.fullScanRegions(connection, v);
  //regionToRegionServerMap = regions;
  LOG.info("Finished to scan the hbase:meta for the current region assignment" +
    "snapshot");
}
 
Example 8
Source File: SplitTableRegionProcedure.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Prepare to Split region.
 * @param env MasterProcedureEnv
 */
@VisibleForTesting
public boolean prepareSplitRegion(final MasterProcedureEnv env) throws IOException {
  // Fail if we are taking snapshot for the given table
  if (env.getMasterServices().getSnapshotManager()
    .isTakingSnapshot(getParentRegion().getTable())) {
    setFailure(new IOException("Skip splitting region " + getParentRegion().getShortNameToLog() +
      ", because we are taking snapshot for the table " + getParentRegion().getTable()));
    return false;
  }
  // Check whether the region is splittable
  RegionStateNode node =
      env.getAssignmentManager().getRegionStates().getRegionStateNode(getParentRegion());

  if (node == null) {
    throw new UnknownRegionException(getParentRegion().getRegionNameAsString());
  }

  RegionInfo parentHRI = node.getRegionInfo();
  if (parentHRI == null) {
    LOG.info("Unsplittable; parent region is null; node={}", node);
    return false;
  }
  // Lookup the parent HRI state from the AM, which has the latest updated info.
  // Protect against the case where concurrent SPLIT requests came in and succeeded
  // just before us.
  if (node.isInState(State.SPLIT)) {
    LOG.info("Split of " + parentHRI + " skipped; state is already SPLIT");
    return false;
  }
  if (parentHRI.isSplit() || parentHRI.isOffline()) {
    LOG.info("Split of " + parentHRI + " skipped because offline/split.");
    return false;
  }

  // expected parent to be online or closed
  if (!node.isInState(EXPECTED_SPLIT_STATES)) {
    // We may have SPLIT already?
    setFailure(new IOException("Split " + parentHRI.getRegionNameAsString() +
        " FAILED because state=" + node.getState() + "; expected " +
        Arrays.toString(EXPECTED_SPLIT_STATES)));
    return false;
  }

  // Mostly this check is not used because we already check the switch before submit a split
  // procedure. Just for safe, check the switch again. This procedure can be rollbacked if
  // the switch was set to false after submit.
  if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
    LOG.warn("pid=" + getProcId() + " split switch is off! skip split of " + parentHRI);
    setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString() +
        " failed due to split switch off"));
    return false;
  }

  if (!env.getMasterServices().getTableDescriptors().get(getTableName()).isSplitEnabled()) {
    LOG.warn("pid={}, split is disabled for the table! Skipping split of {}", getProcId(),
      parentHRI);
    setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString()
        + " failed as region split is disabled for the table"));
    return false;
  }

  // set node state as SPLITTING
  node.setState(State.SPLITTING);

  // Since we have the lock and the master is coordinating the operation
  // we are always able to split the region
  return true;
}
 
Example 9
Source File: MapReduceParallelScanGrouper.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private boolean isValidRegion(RegionInfo hri) {
	if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent())) {
		return false;
	}
	return true;
}