This is an automated email from the ASF dual-hosted git repository. xiangweiwei pushed a commit to branch timeoutQuit in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 7c63c4e7367ce366d4514c50af803a8f117e7a00 Author: Alima777 <[email protected]> AuthorDate: Tue Sep 28 10:37:44 2021 +0800 Let sub threads quit more quickly --- .../apache/iotdb/db/query/control/QueryTimeManager.java | 17 +++++++++++++++-- .../dataset/RawQueryDataSetWithoutValueFilter.java | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java b/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java index b04baed8..0b3212a 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java +++ b/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java @@ -116,14 +116,27 @@ public class QueryTimeManager implements IService { return plan instanceof ShowQueryProcesslistPlan ? null : unRegisterQuery(queryId); } - public static void checkQueryAlive(long queryId) { + /** + * Check given query is alive or not. We only throw the queryTimeoutRunTimeException once. If the + * runTimeException is thrown in main thread, it will quit directly while the return value will be + * used to ask sub query threads to quit. Else if it's thrown in one sub thread, other sub threads + * will quit by reading the return value, and main thread will catch and throw the same exception + * by reading the ExceptionBatchData. + * + * @return True if alive. + */ + public static boolean checkQueryAlive(long queryId) { QueryInfo queryInfo = getInstance().queryInfoMap.get(queryId); - if (queryInfo != null && queryInfo.isInterrupted()) { + if (queryInfo == null) { + return false; + } else if (queryInfo.isInterrupted()) { if (getInstance().unRegisterQuery(queryId).get()) { throw new QueryTimeoutRuntimeException( QueryTimeoutRuntimeException.TIMEOUT_EXCEPTION_MESSAGE); } + return false; } + return true; } public Map<Long, QueryInfo> getQueryInfoMap() { diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/RawQueryDataSetWithoutValueFilter.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/RawQueryDataSetWithoutValueFilter.java index 5d3bec6..fac1cbc 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/dataset/RawQueryDataSetWithoutValueFilter.java +++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/RawQueryDataSetWithoutValueFilter.java @@ -70,7 +70,9 @@ public class RawQueryDataSetWithoutValueFilter extends QueryDataSet public void runMayThrow() { try { // check the status of mainThread before next reading - QueryTimeManager.checkQueryAlive(queryId); + if (!QueryTimeManager.checkQueryAlive(queryId)) { + return; + } synchronized (reader) { // if the task is submitted, there must be free space in the queue
