Search in sources :

Example 36 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class IgniteH2Indexing method executeSelectLocal.

/**
 * Queries individual fields (generally used by JDBC drivers).
 *
 * @param qryId Query id.
 * @param qryDesc Query descriptor.
 * @param qryParams Query parameters.
 * @param select Select.
 * @param filter Cache name and key filter.
 * @param mvccTracker Query tracker.
 * @param cancel Query cancel.
 * @param inTx Flag whether the query is executed in transaction.
 * @param timeout Timeout.
 * @return Query result.
 * @throws IgniteCheckedException If failed.
 */
private GridQueryFieldsResult executeSelectLocal(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultSelect select, final IndexingQueryFilter filter, MvccQueryTracker mvccTracker, GridQueryCancel cancel, boolean inTx, int timeout) throws IgniteCheckedException {
    assert !select.mvccEnabled() || mvccTracker != null;
    String qry;
    if (select.forUpdate())
        qry = inTx ? select.forUpdateQueryTx() : select.forUpdateQueryOutTx();
    else
        qry = qryDesc.sql();
    boolean mvccEnabled = mvccTracker != null;
    try {
        assert select != null;
        if (ctx.security().enabled())
            checkSecurity(select.cacheIds());
        MvccSnapshot mvccSnapshot = null;
        if (mvccEnabled)
            mvccSnapshot = mvccTracker.snapshot();
        final QueryContext qctx = new QueryContext(0, filter, null, mvccSnapshot, null, true);
        return new GridQueryFieldsResultAdapter(select.meta(), null) {

            @Override
            public GridCloseableIterator<List<?>> iterator() throws IgniteCheckedException {
                H2PooledConnection conn = connections().connection(qryDesc.schemaName());
                try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_ITER_OPEN, MTC.span()))) {
                    H2Utils.setupConnection(conn, qctx, qryDesc.distributedJoins(), qryDesc.enforceJoinOrder(), qryParams.lazy());
                    PreparedStatement stmt = conn.prepareStatement(qry, H2StatementCache.queryFlags(qryDesc));
                    // Convert parameters into BinaryObjects.
                    Marshaller m = ctx.config().getMarshaller();
                    byte[] paramsBytes = U.marshal(m, qryParams.arguments());
                    final ClassLoader ldr = U.resolveClassLoader(ctx.config());
                    Object[] params;
                    if (m instanceof BinaryMarshaller) {
                        params = BinaryUtils.rawArrayFromBinary(((BinaryMarshaller) m).binaryMarshaller().unmarshal(paramsBytes, ldr));
                    } else
                        params = U.unmarshal(m, paramsBytes, ldr);
                    H2Utils.bindParameters(stmt, F.asList(params));
                    H2QueryInfo qryInfo = new H2QueryInfo(H2QueryInfo.QueryType.LOCAL, stmt, qry, ctx.localNodeId(), qryId);
                    ResultSet rs = executeSqlQueryWithTimer(stmt, conn, qry, timeout, cancel, qryParams.dataPageScanEnabled(), qryInfo);
                    return new H2FieldsIterator(rs, mvccTracker, conn, qryParams.pageSize(), log, IgniteH2Indexing.this, qryInfo, ctx.tracing());
                } catch (IgniteCheckedException | RuntimeException | Error e) {
                    conn.close();
                    try {
                        if (mvccTracker != null)
                            mvccTracker.onDone();
                    } catch (Exception e0) {
                        e.addSuppressed(e0);
                    }
                    throw e;
                }
            }
        };
    } catch (Exception e) {
        GridNearTxLocal tx = null;
        if (mvccEnabled && (tx != null || (tx = tx(ctx)) != null))
            tx.setRollbackOnly();
        throw e;
    }
}
Also used : MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridQueryFieldsResultAdapter(org.apache.ignite.internal.processors.query.GridQueryFieldsResultAdapter) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) PreparedStatement(java.sql.PreparedStatement) H2Utils.generateFieldsQueryString(org.apache.ignite.internal.processors.query.h2.H2Utils.generateFieldsQueryString) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext) 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) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ResultSet(java.sql.ResultSet) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 37 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class IgniteH2Indexing method executeDml.

/**
 * Execute an all-ready {@link SqlFieldsQuery}.
 *
 * @param qryDesc Plan key.
 * @param qryParams Parameters.
 * @param dml DML.
 * @param cancel Query cancel state holder.
 * @return Query result.
 */
