Search in sources :

Example 1 with RpcClient

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

the class TestHCM method testConnectionClose.

private void testConnectionClose(boolean allowsInterrupt) throws Exception {
    TableName tableName = TableName.valueOf("HCM-testConnectionClose" + allowsInterrupt);
    TEST_UTIL.createTable(tableName, FAM_NAM).close();
    boolean previousBalance = TEST_UTIL.getAdmin().setBalancerRunning(false, true);
    Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
    // We want to work on a separate connection.
    c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
    // retry a lot
    c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 100);
    // don't wait between retries.
    c2.setInt(HConstants.HBASE_CLIENT_PAUSE, 1);
    // Server do not really expire
    c2.setInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, 0);
    c2.setBoolean(RpcClient.SPECIFIC_WRITE_THREAD, allowsInterrupt);
    // to avoid the client to be stuck when do the Get
    c2.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 10000);
    c2.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 10000);
    c2.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 5000);
    Connection connection = ConnectionFactory.createConnection(c2);
    final Table table = connection.getTable(tableName);
    Put put = new Put(ROW);
    put.addColumn(FAM_NAM, ROW, ROW);
    table.put(put);
    // 4 steps: ready=0; doGets=1; mustStop=2; stopped=3
    final AtomicInteger step = new AtomicInteger(0);
    final AtomicReference<Throwable> failed = new AtomicReference<>(null);
    Thread t = new Thread("testConnectionCloseThread") {

        @Override
        public void run() {
            int done = 0;
            try {
                step.set(1);
                while (step.get() == 1) {
                    Get get = new Get(ROW);
                    table.get(get);
                    done++;
                    if (done % 100 == 0)
                        LOG.info("done=" + done);
                    // without the sleep, will cause the exception for too many files in
                    // org.apache.hadoop.hdfs.server.datanode.DataXceiver
                    Thread.sleep(100);
                }
            } catch (Throwable t) {
                failed.set(t);
                LOG.error(t);
            }
            step.set(3);
        }
    };
    t.start();
    TEST_UTIL.waitFor(20000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return step.get() == 1;
        }
    });
    ServerName sn;
    try (RegionLocator rl = connection.getRegionLocator(tableName)) {
        sn = rl.getRegionLocation(ROW).getServerName();
    }
    ConnectionImplementation conn = (ConnectionImplementation) connection;
    RpcClient rpcClient = conn.getRpcClient();
    LOG.info("Going to cancel connections. connection=" + conn.toString() + ", sn=" + sn);
    for (int i = 0; i < 5000; i++) {
        rpcClient.cancelConnections(sn);
        Thread.sleep(5);
    }
    step.compareAndSet(1, 2);
    // The test may fail here if the thread doing the gets is stuck. The way to find
    //  out what's happening is to look for the thread named 'testConnectionCloseThread'
    TEST_UTIL.waitFor(40000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return step.get() == 3;
        }
    });
    table.close();
    connection.close();
    Assert.assertTrue("Unexpected exception is " + failed.get(), failed.get() == null);
    TEST_UTIL.getAdmin().setBalancerRunning(previousBalance, true);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) ServerTooBusyException(org.apache.hadoop.hbase.ipc.ServerTooBusyException) RegionMovedException(org.apache.hadoop.hbase.exceptions.RegionMovedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) TableName(org.apache.hadoop.hbase.TableName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerName(org.apache.hadoop.hbase.ServerName) Waiter(org.apache.hadoop.hbase.Waiter) RpcClient(org.apache.hadoop.hbase.ipc.RpcClient)

Example 2 with RpcClient

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

the class TestConnection method testCancelConnectionMemoryLeak.

// There is no assertion, but you need to confirm that there is no resource leak output from netty
@Test
public void testCancelConnectionMemoryLeak() throws IOException, InterruptedException {
    TableName tableName = TableName.valueOf(name.getMethodName());
    TEST_UTIL.createTable(tableName, FAM_NAM).close();
    TEST_UTIL.getAdmin().balancerSwitch(false, true);
    try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
        Table table = connection.getTable(tableName)) {
        table.get(new Get(Bytes.toBytes("1")));
        ServerName sn = TEST_UTIL.getRSForFirstRegionInTable(tableName).getServerName();
        RpcClient rpcClient = ((AsyncConnectionImpl) connection.toAsyncConnection()).rpcClient;
        rpcClient.cancelConnections(sn);
        Thread.sleep(1000);
        System.gc();
        Thread.sleep(1000);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) RpcClient(org.apache.hadoop.hbase.ipc.RpcClient) Test(org.junit.Test)

Example 3 with RpcClient

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

the class TestSecureIPC method callRpcService.

/**
 * Sets up a RPC Server and a Client. Does a RPC checks the result. If an exception is thrown from
 * the stub, this function will throw root cause of that exception.
 */
private void callRpcService(User clientUser) throws Exception {
    SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
    Mockito.when(securityInfoMock.getServerPrincipal()).thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
    SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock);
    InetSocketAddress isa = new InetSocketAddress(HOST, 0);
    RpcServerInterface rpcServer = RpcServerFactory.createRpcServer(null, "AbstractTestSecureIPC", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface((BlockingService) SERVICE, null)), isa, serverConf, new FifoRpcScheduler(serverConf, 1));
    rpcServer.start();
    try (RpcClient rpcClient = RpcClientFactory.createClient(clientConf, HConstants.DEFAULT_CLUSTER_ID.toString())) {
        BlockingInterface stub = newBlockingStub(rpcClient, rpcServer.getListenerAddress(), clientUser);
        TestThread th1 = new TestThread(stub);
        final Throwable[] exception = new Throwable[1];
        Collections.synchronizedList(new ArrayList<Throwable>());
        Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread th, Throwable ex) {
                exception[0] = ex;
            }
        };
        th1.setUncaughtExceptionHandler(exceptionHandler);
        th1.start();
        th1.join();
        if (exception[0] != null) {
            // throw root cause.
            while (exception[0].getCause() != null) {
                exception[0] = exception[0].getCause();
            }
            throw (Exception) exception[0];
        }
    } finally {
        rpcServer.stop();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FifoRpcScheduler(org.apache.hadoop.hbase.ipc.FifoRpcScheduler) SaslException(javax.security.sasl.SaslException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) BlockingRpcClient(org.apache.hadoop.hbase.ipc.BlockingRpcClient) RpcClient(org.apache.hadoop.hbase.ipc.RpcClient) NettyRpcClient(org.apache.hadoop.hbase.ipc.NettyRpcClient)

Example 4 with RpcClient

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

the class TestConnection method testConnectionClose.

private void testConnectionClose(boolean allowsInterrupt) throws Exception {
    TableName tableName = TableName.valueOf("HCM-testConnectionClose" + allowsInterrupt);
    TEST_UTIL.createTable(tableName, FAM_NAM).close();
    TEST_UTIL.getAdmin().balancerSwitch(false, true);
    Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
    // We want to work on a separate connection.
    c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
    // retry a lot
    c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 100);
    // don't wait between retries.
    c2.setInt(HConstants.HBASE_CLIENT_PAUSE, 1);
    // Server do not really expire
    c2.setInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, 0);
    c2.setBoolean(RpcClient.SPECIFIC_WRITE_THREAD, allowsInterrupt);
    // to avoid the client to be stuck when do the Get
    c2.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 10000);
    c2.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 10000);
    c2.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 5000);
    Connection connection = ConnectionFactory.createConnection(c2);
    final Table table = connection.getTable(tableName);
    Put put = new Put(ROW);
    put.addColumn(FAM_NAM, ROW, ROW);
    table.put(put);
    // 4 steps: ready=0; doGets=1; mustStop=2; stopped=3
    final AtomicInteger step = new AtomicInteger(0);
    final AtomicReference<Throwable> failed = new AtomicReference<>(null);
    Thread t = new Thread("testConnectionCloseThread") {

        @Override
        public void run() {
            int done = 0;
            try {
                step.set(1);
                while (step.get() == 1) {
                    Get get = new Get(ROW);
                    table.get(get);
                    done++;
                    if (done % 100 == 0) {
                        LOG.info("done=" + done);
                    }
                    // without the sleep, will cause the exception for too many files in
                    // org.apache.hadoop.hdfs.server.datanode.DataXceiver
                    Thread.sleep(100);
                }
            } catch (Throwable t) {
                failed.set(t);
                LOG.error(t.toString(), t);
            }
            step.set(3);
        }
    };
    t.start();
    TEST_UTIL.waitFor(20000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return step.get() == 1;
        }
    });
    ServerName sn;
    try (RegionLocator rl = connection.getRegionLocator(tableName)) {
        sn = rl.getRegionLocation(ROW).getServerName();
    }
    RpcClient rpcClient = ((AsyncConnectionImpl) connection.toAsyncConnection()).rpcClient;
    LOG.info("Going to cancel connections. connection=" + connection.toString() + ", sn=" + sn);
    for (int i = 0; i < 500; i++) {
        rpcClient.cancelConnections(sn);
        Thread.sleep(50);
    }
    step.compareAndSet(1, 2);
    // The test may fail here if the thread doing the gets is stuck. The way to find
    // out what's happening is to look for the thread named 'testConnectionCloseThread'
    TEST_UTIL.waitFor(40000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return step.get() == 3;
        }
    });
    table.close();
    connection.close();
    Assert.assertTrue("Unexpected exception is " + failed.get(), failed.get() == null);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AtomicReference(java.util.concurrent.atomic.AtomicReference) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) TableName(org.apache.hadoop.hbase.TableName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerName(org.apache.hadoop.hbase.ServerName) Waiter(org.apache.hadoop.hbase.Waiter) RpcClient(org.apache.hadoop.hbase.ipc.RpcClient)

Aggregations

RpcClient (org.apache.hadoop.hbase.ipc.RpcClient)4 IOException (java.io.IOException)3 ServerName (org.apache.hadoop.hbase.ServerName)3 TableName (org.apache.hadoop.hbase.TableName)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Configuration (org.apache.hadoop.conf.Configuration)2 Waiter (org.apache.hadoop.hbase.Waiter)2 InetSocketAddress (java.net.InetSocketAddress)1 SocketTimeoutException (java.net.SocketTimeoutException)1 SaslException (javax.security.sasl.SaslException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)1 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)1 RegionMovedException (org.apache.hadoop.hbase.exceptions.RegionMovedException)1 BlockingRpcClient (org.apache.hadoop.hbase.ipc.BlockingRpcClient)1 FifoRpcScheduler (org.apache.hadoop.hbase.ipc.FifoRpcScheduler)1 NettyRpcClient (org.apache.hadoop.hbase.ipc.NettyRpcClient)1 RpcServerInterface (org.apache.hadoop.hbase.ipc.RpcServerInterface)1 ServerTooBusyException (org.apache.hadoop.hbase.ipc.ServerTooBusyException)1