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

The following examples show how to use org.apache.hadoop.hbase.client.RegionInfo#encodeRegionName() . 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: 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 2
Source File: SnapshotManifest.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the region encoded name from the region manifest
 */
static String getRegionNameFromManifest(final SnapshotRegionManifest manifest) {
  byte[] regionName = RegionInfo.createRegionName(
          ProtobufUtil.toTableName(manifest.getRegionInfo().getTableName()),
          manifest.getRegionInfo().getStartKey().toByteArray(),
          manifest.getRegionInfo().getRegionId(), true);
  return RegionInfo.encodeRegionName(regionName);
}
 
Example 3
Source File: Action.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected void unbalanceRegions(ClusterMetrics clusterStatus,
    List<ServerName> fromServers, List<ServerName> toServers,
    double fractionOfRegions) throws Exception {
  List<byte[]> victimRegions = new LinkedList<>();
  for (Map.Entry<ServerName, ServerMetrics> entry
    : clusterStatus.getLiveServerMetrics().entrySet()) {
    ServerName sn = entry.getKey();
    ServerMetrics serverLoad = entry.getValue();
    // Ugh.
    List<byte[]> regions = new LinkedList<>(serverLoad.getRegionMetrics().keySet());
    int victimRegionCount = (int)Math.ceil(fractionOfRegions * regions.size());
    getLogger().debug("Removing {} regions from {}", victimRegionCount, sn);
    for (int i = 0; i < victimRegionCount; ++i) {
      int victimIx = RandomUtils.nextInt(0, regions.size());
      String regionId = RegionInfo.encodeRegionName(regions.remove(victimIx));
      victimRegions.add(Bytes.toBytes(regionId));
    }
  }

  getLogger().info("Moving {} regions from {} servers to {} different servers",
    victimRegions.size(), fromServers.size(), toServers.size());
  Admin admin = this.context.getHBaseIntegrationTestingUtility().getAdmin();
  for (byte[] victimRegion : victimRegions) {
    // Don't keep moving regions if we're
    // trying to stop the monkey.
    if (context.isStopping()) {
      break;
    }
    int targetIx = RandomUtils.nextInt(0, toServers.size());
    admin.move(victimRegion, toServers.get(targetIx));
  }
}
 
Example 4
Source File: HRegionServer.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @return HRegion for the passed binary <code>regionName</code> or null if
 *         named region is not member of the online regions.
 */
public HRegion getOnlineRegion(final byte[] regionName) {
  String encodedRegionName = RegionInfo.encodeRegionName(regionName);
  return this.onlineRegions.get(encodedRegionName);
}
 
Example 5
Source File: HFilePrettyPrinter.java    From hbase with Apache License 2.0 4 votes vote down vote up
public boolean parseOptions(String args[]) throws ParseException,
    IOException {
  if (args.length == 0) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("hfile", options, true);
    return false;
  }
  CommandLineParser parser = new PosixParser();
  CommandLine cmd = parser.parse(options, args);

  verbose = cmd.hasOption("v");
  printValue = cmd.hasOption("p");
  printKey = cmd.hasOption("e") || printValue;
  shouldPrintMeta = cmd.hasOption("m");
  printBlockIndex = cmd.hasOption("b");
  printBlockHeaders = cmd.hasOption("h");
  printStats = cmd.hasOption("s");
  checkRow = cmd.hasOption("k");
  checkFamily = cmd.hasOption("a");
  checkMobIntegrity = cmd.hasOption("i");

  if (cmd.hasOption("f")) {
    files.add(new Path(cmd.getOptionValue("f")));
  }

  if (cmd.hasOption("w")) {
    String key = cmd.getOptionValue("w");
    if (key != null && key.length() != 0) {
      row = Bytes.toBytesBinary(key);
      isSeekToRow = true;
    } else {
      err.println("Invalid row is specified.");
      System.exit(-1);
    }
  }

  if (cmd.hasOption("r")) {
    String regionName = cmd.getOptionValue("r");
    byte[] rn = Bytes.toBytes(regionName);
    byte[][] hri = RegionInfo.parseRegionName(rn);
    Path rootDir = CommonFSUtils.getRootDir(getConf());
    Path tableDir = CommonFSUtils.getTableDir(rootDir, TableName.valueOf(hri[0]));
    String enc = RegionInfo.encodeRegionName(rn);
    Path regionDir = new Path(tableDir, enc);
    if (verbose)
      out.println("region dir -> " + regionDir);
    List<Path> regionFiles = HFile.getStoreFiles(FileSystem.get(getConf()),
        regionDir);
    if (verbose)
      out.println("Number of region files found -> "
          + regionFiles.size());
    if (verbose) {
      int i = 1;
      for (Path p : regionFiles) {
        if (verbose)
          out.println("Found file[" + i++ + "] -> " + p);
      }
    }
    files.addAll(regionFiles);
  }

  if(checkMobIntegrity) {
    if (verbose) {
      System.out.println("checkMobIntegrity is enabled");
    }
    mobFileLocations = new HashMap<>();
  }

  cmd.getArgList().forEach((file) -> files.add(new Path(file)));

  return true;
}
 
