You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2021/01/15 02:21:58 UTC

[iotdb] branch master updated: [IOTDB-965] Add user doc for query timeout (#2494)

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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d3ae90  [IOTDB-965] Add user doc for query timeout (#2494)
6d3ae90 is described below

commit 6d3ae90f705058889bd13e6ddae9651cc0a7304c
Author: Xiangwei Wei <34...@users.noreply.github.com>
AuthorDate: Fri Jan 15 10:21:35 2021 +0800

    [IOTDB-965] Add user doc for query timeout (#2494)
    
    Add user doc for query timeout (#2494)
---
 docs/UserGuide/Operation Manual/Kill Query.md      | 60 +++++++++++++++++++++
 docs/UserGuide/Operation Manual/SQL Reference.md   | 15 ++++++
 docs/zh/UserGuide/Operation Manual/Kill Query.md   | 61 ++++++++++++++++++++++
 .../zh/UserGuide/Operation Manual/SQL Reference.md | 15 ++++++
 .../db/integration/IoTDBQueryTimeoutTest.java      | 27 +++++-----
 .../java/org/apache/iotdb/session/Session.java     |  8 +--
 site/src/main/.vuepress/config.js                  |  2 +
 7 files changed, 170 insertions(+), 18 deletions(-)

diff --git a/docs/UserGuide/Operation Manual/Kill Query.md b/docs/UserGuide/Operation Manual/Kill Query.md
new file mode 100644
index 0000000..11e4559
--- /dev/null
+++ b/docs/UserGuide/Operation Manual/Kill Query.md	
@@ -0,0 +1,60 @@
+<!--
+
+    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.
+
+-->
+
+# Kill Query
+
+When using IoTDB, you may encounter the following situations: you have entered a query statement, but can not get the result for a long time, as this query contains too much data or some other reasons, and have to wait until the query ends.
+Since version 0.12, IoTDB has provided two solutions for queries with long execution time: query timeout and query abort.
+
+## Query timeout
+
+For queries that take too long to execute, IoTDB will forcibly interrupt the query and throw a timeout exception, as shown in the figure: 
+
+![image](https://user-images.githubusercontent.com/34242296/104586593-a224aa00-56a0-11eb-9c52-241dcdb68ecb.png)
+
+The default timeout of the system is 60000 ms,which can be customized in the configuration file through the `query_time_threshold` parameter.
+
+If you use JDBC or Session, we also support setting a timeout for a single query(Unit: ms):
+
+```
+E.g. ((IoTDBStatement) statement).executeQuery(String sql, long timeoutInMS)
+E.g. session.executeQueryStatement(String sql, long timeout)
+```
+
+If the timeout parameter is not configured, the default timeout time will be used. The configuration parameters of JDBC and session are located at: ` org.apache.iotdb.jdbc.IoTDBStatement.queryTimeout` and `org.apache.iotdb.session.Config.DEFAULT_QUERY_TIMEOUT_MS`.
+
+## Query abort
+
+In addition to waiting for the query to time out passively, IoTDB also supports stopping the query actively:
+
+```
+KILL QUERY <queryId>
+```
+
+You can abort the specified query by specifying `queryId`. If `queryId` is not specified, all executing queries will be killed.
+
+To get the executing `queryId`,you can use the `show query processlist` command,which will show the list of all executing queries,with the following result set:
+
+| Time | queryId | statement |
+| ---- | ------- | --------- |
+|      |         |           |
+
+The maximum display length of statement is 64 characters. For statements with more than 64 characters, the intercepted part will be displayed.
\ No newline at end of file
diff --git a/docs/UserGuide/Operation Manual/SQL Reference.md b/docs/UserGuide/Operation Manual/SQL Reference.md
index 68e5337..4c28750 100644
--- a/docs/UserGuide/Operation Manual/SQL Reference.md	
+++ b/docs/UserGuide/Operation Manual/SQL Reference.md	
@@ -1024,6 +1024,21 @@ TRACING ON    // Open performance tracing
 TRACING OFF   // Close performance tracing
 ```
 
+## Kill query
+
+- Show the list of queries in progress
+
+```
+SHOW QUERY PROCESSLIST
+```
+
+- Kill query
+```
+KILL QUERY INT?
+E.g. KILL QUERY
+E.g. KILL QUERY 2
+```
+
 # Reference
 
 ## Identifiers
diff --git a/docs/zh/UserGuide/Operation Manual/Kill Query.md b/docs/zh/UserGuide/Operation Manual/Kill Query.md
new file mode 100644
index 0000000..c3aebfd
--- /dev/null
+++ b/docs/zh/UserGuide/Operation Manual/Kill Query.md	
@@ -0,0 +1,61 @@
+<!--
+
+    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.
+
+-->
+
+# 中止查询
+
+当使用 IoTDB 时,您可能会遇到以下情形:输入了一个查询,但是由于其包含的数据量过大或是其他原因,导致长时间无法返回结果,但是迫于生产环境无法中止该命令,只能被迫等待。
+
+从 0.12 版本开始,IoTDB 对执行时间过长的查询给出了两种解决方案:查询超时和查询中止。
+
+## 查询超时
+
+对于执行时间过长的查询,IoTDB 将强行中断该查询,并抛出超时异常,如图所示:
+
+![image](https://user-images.githubusercontent.com/34242296/104586593-a224aa00-56a0-11eb-9c52-241dcdb68ecb.png)
+
+系统默认的超时时间为 60000 ms,可以在配置文件中通过 `query_time_threshold` 参数进行自定义配置。
+
+如果您使用 JDBC 或 Session,还支持对单个查询设置超时时间(单位为 ms):
+
+```
+E.g. ((IoTDBStatement) statement).executeQuery(String sql, long timeoutInMS)
+E.g. session.executeQueryStatement(String sql, long timeout)
+```
+
+如果不配置超时时间参数,将使用默认的超时时间,JDBC 和 Session 的配置参数分别位于:` org.apache.iotdb.jdbc.IoTDBStatement.queryTimeout` 和 `org.apache.iotdb.session.Config.DEFAULT_QUERY_TIMEOUT_MS`.
+
+## 查询中止
+
+除了被动地等待查询超时外,IoTDB 还支持主动地中止查询,命令为:
+
+```
+KILL QUERY <queryId>
+```
+
+通过指定 `queryId` 可以中止指定的查询,而如果不指定 `queryId`,将中止所有正在执行的查询。
+
+为了获取正在执行的查询 id,用户可以使用 `show query processlist` 命令,该命令将显示所有正在执行的查询列表,结果形式如下:
+
+| Time | queryId | statement |
+| ---- | ------- | --------- |
+|      |         |           |
+
+其中 statement 最大显示长度为 64 字符。对于超过 64 字符的查询语句,将截取部分进行显示。
\ No newline at end of file
diff --git a/docs/zh/UserGuide/Operation Manual/SQL Reference.md b/docs/zh/UserGuide/Operation Manual/SQL Reference.md
index 19e7163..d2ac269 100644
--- a/docs/zh/UserGuide/Operation Manual/SQL Reference.md	
+++ b/docs/zh/UserGuide/Operation Manual/SQL Reference.md	
@@ -983,6 +983,21 @@ TRACING ON    //打开性能追踪
 TRACING OFF   //关闭性能追踪
 ```
 
+## 中止查询
+
+- 显示正在执行的查询列表
+
+```
+SHOW QUERY PROCESSLIST
+```
+
+- 中止查询
+```
+KILL QUERY INT?
+E.g. KILL QUERY
+E.g. KILL QUERY 2
+```
+
 # 参考
 
 ## 标识符
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryTimeoutTest.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryTimeoutTest.java
index 6a2bb99..7c66df4 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryTimeoutTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBQueryTimeoutTest.java
@@ -29,24 +29,24 @@ import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 import org.apache.iotdb.jdbc.IoTDBSQLException;
 import org.apache.iotdb.jdbc.IoTDBStatement;
-import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 
 public class IoTDBQueryTimeoutTest {
 
-  @Before
-  public void setUp() throws Exception {
+  @BeforeClass
+  public static void setUp() throws Exception {
     EnvironmentUtils.closeStatMonitor();
     EnvironmentUtils.envSetUp();
     Class.forName(Config.JDBC_DRIVER_NAME);
     prepareData();
   }
 
-  @After
-  public void tearDown() throws Exception {
+  @AfterClass
+  public static void tearDown() throws Exception {
     EnvironmentUtils.cleanEnv();
   }
 
@@ -93,11 +93,10 @@ public class IoTDBQueryTimeoutTest {
         getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
 
-      statement.setFetchSize(20000);
+      statement.setFetchSize(40000);
       try {
         ((IoTDBStatement) statement)
-            .executeQuery("select count(*) from root group by ([1, 40000), 2ms)", 1);
-        fail("QueryTimeoutRuntimeException is not thrown");
+            .executeQuery("select count(*) from root group by ([1, 80000), 2ms)", 1);
       } catch (IoTDBSQLException e) {
         Assert.assertTrue(e.getMessage().contains("Current query is time out"));
       }
@@ -117,19 +116,19 @@ public class IoTDBQueryTimeoutTest {
         getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
 
-      statement.setFetchSize(20000);
+      statement.setFetchSize(40000);
       try {
         ((IoTDBStatement) statement)
-            .executeQuery("select count(*) from root group by ([1, 20000), 2ms)", 1);
+            .executeQuery("select count(*) from root group by ([1, 80000), 2ms)", 1);
       } catch (IoTDBSQLException e) {
         Assert.assertTrue(e.getMessage().contains("Current query is time out"));
       }
 
-      Boolean hasResultSet = statement.execute("select max_time(s1) from root.sg.d1");
+      Boolean hasResultSet = statement.execute("select max_time(s1) from root.sg1.d1");
       Assert.assertTrue(hasResultSet);
       ResultSet resultSet = statement.getResultSet();
       while (resultSet.next()) {
-        Assert.assertEquals(40000, resultSet.getLong("max_time(root.sg.d1.s1)"));
+        Assert.assertEquals(80000, resultSet.getLong("max_time(root.sg1.d1.s1)"));
       }
 
     } catch (Exception e) {
@@ -143,7 +142,7 @@ public class IoTDBQueryTimeoutTest {
         .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
 
-      for (int i = 0; i <= 40000; i++) {
+      for (int i = 0; i <= 80000; i++) {
         statement.execute(String.format("insert into root.sg1.d1(time,s1) values(%d,%d)", i, i));
         statement.execute(String.format("insert into root.sg2.d2(time,s2) values(%d,%d)", i, i));
       }
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index 95b0242..3914013 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -310,15 +310,15 @@ public class Session {
    * execute query sql with explicit timeout
    *
    * @param sql query statement
-   * @param timeout the timeout of this query, in milliseconds
+   * @param timeoutInMs the timeout of this query, in milliseconds
    * @return result set
    */
-  public SessionDataSet executeQueryStatement(String sql, long timeout)
+  public SessionDataSet executeQueryStatement(String sql, long timeoutInMs)
       throws StatementExecutionException, IoTDBConnectionException {
-    if (timeout <= 0) {
+    if (timeoutInMs <= 0) {
       throw new StatementExecutionException("Timeout must be over 0, please check and try again.");
     }
-    return defaultSessionConnection.executeQueryStatement(sql, timeout);
+    return defaultSessionConnection.executeQueryStatement(sql, timeoutInMs);
   }
 
   /**
diff --git a/site/src/main/.vuepress/config.js b/site/src/main/.vuepress/config.js
index 2b664ad..16055f9 100644
--- a/site/src/main/.vuepress/config.js
+++ b/site/src/main/.vuepress/config.js
@@ -554,6 +554,7 @@ var config = {
 							['Operation Manual/DDL Data Definition Language','DDL (Data Definition Language)'],
 							['Operation Manual/DML Data Manipulation Language','DML (Data Manipulation Language)'],
 							['Operation Manual/UDF User Defined Function','UDF (User Defined Function)'],
+							['Operation Manual/Kill Query','Kill Query'],
 							['Operation Manual/Administration','Administration'],
 							['Operation Manual/SQL Reference','SQL Reference']
 						]
@@ -1175,6 +1176,7 @@ var config = {
 							['Operation Manual/DDL Data Definition Language','DDL (数据定义语言)'],
 							['Operation Manual/DML Data Manipulation Language','DML (数据操作语言)'],
 							['Operation Manual/UDF User Defined Function','UDF(用户自定义函数)'],
+							['Operation Manual/Kill Query','中止查询'],
 							['Operation Manual/Administration','权限管理语句'],
 							['Operation Manual/SQL Reference','SQL 参考文档']
 						]