This is an automated email from the ASF dual-hosted git repository. av pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new 7950200445f IGNITE-21367 IgniteH2Indexing transactional code removal (#11242) 7950200445f is described below commit 7950200445fb2daef8e78134f5ed0380ee7b7c1b Author: Ilya Shishkov <shishkovi...@gmail.com> AuthorDate: Tue Mar 19 12:22:18 2024 +0300 IGNITE-21367 IgniteH2Indexing transactional code removal (#11242) --- .../processors/query/GridQueryIndexing.java | 33 -- .../processors/query/GridQueryProcessor.java | 51 --- .../processors/query/UpdateSourceIterator.java | 89 ----- .../main/resources/META-INF/classnames.properties | 1 - .../processors/query/DummyQueryIndexing.java | 19 - .../processors/query/h2/IgniteH2Indexing.java | 395 ++++----------------- .../internal/processors/query/h2/QueryParser.java | 69 +--- .../query/h2/QueryParserResultSelect.java | 75 +--- .../query/h2/dml/DmlUpdateResultsIterator.java | 70 ---- .../query/h2/dml/DmlUpdateSingleEntryIterator.java | 66 ---- .../processors/query/h2/dml/UpdatePlan.java | 211 ----------- .../query/h2/sql/SqlUnsupportedSelfTest.java | 2 + 12 files changed, 82 insertions(+), 999 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java index f0e3c20db31..32323300a8d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java @@ -28,7 +28,6 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheContextInfo; -import org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot; import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.odbc.jdbc.JdbcParameterMeta; import org.apache.ignite.internal.processors.query.running.RunningQueryManager; @@ -153,38 +152,6 @@ public interface GridQueryIndexing { */ public void unregisterCache(GridCacheContextInfo<?, ?> cacheInfo); - /** - * - * @param cctx Cache context. - * @param ids Involved cache ids. - * @param parts Partitions. - * @param schema Schema name. - * @param qry Query string. - * @param params Query parameters. - * @param flags Flags. - * @param pageSize Fetch page size. - * @param timeout Timeout. - * @param topVer Topology version. - * @param mvccSnapshot MVCC snapshot. - * @param cancel Query cancel object. - * @return Cursor over entries which are going to be changed. - * @throws IgniteCheckedException If failed. - */ - 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; - /** * Jdbc parameters metadata of the specified query. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index adac49aadb9..da378a5833b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -87,7 +87,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; -import org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot; import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType; @@ -2905,56 +2904,6 @@ public class GridQueryProcessor extends GridProcessorAdapter { } } - /** - * Execute update on DHT node (i.e. when it is possible to execute and update on all nodes independently). - * - * @param cctx Cache context. - * @param cacheIds Involved cache ids. - * @param parts Partitions. - * @param schema Schema name. - * @param qry Query string. - * @param params Query parameters. - * @param flags Flags. - * @param pageSize Fetch page size. - * @param timeout Timeout. - * @param topVer Topology version. - * @param mvccSnapshot MVCC snapshot. - * @param cancel Query cancel object. - * @return Cursor over entries which are going to be changed. - * @throws IgniteCheckedException If failed. - */ - public UpdateSourceIterator<?> executeUpdateOnDataNodeTransactional( - GridCacheContext<?, ?> cctx, - int[] cacheIds, - int[] parts, - String schema, - String qry, - Object[] params, - int flags, - int pageSize, - int timeout, - AffinityTopologyVersion topVer, - MvccSnapshot mvccSnapshot, - GridQueryCancel cancel - ) throws IgniteCheckedException { - checkxIndexingEnabled(); - - return idx.executeUpdateOnDataNodeTransactional( - cctx, - cacheIds, - parts, - schema, - qry, - params, - flags, - pageSize, - timeout, - topVer, - mvccSnapshot, - cancel - ); - } - /** * Query SQL fields. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/UpdateSourceIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/UpdateSourceIterator.java deleted file mode 100644 index 69feb0fc194..00000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/UpdateSourceIterator.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.query; - -import java.util.Iterator; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteException; -import org.apache.ignite.internal.util.lang.GridCloseableIterator; -import org.jetbrains.annotations.NotNull; - -/** */ -public interface UpdateSourceIterator<T> extends GridCloseableIterator<T> { - /** - * @return Operation. - */ - public EnlistOperation operation(); - - /** - * Callback method which should be called before moving iteration into another thread. - */ - public default void beforeDetach() { - // No-op. - } - - /** {@inheritDoc} */ - @Override default void close() throws IgniteCheckedException { - // No-op. - } - - /** {@inheritDoc} */ - @Override default boolean isClosed() { - return false; - } - - /** {@inheritDoc} */ - @Override default void removeX() throws IgniteCheckedException { - throw new UnsupportedOperationException("remove"); - } - - /** {@inheritDoc} */ - @Override default boolean hasNext() { - try { - return hasNextX(); - } - catch (IgniteCheckedException e) { - throw new IgniteException(e); - } - } - - /** {@inheritDoc} */ - @Override default T next() { - try { - return nextX(); - } - catch (IgniteCheckedException e) { - throw new IgniteException(e); - } - } - - /** {@inheritDoc} */ - @Override default void remove() { - try { - removeX(); - } - catch (IgniteCheckedException e) { - throw new IgniteException(e); - } - } - - /** {@inheritDoc} */ - @Override @NotNull default Iterator<T> iterator() { - return this; - } -} diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index ba8ec659f20..df34244fe99 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -1649,7 +1649,6 @@ org.apache.ignite.internal.processors.query.QueryField org.apache.ignite.internal.processors.query.QueryIndexKey org.apache.ignite.internal.processors.query.QuerySchema org.apache.ignite.internal.processors.query.running.RunningQueryManager$1 -org.apache.ignite.internal.processors.query.UpdateSourceIterator org.apache.ignite.internal.processors.query.aware.IndexBuildStatusHolder$Status org.apache.ignite.internal.processors.query.aware.IndexRebuildCacheInfo org.apache.ignite.internal.processors.query.h2.twostep.messages.GridQueryCancelRequest diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java index 44be692e128..0d5244cff4b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/query/DummyQueryIndexing.java @@ -27,7 +27,6 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheContextInfo; -import org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot; import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.odbc.jdbc.JdbcParameterMeta; import org.apache.ignite.internal.processors.query.running.RunningQueryManager; @@ -123,24 +122,6 @@ public class DummyQueryIndexing implements GridQueryIndexing { } - /** {@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 { - return null; - } - /** {@inheritDoc} */ @Override public List<JdbcParameterMeta> parameterMetaData( String schemaName, diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index ec627587d9f..2356550a4d8 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -62,15 +62,10 @@ import org.apache.ignite.internal.processors.cache.GridCacheContextInfo; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException; import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; -import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal; -import org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker; -import org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot; -import org.apache.ignite.internal.processors.cache.mvcc.StaticMvccQueryTracker; import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable; import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; -import org.apache.ignite.internal.processors.cache.transactions.IgniteTxAdapter; import org.apache.ignite.internal.processors.cache.tree.CacheDataTree; import org.apache.ignite.internal.processors.odbc.jdbc.JdbcParameterMeta; import org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator; @@ -86,7 +81,6 @@ import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.QueryField; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.processors.query.SqlClientContext; -import org.apache.ignite.internal.processors.query.UpdateSourceIterator; import org.apache.ignite.internal.processors.query.h2.affinity.H2PartitionResolver; import org.apache.ignite.internal.processors.query.h2.affinity.PartitionExtractor; import org.apache.ignite.internal.processors.query.h2.dml.DmlDistributedPlanInfo; @@ -116,8 +110,6 @@ import org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings; import org.apache.ignite.internal.processors.tracing.Span; import org.apache.ignite.internal.sql.SqlParseException; import org.apache.ignite.internal.sql.command.SqlCommand; -import org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand; -import org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand; import org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult; import org.apache.ignite.internal.util.GridEmptyCloseableIterator; import org.apache.ignite.internal.util.GridSpinBusyLock; @@ -127,7 +119,6 @@ import org.apache.ignite.internal.util.lang.IgniteInClosure2X; import org.apache.ignite.internal.util.lang.IgniteSingletonIterator; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiClosure; import org.apache.ignite.lang.IgniteBiTuple; @@ -147,11 +138,8 @@ import org.h2.util.JdbcUtils; import org.h2.value.CompareMode; import org.jetbrains.annotations.Nullable; -import static java.lang.Math.max; -import static java.lang.Math.min; import static java.util.Collections.singletonList; import static org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION; -import static org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.tx; import static org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.TEXT; import static org.apache.ignite.internal.processors.query.h2.H2Utils.UPDATE_RESULT_META; import static org.apache.ignite.internal.processors.query.h2.H2Utils.generateFieldsQueryString; @@ -392,9 +380,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @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. */ @@ -404,139 +390,92 @@ public class IgniteH2Indexing implements GridQueryIndexing { QueryParameters qryParams, QueryParserResultSelect select, final IndexingQueryFilter filter, - MvccQueryTracker mvccTracker, GridQueryCancel cancel, - boolean inTx, int timeout ) { - String qry; + String qry = qryDesc.sql(); - 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()); + assert select != null; - MvccSnapshot mvccSnapshot = null; + if (ctx.security().enabled()) + checkSecurity(select.cacheIds()); - if (mvccEnabled) - mvccSnapshot = mvccTracker.snapshot(); + final QueryContext qctx = new QueryContext( + 0, + filter, + null, + null, + null, + true + ); - 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()); - 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()); - 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)); - 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()); - // 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; - Object[] params; + if (m instanceof BinaryMarshaller) { + params = BinaryUtils.rawArrayFromBinary(((BinaryMarshaller)m).binaryMarshaller() + .unmarshal(paramsBytes, ldr)); + } + else + params = U.unmarshal(m, paramsBytes, ldr); - 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); - - if (ctx.performanceStatistics().enabled()) { - ctx.performanceStatistics().queryProperty( - GridCacheQueryType.SQL_FIELDS, - qryInfo.nodeId(), - qryInfo.queryId(), - "Local plan", - qryInfo.plan() - ); - } + H2Utils.bindParameters(stmt, F.asList(params)); - ResultSet rs = executeSqlQueryWithTimer( - stmt, - conn, - qry, - timeout, - cancel, - qryParams.dataPageScanEnabled(), - qryInfo - ); + H2QueryInfo qryInfo = new H2QueryInfo(H2QueryInfo.QueryType.LOCAL, stmt, qry, + ctx.localNodeId(), qryId); - return new H2FieldsIterator( - rs, - mvccTracker, - conn, - qryParams.pageSize(), - log, - IgniteH2Indexing.this, - qryInfo, - ctx.tracing() + if (ctx.performanceStatistics().enabled()) { + ctx.performanceStatistics().queryProperty( + GridCacheQueryType.SQL_FIELDS, + qryInfo.nodeId(), + qryInfo.queryId(), + "Local plan", + qryInfo.plan() ); } - catch (IgniteCheckedException | RuntimeException | Error e) { - conn.close(); - try { - if (mvccTracker != null) - mvccTracker.onDone(); - } - catch (Exception e0) { - e.addSuppressed(e0); - } + ResultSet rs = executeSqlQueryWithTimer( + stmt, + conn, + qry, + timeout, + cancel, + qryParams.dataPageScanEnabled(), + qryInfo + ); - throw e; - } + return new H2FieldsIterator( + rs, + null, + conn, + qryParams.pageSize(), + log, + IgniteH2Indexing.this, + qryInfo, + ctx.tracing() + ); } - }; - } - catch (Exception e) { - GridNearTxLocal tx = null; - - if (mvccEnabled && (tx != null || (tx = tx(ctx)) != null)) - tx.setRollbackOnly(); + catch (IgniteCheckedException | RuntimeException | Error e) { + conn.close(); - throw e; - } - } - - /** - * @param qryTimeout Query timeout in milliseconds. - * @param tx Transaction. - * @return Timeout for operation in milliseconds based on query and tx timeouts. - */ - public static int operationTimeout(int qryTimeout, IgniteTxAdapter tx) { - if (tx != null) { - int remaining = (int)tx.remainingTime(); - - return remaining > 0 && qryTimeout > 0 ? min(remaining, qryTimeout) : max(remaining, qryTimeout); - } - - return qryTimeout; + throw e; + } + } + }; } /** {@inheritDoc} */ @@ -684,8 +623,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { selectParseRes.select(), null, null, - null, - false, 0 ); @@ -953,23 +890,10 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** - * Check whether command could be executed with the given cluster state. - * - * @param parseRes Parsing result. + * Check cluster state. */ - private void checkClusterState(QueryParserResult parseRes) { + private void checkClusterState() { if (!ctx.state().publicApiActiveState(true)) { - if (parseRes.isCommand()) { - QueryParserResultCommand cmd = parseRes.command(); - - assert cmd != null; - - SqlCommand cmd0 = cmd.commandNative(); - - if (cmd0 instanceof SqlCommitTransactionCommand || cmd0 instanceof SqlRollbackTransactionCommand) - return; - } - throw new IgniteException("Can not perform the operation because the cluster is inactive. Note, " + "that the cluster is considered inactive by default if Ignite Persistent Store is used to " + "let all the nodes join the cluster. To activate the cluster call" + @@ -1018,7 +942,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { } // Check if cluster state is valid. - checkClusterState(parseRes); + checkClusterState(); // Execute. if (parseRes.isCommand()) { @@ -1188,28 +1112,14 @@ public class IgniteH2Indexing implements GridQueryIndexing { 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; - - 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()); + qryParams.timeout()); RegisteredQueryCursor<List<?>> cursor = new RegisteredQueryCursor<>(iter, cancel, runningQueryManager(), qryParams.lazy(), qryId, ctx.tracing()); @@ -1241,7 +1151,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @param qryId Query id. * @param schema Schema. * @param selectQry Select query. - * @param mvccTracker MVCC tracker. * @param cancel Cancel. * @param timeout Timeout. * @return Fields query. @@ -1250,7 +1159,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { long qryId, String schema, SqlFieldsQuery selectQry, - MvccQueryTracker mvccTracker, GridQueryCancel cancel, int timeout ) { @@ -1266,9 +1174,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { parseRes.queryParameters(), select, true, - mvccTracker, cancel, - false, timeout ); @@ -1289,9 +1195,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @param qryParams Parameters. * @param select Select. * @param keepBinary Whether binary objects must not be deserialized automatically. - * @param mvccTracker MVCC tracker. * @param cancel Query cancel state holder. - * @param inTx Flag whether query is executed within transaction. * @param timeout Timeout. * @return Query result. */ @@ -1301,9 +1205,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { QueryParameters qryParams, QueryParserResultSelect select, boolean keepBinary, - MvccQueryTracker mvccTracker, GridQueryCancel cancel, - boolean inTx, int timeout ) { // Check security. @@ -1314,8 +1216,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { if (select.splitNeeded()) { // Distributed query. - GridCacheTwoStepQuery twoStepQry = select.forUpdate() && inTx ? - select.forUpdateTwoStepQuery() : select.twoStepQuery(); + GridCacheTwoStepQuery twoStepQry = select.twoStepQuery(); assert twoStepQry != null; @@ -1325,7 +1226,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { qryParams, twoStepQry, keepBinary, - mvccTracker, cancel, timeout ); @@ -1340,9 +1240,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { qryParams, select, filter, - mvccTracker, cancel, - inTx, timeout ); @@ -1359,21 +1257,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { return iter; } - /** - * Locks rows from query cursor and returns the select result. - * - * @param cur Query cursor. - * @param cctx Cache context. - * @param pageSize Page size. - * @param timeout Timeout. - * @return Query results cursor. - */ - private Iterable<List<?>> lockSelectedRows(Iterable<List<?>> cur, GridCacheContext cctx, int pageSize, long timeout) { - assert false; // ex mvcc code, should never happen - - return null; - } - /** * Register running query. * @@ -1477,123 +1360,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { return runningQueryManager().unregisterQueryFinishedListener(lsnr); } - /** {@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 - ) { - 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; - - // Do a two-step query only if locality flag is not set AND if plan's SELECT corresponds to an actual - // 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); - } - /** * Run distributed query on detected set of partitions. * @@ -1602,7 +1368,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @param qryParams Query parameters. * @param twoStepQry Two-step query. * @param keepBinary Keep binary flag. - * @param mvccTracker Query tracker. * @param cancel Cancel handler. * @param timeout Timeout. * @return Cursor representing distributed query result. @@ -1614,7 +1379,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { final QueryParameters qryParams, final GridCacheTwoStepQuery twoStepQry, final boolean keepBinary, - MvccQueryTracker mvccTracker, final GridQueryCancel cancel, int timeout ) { @@ -1660,17 +1424,11 @@ public class IgniteH2Indexing implements GridQueryIndexing { qryParams.arguments(), parts, qryParams.lazy(), - mvccTracker, + null, qryParams.dataPageScanEnabled(), qryParams.pageSize() ); } - catch (Throwable e) { - if (mvccTracker != null) - mvccTracker.onDone(); - - throw e; - } } }; } @@ -2326,7 +2084,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { UpdateResult r; try { - r = executeUpdateNonTransactional( + r = executeUpdate0( qryId, qryDesc, qryParams, @@ -2360,7 +2118,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { } /** - * Execute update in non-transactional mode. + * Execute update. * * @param qryId Query id. * @param qryDesc Query descriptor. @@ -2372,7 +2130,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { * @return Update result. * @throws IgniteCheckedException If failed. */ - private UpdateResult executeUpdateNonTransactional( + private UpdateResult executeUpdate0( long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, @@ -2424,7 +2182,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { .setLocal(qryDesc.local()) .setPageSize(qryParams.pageSize()) .setTimeout(qryParams.timeout(), TimeUnit.MILLISECONDS) - // On no MVCC mode we cannot use lazy mode when UPDATE query contains updated columns + // We cannot use lazy mode when UPDATE query contains updated columns // in WHERE condition because it may be cause of update one entry several times // (when index for such columns is selected for scan): // e.g. : UPDATE test SET val = val + 1 WHERE val >= ? @@ -2441,7 +2199,6 @@ public class IgniteH2Indexing implements GridQueryIndexing { qryId, qryDesc.schemaName(), selectFieldsQry, - null, selectCancel, qryParams.timeout() ); @@ -2459,9 +2216,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { selectParseRes.queryParameters(), selectParseRes.select(), filters, - null, selectCancel, - false, qryParams.timeout() ); diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParser.java index ec27eee5da3..abe10324d88 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParser.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParser.java @@ -43,12 +43,10 @@ import org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan; import org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table; import org.apache.ignite.internal.processors.query.h2.opt.QueryContext; -import org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlias; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlInsert; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuery; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter; -import org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; import org.apache.ignite.internal.processors.tracing.MTC; import org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings; @@ -64,7 +62,6 @@ import org.h2.command.Prepared; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.failure.FailureType.CRITICAL_ERROR; -import static org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter.keyColumn; import static org.apache.ignite.internal.processors.tracing.SpanTags.SQL_PARSER_CACHE_HIT; import static org.apache.ignite.internal.processors.tracing.SpanType.SQL_QRY_PARSE; @@ -456,7 +453,6 @@ public class QueryParser { GridSqlQuery selectStmt = (GridSqlQuery)parser.parse(prepared); List<Integer> cacheIds = parser.cacheIds(); - Integer mvccCacheId = null; // Calculate if query is in fact can be executed locally. boolean loc = qry.isLocal(); @@ -481,62 +477,9 @@ public class QueryParser { // node stripes in parallel and then merged through reduce process. boolean splitNeeded = !loc || locSplit; - String forUpdateQryOutTx = null; - String forUpdateQryTx = null; - GridCacheTwoStepQuery forUpdateTwoStepQry = null; - - boolean forUpdate = GridSqlQueryParser.isForUpdateQuery(prepared); - - // SELECT FOR UPDATE case handling. We need to create extra queries with appended _key - // column to be able to lock selected rows further. - if (forUpdate) { - // We have checked above that it's not an UNION query, so it's got to be SELECT. - assert selectStmt instanceof GridSqlSelect; - - // Check FOR UPDATE invariants: only one table, MVCC is there. - if (cacheIds.size() != 1) - throw new IgniteSQLException("SELECT FOR UPDATE is supported only for queries " + - "that involve single transactional cache."); - - if (mvccCacheId == null) - throw new IgniteSQLException("SELECT FOR UPDATE query requires transactional cache " + - "with MVCC enabled.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION); - - // We need a copy because we are going to modify AST a bit. We do not want to modify original select. - GridSqlSelect selForUpdate = ((GridSqlSelect)selectStmt).copySelectForUpdate(); - - // Clear forUpdate flag to run it as a plain query. - selForUpdate.forUpdate(false); - ((GridSqlSelect)selectStmt).forUpdate(false); - - // Remember sql string without FOR UPDATE clause. - forUpdateQryOutTx = selForUpdate.getSQL(); - - GridSqlAlias keyCol = keyColumn(selForUpdate); - - selForUpdate.addColumn(keyCol, true); - - // Remember sql string without FOR UPDATE clause and with _key column. - forUpdateQryTx = selForUpdate.getSQL(); - - // Prepare additional two-step query for FOR UPDATE case. - if (splitNeeded) { - c.schema(newQry.getSchema()); - - forUpdateTwoStepQry = GridSqlQuerySplitter.split( - c, - selForUpdate, - forUpdateQryTx, - newQry.isCollocated(), - newQry.isDistributedJoins(), - newQry.isEnforceJoinOrder(), - locSplit, - idx, - paramsCnt, - log - ); - } - } + if (GridSqlQueryParser.isForUpdateQuery(prepared)) + throw new IgniteSQLException("SELECT FOR UPDATE queries are not supported.", + IgniteQueryErrorCode.UNSUPPORTED_OPERATION); GridCacheTwoStepQuery twoStepQry = null; @@ -564,12 +507,8 @@ public class QueryParser { QueryParserResultSelect select = new QueryParserResultSelect( selectStmt, twoStepQry, - forUpdateTwoStepQry, meta, - cacheIds, - mvccCacheId, - forUpdateQryOutTx, - forUpdateQryTx + cacheIds ); return new QueryParserResult( diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParserResultSelect.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParserResultSelect.java index 8c6c5ff4d62..d4b4443c43d 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParserResultSelect.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/QueryParserResultSelect.java @@ -33,68 +33,30 @@ public class QueryParserResultSelect { /** Two-step query, or {@code} null if this result is for local query. */ private final GridCacheTwoStepQuery twoStepQry; - /** - * Two-step query in SELECT FOR UPDATE case, or {@code} null if this result is for local query. - * If a query is for update, we need to save two variants of the this query. - * First variant {@link QueryParserResultSelect#twoStepQry} is used when the query is executed outside - * of transaction - it is executed as a plain query. The second variant of the query - is actually - * a "for update" query which is used when running within transaction. In this query an extra _key column - * is implicitly appended to query columns. This extra column is used to lock the selected rows. - * This column is hidden from client. - */ - private final GridCacheTwoStepQuery forUpdateTwoStepQry; - /** Metadata for two-step query, or {@code} null if this result is for local query. */ private final List<GridQueryFieldMetadata> meta; /** Involved cache IDs. */ private final List<Integer> cacheIds; - /** ID of the first MVCC cache. */ - private final Integer mvccCacheId; - - /** - * Sql query with cleared "FOR UPDATE" statement. - * This string is used when query is executed out of transaction. - */ - private final String forUpdateQryOutTx; - - /** - * Sql query for update. Contains additional "_key" column. - * This string is used when executing query within explicit transaction. - */ - private final String forUpdateQryTx; - /** * Constructor. * * @param stmt Statement. * @param twoStepQry Distributed query plan. - * @param forUpdateTwoStepQry FOR UPDATE query for execution within transaction. * @param meta Fields metadata. * @param cacheIds Cache IDs. - * @param mvccCacheId ID of the first MVCC cache. - * @param forUpdateQryOutTx FOR UPDATE query string for execution out of transaction. - * @param forUpdateQryTx FOR UPDATE query string for execution within transaction. */ public QueryParserResultSelect( GridSqlStatement stmt, @Nullable GridCacheTwoStepQuery twoStepQry, - @Nullable GridCacheTwoStepQuery forUpdateTwoStepQry, List<GridQueryFieldMetadata> meta, - List<Integer> cacheIds, - @Nullable Integer mvccCacheId, - String forUpdateQryOutTx, - String forUpdateQryTx + List<Integer> cacheIds ) { this.stmt = stmt; this.twoStepQry = twoStepQry; - this.forUpdateTwoStepQry = forUpdateTwoStepQry; this.meta = meta; this.cacheIds = cacheIds; - this.mvccCacheId = mvccCacheId; - this.forUpdateQryOutTx = forUpdateQryOutTx; - this.forUpdateQryTx = forUpdateQryTx; } /** @@ -111,13 +73,6 @@ public class QueryParserResultSelect { return twoStepQry; } - /** - * @return Two-step query for update, or {@code} null if this result is for local query. - */ - @Nullable public GridCacheTwoStepQuery forUpdateTwoStepQuery() { - return forUpdateTwoStepQry; - } - /** * @return Two-step query metadata. */ @@ -138,32 +93,4 @@ public class QueryParserResultSelect { public List<Integer> cacheIds() { return cacheIds; } - - /** - * @return ID of the first MVCC cache. - */ - public Integer mvccCacheId() { - return mvccCacheId; - } - - /** - * @return Whether this is FOR UPDATE query. - */ - public boolean forUpdate() { - return forUpdateQryTx != null; - } - - /** - * @return Sql FOR UPDATE query for execution out of transaction. - */ - public String forUpdateQueryOutTx() { - return forUpdateQryOutTx; - } - - /** - * @return Sql FOR UPDATE query for execution within transaction. - */ - public String forUpdateQueryTx() { - return forUpdateQryTx; - } } diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateResultsIterator.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateResultsIterator.java deleted file mode 100644 index 5dd9ea203f4..00000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateResultsIterator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.query.h2.dml; - -import java.util.Iterator; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.processors.query.EnlistOperation; -import org.apache.ignite.internal.processors.query.UpdateSourceIterator; - -/** - * DML update results iterator. - */ -public class DmlUpdateResultsIterator implements UpdateSourceIterator<Object> { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final EnlistOperation op; - - /** */ - private final UpdatePlan plan; - - /** */ - private Iterator<List<?>> it; - - /** - * Constructor. - * - * @param op Operation. - * @param plan Plan. - * @param rows Rows. - */ - public DmlUpdateResultsIterator(EnlistOperation op, UpdatePlan plan, Iterable<List<?>> rows) { - this.op = op; - this.plan = plan; - - it = rows.iterator(); - } - - /** {@inheritDoc} */ - @Override public EnlistOperation operation() { - return op; - } - - /** {@inheritDoc} */ - @Override public boolean hasNextX() { - return it.hasNext(); - } - - /** {@inheritDoc} */ - @Override public Object nextX() throws IgniteCheckedException { - return plan.processRowForTx(it.next()); - } -} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateSingleEntryIterator.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateSingleEntryIterator.java deleted file mode 100644 index 0266806a565..00000000000 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUpdateSingleEntryIterator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.query.h2.dml; - -import org.apache.ignite.internal.processors.query.EnlistOperation; -import org.apache.ignite.internal.processors.query.UpdateSourceIterator; - -/** */ -public class DmlUpdateSingleEntryIterator<T> implements UpdateSourceIterator<T> { - /** */ - private static final long serialVersionUID = 0L; - - /** */ - private final EnlistOperation op; - - /** */ - private final T entry; - - /** */ - private boolean first = true; - - /** - * Constructor. - * - * @param op Operation. - * @param entry Entry. - */ - public DmlUpdateSingleEntryIterator(EnlistOperation op, T entry) { - this.op = op; - this.entry = entry; - } - - /** {@inheritDoc} */ - @Override public EnlistOperation operation() { - return op; - } - - /** {@inheritDoc} */ - @Override public boolean hasNextX() { - return first; - } - - /** {@inheritDoc} */ - @Override public T nextX() { - T res = first ? entry : null; - - first = false; - - return res; - } -} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlan.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlan.java index 5151b673839..e68b71682e2 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlan.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/UpdatePlan.java @@ -19,26 +19,20 @@ package org.apache.ignite.internal.processors.query.h2.dml; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.binary.BinaryObjectBuilder; -import org.apache.ignite.cache.query.QueryCursor; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; -import org.apache.ignite.internal.processors.query.EnlistOperation; import org.apache.ignite.internal.processors.query.GridQueryProperty; import org.apache.ignite.internal.processors.query.GridQueryRowDescriptor; import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.QueryUtils; -import org.apache.ignite.internal.processors.query.UpdateSourceIterator; -import org.apache.ignite.internal.processors.query.h2.ConnectionManager; import org.apache.ignite.internal.processors.query.h2.UpdateResult; import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table; -import org.apache.ignite.internal.util.GridCloseableIteratorAdapterEx; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.T3; import org.apache.ignite.lang.IgniteBiTuple; @@ -375,13 +369,6 @@ public final class UpdatePlan { return new T3<>(key, oldVal, newVal); } - /** - * @return {@code True} if DML can be fast processed. - */ - public boolean fastResult() { - return fastUpdate != null; - } - /** * Process fast DML operation if possible. * @@ -496,48 +483,6 @@ public final class UpdatePlan { } } - /** - * Create iterator for transaction. - * - * @param connMgr Connection manager. - * @param cur Cursor. - * @return Iterator. - */ - public UpdateSourceIterator<?> iteratorForTransaction(ConnectionManager connMgr, QueryCursor<List<?>> cur) { - switch (mode) { - case MERGE: - return new InsertIterator(cur, this, EnlistOperation.UPSERT); - case INSERT: - return new InsertIterator(cur, this, EnlistOperation.INSERT); - case UPDATE: - return new UpdateIterator(cur, this, EnlistOperation.UPDATE); - case DELETE: - return new DeleteIterator( cur, this, EnlistOperation.DELETE); - - default: - throw new IllegalArgumentException(String.valueOf(mode)); - } - } - - /** - * @param updMode Update plan mode. - * @return Operation. - */ - public static EnlistOperation enlistOperation(UpdateMode updMode) { - switch (updMode) { - case INSERT: - return EnlistOperation.INSERT; - case MERGE: - return EnlistOperation.UPSERT; - case UPDATE: - return EnlistOperation.UPDATE; - case DELETE: - return EnlistOperation.DELETE; - default: - throw new IllegalArgumentException(String.valueOf(updMode)); - } - } - /** * @return Update mode. */ @@ -580,166 +525,10 @@ public final class UpdatePlan { return isLocSubqry; } - /** - * @param args Query parameters. - * @return Iterator. - * @throws IgniteCheckedException If failed. - */ - public IgniteBiTuple getFastRow(Object[] args) throws IgniteCheckedException { - if (fastUpdate != null) - return fastUpdate.getRow(args); - - return null; - } - - /** - * @param row Row. - * @return Resulting entry. - * @throws IgniteCheckedException If failed. - */ - public Object processRowForTx(List<?> row) throws IgniteCheckedException { - switch (mode()) { - case INSERT: - case MERGE: - return processRow(row); - - case UPDATE: { - T3<Object, Object, Object> row0 = processRowForUpdate(row); - - return new IgniteBiTuple<>(row0.get1(), row0.get3()); - } - case DELETE: - return row.get(0); - - default: - throw new UnsupportedOperationException(String.valueOf(mode())); - } - } - /** * @return {@code true} is the SELECT query may be executed in lazy mode. */ public boolean canSelectBeLazy() { return canSelectBeLazy; } - - /** - * Abstract iterator. - */ - private abstract static class AbstractIterator extends GridCloseableIteratorAdapterEx<Object> - implements UpdateSourceIterator<Object> { - /** */ - private final QueryCursor<List<?>> cur; - - /** */ - protected final UpdatePlan plan; - - /** */ - private final Iterator<List<?>> it; - - /** */ - private final EnlistOperation op; - - /** - * @param cur Query cursor. - * @param plan Update plan. - * @param op Operation. - */ - private AbstractIterator(QueryCursor<List<?>> cur, UpdatePlan plan, - EnlistOperation op) { - this.cur = cur; - this.plan = plan; - this.op = op; - - it = cur.iterator(); - } - - /** {@inheritDoc} */ - @Override public EnlistOperation operation() { - return op; - } - - /** {@inheritDoc} */ - @Override protected void onClose() { - cur.close(); - } - - /** {@inheritDoc} */ - @Override protected Object onNext() throws IgniteCheckedException { - return process(it.next()); - } - - /** {@inheritDoc} */ - @Override protected boolean onHasNext() throws IgniteCheckedException { - return it.hasNext(); - } - - /** */ - protected abstract Object process(List<?> row) throws IgniteCheckedException; - } - - /** */ - private static final class UpdateIterator extends AbstractIterator { - /** */ - private static final long serialVersionUID = -4949035950470324961L; - - /** - * @param cur Query cursor. - * @param plan Update plan. - * @param op Operation. - */ - private UpdateIterator(QueryCursor<List<?>> cur, UpdatePlan plan, - EnlistOperation op) { - super(cur, plan, op); - } - - /** {@inheritDoc} */ - @Override protected Object process(List<?> row) throws IgniteCheckedException { - T3<Object, Object, Object> row0 = plan.processRowForUpdate(row); - - return new IgniteBiTuple<>(row0.get1(), row0.get3()); - } - } - - /** */ - private static final class DeleteIterator extends AbstractIterator { - /** */ - private static final long serialVersionUID = -4949035950470324961L; - - /** - * @param cur Query cursor. - * @param plan Update plan. - * @param op Operation. - */ - private DeleteIterator(QueryCursor<List<?>> cur, UpdatePlan plan, - EnlistOperation op) { - super(cur, plan, op); - } - - /** {@inheritDoc} */ - @Override protected Object process(List<?> row) throws IgniteCheckedException { - return row.get(0); - } - } - - /** */ - private static final class InsertIterator extends AbstractIterator { - /** */ - private static final long serialVersionUID = -4949035950470324961L; - - /** - * @param cur Query cursor. - * @param plan Update plan. - * @param op Operation. - */ - private InsertIterator(QueryCursor<List<?>> cur, UpdatePlan plan, - EnlistOperation op) { - super(cur, plan, op); - } - - /** {@inheritDoc} */ - @Override protected Object process(List<?> row) throws IgniteCheckedException { - return plan.processRow(row); - } - } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/SqlUnsupportedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/SqlUnsupportedSelfTest.java index 66233bbfc6b..456504665ee 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/SqlUnsupportedSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/SqlUnsupportedSelfTest.java @@ -257,6 +257,8 @@ public class SqlUnsupportedSelfTest extends AbstractIndexingCommonTest { assertSqlUnsupported("GRANT SELECT ON test TO PUBLIC"); assertSqlUnsupported("REVOKE SELECT ON test FROM PUBLIC"); + + assertSqlUnsupported("SELECT * FROM TEST FOR UPDATE"); } /**