Search in sources :

Example 21 with HBaseRpcController

use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.

the class ServerManager method sendRegionClose.

/**
   * Sends an CLOSE RPC to the specified server to close the specified region.
   * <p>
   * A region server could reject the close request because it either does not
   * have the specified region or the region is being split.
   * @param server server to open a region
   * @param region region to open
   * @param dest - if the region is moved to another server, the destination server. null otherwise.
   * @throws IOException
   */
public boolean sendRegionClose(ServerName server, HRegionInfo region, ServerName dest) throws IOException {
    if (server == null)
        throw new NullPointerException("Passed server is null");
    AdminService.BlockingInterface admin = getRsAdmin(server);
    if (admin == null) {
        throw new IOException("Attempting to send CLOSE RPC to server " + server.toString() + " for region " + region.getRegionNameAsString() + " failed because no RPC connection found to this server");
    }
    HBaseRpcController controller = newRpcController();
    return ProtobufUtil.closeRegion(controller, admin, server, region.getRegionName(), dest);
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) IOException(java.io.IOException)

Example 22 with HBaseRpcController

use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.

the class AsyncConnectionImpl method getRpcController.

private HBaseRpcController getRpcController() {
    HBaseRpcController controller = this.rpcControllerFactory.newController();
    controller.setCallTimeout((int) TimeUnit.NANOSECONDS.toMillis(connConf.getRpcTimeoutNs()));
    return controller;
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController)

Example 23 with HBaseRpcController

use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.

the class AsyncConnectionImpl method makeMasterStub.

private void makeMasterStub(CompletableFuture<MasterService.Interface> future) {
    registry.getMasterAddress().whenComplete((sn, error) -> {
        if (sn == null) {
            String msg = "ZooKeeper available but no active master location found";
            LOG.info(msg);
            this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException(msg));
            return;
        }
        try {
            MasterService.Interface stub = createMasterStub(sn);
            HBaseRpcController controller = getRpcController();
            stub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {

                @Override
                public void run(IsMasterRunningResponse resp) {
                    if (controller.failed() || resp == null || (resp != null && !resp.getIsMasterRunning())) {
                        masterStubMakeFuture.getAndSet(null).completeExceptionally(new MasterNotRunningException("Master connection is not running anymore"));
                    } else {
                        masterStub.set(stub);
                        masterStubMakeFuture.set(null);
                        future.complete(stub);
                    }
                }
            });
        } catch (IOException e) {
            this.masterStubMakeFuture.getAndSet(null).completeExceptionally(new IOException("Failed to create async master stub", e));
        }
    });
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) IsMasterRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) IOException(java.io.IOException) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService)

Example 24 with HBaseRpcController

use of org.apache.hadoop.hbase.ipc.HBaseRpcController 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 25 with HBaseRpcController

use of org.apache.hadoop.hbase.ipc.HBaseRpcController in project hbase by apache.

the class HBaseAdmin method getOnlineRegions.

@Override
public List<HRegionInfo> getOnlineRegions(final ServerName sn) throws IOException {
    AdminService.BlockingInterface admin = this.connection.getAdmin(sn);
    // TODO: There is no timeout on this controller. Set one!
    HBaseRpcController controller = rpcControllerFactory.newController();
    return ProtobufUtil.getOnlineRegions(controller, admin);
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService)

Aggregations

HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)32 IOException (java.io.IOException)19 AdminService (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService)16 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)12 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)10 InterruptedIOException (java.io.InterruptedIOException)9 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)6 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)6 ArrayList (java.util.ArrayList)5 CellScanner (org.apache.hadoop.hbase.CellScanner)5 ServerName (org.apache.hadoop.hbase.ServerName)5 Result (org.apache.hadoop.hbase.client.Result)4 RpcCallContext (org.apache.hadoop.hbase.ipc.RpcCallContext)4 OperationQuota (org.apache.hadoop.hbase.quotas.OperationQuota)4 RegionActionResult (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)4 RemoteException (org.apache.hadoop.ipc.RemoteException)4 Callable (java.util.concurrent.Callable)3 CellScannable (org.apache.hadoop.hbase.CellScannable)3 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2