Search in sources :

Example 1 with TransportException

use of org.infinispan.client.hotrod.exceptions.TransportException in project infinispan by infinispan.

the class HeaderDecoder method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    if (operation != null) {
        operation.exceptionCaught(ctx.channel(), cause);
    } else {
        TransportException transportException = log.errorFromUnknownOperation(ctx.channel(), cause, ctx.channel().remoteAddress());
        for (HotRodOperation<?> op : incomplete.values()) {
            try {
                op.exceptionCaught(ctx.channel(), transportException);
            } catch (Throwable t) {
                HOTROD.errorf(t, "Failed to complete %s", op);
            }
        }
        if (log.isTraceEnabled()) {
            log.tracef(cause, "Requesting %s close due to exception", ctx.channel());
        }
        ctx.close();
    }
}
Also used : TransportException(org.infinispan.client.hotrod.exceptions.TransportException)

Example 2 with TransportException

use of org.infinispan.client.hotrod.exceptions.TransportException in project infinispan by infinispan.

the class RetryOnFailureOperation method handleException.

protected Throwable handleException(Throwable cause, Channel channel, SocketAddress address) {
    while (cause instanceof DecoderException && cause.getCause() != null) {
        cause = cause.getCause();
    }
    if (cause instanceof RemoteIllegalLifecycleStateException || cause instanceof IOException || cause instanceof TransportException) {
        if (Thread.interrupted()) {
            // Don't invalidate the transport if our thread was interrupted
            completeExceptionally(new InterruptedException());
            return null;
        }
        if (address != null) {
            addFailedServer(address);
        }
        if (channel != null) {
            // We need to remove decoder even if we're about to close the channel
            // because otherwise we would be notified through channelInactive and we would retry (again).
            HeaderDecoder headerDecoder = (HeaderDecoder) channel.pipeline().get(HeaderDecoder.NAME);
            if (headerDecoder != null) {
                channel.pipeline().remove(HeaderDecoder.NAME);
            }
            HOTROD.closingChannelAfterError(channel, cause);
            channel.close();
            if (headerDecoder != null) {
                headerDecoder.failoverClientListeners();
            }
        }
        logAndRetryOrFail(cause);
        return null;
    } else if (cause instanceof RemoteNodeSuspectException) {
        // TODO Clients should never receive a RemoteNodeSuspectException, see ISPN-11636
        logAndRetryOrFail(cause);
        return null;
    } else if (cause instanceof HotRodClientException && ((HotRodClientException) cause).isServerError()) {
        // fail the operation (don't retry) but don't close the channel
        completeExceptionally(cause);
        return null;
    } else {
        return cause;
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) HeaderDecoder(org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder) RemoteIllegalLifecycleStateException(org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException) IOException(java.io.IOException) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) TransportException(org.infinispan.client.hotrod.exceptions.TransportException) RemoteNodeSuspectException(org.infinispan.client.hotrod.exceptions.RemoteNodeSuspectException)

Example 3 with TransportException

use of org.infinispan.client.hotrod.exceptions.TransportException in project infinispan by infinispan.

the class CompleteShutdownReplRetryTest method testRetryAfterCompleteShutdown.

