Search in sources :

Example 1 with HBaseRpcController

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

the class AsyncBatchRpcRetryingCaller method send.

private void send(Map<ServerName, ServerRequest> actionsByServer, int tries) {
    long remainingNs;
    if (operationTimeoutNs > 0) {
        remainingNs = remainingTimeNs();
        if (remainingNs <= 0) {
            failAll(actionsByServer.values().stream().flatMap(m -> m.actionsByRegion.values().stream()).flatMap(r -> r.actions.stream()), tries);
            return;
        }
    } else {
        remainingNs = Long.MAX_VALUE;
    }
    actionsByServer.forEach((sn, serverReq) -> {
        ClientService.Interface stub;
        try {
            stub = conn.getRegionServerStub(sn);
        } catch (IOException e) {
            onError(serverReq.actionsByRegion, tries, e, sn);
            return;
        }
        ClientProtos.MultiRequest req;
        List<CellScannable> cells = new ArrayList<>();
        try {
            req = buildReq(serverReq.actionsByRegion, cells);
        } catch (IOException e) {
            onError(serverReq.actionsByRegion, tries, e, sn);
            return;
        }
        HBaseRpcController controller = conn.rpcControllerFactory.newController();
        resetController(controller, Math.min(rpcTimeoutNs, remainingNs));
        if (!cells.isEmpty()) {
            controller.setCellScanner(createCellScanner(cells));
        }
        stub.multi(controller, req, resp -> {
            if (controller.failed()) {
                onError(serverReq.actionsByRegion, tries, controller.getFailed(), sn);
            } else {
                try {
                    onComplete(serverReq.actionsByRegion, tries, sn, ResponseConverter.getResults(req, resp, controller.cellScanner()));
                } catch (Exception e) {
                    onError(serverReq.actionsByRegion, tries, e, sn);
                    return;
                }
            }
        });
    });
}
Also used : ConnectionUtils.getPauseTime(org.apache.hadoop.hbase.client.ConnectionUtils.getPauseTime) ResponseConverter(org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConnectionUtils.translateException(org.apache.hadoop.hbase.client.ConnectionUtils.translateException) RegionResult(org.apache.hadoop.hbase.client.MultiResponse.RegionResult) Map(java.util.Map) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) CellScannable(org.apache.hadoop.hbase.CellScannable) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableName(org.apache.hadoop.hbase.TableName) IdentityHashMap(java.util.IdentityHashMap) CellUtil.createCellScanner(org.apache.hadoop.hbase.CellUtil.createCellScanner) ThrowableWithExtraContext(org.apache.hadoop.hbase.client.RetriesExhaustedException.ThrowableWithExtraContext) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) CollectionUtils.computeIfAbsent(org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent) Collectors(java.util.stream.Collectors) RequestConverter(org.apache.hadoop.hbase.shaded.protobuf.RequestConverter) TimeUnit(java.util.concurrent.TimeUnit) ConnectionUtils.resetController(org.apache.hadoop.hbase.client.ConnectionUtils.resetController) List(java.util.List) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Stream(java.util.stream.Stream) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) SLEEP_DELTA_NS(org.apache.hadoop.hbase.client.ConnectionUtils.SLEEP_DELTA_NS) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) HashedWheelTimer(io.netty.util.HashedWheelTimer) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) InterfaceAudience(org.apache.hadoop.hbase.classification.InterfaceAudience) ClientService(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CellScannable(org.apache.hadoop.hbase.CellScannable) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ClientService(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService) ArrayList(java.util.ArrayList) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) ConnectionUtils.translateException(org.apache.hadoop.hbase.client.ConnectionUtils.translateException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 2 with HBaseRpcController

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

the class AsyncConnectionImpl method getMasterStub.

CompletableFuture<MasterService.Interface> getMasterStub() {
    MasterService.Interface masterStub = this.masterStub.get();
    if (masterStub == null) {
        for (; ; ) {
            if (this.masterStubMakeFuture.compareAndSet(null, new CompletableFuture<>())) {
                CompletableFuture<MasterService.Interface> future = this.masterStubMakeFuture.get();
                makeMasterStub(future);
            } else {
                CompletableFuture<MasterService.Interface> future = this.masterStubMakeFuture.get();
                if (future != null) {
                    return future;
                }
            }
        }
    }
    for (; ; ) {
        if (masterStubMakeFuture.compareAndSet(null, new CompletableFuture<>())) {
            CompletableFuture<MasterService.Interface> future = masterStubMakeFuture.get();
            HBaseRpcController controller = getRpcController();
            masterStub.isMasterRunning(controller, RequestConverter.buildIsMasterRunningRequest(), new RpcCallback<IsMasterRunningResponse>() {

                @Override
                public void run(IsMasterRunningResponse resp) {
                    if (controller.failed() || resp == null || (resp != null && !resp.getIsMasterRunning())) {
                        makeMasterStub(future);
                    } else {
                        future.complete(masterStub);
                    }
                }
            });
        } else {
            CompletableFuture<MasterService.Interface> future = masterStubMakeFuture.get();
            if (future != null) {
                return future;
            }
        }
    }
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) IsMasterRunningResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningResponse) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService)

