Search in sources :

Example 1 with IpcSharedMemoryClientEndpoint

use of org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint in project ignite by apache.

the class HadoopExternalCommunication method createShmemClient.

/**
 * @param desc Process descriptor.
 * @param port Port.
 * @return Client.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
protected HadoopCommunicationClient createShmemClient(HadoopProcessDescriptor desc, int port) throws IgniteCheckedException {
    int attempt = 1;
    int connectAttempts = 1;
    long connTimeout0 = connTimeout;
    while (true) {
        IpcEndpoint clientEndpoint;
        try {
            clientEndpoint = new IpcSharedMemoryClientEndpoint(port, (int) connTimeout, log);
        } catch (IgniteCheckedException e) {
            // Reconnect for the second time, if connection is not established.
            if (connectAttempts < 2 && X.hasCause(e, ConnectException.class)) {
                connectAttempts++;
                continue;
            }
            throw e;
        }
        HadoopCommunicationClient client = null;
        try {
            ShmemWorker worker = new ShmemWorker(clientEndpoint, false);
            shmemWorkers.add(worker);
            GridNioSession ses = worker.session();
            HandshakeFinish fin = new HandshakeFinish();
            // We are in lock, it is safe to get session and attach
            ses.addMeta(HANDSHAKE_FINISH_META, fin);
            client = new HadoopTcpNioCommunicationClient(ses);
            new IgniteThread(worker).start();
            fin.await(connTimeout0);
        } catch (HadoopHandshakeTimeoutException e) {
            if (log.isDebugEnabled())
                log.debug("Handshake timed out (will retry with increased timeout) [timeout=" + connTimeout0 + ", err=" + e.getMessage() + ", client=" + client + ']');
            if (client != null)
                client.forceClose();
            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 (RuntimeException | Error e) {
            if (log.isDebugEnabled())
                log.debug("Caught exception (will close client) [err=" + e.getMessage() + ", client=" + client + ']');
            if (client != null)
                client.forceClose();
            throw e;
        }
        return client;
    }
}
Also used : IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint) IpcEndpoint(org.apache.ignite.internal.util.ipc.IpcEndpoint) IpcSharedMemoryClientEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)1 IpcSharedMemoryClientEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryClientEndpoint)1 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)1 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)1 IgniteThread (org.apache.ignite.thread.IgniteThread)1 Nullable (org.jetbrains.annotations.Nullable)1