Alima777 commented on a change in pull request #2352:
URL: https://github.com/apache/iotdb/pull/2352#discussion_r555030657



##########
File path: 
server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
##########
@@ -327,6 +339,32 @@ private void operateCreateSnapshot() {
     IoTDB.metaManager.createMTreeSnapshot();
   }
 
+  private void operateKillQuery(KillQueryPlan killQueryPlan) throws 
QueryIdNotExsitException {
+    QueryTimeManager queryTimeManager = QueryTimeManager.getInstance();
+    long killQueryId = killQueryPlan.getQueryId();
+    if (killQueryId != -1) {
+      if (queryTimeManager.getQueryThreadMap().get(killQueryId) != null) {
+        queryTimeManager.getQueryThreadMap().computeIfPresent(killQueryId, (k, 
v) -> {
+          queryTimeManager.killQuery(k);
+          return null;
+        });
+      } else {
+        throw new QueryIdNotExsitException(String
+            .format("Query Id %d is not exist, please check it.", 
killQueryPlan.getQueryId()));
+      }
+    } else {
+      // if queryId is not specified, kill all running queries
+      if (!queryTimeManager.getQueryThreadMap().isEmpty()) {
+        synchronized (queryTimeManager.getQueryThreadMap()) {

Review comment:
       To keep thread safe while iterating.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to