Search in sources :

Example 11 with ServiceException

use of com.google.protobuf.ServiceException in project hadoop by apache.

the class TestProtoBufRpc method testLogSlowRPC.

@Test(timeout = 12000)
public void testLogSlowRPC() throws IOException, ServiceException {
    TestRpcService2 client = getClient2();
    // make 10 K fast calls
    for (int x = 0; x < 10000; x++) {
        try {
            client.ping2(null, newEmptyRequest());
        } catch (Exception ex) {
            throw ex;
        }
    }
    // Ensure RPC metrics are updated
    RpcMetrics rpcMetrics = server.getRpcMetrics();
    assertTrue(rpcMetrics.getProcessingSampleCount() > 999L);
    long before = rpcMetrics.getRpcSlowCalls();
    // make a really slow call. Sleep sleeps for 1000ms
    client.sleep(null, newSleepRequest(SLEEP_DURATION * 3));
    long after = rpcMetrics.getRpcSlowCalls();
    // Ensure slow call is logged.
    Assert.assertEquals(before + 1L, after);
}
Also used : RpcMetrics(org.apache.hadoop.ipc.metrics.RpcMetrics) ServiceException(com.google.protobuf.ServiceException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with ServiceException

use of com.google.protobuf.ServiceException in project hadoop by apache.

the class TestRPC method testClientBackOffByResponseTime.

/**
   *  Test RPC backoff by response time of each priority level.
   */
@Test(timeout = 30000)
public void testClientBackOffByResponseTime() throws Exception {
    final TestRpcService proxy;
    boolean succeeded = false;
    final int numClients = 1;
    GenericTestUtils.setLogLevel(DecayRpcScheduler.LOG, Level.DEBUG);
    GenericTestUtils.setLogLevel(RPC.LOG, Level.DEBUG);
    final List<Future<Void>> res = new ArrayList<Future<Void>>();
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);
    conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
    final String ns = CommonConfigurationKeys.IPC_NAMESPACE + ".0";
    Server server = setupDecayRpcSchedulerandTestServer(ns + ".");
    @SuppressWarnings("unchecked") CallQueueManager<Call> spy = spy((CallQueueManager<Call>) Whitebox.getInternalState(server, "callQueue"));
    Whitebox.setInternalState(server, "callQueue", spy);
    Exception lastException = null;
    proxy = getClient(addr, conf);
    MetricsRecordBuilder rb1 = getMetrics("DecayRpcSchedulerMetrics2." + ns);
    final long beginDecayedCallVolume = MetricsAsserts.getLongCounter("DecayedCallVolume", rb1);
    final long beginRawCallVolume = MetricsAsserts.getLongCounter("CallVolume", rb1);
    final int beginUniqueCaller = MetricsAsserts.getIntCounter("UniqueCallers", rb1);
    try {
        // start a sleep RPC call that sleeps 3s.
        for (int i = 0; i < numClients; i++) {
            res.add(executorService.submit(new Callable<Void>() {

                @Override
                public Void call() throws ServiceException, InterruptedException {
                    proxy.sleep(null, newSleepRequest(3000));
                    return null;
                }
            }));
            verify(spy, timeout(500).times(i + 1)).offer(Mockito.<Call>anyObject());
        }
        // avg response time(3s) exceeds threshold (2s).
        try {
            // wait for the 1st response time update
            Thread.sleep(5500);
            proxy.sleep(null, newSleepRequest(100));
        } catch (ServiceException e) {
            RemoteException re = (RemoteException) e.getCause();
            IOException unwrapExeption = re.unwrapRemoteException();
            if (unwrapExeption instanceof RetriableException) {
                succeeded = true;
            } else {
                lastException = unwrapExeption;
            }
            // Lets Metric system update latest metrics
            GenericTestUtils.waitFor(new Supplier<Boolean>() {

                @Override
                public Boolean get() {
                    MetricsRecordBuilder rb2 = getMetrics("DecayRpcSchedulerMetrics2." + ns);
                    long decayedCallVolume1 = MetricsAsserts.getLongCounter("DecayedCallVolume", rb2);
                    long rawCallVolume1 = MetricsAsserts.getLongCounter("CallVolume", rb2);
                    int uniqueCaller1 = MetricsAsserts.getIntCounter("UniqueCallers", rb2);
                    long callVolumePriority0 = MetricsAsserts.getLongGauge("Priority.0.CompletedCallVolume", rb2);
                    long callVolumePriority1 = MetricsAsserts.getLongGauge("Priority.1.CompletedCallVolume", rb2);
                    double avgRespTimePriority0 = MetricsAsserts.getDoubleGauge("Priority.0.AvgResponseTime", rb2);
                    double avgRespTimePriority1 = MetricsAsserts.getDoubleGauge("Priority.1.AvgResponseTime", rb2);
                    LOG.info("DecayedCallVolume: " + decayedCallVolume1);
                    LOG.info("CallVolume: " + rawCallVolume1);
                    LOG.info("UniqueCaller: " + uniqueCaller1);
                    LOG.info("Priority.0.CompletedCallVolume: " + callVolumePriority0);
                    LOG.info("Priority.1.CompletedCallVolume: " + callVolumePriority1);
                    LOG.info("Priority.0.AvgResponseTime: " + avgRespTimePriority0);
                    LOG.info("Priority.1.AvgResponseTime: " + avgRespTimePriority1);
                    return decayedCallVolume1 > beginDecayedCallVolume && rawCallVolume1 > beginRawCallVolume && uniqueCaller1 > beginUniqueCaller;
                }
            }, 30, 60000);
        }
    } finally {
        executorService.shutdown();
        stop(server, proxy);
    }
    if (lastException != null) {
        LOG.error("Last received non-RetriableException:", lastException);
    }
    assertTrue("RetriableException not received", succeeded);
}
Also used : Call(org.apache.hadoop.ipc.Server.Call) ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AccessControlException(org.apache.hadoop.security.AccessControlException) Callable(java.util.concurrent.Callable) ServiceException(com.google.protobuf.ServiceException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Supplier(com.google.common.base.Supplier) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 13 with ServiceException

use of com.google.protobuf.ServiceException in project hadoop by apache.

the class TestRPC method testReaderExceptions.

@Test(timeout = 30000)
public void testReaderExceptions() throws Exception {
    Server server = null;
    TestRpcService proxy = null;
    // will attempt to return this exception from a reader with and w/o
    // the connection closing.
    IOException expectedIOE = new TestReaderException("testing123");
    @SuppressWarnings("serial") IOException rseError = new RpcServerException("keepalive", expectedIOE) {

        @Override
        public RpcStatusProto getRpcStatusProto() {
            return RpcStatusProto.ERROR;
        }
    };
    @SuppressWarnings("serial") IOException rseFatal = new RpcServerException("disconnect", expectedIOE) {

        @Override
        public RpcStatusProto getRpcStatusProto() {
            return RpcStatusProto.FATAL;
        }
    };
    try {
        RPC.Builder builder = newServerBuilder(conf).setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
        server = setupTestServer(builder);
        Whitebox.setInternalState(server, "rpcRequestClass", FakeRequestClass.class);
        MutableCounterLong authMetric = (MutableCounterLong) Whitebox.getInternalState(server.getRpcMetrics(), "rpcAuthorizationSuccesses");
        proxy = getClient(addr, conf);
        boolean isDisconnected = true;
        Connection lastConn = null;
        long expectedAuths = 0;
        // fuzz the client.
        for (int i = 0; i < 128; i++) {
            String reqName = "request[" + i + "]";
            int r = ThreadLocalRandom.current().nextInt();
            final boolean doDisconnect = r % 4 == 0;
            LOG.info("TestDisconnect request[" + i + "] " + " shouldConnect=" + isDisconnected + " willDisconnect=" + doDisconnect);
            if (isDisconnected) {
                expectedAuths++;
            }
            try {
                FakeRequestClass.exception = doDisconnect ? rseFatal : rseError;
                proxy.ping(null, newEmptyRequest());
                fail(reqName + " didn't fail");
            } catch (ServiceException e) {
                RemoteException re = (RemoteException) e.getCause();
                assertEquals(reqName, expectedIOE, re.unwrapRemoteException());
            }
            // check authorizations to ensure new connection when expected,
            // then conclusively determine if connections are disconnected
            // correctly.
            assertEquals(reqName, expectedAuths, authMetric.value());
            if (!doDisconnect) {
                // if it wasn't fatal, verify there's only one open connection.
                Connection[] conns = server.getConnections();
                assertEquals(reqName, 1, conns.length);
                // verify whether the connection should have been reused.
                if (isDisconnected) {
                    assertNotSame(reqName, lastConn, conns[0]);
                } else {
                    assertSame(reqName, lastConn, conns[0]);
                }
                lastConn = conns[0];
            } else if (lastConn != null) {
                // avoid race condition in server where connection may not be
                // fully removed yet.  just make sure it's marked for being closed.
                // the open connection checks above ensure correct behavior.
                assertTrue(reqName, lastConn.shouldClose());
            }
            isDisconnected = doDisconnect;
        }
    } finally {
        stop(server, proxy);
    }
}
Also used : MutableCounterLong(org.apache.hadoop.metrics2.lib.MutableCounterLong) Connection(org.apache.hadoop.ipc.Server.Connection) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException) Test(org.junit.Test)

