Search in sources :

Example 1 with RegisteredQueryCursor

use of org.apache.ignite.internal.processors.cache.query.RegisteredQueryCursor in project ignite by apache.

the class IgniteH2Indexing method executeSelect.

/**
 * Execute an all-ready {@link SqlFieldsQuery}.
 *
 * @param qryDesc Plan key.
 * @param qryParams Parameters.
 * @param select Select.
 * @param keepBinary Whether binary objects must not be deserialized automatically.
 * @param cancel Query cancel state holder.
 * @return Query result.
 */
private List<? extends FieldsQueryCursor<List<?>>> executeSelect(QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultSelect select, boolean keepBinary, GridQueryCancel cancel) {
    assert cancel != null;
    // Register query.
    long qryId = registerRunningQuery(qryDesc, qryParams, cancel, select.statement());
    try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_CURSOR_OPEN, MTC.span()))) {
        GridNearTxLocal tx = null;
        MvccQueryTracker tracker = null;
        GridCacheContext mvccCctx = null;
        boolean inTx = false;
        if (select.mvccEnabled()) {
            mvccCctx = ctx.cache().context().cacheContext(select.mvccCacheId());
            if (mvccCctx == null)
                throw new IgniteCheckedException("Cache has been stopped concurrently [cacheId=" + select.mvccCacheId() + ']');
            boolean autoStartTx = !qryParams.autoCommit() && tx(ctx) == null;
            // Start new user tx in case of autocommit == false.
            if (autoStartTx)
                txStart(ctx, qryParams.timeout());
            tx = tx(ctx);
            checkActive(tx);
            inTx = tx != null;
            tracker = MvccUtils.mvccTracker(mvccCctx, tx);
        }
        int timeout = operationTimeout(qryParams.timeout(), tx);
        Iterable<List<?>> iter = executeSelect0(qryId, qryDesc, qryParams, select, keepBinary, tracker, cancel, inTx, timeout);
        // Execute SELECT FOR UPDATE if needed.
        if (select.forUpdate() && inTx)
            iter = lockSelectedRows(iter, mvccCctx, timeout, qryParams.pageSize());
        RegisteredQueryCursor<List<?>> cursor = new RegisteredQueryCursor<>(iter, cancel, runningQueryManager(), qryParams.lazy(), qryId, ctx.tracing());
        cancel.add(cursor::cancel);
        cursor.fieldsMeta(select.meta());
        cursor.partitionResult(select.twoStepQuery() != null ? select.twoStepQuery().derivedPartitions() : null);
        return singletonList(cursor);
    } catch (Exception e) {
        runningQryMgr.unregister(qryId, e);
        if (e instanceof IgniteCheckedException)
            throw U.convertException((IgniteCheckedException) e);
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        throw new IgniteSQLException("Failed to execute SELECT statement: " + qryDesc.sql(), e);
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) BatchUpdateException(java.sql.BatchUpdateException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) StaticMvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker) MvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker) RegisteredQueryCursor(org.apache.ignite.internal.processors.cache.query.RegisteredQueryCursor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 CacheException (javax.cache.CacheException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)1 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 IgniteClusterReadOnlyException (org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 MvccQueryTracker (org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker)1 StaticMvccQueryTracker (org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker)1 RegisteredQueryCursor (org.apache.ignite.internal.processors.cache.query.RegisteredQueryCursor)1 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)1 TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)1