zstan commented on code in PR #13366: URL: https://github.com/apache/ignite/pull/13366#discussion_r3733947037
########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlSelectForUpdate.java: ########## @@ -0,0 +1,131 @@ +/* + * 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.calcite.sql; + +import java.util.List; +import org.apache.calcite.sql.SqlCall; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; +import org.jetbrains.annotations.Nullable; + +/** + * Parse tree for {@code SELECT ... FOR UPDATE [OF col [, col ...]] [WAIT n | NOWAIT]} statement. + * + * <p>The {@code FOR UPDATE} clause requests pessimistic row-level locks on rows returned by the query. + * When {@code OF} is specified, only tables owning the listed columns are locked. + * + * <p>Fields: + * <ul> + * <li>{@code query} — the underlying SELECT/WITH/VALUES query</li> + * <li>{@code ofList} — optional list of column references identifying which tables to lock; + * {@code null} means all tables referenced in FROM</li> + * <li>{@code waitSeconds} — {@code null} = use transaction timeout, + * {@code 0} = NOWAIT, positive = WAIT n seconds</li> + * </ul> + */ +public class IgniteSqlSelectForUpdate extends SqlCall { + /** */ + private static final SqlOperator OPERATOR = + new SqlSpecialOperator("SELECT FOR UPDATE", SqlKind.OTHER); + + /** The wrapped SELECT / WITH / VALUES query. */ + private final SqlNode query; + + /** + * Columns from the {@code OF} list, or {@code null} when not specified (lock all tables). + * Each element is a {@link org.apache.calcite.sql.SqlIdentifier} referencing a table column. + */ + @Nullable private final SqlNodeList ofList; Review Comment: ```suggestion @Nullable private final SqlNodeList lockColumns; ``` ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java: ########## @@ -3175,17 +3175,39 @@ public CacheMetricsImpl metrics0() { try { for (int i = 0; i < txEntries.size(); i++) { - GridCacheEntryEx cached = txEntries.get(i).cached(); - EntryGetResult getRes = cached.innerGetVersioned( - null, - tx, - /*update-metrics*/false, - /*event*/false, - null, - tx.resolveTaskName(), - null, - false, - null); + IgniteTxEntry txEntry = txEntries.get(i); + EntryGetResult getRes; + + while (true) { + try { + GridCacheEntryEx cached = txEntry.cached(); + + getRes = cached.innerGetVersioned( + null, + tx, + /*update-metrics*/false, + /*event*/false, + null, + tx.resolveTaskName(), + null, + false, + null); + + break; + } + catch (GridCacheEntryRemovedException ignored) { + if (log.isDebugEnabled()) + log.debug("Got removed exception in lockTxEntries postLock (will retry): " + + txEntry.cached()); + + KeyCacheObject key = txEntry.key(); + GridCacheEntryEx cached = ctx.isColocated() + ? ctx.colocated().entryExx(key, tx.topologyVersion(), true) + : entryEx(key, tx.topologyVersion()); + + txEntry.cached(cached); Review Comment: As i can see - you found that entry is obsolete here and renew cached ver is it correct ? Also i wonder - do we really need `while (true)` here ? I see that single repeated call will be enough for tests passed, did i miss smth ? smth like : ``` catch (GridCacheEntryRemovedException ignored) { if (log.isDebugEnabled()) log.info("removed exception in lockTxEntries postLock (will retry): " + txEntry.cached()); KeyCacheObject key = txEntry.key(); GridCacheEntryEx cached = ctx.isColocated() ? ctx.colocated().entryExx(key, tx.topologyVersion(), true) : entryEx(key, tx.topologyVersion()); try { getRes = cached.innerGetVersioned( <--- single repeated call, but i still don\`t know - is it correct for obsolete ... need dig more here ``` ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/sql/SqlSelectForUpdateParserTest.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.calcite.sql; + +import org.apache.calcite.sql.SqlExplain; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlSelect; +import org.apache.calcite.sql.parser.SqlParseException; +import org.apache.calcite.sql.parser.SqlParser; +import org.apache.ignite.internal.processors.query.calcite.sql.generated.IgniteSqlParserImpl; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; Review Comment: Deprecated !!! use import static org.hamcrest.MatcherAssert.assertThat; instead ########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlSelectForUpdate.java: ########## @@ -0,0 +1,131 @@ +/* + * 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.calcite.sql; + +import java.util.List; +import org.apache.calcite.sql.SqlCall; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; +import org.jetbrains.annotations.Nullable; + +/** + * Parse tree for {@code SELECT ... FOR UPDATE [OF col [, col ...]] [WAIT n | NOWAIT]} statement. + * + * <p>The {@code FOR UPDATE} clause requests pessimistic row-level locks on rows returned by the query. + * When {@code OF} is specified, only tables owning the listed columns are locked. + * + * <p>Fields: + * <ul> + * <li>{@code query} — the underlying SELECT/WITH/VALUES query</li> + * <li>{@code ofList} — optional list of column references identifying which tables to lock; + * {@code null} means all tables referenced in FROM</li> + * <li>{@code waitSeconds} — {@code null} = use transaction timeout, + * {@code 0} = NOWAIT, positive = WAIT n seconds</li> + * </ul> + */ +public class IgniteSqlSelectForUpdate extends SqlCall { + /** */ + private static final SqlOperator OPERATOR = + new SqlSpecialOperator("SELECT FOR UPDATE", SqlKind.OTHER); + + /** The wrapped SELECT / WITH / VALUES query. */ + private final SqlNode query; + + /** + * Columns from the {@code OF} list, or {@code null} when not specified (lock all tables). + * Each element is a {@link org.apache.calcite.sql.SqlIdentifier} referencing a table column. + */ + @Nullable private final SqlNodeList ofList; + + /** + * Lock-wait limit: {@code null} = use transaction timeout, {@code 0} = NOWAIT, + * positive = WAIT n seconds. + */ + @Nullable private final Long waitSeconds; + + /** */ + public IgniteSqlSelectForUpdate( + SqlParserPos pos, + SqlNode query, + @Nullable SqlNodeList ofList, Review Comment: ```suggestion @Nullable SqlNodeList lockColumns, ``` ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SystemColumnsScanTest.java: ########## @@ -0,0 +1,345 @@ +/* + * 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.calcite.integration; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.query.IgniteSQLException; +import org.apache.ignite.internal.processors.query.QueryUtils; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.exec.ArrayRowHandler; +import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.internal.processors.query.calcite.exec.tracker.NoOpIoTracker; +import org.apache.ignite.internal.processors.query.calcite.exec.tracker.NoOpMemoryTracker; +import org.apache.ignite.internal.processors.query.calcite.metadata.ColocationGroup; +import org.apache.ignite.internal.processors.query.calcite.metadata.FragmentDescription; +import org.apache.ignite.internal.processors.query.calcite.metadata.FragmentMapping; +import org.apache.ignite.internal.processors.query.calcite.prepare.BaseQueryContext; +import org.apache.ignite.internal.processors.query.calcite.prepare.MappingQueryContext; +import org.apache.ignite.internal.processors.query.calcite.schema.ColumnDescriptor; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteCacheTable; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteIndex; +import org.apache.ignite.internal.processors.query.calcite.util.Commons; +import org.apache.ignite.transactions.Transaction; +import org.junit.Test; + +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** Tests system columns returned by direct table and index scans. */ +public class SystemColumnsScanTest extends AbstractBasicIntegrationTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setTransactionConfiguration(new TransactionConfiguration() + .setTxAwareQueriesEnabled(true)); Review Comment: why do we need this flag here ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
