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();
}
}
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();
}
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);
}
}
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;
}
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);
}
}
Aggregations