public void testRetryAfterCompleteShutdown() {
    ConfigurationBuilder builder = hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false));
    createHotRodServers(3, builder);
    try {
        int initialServerPort = server(0).getPort();
        assertClusterSize("Cluster should be formed", 3);
        RemoteCache<Integer, String> client = client(0).getCache();
        client.put(1, "one");
        assertEquals("one", client.get(1));
        killServer(0);
        assertEquals("one", client.get(1));
        killServer(0);
        assertEquals("one", client.get(1));
        killServer(0);
        try {
            assertEquals("one", client.get(1));
            fail("Should have thrown exception");
        } catch (TransportException e) {
        // Ignore, expected
        }
        addHotRodServer(builder, initialServerPort);
        client.put(1, "one");
        assertEquals("one", client.get(1));
    } finally {
        destroy();
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TransportException(org.infinispan.client.hotrod.exceptions.TransportException)

Example 4 with TransportException

use of org.infinispan.client.hotrod.exceptions.TransportException in project infinispan by infinispan.

the class ResilienceMaxRetryIT method testMaxRetries0.

@Test
public void testMaxRetries0() {
    // Start the client with initial_server_list=server0 and max_retries=0
    RemoteCache<Integer, String> cache = SERVER_TEST.hotrod().withClientConfiguration(new ConfigurationBuilder().maxRetries(0).connectionTimeout(500)).withCacheMode(CacheMode.REPL_SYNC).create(0);
    // Perform an operation so the client receives a topology update with server0, server1, and server2
    cache.get(ThreadLocalRandom.current().nextInt());
    // Stop server0
    InetSocketAddress serverAddress0 = SERVERS.getServerDriver().getServerSocket(0, SERVERS.getTestServer().getDefaultPortNumber());
    InetSocketAddress serverAddress1 = SERVERS.getServerDriver().getServerSocket(1, SERVERS.getTestServer().getDefaultPortNumber());
    InetSocketAddress serverAddress2 = SERVERS.getServerDriver().getServerSocket(2, SERVERS.getTestServer().getDefaultPortNumber());
    SERVERS.getServerDriver().stop(0);
    // Execute cache operations so the client connects to server1 or server2 and receives a topology update
    // The client keeps trying to connect to failed servers for each new operation,
    // so the number of operations we need depends on which server owns each key
    byte[] cacheNameBytes = cache.getName().getBytes();
    for (int i = 0; i < 10; i++) {
        try {
            cache.get(ThreadLocalRandom.current().nextInt());
            break;
        } catch (TransportException e) {
            // Assert that the failed server is the one that we killed
            assertTrue(serverAddress0.toString() + " not found in " + e.getMessage(), e.getMessage().contains(serverAddress0.toString()));
        }
    }
    // Check that the stopped server was properly removed from the list
    Collection<InetSocketAddress> currentServers = cache.getRemoteCacheManager().getChannelFactory().getServers(cacheNameBytes);
    assertEquals(new HashSet<>(asList(serverAddress1, serverAddress2)), new HashSet<>(resolveAddresses(currentServers)));
    // Stop server1 and server2, start server0
    SERVERS.getServerDriver().stop(1);
    SERVERS.getServerDriver().stop(2);
    SERVERS.getServerDriver().restart(0);
    // so the number of operations we need depends on which server owns each key
    for (int i = 0; i < 10; i++) {
        try {
            cache.get(ThreadLocalRandom.current().nextInt());
            break;
        } catch (TransportException e) {
            // Expected to fail to connect to server1 or server2, not server0
            assertTrue(e.getMessage(), e.getMessage().contains(serverAddress1.toString()) || e.getMessage().contains(serverAddress2.toString()));
        }
    }
    // Check that the client switched to the initial server list
    currentServers = cache.getRemoteCacheManager().getChannelFactory().getServers(cacheNameBytes);
    assertEquals(singletonList(serverAddress0), resolveAddresses(currentServers));
    // Do another operation, it should succeed
    cache.get(ThreadLocalRandom.current().nextInt());
}
Also used : ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) TransportException(org.infinispan.client.hotrod.exceptions.TransportException) Test(org.junit.Test)

Example 5 with TransportException

use of org.infinispan.client.hotrod.exceptions.TransportException in project infinispan by infinispan.

the class RemoteInnerPublisherHandler method handleThrowableInResponse.

@Override
protected void handleThrowableInResponse(Throwable t, Map.Entry<SocketAddress, IntSet> target) {
    if (t instanceof TransportException || t instanceof RemoteIllegalLifecycleStateException) {
        log.throwableDuringPublisher(t);
        if (log.isTraceEnabled()) {
            IntSet targetSegments = target.getValue();
            if (targetSegments != null) {
                log.tracef("There are still outstanding segments %s that will need to be retried", targetSegments);
            }
        }
        publisher.erroredServer(target.getKey());
        // Try next target if possible
        targetComplete();
        accept(0);
    } else {
        t.addSuppressed(new TraceException());
        super.handleThrowableInResponse(t, target);
    }
}
Also used : TraceException(org.infinispan.commons.util.logging.TraceException) IntSet(org.infinispan.commons.util.IntSet) RemoteIllegalLifecycleStateException(org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException) TransportException(org.infinispan.client.hotrod.exceptions.TransportException)

Aggregations

TransportException (org.infinispan.client.hotrod.exceptions.TransportException)6 RemoteIllegalLifecycleStateException (org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException)2 Channel (io.netty.channel.Channel)1 DecoderException (io.netty.handler.codec.DecoderException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)1 RemoteNodeSuspectException (org.infinispan.client.hotrod.exceptions.RemoteNodeSuspectException)1 HeaderDecoder (org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder)1 IntSet (org.infinispan.commons.util.IntSet)1 TraceException (org.infinispan.commons.util.logging.TraceException)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 Test (org.junit.Test)1