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 2022/11/20 07:18:15 UTC

[iotdb] branch master updated: [IOTDB-4915][IOTDB-4956] Fix ClassCastException and drop trigger when onDrop throws exception (#8045)

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 0152d95887 [IOTDB-4915][IOTDB-4956] Fix ClassCastException and drop trigger when onDrop throws exception (#8045)
0152d95887 is described below

commit 0152d95887bd5ee7026626320def3bcb3deb6eba
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Sun Nov 20 15:18:10 2022 +0800

    [IOTDB-4915][IOTDB-4956] Fix ClassCastException and drop trigger when onDrop throws exception (#8045)
---
 .../org/apache/iotdb/commons/trigger/TriggerTable.java    |  4 ++--
 .../iotdb/commons/udf/service/UDFManagementService.java   |  3 ++-
 .../config/executor/ClusterConfigTaskExecutor.java        |  6 ++++--
 .../db/trigger/service/TriggerManagementService.java      | 15 +++++++--------
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/trigger/TriggerTable.java b/node-commons/src/main/java/org/apache/iotdb/commons/trigger/TriggerTable.java
index ecc79c3e6d..9962477057 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/trigger/TriggerTable.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/trigger/TriggerTable.java
@@ -57,8 +57,8 @@ public class TriggerTable {
     return triggerTable.get(triggerName);
   }
 
-  public void removeTriggerInformation(String triggerName) {
-    triggerTable.remove(triggerName);
+  public TriggerInformation removeTriggerInformation(String triggerName) {
+    return triggerTable.remove(triggerName);
   }
 
   public void setTriggerInformation(String triggerName, TriggerInformation triggerInformation) {
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
index 045b80a12f..fedfa1c3d0 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFManagementService.java
@@ -213,7 +213,8 @@ public class UDFManagementService {
         | InvocationTargetException
         | NoSuchMethodException
         | IllegalAccessException
-        | ClassNotFoundException e) {
+        | ClassNotFoundException
+        | ClassCastException e) {
       String errorMessage =
           String.format(
               "Failed to register UDF %s(%s), because its instance can not be constructed successfully. Exception: %s",
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index ec40b9e9d0..b56b79ab8e 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -364,7 +364,8 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
           | NoSuchMethodException
           | InstantiationException
           | IllegalAccessException
-          | InvocationTargetException e) {
+          | InvocationTargetException
+          | ClassCastException e) {
         LOGGER.warn(
             "Failed to create function when try to create UDF({}) instance first, the cause is: {}",
             createFunctionStatement.getUdfName(),
@@ -529,7 +530,8 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
           | NoSuchMethodException
           | InstantiationException
           | IllegalAccessException
-          | InvocationTargetException e) {
+          | InvocationTargetException
+          | ClassCastException e) {
         LOGGER.warn(
             "Failed to create trigger when try to create trigger({}) instance first, the cause is: {}",
             createTriggerStatement.getTriggerName(),
diff --git a/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerManagementService.java b/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerManagementService.java
index eff5cfc029..8ba713b9e9 100644
--- a/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerManagementService.java
+++ b/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerManagementService.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.path.PatternTreeMap;
 import org.apache.iotdb.commons.trigger.TriggerInformation;
 import org.apache.iotdb.commons.trigger.TriggerTable;
+import org.apache.iotdb.commons.trigger.exception.TriggerExecutionException;
 import org.apache.iotdb.commons.trigger.exception.TriggerManagementException;
 import org.apache.iotdb.commons.trigger.service.TriggerExecutableManager;
 import org.apache.iotdb.commons.utils.TestOnly;
@@ -115,16 +116,11 @@ public class TriggerManagementService {
   public void dropTrigger(String triggerName, boolean needToDeleteJar) throws IOException {
     try {
       acquireLock();
-      TriggerInformation triggerInformation = triggerTable.getTriggerInformation(triggerName);
-      TriggerExecutor executor = executorMap.get(triggerName);
+      TriggerInformation triggerInformation = triggerTable.removeTriggerInformation(triggerName);
+      TriggerExecutor executor = executorMap.remove(triggerName);
       if (executor != null) {
         executor.onDrop();
       }
-      // exception could be thrown when executing executor.onDrop()
-      // we delete trigger in map after successfully executing onDrop
-      triggerTable.removeTriggerInformation(triggerName);
-      executorMap.remove(triggerName);
-
       if (triggerInformation == null) {
         return;
       }
@@ -136,6 +132,8 @@ public class TriggerManagementService {
             .removeFileUnderLibRoot(triggerInformation.getJarName());
         TriggerExecutableManager.getInstance().removeFileUnderTemporaryRoot(triggerName + ".txt");
       }
+    } catch (TriggerExecutionException ignored) {
+      // Drop trigger can success even onDrop throw an exception for now
     } finally {
       releaseLock();
     }
@@ -324,7 +322,8 @@ public class TriggerManagementService {
         | InvocationTargetException
         | NoSuchMethodException
         | IllegalAccessException
-        | ClassNotFoundException e) {
+        | ClassNotFoundException
+        | ClassCastException e) {
       throw new TriggerManagementException(
           String.format(
               "Failed to reflect trigger instance with className(%s), because %s", className, e));