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

The following examples show how to use org.apache.hadoop.hbase.MetaTableAccessor#putsToMetaTable() . 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: FavoredNodeAssignmentHelper.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Update meta table with favored nodes info
 * @param regionToFavoredNodes map of RegionInfo's to their favored nodes
 * @param connection connection to be used
 * @throws IOException
 */
public static void updateMetaWithFavoredNodesInfo(
    Map<RegionInfo, List<ServerName>> regionToFavoredNodes,
    Connection connection) throws IOException {
  List<Put> puts = new ArrayList<>();
  for (Map.Entry<RegionInfo, List<ServerName>> entry : regionToFavoredNodes.entrySet()) {
    Put put = makePutFromRegionInfo(entry.getKey(), entry.getValue());
    if (put != null) {
      puts.add(put);
    }
  }
  MetaTableAccessor.putsToMetaTable(connection, puts);
  LOG.info("Added " + puts.size() + " regions in META");
}
 
Example 2
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Update state of the region in meta only. This is required by hbck in some situations to cleanup
 * stuck assign/ unassign regions procedures for the table.
 *
 * @return previous states of the regions
 */
@Override
public SetRegionStateInMetaResponse setRegionStateInMeta(RpcController controller,
  SetRegionStateInMetaRequest request) throws ServiceException {
  SetRegionStateInMetaResponse.Builder builder = SetRegionStateInMetaResponse.newBuilder();
  try {
    for (RegionSpecifierAndState s : request.getStatesList()) {
      RegionSpecifier spec = s.getRegionSpecifier();
      String encodedName;
      if (spec.getType() == RegionSpecifierType.ENCODED_REGION_NAME) {
        encodedName = spec.getValue().toStringUtf8();
      } else {
        // TODO: actually, a full region name can save a lot on meta scan, improve later.
        encodedName = RegionInfo.encodeRegionName(spec.getValue().toByteArray());
      }
      RegionInfo info = this.master.getAssignmentManager().loadRegionFromMeta(encodedName);
      LOG.trace("region info loaded from meta table: {}", info);
      RegionState prevState =
        this.master.getAssignmentManager().getRegionStates().getRegionState(info);
      RegionState.State newState = RegionState.State.convert(s.getState());
      LOG.info("{} set region={} state from {} to {}", master.getClientIdAuditPrefix(), info,
        prevState.getState(), newState);
      Put metaPut = MetaTableAccessor.makePutFromRegionInfo(info, System.currentTimeMillis());
      metaPut.addColumn(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER,
        Bytes.toBytes(newState.name()));
      List<Put> putList = new ArrayList<>();
      putList.add(metaPut);
      MetaTableAccessor.putsToMetaTable(this.master.getConnection(), putList);
      // Loads from meta again to refresh AM cache with the new region state
      this.master.getAssignmentManager().loadRegionFromMeta(encodedName);
      builder.addStates(RegionSpecifierAndState.newBuilder().setRegionSpecifier(spec)
        .setState(prevState.getState().convert()));
    }
  } catch (Exception e) {
    throw new ServiceException(e);
  }
  return builder.build();
}
 
Example 3
Source File: TestMetaFixer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static RegionInfo makeOverlap(MasterServices services, RegionInfo a, RegionInfo b)
    throws IOException {
  RegionInfo overlapRegion = RegionInfoBuilder.newBuilder(a.getTable()).
      setStartKey(a.getStartKey()).
      setEndKey(b.getEndKey()).
      build();
  MetaTableAccessor.putsToMetaTable(services.getConnection(),
      Collections.singletonList(MetaTableAccessor.makePutFromRegionInfo(overlapRegion,
          System.currentTimeMillis())));
  // TODO: Add checks at assign time to PREVENT being able to assign over existing assign.
  services.getAssignmentManager().assign(overlapRegion);
  return overlapRegion;
}