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

The following examples show how to use org.apache.hadoop.hbase.MetaTableAccessor#makePutFromRegionInfo() . 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: IndexSplitTransaction.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void offlineParentInMetaAndputMetaEntries(Connection conn,
    HRegionInfo parent, HRegionInfo splitA, HRegionInfo splitB,
    ServerName serverName, List<Mutation> metaEntries) throws IOException {
  List<Mutation> mutations = metaEntries;
  HRegionInfo copyOfParent = new HRegionInfo(parent);
  copyOfParent.setOffline(true);
  copyOfParent.setSplit(true);

  //Put for parent
  Put putParent = MetaTableAccessor.makePutFromRegionInfo(copyOfParent);
  MetaTableAccessor.addDaughtersToPut(putParent, splitA, splitB);
  mutations.add(putParent);
  
  //Puts for daughters
  Put putA = MetaTableAccessor.makePutFromRegionInfo(splitA);
  Put putB = MetaTableAccessor.makePutFromRegionInfo(splitB);

  addLocation(putA, serverName, 1); //these are new regions, openSeqNum = 1 is fine.
  addLocation(putB, serverName, 1);
  mutations.add(putA);
  mutations.add(putB);
  MetaTableAccessor.mutateMetaTable(conn, mutations);
}
 
Example 2
Source File: FavoredNodeAssignmentHelper.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Generates and returns a Put containing the region info for the catalog table and the servers
 * @return Put object
 */
private static Put makePutFromRegionInfo(RegionInfo regionInfo, List<ServerName> favoredNodeList)
    throws IOException {
  Put put = null;
  if (favoredNodeList != null) {
    long time = EnvironmentEdgeManager.currentTime();
    put = MetaTableAccessor.makePutFromRegionInfo(regionInfo, time);
    byte[] favoredNodes = getFavoredNodes(favoredNodeList);
    put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
        .setRow(put.getRow())
        .setFamily(HConstants.CATALOG_FAMILY)
        .setQualifier(FAVOREDNODES_QUALIFIER)
        .setTimestamp(time)
        .setType(Type.Put)
        .setValue(favoredNodes)
        .build());
    LOG.debug("Create the region {} with favored nodes {}", regionInfo.getRegionNameAsString(),
      favoredNodeList);
  }
  return put;
}
 
Example 3
Source File: HBaseFsck.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Reset the split parent region info in meta table
 */
private void resetSplitParent(HbckRegionInfo hi) throws IOException {
  RowMutations mutations = new RowMutations(hi.getMetaEntry().getRegionInfo().getRegionName());
  Delete d = new Delete(hi.getMetaEntry().getRegionInfo().getRegionName());
  d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER);
  d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER);
  mutations.add(d);

  RegionInfo hri = RegionInfoBuilder.newBuilder(hi.getMetaEntry().getRegionInfo())
    .setOffline(false).setSplit(false).build();
  Put p = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime());
  mutations.add(p);

  meta.mutateRow(mutations);
  LOG.info("Reset split parent " + hi.getMetaEntry().getRegionInfo().getRegionNameAsString() +
    " in META");
}
 
Example 4
Source File: HBaseFsckRepair.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Puts the specified RegionInfo into META with replica related columns
 */
public static void fixMetaHoleOnlineAndAddReplicas(Configuration conf,
    RegionInfo hri, Collection<ServerName> servers, int numReplicas) throws IOException {
  Connection conn = ConnectionFactory.createConnection(conf);
  Table meta = conn.getTable(TableName.META_TABLE_NAME);
  Put put = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime());
  if (numReplicas > 1) {
    Random r = new Random();
    ServerName[] serversArr = servers.toArray(new ServerName[servers.size()]);
    for (int i = 1; i < numReplicas; i++) {
      ServerName sn = serversArr[r.nextInt(serversArr.length)];
      // the column added here is just to make sure the master is able to
      // see the additional replicas when it is asked to assign. The
      // final value of these columns will be different and will be updated
      // by the actual regionservers that start hosting the respective replicas
      MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), i);
    }
  }
  meta.put(put);
  meta.close();
  conn.close();
}
 
