Search in sources :

Example 1 with BlockingRpcChannel

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel in project hbase by apache.

the class TestHMasterRPCException method testRPCException.

@Test
public void testRPCException() throws IOException, InterruptedException, KeeperException {
    ServerName sm = master.getServerName();
    boolean fakeZNodeDelete = false;
    for (int i = 0; i < 20; i++) {
        try {
            BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
            MasterProtos.MasterService.BlockingInterface stub = MasterProtos.MasterService.newBlockingStub(channel);
            assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance()).getIsMasterRunning());
            return;
        } catch (ServiceException ex) {
            IOException ie = ProtobufUtil.handleRemoteException(ex);
            // No SocketTimeoutException here. RpcServer is already started after the construction of
            // HMaster.
            assertTrue(ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
            LOG.info("Expected exception: ", ie);
            if (!fakeZNodeDelete) {
                testUtil.getZooKeeperWatcher().getRecoverableZooKeeper().delete(testUtil.getZooKeeperWatcher().znodePaths.masterAddressZNode, -1);
                fakeZNodeDelete = true;
            }
        }
        Thread.sleep(1000);
    }
}
Also used : ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) BlockingRpcChannel(org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with BlockingRpcChannel

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel in project hbase by apache.

the class HRegionServer method createRegionServerStatusStub.

/**
   * Get the current master from ZooKeeper and open the RPC connection to it. To get a fresh
   * connection, the current rssStub must be null. Method will block until a master is available.
   * You can break from this block by requesting the server stop.
   * @param refresh If true then master address will be read from ZK, otherwise use cached data
   * @return master + port, or null if server has been stopped
   */
@VisibleForTesting
protected synchronized ServerName createRegionServerStatusStub(boolean refresh) {
    if (rssStub != null) {
        return masterAddressTracker.getMasterAddress();
    }
    ServerName sn = null;
    long previousLogTime = 0;
    RegionServerStatusService.BlockingInterface intRssStub = null;
    LockService.BlockingInterface intLockStub = null;
    boolean interrupted = false;
    try {
        while (keepLooping()) {
            sn = this.masterAddressTracker.getMasterAddress(refresh);
            if (sn == null) {
                if (!keepLooping()) {
                    // give up with no connection.
                    LOG.debug("No master found and cluster is stopped; bailing out");
                    return null;
                }
                if (System.currentTimeMillis() > (previousLogTime + 1000)) {
                    LOG.debug("No master found; retry");
                    previousLogTime = System.currentTimeMillis();
                }
                // let's try pull it from ZK directly
                refresh = true;
                if (sleep(200)) {
                    interrupted = true;
                }
                continue;
            }
            // If we are on the active master, use the shortcut
            if (this instanceof HMaster && sn.equals(getServerName())) {
                intRssStub = ((HMaster) this).getMasterRpcServices();
                intLockStub = ((HMaster) this).getMasterRpcServices();
                break;
            }
            try {
                BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), shortOperationTimeout);
                intRssStub = RegionServerStatusService.newBlockingStub(channel);
                intLockStub = LockService.newBlockingStub(channel);
                break;
            } catch (IOException e) {
                if (System.currentTimeMillis() > (previousLogTime + 1000)) {
                    e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;
                    if (e instanceof ServerNotRunningYetException) {
                        LOG.info("Master isn't available yet, retrying");
                    } else {
                        LOG.warn("Unable to connect to master. Retrying. Error was:", e);
                    }
                    previousLogTime = System.currentTimeMillis();
                }
                if (sleep(200)) {
                    interrupted = true;
                }
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
    this.rssStub = intRssStub;
    this.lockStub = intLockStub;
    return sn;
}
Also used : LockService(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionServerStatusService(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService) BlockingRpcChannel(org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

IOException (java.io.IOException)2 ServerName (org.apache.hadoop.hbase.ServerName)2 BlockingRpcChannel (org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingRpcChannel)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InterruptedIOException (java.io.InterruptedIOException)1 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)1 HMaster (org.apache.hadoop.hbase.master.HMaster)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 LockService (org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService)1 RegionServerStatusService (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 Test (org.junit.Test)1