private List<? extends FieldsQueryCursor<List<?>>> executeDml(QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultDml dml, GridQueryCancel cancel) {
    IndexingQueryFilter filter = (qryDesc.local() ? backupFilter(null, qryParams.partitions()) : null);
    long qryId = registerRunningQuery(qryDesc, qryParams, cancel, dml.statement());
    Exception failReason = null;
    try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_DML_QRY_EXECUTE, MTC.span()))) {
        if (!dml.mvccEnabled() && !updateInTxAllowed && ctx.cache().context().tm().inUserTx()) {
            throw new IgniteSQLException("DML statements are not allowed inside a transaction over " + "cache(s) with TRANSACTIONAL atomicity mode (change atomicity mode to " + "TRANSACTIONAL_SNAPSHOT or disable this error message with system property " + "\"-DIGNITE_ALLOW_DML_INSIDE_TRANSACTION=true\")");
        }
        if (!qryDesc.local()) {
            return executeUpdateDistributed(qryId, qryDesc, qryParams, dml, cancel);
        } else {
            UpdateResult updRes = executeUpdate(qryId, qryDesc, qryParams, dml, true, filter, cancel);
            return singletonList(new QueryCursorImpl<>(new Iterable<List<?>>() {

                @Override
                public Iterator<List<?>> iterator() {
                    return new IgniteSingletonIterator<>(singletonList(updRes.counter()));
                }
            }, cancel, true, false));
        }
    } catch (IgniteException e) {
        failReason = e;
        throw e;
    } catch (IgniteCheckedException e) {
        failReason = e;
        IgniteClusterReadOnlyException roEx = X.cause(e, IgniteClusterReadOnlyException.class);
        if (roEx != null) {
            throw new IgniteSQLException("Failed to execute DML statement. Cluster in read-only mode [stmt=" + qryDesc.sql() + ", params=" + Arrays.deepToString(qryParams.arguments()) + "]", IgniteQueryErrorCode.CLUSTER_READ_ONLY_MODE_ENABLED, e);
        }
        throw new IgniteSQLException("Failed to execute DML statement [stmt=" + qryDesc.sql() + ", params=" + Arrays.deepToString(qryParams.arguments()) + "]", e);
    } finally {
        runningQryMgr.unregister(qryId, failReason);
    }
}
Also used : IgniteSingletonIterator(org.apache.ignite.internal.util.lang.IgniteSingletonIterator) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) 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) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class H2TreeIndex method onIndexRangeResponse.

/**
 * @param node Responded node.
 * @param msg Response message.
 */
private void onIndexRangeResponse(ClusterNode node, GridH2IndexRangeResponse msg) {
    try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_IDX_RANGE_RESP, MTC.span()))) {
        QueryContext qctx = qryCtxRegistry.getShared(msg.originNodeId(), msg.queryId(), msg.originSegmentId());
        if (qctx == null)
            return;
        DistributedJoinContext joinCtx = qctx.distributedJoinContext();
        assert joinCtx != null;
        Map<SegmentKey, RangeStream> streams = joinCtx.getStreams(msg.batchLookupId());
        if (streams == null)
            return;
        RangeStream stream = streams.get(new SegmentKey(node, msg.segment()));
        assert stream != null;
        stream.onResponse(msg);
    }
}
Also used : SegmentKey(org.apache.ignite.internal.processors.query.h2.opt.join.SegmentKey) DistributedJoinContext(org.apache.ignite.internal.processors.query.h2.opt.join.DistributedJoinContext) RangeStream(org.apache.ignite.internal.processors.query.h2.opt.join.RangeStream) IndexQueryContext(org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 39 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class H2ResultSetIterator method fetchPage.

/**
 * @return {@code true} if the next page is available.
 * @throws IgniteCheckedException On cancel.
 */
private boolean fetchPage() throws IgniteCheckedException {
    lockTables();
    try (TraceSurroundings ignored = MTC.support(tracing.create(SQL_PAGE_FETCH, MTC.span()))) {
        GridH2Table.checkTablesVersions(ses);
        page.clear();
        try {
            if (data.isClosed())
                return false;
        } catch (SQLException e) {
            if (e.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
                throw new QueryCancelledException();
            throw new IgniteSQLException(e);
        }
        for (int i = 0; i < pageSize; ++i) {
            try {
                if (!data.next())
                    break;
                row = new Object[colCnt];
                readRow();
                page.add(row);
            } catch (SQLException e) {
                close();
                if (e.getCause() instanceof IgniteSQLException)
                    throw (IgniteSQLException) e.getCause();
                if (e.getErrorCode() == ErrorCode.STATEMENT_WAS_CANCELED)
                    throw new QueryCancelledException();
                throw new IgniteSQLException(e);
            }
        }
        MTC.span().addTag(SQL_PAGE_ROWS, () -> Integer.toString(page.size()));
        if (F.isEmpty(page)) {
            rowIter = null;
            return false;
        } else {
            rowIter = page.iterator();
            return true;
        }
    } finally {
        unlockTables();
    }
}
Also used : SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 40 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class H2ResultSetIterator method closeInternal.

/**
 * @throws IgniteCheckedException On error.
 */
private synchronized void closeInternal() throws IgniteCheckedException {
    if (closed)
        return;
    try (TraceSurroundings ignored = MTC.support(tracing.create(SQL_ITER_CLOSE, MTC.span()))) {
        closed = true;
        onClose();
    }
}
Also used : TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Aggregations

TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)49 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)11 SQLException (java.sql.SQLException)10 IgniteException (org.apache.ignite.IgniteException)10 ArrayList (java.util.ArrayList)9 CacheException (javax.cache.CacheException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 List (java.util.List)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 Collections.singletonList (java.util.Collections.singletonList)5 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)5 BatchUpdateException (java.sql.BatchUpdateException)4 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)4 QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteClusterReadOnlyException (org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)4 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)4 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)4