You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2023/07/11 17:16:49 UTC

[iotdb] branch master updated: [ISSUE-10465] Fixed rest api query isn't closed (kill query doesn't work) (#10511)

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

rong 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 3b7584ea2c5 [ISSUE-10465] Fixed rest api query isn't closed (kill query doesn't work) (#10511)
3b7584ea2c5 is described below

commit 3b7584ea2c516ccebd8c209c4d1a50d462a7dec5
Author: CloudWise-Lukemiao <76...@users.noreply.github.com>
AuthorDate: Wed Jul 12 01:16:42 2023 +0800

    [ISSUE-10465] Fixed rest api query isn't closed (kill query doesn't work) (#10511)
    
    Co-authored-by: Cloudwise_Luke <28...@qq.com>
---
 .../rest/v1/impl/GrafanaApiServiceImpl.java        | 21 ++++++++++++++++---
 .../protocol/rest/v1/impl/RestApiServiceImpl.java  | 24 ++++++++++++++++++----
 .../rest/v2/impl/GrafanaApiServiceImpl.java        | 21 ++++++++++++++++---
 .../protocol/rest/v2/impl/RestApiServiceImpl.java  | 22 +++++++++++++++++---
 4 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java
index d02c5fee123..882dec8b86e 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java
@@ -87,6 +87,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
 
   @Override
   public Response variables(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -106,7 +107,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -132,11 +133,16 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response expression(ExpressionRequest expressionRequest, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateExpressionRequest(expressionRequest);
 
@@ -168,7 +174,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -198,6 +204,10 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
@@ -213,6 +223,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
 
   @Override
   public Response node(List<String> requestBody, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       if (requestBody != null && !requestBody.isEmpty()) {
         PartialPath path = new PartialPath(Joiner.on(".").join(requestBody));
@@ -224,7 +235,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
           return response;
         }
 
-        final long queryId = SESSION_MANAGER.requestQueryId();
+        queryId = SESSION_MANAGER.requestQueryId();
         // create and cache dataset
         ExecutionResult result =
             COORDINATOR.execute(
@@ -254,6 +265,10 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
index e758b7cd4af..f48f0203b06 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
@@ -74,6 +74,7 @@ public class RestApiServiceImpl extends RestApiService {
 
   @Override
   public Response executeNonQueryStatement(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -93,10 +94,11 @@ public class RestApiServiceImpl extends RestApiService {
       if (response != null) {
         return response;
       }
+      queryId = SESSION_MANAGER.requestQueryId();
       ExecutionResult result =
           COORDINATOR.execute(
               statement,
-              SESSION_MANAGER.requestQueryId(),
+              queryId,
               null,
               sql.getSql(),
               partitionFetcher,
@@ -116,11 +118,16 @@ public class RestApiServiceImpl extends RestApiService {
           .build();
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response executeQueryStatement(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -141,7 +148,7 @@ public class RestApiServiceImpl extends RestApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -170,12 +177,17 @@ public class RestApiServiceImpl extends RestApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response insertTablet(
       InsertTabletRequest insertTabletRequest, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateInsertTabletRequest(insertTabletRequest);
 
@@ -187,11 +199,11 @@ public class RestApiServiceImpl extends RestApiService {
       if (response != null) {
         return response;
       }
-
+      queryId = SESSION_MANAGER.requestQueryId();
       ExecutionResult result =
           COORDINATOR.execute(
               insertTabletStatement,
-              SESSION_MANAGER.requestQueryId(),
+              queryId,
               null,
               "",
               partitionFetcher,
@@ -211,6 +223,10 @@ public class RestApiServiceImpl extends RestApiService {
           .build();
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java
index e47863d9678..a7eb24066e3 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java
@@ -87,6 +87,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
 
   @Override
   public Response variables(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -106,7 +107,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -132,11 +133,16 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response expression(ExpressionRequest expressionRequest, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateExpressionRequest(expressionRequest);
 
@@ -168,7 +174,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -198,6 +204,10 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
@@ -213,6 +223,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
 
   @Override
   public Response node(List<String> requestBody, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       if (requestBody != null && !requestBody.isEmpty()) {
         PartialPath path = new PartialPath(Joiner.on(".").join(requestBody));
@@ -224,7 +235,7 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
           return response;
         }
 
-        final long queryId = SESSION_MANAGER.requestQueryId();
+        queryId = SESSION_MANAGER.requestQueryId();
         // create and cache dataset
         ExecutionResult result =
             COORDINATOR.execute(
@@ -254,6 +265,10 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
index ff415ad63c9..91595a1f92d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
@@ -74,6 +74,7 @@ public class RestApiServiceImpl extends RestApiService {
 
   @Override
   public Response executeNonQueryStatement(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -93,10 +94,11 @@ public class RestApiServiceImpl extends RestApiService {
       if (response != null) {
         return response;
       }
+      queryId = SESSION_MANAGER.requestQueryId();
       ExecutionResult result =
           COORDINATOR.execute(
               statement,
-              SESSION_MANAGER.requestQueryId(),
+              queryId,
               null,
               sql.getSql(),
               partitionFetcher,
@@ -116,11 +118,16 @@ public class RestApiServiceImpl extends RestApiService {
           .build();
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response executeQueryStatement(SQL sql, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateSQL(sql);
 
@@ -141,7 +148,7 @@ public class RestApiServiceImpl extends RestApiService {
         return response;
       }
 
-      final long queryId = SESSION_MANAGER.requestQueryId();
+      queryId = SESSION_MANAGER.requestQueryId();
       // create and cache dataset
       ExecutionResult result =
           COORDINATOR.execute(
@@ -170,12 +177,17 @@ public class RestApiServiceImpl extends RestApiService {
       }
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 
   @Override
   public Response insertTablet(
       InsertTabletRequest insertTabletRequest, SecurityContext securityContext) {
+    Long queryId = null;
     try {
       RequestValidationHandler.validateInsertTabletRequest(insertTabletRequest);
 
@@ -187,7 +199,7 @@ public class RestApiServiceImpl extends RestApiService {
       if (response != null) {
         return response;
       }
-
+      queryId = SESSION_MANAGER.requestQueryId();
       ExecutionResult result =
           COORDINATOR.execute(
               insertTabletStatement,
@@ -211,6 +223,10 @@ public class RestApiServiceImpl extends RestApiService {
           .build();
     } catch (Exception e) {
       return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
+    } finally {
+      if (queryId != null) {
+        COORDINATOR.cleanupQueryExecution(queryId);
+      }
     }
   }
 }