Search in sources :

Example 1 with StaticMvccQueryTracker

use of org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker in project ignite by apache.

the class IgniteH2Indexing method executeUpdateOnDataNodeTransactional.

/**
 * {@inheritDoc}
 */
@Override
public UpdateSourceIterator<?> executeUpdateOnDataNodeTransactional(GridCacheContext<?, ?> cctx, int[] ids, int[] parts, String schema, String qry, Object[] params, int flags, int pageSize, int timeout, AffinityTopologyVersion topVer, MvccSnapshot mvccSnapshot, GridQueryCancel cancel) throws IgniteCheckedException {
    SqlFieldsQuery fldsQry = QueryUtils.withQueryTimeout(new SqlFieldsQuery(qry), timeout, TimeUnit.MILLISECONDS);
    if (params != null)
        fldsQry.setArgs(params);
    fldsQry.setEnforceJoinOrder(U.isFlagSet(flags, GridH2QueryRequest.FLAG_ENFORCE_JOIN_ORDER));
    fldsQry.setTimeout(timeout, TimeUnit.MILLISECONDS);
    fldsQry.setPageSize(pageSize);
    fldsQry.setLocal(true);
    fldsQry.setLazy(U.isFlagSet(flags, GridH2QueryRequest.FLAG_LAZY));
    boolean loc = true;
    final boolean replicated = U.isFlagSet(flags, GridH2QueryRequest.FLAG_REPLICATED);
    GridCacheContext<?, ?> cctx0;
    if (!replicated && !F.isEmpty(ids) && (cctx0 = CU.firstPartitioned(cctx.shared(), ids)) != null && cctx0.config().getQueryParallelism() > 1) {
        fldsQry.setDistributedJoins(true);
        loc = false;
    }
    QueryParserResult parseRes = parser.parse(schema, fldsQry, false);
    assert parseRes.remainingQuery() == null;
    QueryParserResultDml dml = parseRes.dml();
    assert dml != null;
    IndexingQueryFilter filter = backupFilter(topVer, parts);
    UpdatePlan plan = dml.plan();
    GridCacheContext planCctx = plan.cacheContext();
    // Force keepBinary for operation context to avoid binary deserialization inside entry processor
    DmlUtils.setKeepBinaryContext(planCctx);
    SqlFieldsQuery selectFieldsQry = QueryUtils.withQueryTimeout(new SqlFieldsQuery(plan.selectQuery(), fldsQry.isCollocated()), fldsQry.getTimeout(), TimeUnit.MILLISECONDS).setArgs(fldsQry.getArgs()).setDistributedJoins(fldsQry.isDistributedJoins()).setEnforceJoinOrder(fldsQry.isEnforceJoinOrder()).setLocal(fldsQry.isLocal()).setPageSize(fldsQry.getPageSize()).setTimeout(fldsQry.getTimeout(), TimeUnit.MILLISECONDS).setLazy(fldsQry.isLazy());
    QueryCursorImpl<List<?>> cur;
    // sub-query and not some dummy stuff like "select 1, 2, 3;"
    if (!loc && !plan.isLocalSubquery()) {
        cur = executeSelectForDml(RunningQueryManager.UNDEFINED_QUERY_ID, schema, selectFieldsQry, new StaticMvccQueryTracker(planCctx, mvccSnapshot), cancel, timeout);
    } else {
        selectFieldsQry.setLocal(true);
        QueryParserResult selectParseRes = parser.parse(schema, selectFieldsQry, false);
        GridQueryFieldsResult res = executeSelectLocal(RunningQueryManager.UNDEFINED_QUERY_ID, selectParseRes.queryDescriptor(), selectParseRes.queryParameters(), selectParseRes.select(), filter, new StaticMvccQueryTracker(planCctx, mvccSnapshot), cancel, true, timeout);
        cur = new QueryCursorImpl<>(new Iterable<List<?>>() {

            @Override
            public Iterator<List<?>> iterator() {
                try {
                    return res.iterator();
                } catch (IgniteCheckedException e) {
                    throw new IgniteException(e);
                }
            }
        }, cancel, true, selectParseRes.queryParameters().lazy());
    }
    return plan.iteratorForTransaction(connMgr, cur);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) StaticMvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridQueryFieldsResult(org.apache.ignite.internal.processors.query.GridQueryFieldsResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)

Aggregations

ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 StaticMvccQueryTracker (org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker)1 GridQueryFieldsResult (org.apache.ignite.internal.processors.query.GridQueryFieldsResult)1 UpdatePlan (org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)1 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)1