Search in sources :

Example 1 with GetRegionInfoRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest in project hbase by apache.

the class RequestConverter method buildGetRegionInfoRequest.

/**
   * Create a protocol buffer GetRegionInfoRequest for a given region name
   *
   * @param regionName the name of the region to get info
   * @param includeCompactionState indicate if the compaction state is requested
   * @return a protocol buffer GetRegionInfoRequest
   */
public static GetRegionInfoRequest buildGetRegionInfoRequest(final byte[] regionName, final boolean includeCompactionState) {
    GetRegionInfoRequest.Builder builder = GetRegionInfoRequest.newBuilder();
    RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
    builder.setRegion(region);
    if (includeCompactionState) {
        builder.setCompactionState(includeCompactionState);
    }
    return builder.build();
}
Also used : GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 2 with GetRegionInfoRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest in project hbase by apache.

the class HBaseAdmin method getCompactionState.

/**
   * {@inheritDoc}
   */
@Override
public CompactionState getCompactionState(final TableName tableName, CompactType compactType) throws IOException {
    AdminProtos.GetRegionInfoResponse.CompactionState state = AdminProtos.GetRegionInfoResponse.CompactionState.NONE;
    checkTableExists(tableName);
    // TODO: There is no timeout on this controller. Set one!
    final HBaseRpcController rpcController = rpcControllerFactory.newController();
    switch(compactType) {
        case MOB:
            final AdminProtos.AdminService.BlockingInterface masterAdmin = this.connection.getAdmin(getMasterAddress());
            Callable<AdminProtos.GetRegionInfoResponse.CompactionState> callable = new Callable<AdminProtos.GetRegionInfoResponse.CompactionState>() {

                @Override
                public AdminProtos.GetRegionInfoResponse.CompactionState call() throws Exception {
                    HRegionInfo info = getMobRegionInfo(tableName);
                    GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(info.getRegionName(), true);
                    GetRegionInfoResponse response = masterAdmin.getRegionInfo(rpcController, request);
                    return response.getCompactionState();
                }
            };
            state = ProtobufUtil.call(callable);
            break;
        case NORMAL:
        default:
            ZooKeeperWatcher zookeeper = null;
            try {
                List<Pair<HRegionInfo, ServerName>> pairs;
                if (TableName.META_TABLE_NAME.equals(tableName)) {
                    zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
                    pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
                } else {
                    pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
                }
                for (Pair<HRegionInfo, ServerName> pair : pairs) {
                    if (pair.getFirst().isOffline())
                        continue;
                    if (pair.getSecond() == null)
                        continue;
                    final ServerName sn = pair.getSecond();
                    final byte[] regionName = pair.getFirst().getRegionName();
                    final AdminService.BlockingInterface snAdmin = this.connection.getAdmin(sn);
                    try {
                        Callable<GetRegionInfoResponse> regionInfoCallable = new Callable<GetRegionInfoResponse>() {

                            @Override
                            public GetRegionInfoResponse call() throws Exception {
                                GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionName, true);
                                return snAdmin.getRegionInfo(rpcController, request);
                            }
                        };
                        GetRegionInfoResponse response = ProtobufUtil.call(regionInfoCallable);
                        switch(response.getCompactionState()) {
                            case MAJOR_AND_MINOR:
                                return CompactionState.MAJOR_AND_MINOR;
                            case MAJOR:
                                if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MINOR) {
                                    return CompactionState.MAJOR_AND_MINOR;
                                }
                                state = AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR;
                                break;
                            case MINOR:
                                if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR) {
                                    return CompactionState.MAJOR_AND_MINOR;
                                }
                                state = AdminProtos.GetRegionInfoResponse.CompactionState.MINOR;
                                break;
                            case NONE:
                            // nothing, continue
                            default:
                        }
                    } catch (NotServingRegionException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
                        }
                    } catch (RemoteException e) {
                        if (e.getMessage().indexOf(NotServingRegionException.class.getName()) >= 0) {
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
                            }
                        } else {
                            throw e;
                        }
                    }
                }
            } finally {
                if (zookeeper != null) {
                    zookeeper.close();
                }
            }
            break;
    }
    if (state != null) {
        return ProtobufUtil.createCompactionState(state);
    }
    return null;
}
Also used : AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Callable(java.util.concurrent.Callable) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) AdminProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos) ServerName(org.apache.hadoop.hbase.ServerName) RemoteException(org.apache.hadoop.ipc.RemoteException) Pair(org.apache.hadoop.hbase.util.Pair) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)

Example 3 with GetRegionInfoRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest in project hbase by apache.

the class HBaseAdmin method getCompactionStateForRegion.

@Override
public CompactionState getCompactionStateForRegion(final byte[] regionName) throws IOException {
    final Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionName);
    if (regionServerPair == null) {
        throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName));
    }
    if (regionServerPair.getSecond() == null) {
        throw new NoServerForRegionException(Bytes.toStringBinary(regionName));
    }
    ServerName sn = regionServerPair.getSecond();
    final AdminService.BlockingInterface admin = this.connection.getAdmin(sn);
    // TODO: There is no timeout on this controller. Set one!
    HBaseRpcController controller = rpcControllerFactory.newController();
    GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionServerPair.getFirst().getRegionName(), true);
    GetRegionInfoResponse response;
    try {
        response = admin.getRegionInfo(controller, request);
    } catch (ServiceException e) {
        throw ProtobufUtil.handleRemoteException(e);
    }
    if (response.getCompactionState() != null) {
        return ProtobufUtil.createCompactionState(response.getCompactionState());
    }
    return null;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse) ServerName(org.apache.hadoop.hbase.ServerName)

Example 4 with GetRegionInfoRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest in project hbase by apache.

the class ProtobufUtil method getRegionInfo.

// End helpers for Client
// Start helpers for Admin
/**
   * A helper to retrieve region info given a region name
   * using admin protocol.
   *
   * @param admin
   * @param regionName
   * @return the retrieved region info
   * @throws IOException
   */
public static HRegionInfo getRegionInfo(final RpcController controller, final AdminService.BlockingInterface admin, final byte[] regionName) throws IOException {
    try {
        GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionName);
        GetRegionInfoResponse response = admin.getRegionInfo(controller, request);
        return HRegionInfo.convert(response.getRegionInfo());
    } catch (ServiceException se) {
        throw getRemoteException(se);
    }
}
Also used : GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse)

Aggregations

GetRegionInfoRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest)4 GetRegionInfoResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse)3 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 ServerName (org.apache.hadoop.hbase.ServerName)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)2 AdminService (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService)2 Callable (java.util.concurrent.Callable)1 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)1 AdminProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos)1 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)1 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)1 Pair (org.apache.hadoop.hbase.util.Pair)1 MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)1 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1