Search in sources :

Example 56 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class TcpCommunicationSpi method createNioClient.

/**
 * @param node Node to create client for.
 * @param connIdx Connection index.
 * @return Client.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
private GridCommunicationClient createNioClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
    assert node != null;
    Integer shmemPort = node.attribute(createSpiAttributeName(ATTR_SHMEM_PORT));
    ClusterNode locNode = getSpiContext().localNode();
    if (locNode == null)
        throw new IgniteCheckedException("Failed to create NIO client (local node is stopping)");
    if (log.isDebugEnabled())
        log.debug("Creating NIO client to node: " + node);
    // then we are likely to run on the same host and shared memory communication could be tried.
    if (shmemPort != null && U.sameMacs(locNode, node)) {
        try {
            GridCommunicationClient client = createShmemClient(node, connIdx, shmemPort);
            if (log.isDebugEnabled())
                log.debug("Shmem client created: " + client);
            return client;
        } catch (IgniteCheckedException e) {
            if (e.hasCause(IpcOutOfSystemResourcesException.class))
                // Has cause or is itself the IpcOutOfSystemResourcesException.
                LT.warn(log, OUT_OF_RESOURCES_TCP_MSG);
            else if (getSpiContext().node(node.id()) != null)
                LT.warn(log, e.getMessage());
            else if (log.isDebugEnabled())
                log.debug("Failed to establish shared memory connection with local node (node has left): " + node.id());
        }
    }
    connectGate.enter();
    try {
        GridCommunicationClient client = createTcpClient(node, connIdx);
        if (log.isDebugEnabled())
            log.debug("TCP client created: " + client);
        return client;
    } finally {
        connectGate.leave();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IpcOutOfSystemResourcesException(org.apache.ignite.internal.util.ipc.shmem.IpcOutOfSystemResourcesException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheDistributedQueryFuture method cancelQuery.

/**
 * {@inheritDoc}
 */
@Override
protected void cancelQuery() throws IgniteCheckedException {
    final GridCacheQueryManager<K, V> qryMgr = cctx.queries();
    assert qryMgr != null;
    try {
        Collection<ClusterNode> allNodes = cctx.discovery().allNodes();
        Collection<ClusterNode> nodes;
        synchronized (this) {
            nodes = F.retain(allNodes, true, new P1<ClusterNode>() {

                @Override
                public boolean apply(ClusterNode node) {
                    return !cctx.localNodeId().equals(node.id()) && subgrid.contains(node.id());
                }
            });
            subgrid.clear();
        }
        final GridCacheQueryRequest req = new GridCacheQueryRequest(cctx.cacheId(), reqId, fields(), qryMgr.queryTopologyVersion(), cctx.deploymentEnabled());
        // Process cancel query directly (without sending) for local node,
        cctx.closures().callLocalSafe(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                qryMgr.processQueryRequest(cctx.localNodeId(), req);
                return null;
            }
        });
        if (!nodes.isEmpty()) {
            for (ClusterNode node : nodes) {
                try {
                    cctx.io().send(node, req, cctx.ioPolicy());
                } catch (IgniteCheckedException e) {
                    if (cctx.io().checkNodeLeft(node.id(), e, false)) {
                        if (log.isDebugEnabled())
                            log.debug("Failed to send cancel request, node failed: " + node);
                    } else
                        U.error(log, "Failed to send cancel request [node=" + node + ']', e);
                }
            }
        }
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to send cancel request (will cancel query in any case).", e);
    }
    qryMgr.onQueryFutureCanceled(reqId);
    clear();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) P1(org.apache.ignite.internal.util.typedef.P1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 58 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheDistributedQueryManager method sendRequest.

/**
 * Sends query request.
 *
 * @param fut Distributed future.
 * @param req Request.
 * @param nodes Nodes.
 * @throws IgniteCheckedException In case of error.
 */
@SuppressWarnings("unchecked")
private void sendRequest(final GridCacheDistributedQueryFuture<?, ?, ?> fut, final GridCacheQueryRequest req, Collection<ClusterNode> nodes) throws IgniteCheckedException {
    assert fut != null;
    assert req != null;
    assert nodes != null;
    final UUID locNodeId = cctx.localNodeId();
    ClusterNode locNode = null;
    Collection<ClusterNode> rmtNodes = null;
    for (ClusterNode n : nodes) {
        if (n.id().equals(locNodeId))
            locNode = n;
        else {
            if (rmtNodes == null)
                rmtNodes = new ArrayList<>(nodes.size());
            rmtNodes.add(n);
        }
    }
    // the reducer changed by the local node.
    if (!F.isEmpty(rmtNodes)) {
        for (ClusterNode node : rmtNodes) {
            try {
                cctx.io().send(node, req, GridIoPolicy.QUERY_POOL);
            } catch (IgniteCheckedException e) {
                if (cctx.io().checkNodeLeft(node.id(), e, true)) {
                    fut.onNodeLeft(node.id());
                    if (fut.isDone())
                        return;
                } else
                    throw e;
            }
        }
    }
    if (locNode != null) {
        cctx.closures().callLocalSafe(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                req.beforeLocalExecution(cctx);
                processQueryRequest(locNodeId, req);
                return null;
            }
        }, GridIoPolicy.QUERY_POOL);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) NoSuchElementException(java.util.NoSuchElementException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 59 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheQueryFutureAdapter method nextPage.

/**
 * Returns next page for the query.
 *
 * @param timeout Timeout.
 * @param startTime Timeout wait start time.
 * @return Next page or {@code null} if no more pages available.
 * @throws IgniteCheckedException If fetch failed.
 */
private Collection<R> nextPage(long timeout, long startTime) throws IgniteCheckedException {
    Collection<R> res = null;
    while (res == null) {
        synchronized (this) {
            res = queue.poll();
        }
        if (res == null) {
            if (!isDone()) {
                loadPage();
                long waitTime = timeout == 0 ? Long.MAX_VALUE : timeout - (U.currentTimeMillis() - startTime);
                if (waitTime <= 0)
                    break;
                synchronized (this) {
                    try {
                        if (queue.isEmpty() && !isDone())
                            wait(waitTime);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        throw new IgniteCheckedException("Query was interrupted: " + qry, e);
                    }
                }
            } else
                break;
        }
    }
    checkError();
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 60 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheQueryFutureAdapter method onTimeout.

/**
 * {@inheritDoc}
 */
@Override
public void onTimeout() {
    try {
        cancelQuery();
        onDone(new IgniteFutureTimeoutCheckedException("Query timed out."));
    } catch (IgniteCheckedException e) {
        onDone(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96