Search in sources :

Example 1 with HeaderDecoder

use of org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder 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 2 with HeaderDecoder

use of org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder in project infinispan by infinispan.

the class ServerErrorTest method testErrorWhileDoingPut.

public void testErrorWhileDoingPut(Method m) {
    cache.getAdvancedCache().withStorageMediaType().addListener(new ErrorInducingListener());
    remoteCache = remoteCacheManager.getCache();
    remoteCache.put(k(m), v(m));
    assertEquals(v(m), remoteCache.get(k(m)));
    // Obtain a reference to the single connection in the pool
    ChannelFactory channelFactory = remoteCacheManager.getChannelFactory();
    InetSocketAddress address = InetSocketAddress.createUnresolved(hotrodServer.getHost(), hotrodServer.getPort());
    Channel channel = channelFactory.fetchChannelAndInvoke(address, new NoopChannelOperation()).join();
    // Obtain a reference to the scheduled executor and its task queue
    AbstractScheduledEventExecutor scheduledExecutor = ((AbstractScheduledEventExecutor) channel.eventLoop());
    Queue<?> scheduledTaskQueue = TestingUtil.extractField(scheduledExecutor, "scheduledTaskQueue");
    int scheduledTasksBaseline = scheduledTaskQueue.size();
    // Release the channel back into the pool
    channelFactory.releaseChannel(channel);
    assertEquals(0, channelFactory.getNumActive(address));
    assertEquals(1, channelFactory.getNumIdle(address));
    log.debug("Sending failing operation to server");
    expectException(HotRodClientException.class, () -> remoteCache.put("FailFailFail", "whatever..."));
    assertEquals(0, channelFactory.getNumActive(address));
    assertEquals(1, channelFactory.getNumIdle(address));
    // Check that the operation was completed
    HeaderDecoder headerDecoder = channel.pipeline().get(HeaderDecoder.class);
    assertEquals(0, headerDecoder.registeredOperations());
    // Check that the timeout task was cancelled
    assertEquals(scheduledTasksBaseline, scheduledTaskQueue.size());
    log.debug("Sending new request after server failure");
    remoteCache.put(k(m, 2), v(m, 2));
    assertEquals(v(m, 2), remoteCache.get(k(m, 2)));
}
Also used : HeaderDecoder(org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder) InetSocketAddress(java.net.InetSocketAddress) NoopChannelOperation(org.infinispan.client.hotrod.test.NoopChannelOperation) Channel(io.netty.channel.Channel) AbstractScheduledEventExecutor(io.netty.util.concurrent.AbstractScheduledEventExecutor) ChannelFactory(org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)

Aggregations

HeaderDecoder (org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder)2 Channel (io.netty.channel.Channel)1 DecoderException (io.netty.handler.codec.DecoderException)1 AbstractScheduledEventExecutor (io.netty.util.concurrent.AbstractScheduledEventExecutor)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)1 RemoteIllegalLifecycleStateException (org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException)1 RemoteNodeSuspectException (org.infinispan.client.hotrod.exceptions.RemoteNodeSuspectException)1 TransportException (org.infinispan.client.hotrod.exceptions.TransportException)1 ChannelFactory (org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory)1 NoopChannelOperation (org.infinispan.client.hotrod.test.NoopChannelOperation)1