Search in sources :

Example 56 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class DiscoveryClientSocketTest method sslSocketTest.

/**
 * It creates a SSL socket server and client for checks correctness closing when write exceed read.
 *
 * @throws Exception If failed.
 */
@Test
public void sslSocketTest() throws Exception {
    try (ServerSocket listen = sslSrvSockFactory.createServerSocket(PORT_TO_LNSR)) {
        info("Server started.");
        IgniteInternalFuture clientFut = GridTestUtils.runAsync(this::startSslClient);
        Socket connection = listen.accept();
        try {
            fakeTcpDiscoverySpi.configureSocketOptions(connection);
            readHandshake(connection);
            connection.getOutputStream().write(U.IGNITE_HEADER);
            clientFut.get(10_000);
        } catch (IgniteFutureTimeoutCheckedException e) {
            U.dumpThreads(log);
            U.closeQuiet(connection);
            fail("Can't wait connection closed from client side.");
        } catch (Exception e) {
            U.closeQuiet(connection);
            info("Ex: " + e.getMessage() + " (Socket closed)");
        }
    }
}
Also used : IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ServerSocket(java.net.ServerSocket) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 57 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class GridContinuousProcessor method addNotification.

/**
 * @param nodeId ID of the node that started routine.
 * @param routineId Routine ID.
 * @param obj Notification object.
 * @param orderedTopic Topic for ordered notifications. If {@code null}, non-ordered message will be sent.
 * @param sync If {@code true} then waits for event acknowledgment.
 * @param msg If {@code true} then sent data is message.
 * @throws IgniteCheckedException In case of error.
 */