Example 5
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 6
Source File: LocalIndexSplitter.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void preSplitBeforePONR(ObserverContext<RegionCoprocessorEnvironment> ctx,
        byte[] splitKey, List<Mutation> metaEntries) throws IOException {
    RegionCoprocessorEnvironment environment = ctx.getEnvironment();
    HTableDescriptor tableDesc = ctx.getEnvironment().getRegion().getTableDesc();
    if (SchemaUtil.isSystemTable(tableDesc.getName())) {
        return;
    }
    RegionServerServices rss = ctx.getEnvironment().getRegionServerServices();
    if (tableDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) == null
            || !Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(tableDesc
                    .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
        TableName indexTable =
                TableName.valueOf(MetaDataUtil.getLocalIndexPhysicalName(tableDesc.getName()));
        if (!MetaTableAccessor.tableExists(rss.getConnection(), indexTable)) return;

        HRegion indexRegion = IndexUtil.getIndexRegion(environment);
        if (indexRegion == null) {
            LOG.warn("Index region corresponindg to data region " + environment.getRegion()
                    + " not in the same server. So skipping the split.");
            ctx.bypass();
            return;
        }
        try {
            int encodedVersion = VersionUtil.encodeVersion(environment.getHBaseVersion());
            if(encodedVersion >= SPLIT_TXN_MINIMUM_SUPPORTED_VERSION) {
                st = new SplitTransaction(indexRegion, splitKey);
                st.useZKForAssignment =
                        environment.getConfiguration().getBoolean("hbase.assignment.usezk",
                            true);
            } else {
                st = new IndexSplitTransaction(indexRegion, splitKey);
            }

            if (!st.prepare()) {
                LOG.error("Prepare for the table " + indexRegion.getTableDesc().getNameAsString()
                    + " failed. So returning null. ");
                ctx.bypass();
                return;
            }
            indexRegion.forceSplit(splitKey);
            daughterRegions = st.stepsBeforePONR(rss, rss, false);
            HRegionInfo copyOfParent = new HRegionInfo(indexRegion.getRegionInfo());
            copyOfParent.setOffline(true);
            copyOfParent.setSplit(true);
            // Put for parent
            Put putParent = MetaTableAccessor.makePutFromRegionInfo(copyOfParent);
            MetaTableAccessor.addDaughtersToPut(putParent,
                    daughterRegions.getFirst().getRegionInfo(),
                    daughterRegions.getSecond().getRegionInfo());
            metaEntries.add(putParent);
            // Puts for daughters
            Put putA = MetaTableAccessor.makePutFromRegionInfo(
                    daughterRegions.getFirst().getRegionInfo());
            Put putB = MetaTableAccessor.makePutFromRegionInfo(
                    daughterRegions.getSecond().getRegionInfo());
            st.addLocation(putA, rss.getServerName(), 1);
            st.addLocation(putB, rss.getServerName(), 1);
            metaEntries.add(putA);
            metaEntries.add(putB);
        } catch (Exception e) {
            ctx.bypass();
            LOG.warn("index region splitting failed with the exception ", e);
            if (st != null){
                st.rollback(rss, rss);
                st = null;
                daughterRegions = null;
            }
        }
    }
}
 
Example 7
Source File: TestMetaFixer.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * This test covers the case that one of merged parent regions is a merged child region that
 * has not been GCed but there is no reference files anymore. In this case, it will kick off
 * a GC procedure, but no merge will happen.
 */
@Test
public void testMergeWithMergedChildRegion() throws Exception {
  TableName tn = TableName.valueOf(this.name.getMethodName());
  Table t = TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY);
  List<RegionInfo> ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
  assertTrue(ris.size() > 5);
  HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
  CatalogJanitor cj = services.getCatalogJanitor();
  cj.scan();
  CatalogJanitor.Report report = cj.getLastReport();
  assertTrue(report.isEmpty());
  RegionInfo overlapRegion = makeOverlap(services, ris.get(1), ris.get(2));

  cj.scan();
  report = cj.getLastReport();
  assertEquals(2, report.getOverlaps().size());

  // Mark it as a merged child region.
  RegionInfo fakedParentRegion = RegionInfoBuilder.newBuilder(tn).
    setStartKey(overlapRegion.getStartKey()).
    build();

  Table meta = MetaTableAccessor.getMetaHTable(TEST_UTIL.getConnection());
  Put putOfMerged = MetaTableAccessor.makePutFromRegionInfo(overlapRegion,
    HConstants.LATEST_TIMESTAMP);
  String qualifier = String.format(HConstants.MERGE_QUALIFIER_PREFIX_STR + "%04d", 0);
  putOfMerged.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(
    putOfMerged.getRow()).
    setFamily(HConstants.CATALOG_FAMILY).
    setQualifier(Bytes.toBytes(qualifier)).
    setTimestamp(putOfMerged.getTimestamp()).
    setType(Cell.Type.Put).
    setValue(RegionInfo.toByteArray(fakedParentRegion)).
    build());

  meta.put(putOfMerged);

  MetaFixer fixer = new MetaFixer(services);
  fixer.fixOverlaps(report);

  // Wait until all procedures settled down
  HBaseTestingUtility.await(200, () -> {
    return services.getMasterProcedureExecutor().getActiveProcIds().isEmpty();
  });

  // No merge is done, overlap is still there.
  cj.scan();
  report = cj.getLastReport();
  assertEquals(2, report.getOverlaps().size());

  fixer.fixOverlaps(report);

  // Wait until all procedures settled down
  HBaseTestingUtility.await(200, () -> {
    return services.getMasterProcedureExecutor().getActiveProcIds().isEmpty();
  });

  // Merge is done and no more overlaps
  cj.scan();
  report = cj.getLastReport();
  assertEquals(0, report.getOverlaps().size());
}