Java Code Examples for org.apache.hadoop.hbase.HConstants#ADMIN_QOS

The following examples show how to use org.apache.hadoop.hbase.HConstants#ADMIN_QOS . 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 6 votes vote down vote up
/**
 * Compact a region on the master.
 *
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public CompactRegionResponse compactRegion(final RpcController controller,
  final CompactRegionRequest request) throws ServiceException {
  try {
    master.checkInitialized();
    byte[] regionName = request.getRegion().getValue().toByteArray();
    TableName tableName = RegionInfo.getTable(regionName);
    // TODO: support CompactType.MOB
    // if the region is a mob region, do the mob file compaction.
    if (MobUtils.isMobRegionName(tableName, regionName)) {
      checkHFileFormatVersionForMob();
      //TODO: support CompactType.MOB
      // HBASE-23571
      LOG.warn("CompactType.MOB is not supported yet, will run regular compaction."+
          " Refer to HBASE-23571.");
      return super.compactRegion(controller, request);
    } else {
      return super.compactRegion(controller, request);
    }
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 2
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Close a region on the region server.
 *
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public CloseRegionResponse closeRegion(final RpcController controller,
    final CloseRegionRequest request) throws ServiceException {
  final ServerName sn = (request.hasDestinationServer() ?
    ProtobufUtil.toServerName(request.getDestinationServer()) : null);

  try {
    checkOpen();
    throwOnWrongStartCode(request);
    final String encodedRegionName = ProtobufUtil.getRegionEncodedName(request.getRegion());

    requestCount.increment();
    if (sn == null) {
      LOG.info("Close " + encodedRegionName + " without moving");
    } else {
      LOG.info("Close " + encodedRegionName + ", moving to " + sn);
    }
    boolean closed = regionServer.closeRegion(encodedRegionName, false, sn);
    CloseRegionResponse.Builder builder = CloseRegionResponse.newBuilder().setClosed(closed);
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 3
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetOnlineRegionResponse getOnlineRegion(final RpcController controller,
    final GetOnlineRegionRequest request) throws ServiceException {
  try {
    checkOpen();
    requestCount.increment();
    Map<String, HRegion> onlineRegions = regionServer.getOnlineRegions();
    List<RegionInfo> list = new ArrayList<>(onlineRegions.size());
    for (HRegion region: onlineRegions.values()) {
      list.add(region.getRegionInfo());
    }
    list.sort(RegionInfo.COMPARATOR);
    return ResponseConverter.buildGetOnlineRegionResponse(list);
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 4
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public ExecuteProceduresResponse executeProcedures(RpcController controller,
    ExecuteProceduresRequest request) throws ServiceException {
  try {
    checkOpen();
    throwOnWrongStartCode(request);
    regionServer.getRegionServerCoprocessorHost().preExecuteProcedures();
    if (request.getOpenRegionCount() > 0) {
      // Avoid reading from the TableDescritor every time(usually it will read from the file
      // system)
      Map<TableName, TableDescriptor> tdCache = new HashMap<>();
      request.getOpenRegionList().forEach(req -> executeOpenRegionProcedures(req, tdCache));
    }
    if (request.getCloseRegionCount() > 0) {
      request.getCloseRegionList().forEach(this::executeCloseRegionProcedures);
    }
    if (request.getProcCount() > 0) {
      request.getProcList().forEach(this::executeProcedures);
    }
    regionServer.getRegionServerCoprocessorHost().postExecuteProcedures();
    return ExecuteProceduresResponse.getDefaultInstance();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 5
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public ClearSlowLogResponses clearSlowLogsResponses(final RpcController controller,
  final ClearSlowLogResponseRequest request) {
  final SlowLogRecorder slowLogRecorder =
    this.regionServer.getSlowLogRecorder();
  boolean slowLogsCleaned = Optional.ofNullable(slowLogRecorder)
    .map(SlowLogRecorder::clearSlowLogPayloads).orElse(false);
  ClearSlowLogResponses clearSlowLogResponses = ClearSlowLogResponses.newBuilder()
    .setIsCleaned(slowLogsCleaned)
    .build();
  return clearSlowLogResponses;
}
 
Example 6
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public GetLastFlushedSequenceIdResponse getLastFlushedSequenceId(RpcController controller,
    GetLastFlushedSequenceIdRequest request) throws ServiceException {
  try {
    master.checkServiceStarted();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
  byte[] encodedRegionName = request.getRegionName().toByteArray();
  RegionStoreSequenceIds ids = master.getServerManager()
    .getLastFlushedSequenceId(encodedRegionName);
  return ResponseConverter.buildGetLastFlushedSequenceIdResponse(ids);
}
 
Example 7
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public SlowLogResponses getLargeLogResponses(final RpcController controller,
    final SlowLogResponseRequest request) {
  final SlowLogRecorder slowLogRecorder =
    this.regionServer.getSlowLogRecorder();
  final List<SlowLogPayload> slowLogPayloads;
  slowLogPayloads = slowLogRecorder != null
    ? slowLogRecorder.getLargeLogPayloads(request)
    : Collections.emptyList();
  SlowLogResponses slowLogResponses = SlowLogResponses.newBuilder()
    .addAllSlowLogPayloads(slowLogPayloads)
    .build();
  return slowLogResponses;
}
 
Example 8
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public SlowLogResponses getSlowLogResponses(final RpcController controller,
  final SlowLogResponseRequest request) {
  final SlowLogRecorder slowLogRecorder =
    this.regionServer.getSlowLogRecorder();
  final List<SlowLogPayload> slowLogPayloads;
  slowLogPayloads = slowLogRecorder != null
    ? slowLogRecorder.getSlowLogPayloads(request)
    : Collections.emptyList();
  SlowLogResponses slowLogResponses = SlowLogResponses.newBuilder()
    .addAllSlowLogPayloads(slowLogPayloads)
    .build();
  return slowLogResponses;
}
 
Example 9
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Stop the region server.
 *
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public StopServerResponse stopServer(final RpcController controller,
    final StopServerRequest request) throws ServiceException {
  requestCount.increment();
  String reason = request.getReason();
  regionServer.stop(reason);
  return StopServerResponse.newBuilder().build();
}
 
Example 10
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetStoreFileResponse getStoreFile(final RpcController controller,
    final GetStoreFileRequest request) throws ServiceException {
  try {
    checkOpen();
    HRegion region = getRegion(request.getRegion());
    requestCount.increment();
    Set<byte[]> columnFamilies;
    if (request.getFamilyCount() == 0) {
      columnFamilies = region.getTableDescriptor().getColumnFamilyNames();
    } else {
      columnFamilies = new TreeSet<>(Bytes.BYTES_RAWCOMPARATOR);
      for (ByteString cf: request.getFamilyList()) {
        columnFamilies.add(cf.toByteArray());
      }
    }
    int nCF = columnFamilies.size();
    List<String>  fileList = region.getStoreFileList(
      columnFamilies.toArray(new byte[nCF][]));
    GetStoreFileResponse.Builder builder = GetStoreFileResponse.newBuilder();
    builder.addAllStoreFile(fileList);
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 11
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get some information of the region server.
 *
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetServerInfoResponse getServerInfo(final RpcController controller,
    final GetServerInfoRequest request) throws ServiceException {
  try {
    checkOpen();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
  requestCount.increment();
  int infoPort = regionServer.infoServer != null ? regionServer.infoServer.getPort() : -1;
  return ResponseConverter.buildGetServerInfoResponse(regionServer.serverName, infoPort);
}
 
Example 12
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public ClearCompactionQueuesResponse clearCompactionQueues(RpcController controller,
  ClearCompactionQueuesRequest request) throws ServiceException {
  LOG.debug("Client=" + RpcServer.getRequestUserName().orElse(null) + "/"
      + RpcServer.getRemoteAddress().orElse(null) + " clear compactions queue");
  ClearCompactionQueuesResponse.Builder respBuilder = ClearCompactionQueuesResponse.newBuilder();
  requestCount.increment();
  if (clearCompactionQueues.compareAndSet(false,true)) {
    try {
      checkOpen();
      regionServer.getRegionServerCoprocessorHost().preClearCompactionQueues();
      for (String queueName : request.getQueueNameList()) {
        LOG.debug("clear " + queueName + " compaction queue");
        switch (queueName) {
          case "long":
            regionServer.compactSplitThread.clearLongCompactionsQueue();
            break;
          case "short":
            regionServer.compactSplitThread.clearShortCompactionsQueue();
            break;
          default:
            LOG.warn("Unknown queue name " + queueName);
            throw new IOException("Unknown queue name " + queueName);
        }
      }
      regionServer.getRegionServerCoprocessorHost().postClearCompactionQueues();
    } catch (IOException ie) {
      throw new ServiceException(ie);
    } finally {
      clearCompactionQueues.set(false);
    }
  } else {
    LOG.warn("Clear compactions queue is executing by other admin.");
  }
  return respBuilder.build();
}
 
Example 13
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetRegionLoadResponse getRegionLoad(RpcController controller,
    GetRegionLoadRequest request) throws ServiceException {

  List<HRegion> regions;
  if (request.hasTableName()) {
    TableName tableName = ProtobufUtil.toTableName(request.getTableName());
    regions = regionServer.getRegions(tableName);
  } else {
    regions = regionServer.getRegions();
  }
  List<RegionLoad> rLoads = new ArrayList<>(regions.size());
  RegionLoad.Builder regionLoadBuilder = ClusterStatusProtos.RegionLoad.newBuilder();
  RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();

  try {
    for (HRegion region : regions) {
      rLoads.add(regionServer.createRegionLoad(region, regionLoadBuilder, regionSpecifier));
    }
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  GetRegionLoadResponse.Builder builder = GetRegionLoadResponse.newBuilder();
  builder.addAllRegionLoads(rLoads);
  return builder.build();
}
 
Example 14
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetRegionInfoResponse getRegionInfo(final RpcController controller,
  final GetRegionInfoRequest request) throws ServiceException {
  try {
    checkOpen();
    requestCount.increment();
    HRegion region = getRegion(request.getRegion());
    RegionInfo info = region.getRegionInfo();
    byte[] bestSplitRow;
    if (request.hasBestSplitRow() && request.getBestSplitRow()) {
      bestSplitRow = region.checkSplit(true).orElse(null);
      // when all table data are in memstore, bestSplitRow = null
      // try to flush region first
      if (bestSplitRow == null) {
        region.flush(true);
        bestSplitRow = region.checkSplit(true).orElse(null);
      }
    } else {
      bestSplitRow = null;
    }
    GetRegionInfoResponse.Builder builder = GetRegionInfoResponse.newBuilder();
    builder.setRegionInfo(ProtobufUtil.toRegionInfo(info));
    if (request.hasCompactionState() && request.getCompactionState()) {
      builder.setCompactionState(ProtobufUtil.createCompactionState(region.getCompactionState()));
    }
    builder.setSplittable(region.isSplittable());
    builder.setMergeable(region.isMergeable());
    if (request.hasBestSplitRow() && request.getBestSplitRow() && bestSplitRow != null) {
      builder.setBestSplitRow(UnsafeByteOperations.unsafeWrap(bestSplitRow));
    }
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example 15
Source File: AssignRegionHandler.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static AssignRegionHandler create(HRegionServer server, RegionInfo regionInfo,
    long openProcId, TableDescriptor tableDesc, long masterSystemTime) {
  EventType eventType;
  if (regionInfo.isMetaRegion()) {
    eventType = EventType.M_RS_CLOSE_META;
  } else if (regionInfo.getTable().isSystemTable() ||
    (tableDesc != null && tableDesc.getPriority() >= HConstants.ADMIN_QOS)) {
    eventType = EventType.M_RS_OPEN_PRIORITY_REGION;
  } else {
    eventType = EventType.M_RS_OPEN_REGION;
  }
  return new AssignRegionHandler(server, regionInfo, openProcId, tableDesc, masterSystemTime,
    eventType);
}
 
Example 16
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * This method implements Admin getRegionInfo. On RegionServer, it is
 * able to return RegionInfo and detail. On Master, it just returns
 * RegionInfo. On Master it has been hijacked to return Mob detail.
 * Master implementation is good for querying full region name if
 * you only have the encoded name (useful around region replicas
 * for example which do not have a row in hbase:meta).
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public GetRegionInfoResponse getRegionInfo(final RpcController controller,
  final GetRegionInfoRequest request) throws ServiceException {
  RegionInfo ri = null;
  try {
    ri = getRegionInfo(request.getRegion());
  } catch(UnknownRegionException ure) {
    throw new ServiceException(ure);
  }
  GetRegionInfoResponse.Builder builder = GetRegionInfoResponse.newBuilder();
  if (ri != null) {
    builder.setRegionInfo(ProtobufUtil.toRegionInfo(ri));
  } else {
    // Is it a MOB name? These work differently.
    byte [] regionName = request.getRegion().getValue().toByteArray();
    TableName tableName = RegionInfo.getTable(regionName);
    if (MobUtils.isMobRegionName(tableName, regionName)) {
      // a dummy region info contains the compaction state.
      RegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(tableName);
      builder.setRegionInfo(ProtobufUtil.toRegionInfo(mobRegionInfo));
      if (request.hasCompactionState() && request.getCompactionState()) {
        builder.setCompactionState(master.getMobCompactionState(tableName));
      }
    } else {
      // If unknown RegionInfo and not a MOB region, it is unknown.
      throw new ServiceException(new UnknownRegionException(Bytes.toString(regionName)));
    }
  }
  return builder.build();
}
 
Example 17
Source File: RSRpcServices.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Flush a region on the region server.
 *
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
@QosPriority(priority=HConstants.ADMIN_QOS)
public FlushRegionResponse flushRegion(final RpcController controller,
    final FlushRegionRequest request) throws ServiceException {
  try {
    checkOpen();
    requestCount.increment();
    HRegion region = getRegion(request.getRegion());
    LOG.info("Flushing " + region.getRegionInfo().getRegionNameAsString());
    boolean shouldFlush = true;
    if (request.hasIfOlderThanTs()) {
      shouldFlush = region.getEarliestFlushTimeForAllStores() < request.getIfOlderThanTs();
    }
    FlushRegionResponse.Builder builder = FlushRegionResponse.newBuilder();
    if (shouldFlush) {
      boolean writeFlushWalMarker =  request.hasWriteFlushWalMarker() ?
          request.getWriteFlushWalMarker() : false;
      // Go behind the curtain so we can manage writing of the flush WAL marker
      HRegion.FlushResultImpl flushResult =
          region.flushcache(true, writeFlushWalMarker, FlushLifeCycleTracker.DUMMY);
      boolean compactionNeeded = flushResult.isCompactionNeeded();
      if (compactionNeeded) {
        regionServer.compactSplitThread.requestSystemCompaction(region,
          "Compaction through user triggered flush");
      }
      builder.setFlushed(flushResult.isFlushSucceeded());
      builder.setWroteFlushWalMarker(flushResult.wroteFlushWalMarker);
    }
    builder.setLastFlushTime(region.getEarliestFlushTimeForAllStores());
    return builder.build();
  } catch (DroppedSnapshotException ex) {
    // Cache flush can fail in a few places. If it fails in a critical
    // section, we get a DroppedSnapshotException and a replay of wal
    // is required. Currently the only way to do this is a restart of
    // the server.
    regionServer.abort("Replay of WAL required. Forcing server shutdown", ex);
    throw new ServiceException(ex);
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}