public void addNotification(UUID nodeId, final UUID routineId, @Nullable Object obj, @Nullable Object orderedTopic, boolean sync, boolean msg) throws IgniteCheckedException {
    assert nodeId != null;
    assert routineId != null;
    assert !msg || (obj instanceof Message || obj instanceof Collection) : obj;
    assert !nodeId.equals(ctx.localNodeId());
    if (processorStopped)
        return;
    final RemoteRoutineInfo info = rmtInfos.get(routineId);
    if (info != null) {
        assert info.interval == 0 || !sync;
        if (sync) {
            SyncMessageAckFuture fut = new SyncMessageAckFuture(nodeId);
            IgniteUuid futId = IgniteUuid.randomUuid();
            syncMsgFuts.put(futId, fut);
            try {
                sendNotification(nodeId, routineId, futId, obj instanceof Collection ? (Collection) obj : F.asList(obj), null, msg, null);
                info.hnd.onBatchAcknowledged(routineId, info.add(obj), ctx);
            } catch (IgniteCheckedException e) {
                syncMsgFuts.remove(futId);
                throw e;
            }
            while (true) {
                try {
                    fut.get(100, TimeUnit.MILLISECONDS);
                    break;
                } catch (IgniteFutureTimeoutCheckedException ignored) {
                    // in case left/fail event processing failed, hanged or delayed.
                    if (!ctx.discovery().alive(nodeId)) {
                        SyncMessageAckFuture fut0 = syncMsgFuts.remove(futId);
                        if (fut0 != null) {
                            ClusterTopologyCheckedException err = new ClusterTopologyCheckedException("Node left grid after receiving, but before processing the message [node=" + nodeId + "]");
                            fut0.onDone(err);
                        }
                        break;
                    }
                    LT.warn(log, "Failed to wait for ack message. [node=" + nodeId + ", routine=" + routineId + "]");
                }
            }
            assert fut.isDone() : "Future in not finished [fut= " + fut + "]";
        } else {
            final GridContinuousBatch batch = info.add(obj);
            if (batch != null) {
                CI1<IgniteException> ackC = new CI1<IgniteException>() {

                    @Override
                    public void apply(IgniteException e) {
                        if (e == null)
                            info.hnd.onBatchAcknowledged(routineId, batch, ctx);
                    }
                };
                sendNotification(nodeId, routineId, null, batch.collect(), orderedTopic, msg, ackC);
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) CI1(org.apache.ignite.internal.util.typedef.CI1) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 58 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class DataStreamerImpl method doFlush.

/**
 * Performs flush.
 *
 * @throws IgniteCheckedException If failed.
 */
private void doFlush() throws IgniteCheckedException {
    lastFlushTime = U.currentTimeMillis();
    List<IgniteInternalFuture> activeFuts0 = null;
    int doneCnt = 0;
    flushAllThreadsBufs();
    for (IgniteInternalFuture<?> f : activeFuts) {
        if (!f.isDone()) {
            if (activeFuts0 == null)
                activeFuts0 = new ArrayList<>((int) (activeFuts.size() * 1.2));
            activeFuts0.add(f);
        } else {
            f.get();
            doneCnt++;
        }
    }
    if (activeFuts0 == null || activeFuts0.isEmpty())
        return;
    while (true) {
        if (disconnectErr != null)
            throw disconnectErr;
        Queue<IgniteInternalFuture<?>> q = null;
        for (Buffer buf : bufMappings.values()) {
            IgniteInternalFuture<?> flushFut = buf.flush();
            if (flushFut != null) {
                if (q == null)
                    q = new ArrayDeque<>(bufMappings.size() * 2);
                q.add(flushFut);
            }
        }
        if (q != null) {
            assert !q.isEmpty();
            boolean err = false;
            long startTimeMillis = U.currentTimeMillis();
            for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
                try {
                    if (timeout == DFLT_UNLIMIT_TIMEOUT)
                        fut.get();
                    else {
                        long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
                        if (timeRemain <= 0)
                            throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
                        fut.get(timeRemain);
                    }
                } catch (IgniteClientDisconnectedCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw CU.convertToCacheException(e);
                } catch (IgniteFutureTimeoutCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
                } catch (IgniteCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    err = true;
                    if (X.cause(e, IgniteClusterReadOnlyException.class) != null)
                        throw e;
                }
            }
            if (err)
                // Remaps needed - flush buffers.
                continue;
        }
        doneCnt = 0;
        for (int i = 0; i < activeFuts0.size(); i++) {
            IgniteInternalFuture f = activeFuts0.get(i);
            if (f == null)
                doneCnt++;
            else if (f.isDone()) {
                f.get();
                doneCnt++;
                activeFuts0.set(i, null);
            } else
                break;
        }
        if (doneCnt == activeFuts0.size())
            return;
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ArrayDeque(java.util.ArrayDeque) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 59 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class ConnectionClientPool method reserveClient.

/**
 * Returns existing or just created client to node.
 *
 * @param node Node to which client should be open.
 * @param connIdx Connection index.
 * @return The existing or just created client.
 * @throws IgniteCheckedException Thrown if any exception occurs.
 */
public GridCommunicationClient reserveClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
    assert node != null;
    assert (connIdx >= 0 && connIdx < cfg.connectionsPerNode()) || !(cfg.usePairedConnections() && usePairedConnections(node, attrs.pairedConnection())) : connIdx;
    if (locNodeSupplier.get().isClient()) {
        if (node.isClient()) {
            if (DISABLED_CLIENT_PORT.equals(node.attribute(attrs.port())))
                throw new IgniteSpiException("Cannot send message to the client node with no server socket opened.");
        }
    }
    UUID nodeId = node.id();
    if (log.isDebugEnabled())
        log.debug("The node client is going to reserve a connection [nodeId=" + node.id() + ", connIdx=" + connIdx + "]");
    while (true) {
        GridCommunicationClient[] curClients = clients.get(nodeId);
        GridCommunicationClient client = curClients != null && connIdx < curClients.length ? curClients[connIdx] : null;
        if (client == null) {
            if (stopping)
                throw new IgniteSpiException("Node is stopping.");
            // Do not allow concurrent connects.
            GridFutureAdapter<GridCommunicationClient> fut = new ConnectFuture();
            ConnectionKey connKey = new ConnectionKey(nodeId, connIdx, -1);
            GridFutureAdapter<GridCommunicationClient> oldFut = clientFuts.putIfAbsent(connKey, fut);
            if (oldFut == null) {
                try {
                    GridCommunicationClient[] curClients0 = clients.get(nodeId);
                    GridCommunicationClient client0 = curClients0 != null && connIdx < curClients0.length ? curClients0[connIdx] : null;
                    if (client0 == null) {
                        client0 = createCommunicationClient(node, connIdx);
                        if (client0 != null) {
                            addNodeClient(node, connIdx, client0);
                            if (client0 instanceof GridTcpNioCommunicationClient) {
                                GridTcpNioCommunicationClient tcpClient = ((GridTcpNioCommunicationClient) client0);
                                if (tcpClient.session().closeTime() > 0 && removeNodeClient(nodeId, client0)) {
                                    if (log.isDebugEnabled()) {
                                        log.debug("Session was closed after client creation, will retry " + "[node=" + node + ", client=" + client0 + ']');
                                    }
                                    client0 = null;
                                }
                            }
                        } else {
                            U.sleep(200);
                            if (nodeGetter.apply(node.id()) == null)
                                throw new ClusterTopologyCheckedException("Failed to send message " + "(node left topology): " + node);
                        }
                    }
                    fut.onDone(client0);
                } catch (NodeUnreachableException e) {
                    log.warning(e.getMessage());
                    fut = handleUnreachableNodeException(node, connIdx, fut, e);
                } catch (Throwable e) {
                    if (e instanceof NodeUnreachableException)
                        throw e;
                    fut.onDone(e);
                    if (e instanceof IgniteTooManyOpenFilesException)
                        throw e;
                    if (e instanceof Error)
                        throw (Error) e;
                } finally {
                    clientFuts.remove(connKey, fut);
                }
            } else
                fut = oldFut;
            long clientReserveWaitTimeout = registry != null ? registry.getSystemWorkerBlockedTimeout() / 3 : cfg.connectionTimeout() / 3;
            long currTimeout = System.currentTimeMillis();
            // This cycle will eventually quit when future is completed by concurrent thread reserving client.
            while (true) {
                try {
                    client = fut.get(clientReserveWaitTimeout, TimeUnit.MILLISECONDS);
                    break;
                } catch (IgniteFutureTimeoutCheckedException ignored) {
                    currTimeout += clientReserveWaitTimeout;
                    if (log.isDebugEnabled()) {
                        log.debug("Still waiting for reestablishing connection to node " + "[nodeId=" + node.id() + ", waitingTime=" + currTimeout + "ms]");
                    }
                    if (registry != null) {
                        GridWorker wrkr = registry.worker(Thread.currentThread().getName());
                        if (wrkr != null)
                            wrkr.updateHeartbeat();
                    }
                }
            }
            if (client == null) {
                if (clusterStateProvider.isLocalNodeDisconnected())
                    throw new IgniteCheckedException("Unable to create TCP client due to local node disconnecting.");
                else
                    continue;
            }
            if (nodeGetter.apply(nodeId) == null) {
                if (removeNodeClient(nodeId, client))
                    client.forceClose();
                throw new IgniteSpiException("Destination node is not in topology: " + node.id());
            }
        }
        assert connIdx == client.connectionIndex() : client;
        if (client.reserve())
            return client;
        else
            // Client has just been closed by idle worker. Help it and try again.
            removeNodeClient(nodeId, client);
    }
}
Also used : GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) IgniteTooManyOpenFilesException(org.apache.ignite.internal.IgniteTooManyOpenFilesException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 60 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class ConnectionClientPool method handleUnreachableNodeException.

/**
 * Handles {@link NodeUnreachableException}. This means that the method will try to trigger client itself to open connection.
 * The only possible way of doing this is to use {@link TcpCommunicationConfiguration#connectionRequestor()}'s trigger and wait.
 * Specifics of triggers implementation technically should be considered unknown, but for now it's not true and we
 * expect that {@link NodeUnreachableException} won't be thrown in {@link IgniteDiscoveryThread}.
 *
 * @param node Node to open connection to.
 * @param connIdx Connection index.
 * @param fut Current future for opening connection.
 * @param e Curent exception.
 * @return New future that will return the client or error. {@code null} client is possible if newly opened
 *      connection has been closed by idle worker, at least that's what documentation says.
 * @throws IgniteCheckedException If trigerring failed or trigger is not configured.
 */
private GridFutureAdapter<GridCommunicationClient> handleUnreachableNodeException(ClusterNode node, int connIdx, GridFutureAdapter<GridCommunicationClient> fut, NodeUnreachableException e) throws IgniteCheckedException {
    if (cfg.connectionRequestor() != null) {
        ConnectFuture fut0 = (ConnectFuture) fut;
        final ConnectionKey key = new ConnectionKey(node.id(), connIdx, -1);
        ConnectionRequestFuture triggerFut = new ConnectionRequestFuture();
        triggerFut.listen(f -> {
            try {
                fut0.onDone(f.get());
            } catch (Throwable t) {
                fut0.onDone(t);
            } finally {
                clientFuts.remove(key, triggerFut);
            }
        });
        clientFuts.put(key, triggerFut);
        fut = triggerFut;
        try {
            cfg.connectionRequestor().request(node, connIdx);
            long failTimeout = cfg.failureDetectionTimeoutEnabled() ? cfg.failureDetectionTimeout() : cfg.connectionTimeout();
            fut.get(failTimeout);
        } catch (Throwable triggerException) {
            if (forcibleNodeKillEnabled && node.isClient() && triggerException instanceof IgniteFutureTimeoutCheckedException) {
                CommunicationTcpUtils.failNode(node, tcpCommSpi.getSpiContext(), triggerException, log);
            }
            IgniteSpiException spiE = new IgniteSpiException(e);
            spiE.addSuppressed(triggerException);
            String msg = "Failed to wait for establishing inverse communication connection from node " + node;
            log.warning(msg, spiE);
            fut.onDone(spiE);
            throw spiE;
        }
    } else {
        fut.onDone(e);
        throw new IgniteCheckedException(e);
    }
    return fut;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)74 Test (org.junit.Test)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)31 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Ignite (org.apache.ignite.Ignite)18 IgniteEx (org.apache.ignite.internal.IgniteEx)17 IgniteException (org.apache.ignite.IgniteException)16 ArrayList (java.util.ArrayList)14 Transaction (org.apache.ignite.transactions.Transaction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Map (java.util.Map)10 CacheException (javax.cache.CacheException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7