Example 6
Source File: RegionModeStrategy.java    From hbase with Apache License 2.0 4 votes vote down vote up
private Record createRecord(ServerMetrics serverMetrics, RegionMetrics regionMetrics,
  long lastReportTimestamp) {

  Record.Builder builder = Record.builder();

  String regionName = regionMetrics.getNameAsString();
  builder.put(Field.REGION_NAME, regionName);

  String namespaceName = "";
  String tableName = "";
  String region = "";
  String startKey = "";
  String startCode = "";
  String replicaId = "";
  try {
    byte[][] elements = RegionInfo.parseRegionName(regionMetrics.getRegionName());
    TableName tn = TableName.valueOf(elements[0]);
    namespaceName = tn.getNamespaceAsString();
    tableName = tn.getQualifierAsString();
    startKey = Bytes.toStringBinary(elements[1]);
    startCode = Bytes.toString(elements[2]);
    replicaId = elements.length == 4 ?
      Integer.valueOf(Bytes.toString(elements[3])).toString() : "";
    region = RegionInfo.encodeRegionName(regionMetrics.getRegionName());
  } catch (IOException ignored) {
  }

  builder.put(Field.NAMESPACE, namespaceName);
  builder.put(Field.TABLE, tableName);
  builder.put(Field.START_CODE, startCode);
  builder.put(Field.REPLICA_ID, replicaId);
  builder.put(Field.REGION, region);
  builder.put(Field.START_KEY, startKey);
  builder.put(Field.REGION_SERVER, serverMetrics.getServerName().toShortString());
  builder.put(Field.LONG_REGION_SERVER, serverMetrics.getServerName().getServerName());

  RequestCountPerSecond requestCountPerSecond = requestCountPerSecondMap.get(regionName);
  if (requestCountPerSecond == null) {
    requestCountPerSecond = new RequestCountPerSecond();
    requestCountPerSecondMap.put(regionName, requestCountPerSecond);
  }
  requestCountPerSecond.refresh(lastReportTimestamp, regionMetrics.getReadRequestCount(),
    regionMetrics.getFilteredReadRequestCount(), regionMetrics.getWriteRequestCount());

  builder.put(Field.READ_REQUEST_COUNT_PER_SECOND,
    requestCountPerSecond.getReadRequestCountPerSecond());
  builder.put(Field.FILTERED_READ_REQUEST_COUNT_PER_SECOND,
      requestCountPerSecond.getFilteredReadRequestCountPerSecond());
  builder.put(Field.WRITE_REQUEST_COUNT_PER_SECOND,
    requestCountPerSecond.getWriteRequestCountPerSecond());
  builder.put(Field.REQUEST_COUNT_PER_SECOND,
    requestCountPerSecond.getRequestCountPerSecond());

  builder.put(Field.STORE_FILE_SIZE, regionMetrics.getStoreFileSize());
  builder.put(Field.UNCOMPRESSED_STORE_FILE_SIZE, regionMetrics.getUncompressedStoreFileSize());
  builder.put(Field.NUM_STORE_FILES, regionMetrics.getStoreFileCount());
  builder.put(Field.MEM_STORE_SIZE, regionMetrics.getMemStoreSize());
  builder.put(Field.LOCALITY, regionMetrics.getDataLocality());

  long compactingCellCount = regionMetrics.getCompactingCellCount();
  long compactedCellCount = regionMetrics.getCompactedCellCount();
  float compactionProgress = 0;
  if  (compactedCellCount > 0) {
    compactionProgress = 100 * ((float) compactedCellCount / compactingCellCount);
  }

  builder.put(Field.COMPACTING_CELL_COUNT, compactingCellCount);
  builder.put(Field.COMPACTED_CELL_COUNT, compactedCellCount);
  builder.put(Field.COMPACTION_PROGRESS, compactionProgress);

  FastDateFormat df = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
  long lastMajorCompactionTimestamp = regionMetrics.getLastMajorCompactionTimestamp();

  builder.put(Field.LAST_MAJOR_COMPACTION_TIME,
    lastMajorCompactionTimestamp == 0 ? "" : df.format(lastMajorCompactionTimestamp));

  return builder.build();
}
 
Example 7
Source File: HRegionServer.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Protected Utility method for safely obtaining an HRegion handle.
 *
 * @param regionName Name of online {@link HRegion} to return
 * @return {@link HRegion} for <code>regionName</code>
 */
protected HRegion getRegion(final byte[] regionName)
    throws NotServingRegionException {
  String encodedRegionName = RegionInfo.encodeRegionName(regionName);
  return getRegionByEncodedName(regionName, encodedRegionName);
}