This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new a0419644857 branch-3.1: [fix](session variables) Limit query_timeout 
to within LoadTimeout #51222 (#52842)
a0419644857 is described below

commit a0419644857c307634c4dd901f5f5978de457532
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Jul 8 17:41:36 2025 +0800

    branch-3.1: [fix](session variables) Limit query_timeout to within 
LoadTimeout #51222 (#52842)
    
    Cherry-picked from #51222
    
    Co-authored-by: Uniqueyou <[email protected]>
---
 .../transaction/CloudGlobalTransactionMgr.java     |  5 +-
 .../doris/transaction/GlobalTransactionMgr.java    |  6 +--
 .../transaction/GlobalTransactionMgrIface.java     | 22 ++++++--
 .../suites/insert_p0/test_insert_timeout.groovy    | 59 ++++++++++++++++++++++
 4 files changed, 82 insertions(+), 10 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java
 
b/fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java
index 68148214f75..7ee0e548d26 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java
@@ -258,10 +258,11 @@ public class CloudGlobalTransactionMgr implements 
GlobalTransactionMgrIface {
         switch (sourceType) {
             case BACKEND_STREAMING:
                 checkValidTimeoutSecond(timeoutSecond, 
Config.max_stream_load_timeout_second,
-                        Config.min_load_timeout_second);
+                        Config.min_load_timeout_second, sourceType);
                 break;
             default:
-                checkValidTimeoutSecond(timeoutSecond, 
Config.max_load_timeout_second, Config.min_load_timeout_second);
+                checkValidTimeoutSecond(timeoutSecond, 
Config.max_load_timeout_second,
+                        Config.min_load_timeout_second, sourceType);
         }
 
         BeginTxnResponse beginTxnResponse = null;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
index 64a91459fbe..995f43a3330 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java
@@ -164,16 +164,16 @@ public class GlobalTransactionMgr implements 
GlobalTransactionMgrIface {
             switch (sourceType) {
                 case BACKEND_STREAMING:
                     checkValidTimeoutSecond(timeoutSecond, 
Config.max_stream_load_timeout_second,
-                            Config.min_load_timeout_second);
+                            Config.min_load_timeout_second, sourceType);
                     break;
                 default:
                     checkValidTimeoutSecond(timeoutSecond, 
Config.max_load_timeout_second,
-                            Config.min_load_timeout_second);
+                            Config.min_load_timeout_second, sourceType);
             }
 
             DatabaseTransactionMgr dbTransactionMgr = 
getDatabaseTransactionMgr(dbId);
             return dbTransactionMgr.beginTransaction(tableIdList, label, 
requestId,
-                coordinator, sourceType, listenerId, timeoutSecond);
+                    coordinator, sourceType, listenerId, timeoutSecond);
         } catch (DuplicatedRequestException e) {
             throw e;
         } catch (Exception e) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgrIface.java
 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgrIface.java
index c23787eca4d..8f3e4d682f6 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgrIface.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/transaction/GlobalTransactionMgrIface.java
@@ -46,11 +46,23 @@ import java.util.concurrent.TimeoutException;
 
 public interface GlobalTransactionMgrIface extends Writable {
     default void checkValidTimeoutSecond(long timeoutSecond, int 
maxLoadTimeoutSecond,
-            int minLoadTimeOutSecond) throws AnalysisException {
-        if (timeoutSecond > maxLoadTimeoutSecond || timeoutSecond < 
minLoadTimeOutSecond) {
-            throw new AnalysisException("Invalid timeout: " + timeoutSecond + 
". Timeout should between "
-                    + minLoadTimeOutSecond + " and " + maxLoadTimeoutSecond
-                    + " seconds");
+                                         int minLoadTimeOutSecond, 
LoadJobSourceType sourceType)
+            throws AnalysisException {
+        if (timeoutSecond < minLoadTimeOutSecond) {
+            throw new AnalysisException("Invalid timeout: " + timeoutSecond
+                    + ". Timeout should be higher than 
Config.min_load_timeout_second: "
+                    + minLoadTimeOutSecond);
+        } else if (timeoutSecond > maxLoadTimeoutSecond) {
+            switch (sourceType) {
+                case BACKEND_STREAMING:
+                    throw new AnalysisException("Invalid timeout: " + 
timeoutSecond
+                            + ". Timeout should be lower than 
Config.max_stream_load_timeout_second: "
+                            + maxLoadTimeoutSecond);
+                default:
+                    throw new AnalysisException("Invalid timeout: " + 
timeoutSecond
+                            + ". Timeout should be lower than 
Config.max_load_timeout_second: "
+                            + maxLoadTimeoutSecond);
+            }
         }
     }
 
diff --git a/regression-test/suites/insert_p0/test_insert_timeout.groovy 
b/regression-test/suites/insert_p0/test_insert_timeout.groovy
new file mode 100644
index 00000000000..a5f906c82eb
--- /dev/null
+++ b/regression-test/suites/insert_p0/test_insert_timeout.groovy
@@ -0,0 +1,59 @@
+// 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.
+
+// The cases is copied from https://github.com/trinodb/trino/tree/master
+// /testing/trino-product-tests/src/main/resources/sql-tests/testcases
+// and modified by Doris.
+
+suite("test_insert_timeout") {
+    def tableName = "test_insert_timeout_tbl"
+    sql """ DROP TABLE IF EXISTS ${tableName} """
+    sql """
+        CREATE TABLE ${tableName} (
+            `id` int(11) NOT NULL,
+            `name` varchar(50) NULL,
+            `score` int(11) NULL default "-1"
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`id`, `name`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+    """
+
+    try {
+        def timeout = sql "SHOW FRONTEND CONFIG like 
'%max_load_timeout_second%';"
+
+        timeout = Integer.parseInt(timeout[0][1])
+
+        logger.info("${timeout}")
+
+        def invalid_timeout = timeout + 200
+
+        sql " set query_timeout = ${invalid_timeout} "
+
+        test {
+            sql " INSERT INTO ${tableName} VALUES (1, 'Alice', 90), (2, 'Bob', 
85), (3, 'Charlie', 95) "
+            exception "begin transaction failed. errCode = 2, detailMessage = 
Invalid timeout: ${invalid_timeout}. Timeout should be lower than 
Config.max_load_timeout_second: ${timeout}"
+        }
+
+    } finally {
+        sql """
+        UNSET VARIABLE query_timeout;
+        """
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to