Example 14 with ServiceException

use of com.google.protobuf.ServiceException in project hadoop by apache.

the class TestRPC method testCallsInternal.

private void testCallsInternal(Configuration myConf) throws Exception {
    Server server;
    TestRpcService proxy = null;
    server = setupTestServer(myConf, -1);
    try {
        proxy = getClient(addr, myConf);
        proxy.ping(null, newEmptyRequest());
        TestProtos.EchoResponseProto echoResp = proxy.echo(null, newEchoRequest("foo"));
        assertEquals(echoResp.getMessage(), "foo");
        echoResp = proxy.echo(null, newEchoRequest(""));
        assertEquals(echoResp.getMessage(), "");
        // Check rpcMetrics
        MetricsRecordBuilder rb = getMetrics(server.rpcMetrics.name());
        assertCounter("RpcProcessingTimeNumOps", 3L, rb);
        assertCounterGt("SentBytes", 0L, rb);
        assertCounterGt("ReceivedBytes", 0L, rb);
        // Number of calls to echo method should be 2
        rb = getMetrics(server.rpcDetailedMetrics.name());
        assertCounter("EchoNumOps", 2L, rb);
        // Number of calls to ping method should be 1
        assertCounter("PingNumOps", 1L, rb);
        String[] strings = new String[] { "foo", "bar" };
        TestProtos.EchoRequestProto2 echoRequest2 = TestProtos.EchoRequestProto2.newBuilder().addAllMessage(Arrays.asList(strings)).build();
        TestProtos.EchoResponseProto2 echoResponse2 = proxy.echo2(null, echoRequest2);
        assertTrue(Arrays.equals(echoResponse2.getMessageList().toArray(), strings));
        echoRequest2 = TestProtos.EchoRequestProto2.newBuilder().addAllMessage(Collections.<String>emptyList()).build();
        echoResponse2 = proxy.echo2(null, echoRequest2);
        assertTrue(Arrays.equals(echoResponse2.getMessageList().toArray(), new String[] {}));
        TestProtos.AddRequestProto addRequest = TestProtos.AddRequestProto.newBuilder().setParam1(1).setParam2(2).build();
        TestProtos.AddResponseProto addResponse = proxy.add(null, addRequest);
        assertEquals(addResponse.getResult(), 3);
        Integer[] integers = new Integer[] { 1, 2 };
        TestProtos.AddRequestProto2 addRequest2 = TestProtos.AddRequestProto2.newBuilder().addAllParams(Arrays.asList(integers)).build();
        addResponse = proxy.add2(null, addRequest2);
        assertEquals(addResponse.getResult(), 3);
        boolean caught = false;
        try {
            proxy.error(null, newEmptyRequest());
        } catch (ServiceException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Caught " + e);
            }
            caught = true;
        }
        assertTrue(caught);
        rb = getMetrics(server.rpcDetailedMetrics.name());
        assertCounter("RpcServerExceptionNumOps", 1L, rb);
        //proxy.testServerGet();
        // create multiple threads and make them do large data transfers
        System.out.println("Starting multi-threaded RPC test...");
        server.setSocketSendBufSize(1024);
        Thread[] threadId = new Thread[numThreads];
        for (int i = 0; i < numThreads; i++) {
            Transactions trans = new Transactions(proxy, datasize);
            threadId[i] = new Thread(trans, "TransactionThread-" + i);
            threadId[i].start();
        }
        // wait for all transactions to get over
        System.out.println("Waiting for all threads to finish RPCs...");
        for (int i = 0; i < numThreads; i++) {
            try {
                threadId[i].join();
            } catch (InterruptedException e) {
                // retry
                i--;
            }
        }
    } finally {
        stop(server, proxy);
    }
}
Also used : TestProtos(org.apache.hadoop.ipc.protobuf.TestProtos) ServiceException(com.google.protobuf.ServiceException) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 15 with ServiceException

