Search in sources :

Example 1 with GridQueryKillRequest

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()));
    }
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) GridQueryKillResponse(org.apache.ignite.internal.processors.query.messages.GridQueryKillResponse) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) MvccUtils.txStart(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.txStart) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Map(java.util.Map) NoOperation(org.h2.command.dml.NoOperation) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) GridIoPolicy(org.apache.ignite.internal.managers.communication.GridIoPolicy) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) QueryField(org.apache.ignite.internal.processors.query.QueryField) CIX2(org.apache.ignite.internal.util.typedef.CIX2) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) SqlAnalyzeCommand(org.apache.ignite.internal.sql.command.SqlAnalyzeCommand) DataType(org.h2.value.DataType) SqlRefreshStatitsicsCommand(org.apache.ignite.internal.sql.command.SqlRefreshStatitsicsCommand) PARAM_WRAP_VALUE(org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.PARAM_WRAP_VALUE) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) BulkLoadStreamerWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadStreamerWriter) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LinkedHashMap(java.util.LinkedHashMap) Column(org.h2.table.Column) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSqlAlterTableAddColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableAddColumn) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) SqlIndexColumn(org.apache.ignite.internal.sql.command.SqlIndexColumn) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) SqlKillQueryCommand(org.apache.ignite.internal.sql.command.SqlKillQueryCommand) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) Value(org.h2.value.Value) ServiceMXBeanImpl(org.apache.ignite.internal.ServiceMXBeanImpl) GridQueryProperty(org.apache.ignite.internal.processors.query.GridQueryProperty) GridSqlCreateIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateIndex) GridSqlAlterTableDropColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableDropColumn) BulkLoadParser(org.apache.ignite.internal.processors.bulkload.BulkLoadParser) SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) GridRunningQueryInfo(org.apache.ignite.internal.processors.query.GridRunningQueryInfo) DropIndex(org.h2.command.ddl.DropIndex) GridSqlDropTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropTable) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridTopic(org.apache.ignite.internal.GridTopic) SqlClientContext(org.apache.ignite.internal.processors.query.SqlClientContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) TransactionsMXBeanImpl(org.apache.ignite.internal.TransactionsMXBeanImpl) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) CacheMode(org.apache.ignite.cache.CacheMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) DmlBulkLoadDataConverter(org.apache.ignite.internal.processors.query.h2.dml.DmlBulkLoadDataConverter) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) IgniteCluster(org.apache.ignite.IgniteCluster) StatisticsTarget(org.apache.ignite.internal.processors.query.stat.StatisticsTarget) CreateTable(org.h2.command.ddl.CreateTable) QueryEntity(org.apache.ignite.cache.QueryEntity) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand) EventType(org.apache.ignite.events.EventType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridSqlStatement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) SqlKillContinuousQueryCommand(org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SqlKillScanQueryCommand(org.apache.ignite.internal.sql.command.SqlKillScanQueryCommand) BulkLoadAckClientParameters(org.apache.ignite.internal.processors.bulkload.BulkLoadAckClientParameters) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) GridQueryKillRequest(org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest) UpdatePlanBuilder(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) QueryMXBeanImpl(org.apache.ignite.internal.QueryMXBeanImpl) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) MvccUtils.tx(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.tx) HashMap(java.util.HashMap) GridSqlCreateTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateTable) SqlKillServiceCommand(org.apache.ignite.internal.sql.command.SqlKillServiceCommand) IgniteClosureX(org.apache.ignite.internal.util.lang.IgniteClosureX) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) BulkLoadCacheWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadCacheWriter) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) BulkLoadContextCursor(org.apache.ignite.cache.query.BulkLoadContextCursor) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) QueryIndexType(org.apache.ignite.cache.QueryIndexType) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Iterator(java.util.Iterator) SqlKillComputeTaskCommand(org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand) GridSqlDropIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex) SqlDropStatisticsCommand(org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand) SqlKillTransactionCommand(org.apache.ignite.internal.sql.command.SqlKillTransactionCommand) MvccUtils.mvccEnabled(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.mvccEnabled) IgniteQueryErrorCode(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) Prepared(org.h2.command.Prepared) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) BulkLoadProcessor(org.apache.ignite.internal.processors.bulkload.BulkLoadProcessor) CreateIndex(org.h2.command.ddl.CreateIndex) ComputeMXBeanImpl(org.apache.ignite.internal.ComputeMXBeanImpl) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DropTable(org.h2.command.ddl.DropTable) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridRunningQueryInfo(org.apache.ignite.internal.processors.query.GridRunningQueryInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 2 with GridQueryKillRequest

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridQueryKillRequest(org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest) GridQueryKillResponse(org.apache.ignite.internal.processors.query.messages.GridQueryKillResponse)

Example 3 with GridQueryKillRequest

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);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridQueryKillRequest(org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridQueryKillRequest (org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridQueryKillResponse (org.apache.ignite.internal.processors.query.messages.GridQueryKillResponse)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1