Example 3 with HBaseRpcController

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

the class MetaTableLocator method verifyRegionLocation.

/**
   * Verify we can connect to <code>hostingServer</code> and that its carrying
   * <code>regionName</code>.
   * @param hostingServer Interface to the server hosting <code>regionName</code>
   * @param address The servername that goes with the <code>metaServer</code>
   * Interface.  Used logging.
   * @param regionName The regionname we are interested in.
   * @return True if we were able to verify the region located at other side of
   * the Interface.
   * @throws IOException
   */
// TODO: We should be able to get the ServerName from the AdminProtocol
// rather than have to pass it in.  Its made awkward by the fact that the
// HRI is likely a proxy against remote server so the getServerName needs
// to be fixed to go to a local method or to a cache before we can do this.
private boolean verifyRegionLocation(final ClusterConnection connection, AdminService.BlockingInterface hostingServer, final ServerName address, final byte[] regionName) throws IOException {
    if (hostingServer == null) {
        LOG.info("Passed hostingServer is null");
        return false;
    }
    Throwable t;
    HBaseRpcController controller = connection.getRpcControllerFactory().newController();
    try {
        // Try and get regioninfo from the hosting server.
        return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) != null;
    } catch (ConnectException e) {
        t = e;
    } catch (RetriesExhaustedException e) {
        t = e;
    } catch (RemoteException e) {
        IOException ioe = e.unwrapRemoteException();
        t = ioe;
    } catch (IOException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof EOFException) {
            t = cause;
        } else if (cause != null && cause.getMessage() != null && cause.getMessage().contains("Connection reset")) {
            t = cause;
        } else {
            t = e;
        }
    }
    LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) + " at address=" + address + ", exception=" + t.getMessage());
    return false;
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) EOFException(java.io.EOFException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) ConnectException(java.net.ConnectException)

Example 4 with HBaseRpcController

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

the class ReplicationProtbufUtil method replicateWALEntry.

/**
   * A helper to replicate a list of WAL entries using admin protocol.
   * @param admin Admin service
   * @param entries Array of WAL entries to be replicated
   * @param replicationClusterId Id which will uniquely identify source cluster FS client
   *          configurations in the replication configuration directory
   * @param sourceBaseNamespaceDir Path to source cluster base namespace directory
   * @param sourceHFileArchiveDir Path to the source cluster hfile archive directory
   * @throws java.io.IOException
   */
public static void replicateWALEntry(final AdminService.BlockingInterface admin, final Entry[] entries, String replicationClusterId, Path sourceBaseNamespaceDir, Path sourceHFileArchiveDir) throws IOException {
    Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> p = buildReplicateWALEntryRequest(entries, null, replicationClusterId, sourceBaseNamespaceDir, sourceHFileArchiveDir);
    HBaseRpcController controller = new HBaseRpcControllerImpl(p.getSecond());
    try {
        admin.replicateWALEntry(controller, p.getFirst());
    } catch (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException e) {
        throw ProtobufUtil.handleRemoteException(e);
    }
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) HBaseRpcControllerImpl(org.apache.hadoop.hbase.ipc.HBaseRpcControllerImpl) CellScanner(org.apache.hadoop.hbase.CellScanner) SizedCellScanner(org.apache.hadoop.hbase.io.SizedCellScanner)

Example 5 with HBaseRpcController

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

the class ServerManager method isServerReachable.

/**
   * Check if a region server is reachable and has the expected start code
   */
public boolean isServerReachable(ServerName server) {
    if (server == null)
        throw new NullPointerException("Passed server is null");
    RetryCounter retryCounter = pingRetryCounterFactory.create();
    while (retryCounter.shouldRetry()) {
        try {
            HBaseRpcController controller = newRpcController();
            AdminService.BlockingInterface admin = getRsAdmin(server);
            if (admin != null) {
                ServerInfo info = ProtobufUtil.getServerInfo(controller, admin);
                return info != null && info.hasServerName() && server.getStartcode() == info.getServerName().getStartCode();
            }
        } catch (IOException ioe) {
            LOG.debug("Couldn't reach " + server + ", try=" + retryCounter.getAttemptTimes() + " of " + retryCounter.getMaxAttempts(), ioe);
            try {
                retryCounter.sleepUntilNextRetry();
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
        }
    }
    return false;
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) ServerInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ServerInfo) IOException(java.io.IOException)

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