You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "korlov42 (via GitHub)" <gi...@apache.org> on 2025/01/23 15:22:48 UTC

[PR] IGNITE-23792 Sql. Cleanup the query cancellation handling [ignite-3]

korlov42 opened a new pull request, #5111:
URL: https://github.com/apache/ignite-3/pull/5111

   https://issues.apache.org/jira/browse/IGNITE-23792
   
   -------
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23792 Sql. Cleanup the query cancellation handling [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 merged PR #5111:
URL: https://github.com/apache/ignite-3/pull/5111


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23792 Sql. Cleanup the query cancellation handling [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #5111:
URL: https://github.com/apache/ignite-3/pull/5111#discussion_r1928409208


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java:
##########
@@ -357,6 +358,26 @@ public interface ClusterBuilder {
          */
         ClusterBuilder nodes(String firstNodeName, String... otherNodeNames);
 
+        /**
+         * A decorator to wrap {@link CatalogManager} instance which will be used int test cluster.

Review Comment:
   ```suggestion
            * A decorator to wrap {@link CatalogManager} instance which will be used in the test cluster.
   ```



##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlMultiStatementTxTest.java:
##########
@@ -304,6 +305,9 @@ void dmlFailsOnReadOnlyTransaction() {
         assertThrowsSqlException(RUNTIME_ERR, "DML cannot be started by using read only transactions.",
                 () -> await(insCur.nextResult()));
 
+        assertThrowsSqlException(EXECUTION_CANCELLED_ERR, "The query was cancelled while executing.",
+                () -> await(insCur.requestNextAsync(1)));

Review Comment:
   ```suggestion
           expectQueryCancelled(() -> await(insCur.requestNextAsync(1)));
   ```



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/QueryTimeoutTest.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.sql.engine.exec;
+
+import static java.util.UUID.randomUUID;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowWithCauseOrSuppressed;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.lang.reflect.Proxy;
+import java.util.BitSet;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Flow.Publisher;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.QueryCancelledException;
+import org.apache.ignite.internal.sql.engine.QueryProperty;
+import org.apache.ignite.internal.sql.engine.api.kill.CancellableOperationType;
+import org.apache.ignite.internal.sql.engine.api.kill.OperationKillHandler;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler.RowFactory;
+import org.apache.ignite.internal.sql.engine.exec.exp.RangeCondition;
+import org.apache.ignite.internal.sql.engine.exec.mapping.ColocationGroup;
+import org.apache.ignite.internal.sql.engine.framework.TestBuilders;
+import org.apache.ignite.internal.sql.engine.framework.TestCluster;
+import org.apache.ignite.internal.sql.engine.framework.TestNode;
+import org.apache.ignite.internal.sql.engine.property.SqlProperties;
+import org.apache.ignite.internal.sql.engine.property.SqlPropertiesHelper;
+import org.apache.ignite.internal.sql.engine.schema.TableDescriptor;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.util.SubscriptionUtils;
+import org.apache.ignite.sql.SqlException;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Tests cases for cancellation due to timeout. */
+@SuppressWarnings("ThrowableNotThrown")
+public class QueryTimeoutTest extends BaseIgniteAbstractTest {
+    private static final String NODE_NAME = "gateway";
+
+    private final AtomicBoolean ignoreCatalogUpdates = new AtomicBoolean(false);
+
+    private static final SqlProperties PROPS_WITH_TIMEOUT = SqlPropertiesHelper.newBuilder()
+            // Relatively high timeout is set to make tests are stable on TC. The reason is that
+            // query have to make it to the final point which is varied from test to test in
+            // order to 1) make sure timeout is handled properly at particular stages of query
+            // execution, and 2) to fail with proper exception class.
+            .set(QueryProperty.QUERY_TIMEOUT, 2_000L)
+            .build();
+
+    private TestCluster cluster;
+    private TestNode gatewayNode;
+
+    @BeforeEach
+    void startCluster() {
+        ignoreCatalogUpdates.set(false);
+
+        cluster = TestBuilders.cluster()
+                .nodes(NODE_NAME)
+                .catalogManagerDecorator(this::catalogManagerDecorator)
+                .operationKillHandlers(
+                        new OperationKillHandler() {
+                            @Override
+                            public CompletableFuture<Boolean> cancelAsync(String operationId) {
+                                return new CompletableFuture<>();
+                            }
+
+                            @Override
+                            public boolean local() {
+                                return true;
+                            }
+
+                            @Override
+                            public CancellableOperationType type() {
+                                return CancellableOperationType.QUERY;
+                            }
+                        }
+                )
+                .build();
+
+        cluster.start();
+
+
+        gatewayNode = cluster.node(NODE_NAME);
+
+        gatewayNode.initSchema("CREATE TABLE my_table (id INT PRIMARY KEY, val VARCHAR(128))");
+        cluster.setDataProvider("MY_TABLE", neverReplyingScannableTable());
+        cluster.setUpdatableTable("MY_TABLE", neverReplyingUpdatableTable());
+        cluster.setAssignmentsProvider(
+                "MY_TABLE",
+                (partitionsCount, includeBackups) -> IntStream.range(0, partitionsCount)
+                        .mapToObj(p -> List.of(NODE_NAME))
+                        .collect(Collectors.toList())
+        );
+    }
+
+    @AfterEach
+    void stopCluster() throws Exception {
+        cluster.stop();
+    }
+
+    @Test
+    void testTimeoutDdl() {
+        ignoreCatalogUpdates.set(true);
+
+        assertThrows(
+                QueryCancelledException.class,
+                () -> gatewayNode.executeQuery(PROPS_WITH_TIMEOUT, "CREATE TABLE x (id INTEGER PRIMARY KEY, val INTEGER)"),
+                "Query timeout"

Review Comment:
   ```suggestion
                  QueryCancelledException.TIMEOUT_MSG
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23792 Sql. Cleanup the query cancellation handling [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #5111:
URL: https://github.com/apache/ignite-3/pull/5111#discussion_r1928568730


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/QueryTimeoutTest.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.sql.engine.exec;
+
+import static java.util.UUID.randomUUID;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowWithCauseOrSuppressed;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.lang.reflect.Proxy;
+import java.util.BitSet;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Flow.Publisher;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.QueryCancelledException;
+import org.apache.ignite.internal.sql.engine.QueryProperty;
+import org.apache.ignite.internal.sql.engine.api.kill.CancellableOperationType;
+import org.apache.ignite.internal.sql.engine.api.kill.OperationKillHandler;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler.RowFactory;
+import org.apache.ignite.internal.sql.engine.exec.exp.RangeCondition;
+import org.apache.ignite.internal.sql.engine.exec.mapping.ColocationGroup;
+import org.apache.ignite.internal.sql.engine.framework.TestBuilders;
+import org.apache.ignite.internal.sql.engine.framework.TestCluster;
+import org.apache.ignite.internal.sql.engine.framework.TestNode;
+import org.apache.ignite.internal.sql.engine.property.SqlProperties;
+import org.apache.ignite.internal.sql.engine.property.SqlPropertiesHelper;
+import org.apache.ignite.internal.sql.engine.schema.TableDescriptor;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.util.SubscriptionUtils;
+import org.apache.ignite.sql.SqlException;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Tests cases for cancellation due to timeout. */
+@SuppressWarnings("ThrowableNotThrown")
+public class QueryTimeoutTest extends BaseIgniteAbstractTest {
+    private static final String NODE_NAME = "gateway";
+
+    private final AtomicBoolean ignoreCatalogUpdates = new AtomicBoolean(false);
+
+    private static final SqlProperties PROPS_WITH_TIMEOUT = SqlPropertiesHelper.newBuilder()
+            // Relatively high timeout is set to make tests are stable on TC. The reason is that
+            // query have to make it to the final point which is varied from test to test in
+            // order to 1) make sure timeout is handled properly at particular stages of query
+            // execution, and 2) to fail with proper exception class.
+            .set(QueryProperty.QUERY_TIMEOUT, 2_000L)
+            .build();
+
+    private TestCluster cluster;
+    private TestNode gatewayNode;
+
+    @BeforeEach
+    void startCluster() {
+        ignoreCatalogUpdates.set(false);
+
+        cluster = TestBuilders.cluster()
+                .nodes(NODE_NAME)
+                .catalogManagerDecorator(this::catalogManagerDecorator)
+                .operationKillHandlers(
+                        new OperationKillHandler() {
+                            @Override
+                            public CompletableFuture<Boolean> cancelAsync(String operationId) {
+                                return new CompletableFuture<>();
+                            }
+
+                            @Override
+                            public boolean local() {
+                                return true;
+                            }
+
+                            @Override
+                            public CancellableOperationType type() {
+                                return CancellableOperationType.QUERY;
+                            }
+                        }
+                )
+                .build();
+
+        cluster.start();
+
+
+        gatewayNode = cluster.node(NODE_NAME);
+
+        gatewayNode.initSchema("CREATE TABLE my_table (id INT PRIMARY KEY, val VARCHAR(128))");
+        cluster.setDataProvider("MY_TABLE", neverReplyingScannableTable());
+        cluster.setUpdatableTable("MY_TABLE", neverReplyingUpdatableTable());
+        cluster.setAssignmentsProvider(
+                "MY_TABLE",
+                (partitionsCount, includeBackups) -> IntStream.range(0, partitionsCount)
+                        .mapToObj(p -> List.of(NODE_NAME))
+                        .collect(Collectors.toList())
+        );
+    }
+
+    @AfterEach
+    void stopCluster() throws Exception {
+        cluster.stop();
+    }
+
+    @Test
+    void testTimeoutDdl() {
+        ignoreCatalogUpdates.set(true);
+
+        assertThrows(
+                QueryCancelledException.class,
+                () -> gatewayNode.executeQuery(PROPS_WITH_TIMEOUT, "CREATE TABLE x (id INTEGER PRIMARY KEY, val INTEGER)"),
+                "Query timeout"

Review Comment:
   all such literals has been replaced



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-23792 Sql. Cleanup the query cancellation handling [ignite-3]

Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #5111:
URL: https://github.com/apache/ignite-3/pull/5111#discussion_r1928568140


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/framework/TestBuilders.java:
##########
@@ -357,6 +358,26 @@ public interface ClusterBuilder {
          */
         ClusterBuilder nodes(String firstNodeName, String... otherNodeNames);
 
+        /**
+         * A decorator to wrap {@link CatalogManager} instance which will be used int test cluster.

Review Comment:
   fixed, thanks



##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlMultiStatementTxTest.java:
##########
@@ -304,6 +305,9 @@ void dmlFailsOnReadOnlyTransaction() {
         assertThrowsSqlException(RUNTIME_ERR, "DML cannot be started by using read only transactions.",
                 () -> await(insCur.nextResult()));
 
+        assertThrowsSqlException(EXECUTION_CANCELLED_ERR, "The query was cancelled while executing.",
+                () -> await(insCur.requestNextAsync(1)));

Review Comment:
   fixed



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org