Search in sources :

Example 1 with GridShmemCommunicationClient

use of org.apache.ignite.internal.util.nio.GridShmemCommunicationClient in project ignite by apache.

the class TcpCommunicationSpi method createShmemClient.

/**
 * @param node Node.
 * @param port Port.
 * @param connIdx Connection index.
 * @return Client.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
private GridCommunicationClient createShmemClient(ClusterNode node, int connIdx, Integer port) throws IgniteCheckedException {
    int attempt = 1;
    int connectAttempts = 1;
    long connTimeout0 = connTimeout;
    IgniteSpiOperationTimeoutHelper timeoutHelper = new IgniteSpiOperationTimeoutHelper(this, !node.isClient());
    while (true) {
        GridCommunicationClient client;
        try {
            client = new GridShmemCommunicationClient(connIdx, metricsLsnr, port, timeoutHelper.nextTimeoutChunk(connTimeout), log, getSpiContext().messageFormatter());
        } catch (IgniteCheckedException e) {
            if (timeoutHelper.checkFailureTimeoutReached(e))
                throw e;
            // Reconnect for the second time, if connection is not established.
            if (connectAttempts < 2 && X.hasCause(e, ConnectException.class)) {
                connectAttempts++;
                continue;
            }
            throw e;
        }
        try {
            safeShmemHandshake(client, node.id(), timeoutHelper.nextTimeoutChunk(connTimeout0));
        } catch (HandshakeTimeoutException | IgniteSpiOperationTimeoutException e) {
            client.forceClose();
            if (failureDetectionTimeoutEnabled() && (e instanceof HandshakeTimeoutException || timeoutHelper.checkFailureTimeoutReached(e))) {
                if (log.isDebugEnabled())
                    log.debug("Handshake timed out (failure threshold reached) [failureDetectionTimeout=" + failureDetectionTimeout() + ", err=" + e.getMessage() + ", client=" + client + ']');
                throw e;
            }
            assert !failureDetectionTimeoutEnabled();
            if (log.isDebugEnabled())
                log.debug("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", err=" + e.getMessage() + ", client=" + client + ']');
            if (attempt == reconCnt || connTimeout0 > maxConnTimeout) {
                if (log.isDebugEnabled())
                    log.debug("Handshake timedout (will stop attempts to perform the handshake) " + "[timeout=" + connTimeout0 + ", maxConnTimeout=" + maxConnTimeout + ", attempt=" + attempt + ", reconCnt=" + reconCnt + ", err=" + e.getMessage() + ", client=" + client + ']');
                throw e;
            } else {
                attempt++;
                connTimeout0 *= 2;
                continue;
            }
        } catch (IgniteCheckedException | RuntimeException | Error e) {
            if (log.isDebugEnabled())
                log.debug("Caught exception (will close client) [err=" + e.getMessage() + ", client=" + client + ']');
            client.forceClose();
            throw e;
        }
        return client;
    }
}
Also used : IgniteSpiOperationTimeoutHelper(org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridShmemCommunicationClient(org.apache.ignite.internal.util.nio.GridShmemCommunicationClient) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)1 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)1 GridCommunicationClient (org.apache.ignite.internal.util.nio.GridCommunicationClient)1 GridShmemCommunicationClient (org.apache.ignite.internal.util.nio.GridShmemCommunicationClient)1 IgniteSpiOperationTimeoutException (org.apache.ignite.spi.IgniteSpiOperationTimeoutException)1 IgniteSpiOperationTimeoutHelper (org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper)1 Nullable (org.jetbrains.annotations.Nullable)1