use of org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest in project ignite by apache.
the class CommandProcessor method onQueryKillRequest.
/**
* Process request to kill query.
*
* @param msg Message.
* @param node Cluster node.
*/
private void onQueryKillRequest(GridQueryKillRequest msg, ClusterNode node) {
final long qryId = msg.nodeQryId();
String err = null;
GridRunningQueryInfo runningQryInfo = idx.runningQueryManager().runningQueryInfo(qryId);
if (runningQryInfo == null)
err = "Query with provided ID doesn't exist " + "[nodeId=" + ctx.localNodeId() + ", qryId=" + qryId + "]";
else if (!runningQryInfo.cancelable())
err = "Query doesn't support cancellation " + "[nodeId=" + ctx.localNodeId() + ", qryId=" + qryId + "]";
if (msg.asyncResponse() || err != null)
sendKillResponse(msg, node, err);
if (err == null) {
try {
runningQryInfo.cancel();
} catch (Exception e) {
U.warn(log, "Cancellation of query failed: [qryId=" + qryId + "]", e);
if (!msg.asyncResponse())
sendKillResponse(msg, node, e.getMessage());
return;
}
if (!msg.asyncResponse())
runningQryInfo.runningFuture().listen((f) -> sendKillResponse(msg, node, f.result()));
}
}
use of org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest in project ignite by apache.
the class CommandProcessor method onMessage.
/**
* @param nodeId Node ID.
* @param msg Message.
*/
public void onMessage(UUID nodeId, Object msg) {
assert msg != null;
ClusterNode node = ctx.discovery().node(nodeId);
if (node == null)
// Node left, ignore.
return;
boolean processed = true;
if (msg instanceof GridQueryKillRequest)
onQueryKillRequest((GridQueryKillRequest) msg, node);
if (msg instanceof GridQueryKillResponse)
onQueryKillResponse((GridQueryKillResponse) msg);
else
processed = false;
if (processed && log.isDebugEnabled())
log.debug("Processed response: " + nodeId + "->" + ctx.localNodeId() + " " + msg);
}
use of org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest in project ignite by apache.
the class CommandProcessor method processKillQueryCommand.
/**
* Process kill query command
*
* @param cmd Command.
*/
private void processKillQueryCommand(SqlKillQueryCommand cmd) {
GridFutureAdapter<String> fut = new GridFutureAdapter<>();
lock.readLock().lock();
try {
if (stopped)
throw new IgniteSQLException("Failed to cancel query due to node is stopped [nodeId=" + cmd.nodeId() + ",qryId=" + cmd.nodeQueryId() + "]");
ClusterNode node = ctx.discovery().node(cmd.nodeId());
if (node != null) {
if (node.version().compareTo(KILL_COMMAND_SINCE_VER) < 0)
throw new IgniteSQLException("Failed to cancel query: KILL QUERY operation is supported in " + "versions 2.8.0 and newer");
KillQueryRun qryRun = new KillQueryRun(cmd.nodeId(), cmd.nodeQueryId(), fut);
long reqId = qryCancelReqCntr.incrementAndGet();
cancellationRuns.put(reqId, qryRun);
boolean snd = idx.send(GridTopic.TOPIC_QUERY, GridTopic.TOPIC_QUERY.ordinal(), Collections.singleton(node), new GridQueryKillRequest(reqId, cmd.nodeQueryId(), cmd.async()), null, locNodeMsgHnd, GridIoPolicy.MANAGEMENT_POOL, cmd.async());
if (!snd) {
cancellationRuns.remove(reqId);
throw new IgniteSQLException("Failed to cancel query due communication problem " + "[nodeId=" + cmd.nodeId() + ",qryId=" + cmd.nodeQueryId() + "]");
}
} else
throw new IgniteSQLException("Failed to cancel query, node is not alive [nodeId=" + cmd.nodeId() + ",qryId=" + cmd.nodeQueryId() + "]");
} finally {
lock.readLock().unlock();
}
try {
String err = fut.get();
if (err != null)
throw new IgniteSQLException("Failed to cancel query [nodeId=" + cmd.nodeId() + ",qryId=" + cmd.nodeQueryId() + ",err=" + err + "]");
} catch (IgniteCheckedException e) {
throw new IgniteSQLException("Failed to cancel query [nodeId=" + cmd.nodeId() + ",qryId=" + cmd.nodeQueryId() + ",err=" + e + "]", e);
}
}
Aggregations