use of com.google.protobuf.ServiceException in project hadoop by apache.

the class TestRPCServerShutdown method testRPCServerShutdown.

/**
   *  Verify the RPC server can shutdown properly when callQueue is full.
   */
@Test(timeout = 30000)
public void testRPCServerShutdown() throws Exception {
    final int numClients = 3;
    final List<Future<Void>> res = new ArrayList<Future<Void>>();
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);
    conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
    RPC.Builder builder = newServerBuilder(conf).setQueueSizePerHandler(1).setNumHandlers(1).setVerbose(true);
    final Server server = setupTestServer(builder);
    final TestRpcService proxy = getClient(addr, conf);
    try {
        // Start another sleep RPC call to make reader thread block on CallQueue.
        for (int i = 0; i < numClients; i++) {
            res.add(executorService.submit(new Callable<Void>() {

                @Override
                public Void call() throws ServiceException, InterruptedException {
                    proxy.sleep(null, newSleepRequest(100000));
                    return null;
                }
            }));
        }
        while (server.getCallQueueLen() != 1 || countThreads(CallQueueManager.class.getName()) != 1 || countThreads(PBServerImpl.class.getName()) != 1) {
            Thread.sleep(100);
        }
    } finally {
        try {
            stop(server, proxy);
            assertEquals("Not enough clients", numClients, res.size());
            for (Future<Void> f : res) {
                try {
                    f.get();
                    fail("Future get should not return");
                } catch (ExecutionException e) {
                    ServiceException se = (ServiceException) e.getCause();
                    assertTrue("Unexpected exception: " + se, se.getCause() instanceof IOException);
                    LOG.info("Expected exception", e.getCause());
                }
            }
        } finally {
            executorService.shutdown();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) ServiceException(com.google.protobuf.ServiceException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

ServiceException (com.google.protobuf.ServiceException)139 IOException (java.io.IOException)66 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)11 FsPermission (org.apache.hadoop.fs.permission.FsPermission)5 Table (org.apache.hadoop.hbase.client.Table)5 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)5 InetSocketAddress (java.net.InetSocketAddress)4 DatanodeCommand (org.apache.hadoop.hdfs.server.protocol.DatanodeCommand)4 ByteString (com.google.protobuf.ByteString)3 InterruptedIOException (java.io.InterruptedIOException)3 ConnectException (java.net.ConnectException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 Callable (java.util.concurrent.Callable)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 EncryptionZone (org.apache.hadoop.hdfs.protocol.EncryptionZone)3 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)3 Server (org.apache.hadoop.ipc.Server)3