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/10/22 02:12:31 UTC
[iotdb] branch master updated: [IOTDB-4706] Call Trigger.restore() when recovering trigger instances
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 30bf896095 [IOTDB-4706] Call Trigger.restore() when recovering trigger instances
30bf896095 is described below
commit 30bf89609588434ff11d7a1236a87b2d5d5dd074
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Sat Oct 22 10:12:25 2022 +0800
[IOTDB-4706] Call Trigger.restore() when recovering trigger instances
---
.../main/java/org/apache/iotdb/db/service/DataNode.java | 2 +-
.../apache/iotdb/db/trigger/executor/TriggerExecutor.java | 14 +++++++++++++-
.../iotdb/db/trigger/service/TriggerManagementService.java | 11 +++++++----
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
index d24af2095f..fe1944cfb1 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -449,7 +449,7 @@ public class DataNode implements DataNodeMBean {
try {
for (TriggerInformation triggerInformation :
resourcesInformationHolder.getTriggerInformationList()) {
- TriggerManagementService.getInstance().doRegister(triggerInformation);
+ TriggerManagementService.getInstance().doRegister(triggerInformation, true);
}
} catch (Exception e) {
throw new StartupException(e);
diff --git a/server/src/main/java/org/apache/iotdb/db/trigger/executor/TriggerExecutor.java b/server/src/main/java/org/apache/iotdb/db/trigger/executor/TriggerExecutor.java
index bd4a87fc6f..6b9e886899 100644
--- a/server/src/main/java/org/apache/iotdb/db/trigger/executor/TriggerExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/trigger/executor/TriggerExecutor.java
@@ -37,11 +37,15 @@ public class TriggerExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(TriggerExecutor.class);
- public TriggerExecutor(TriggerInformation triggerInformation, Trigger trigger) {
+ public TriggerExecutor(
+ TriggerInformation triggerInformation, Trigger trigger, boolean isRestoring) {
this.triggerInformation = triggerInformation;
this.trigger = trigger;
// call Trigger#validate and Trigger#onCreate
onCreate();
+ if (isRestoring) {
+ onRestore();
+ }
}
private void onCreate() {
@@ -62,6 +66,14 @@ public class TriggerExecutor {
}
}
+ private void onRestore() {
+ try {
+ trigger.restore();
+ } catch (Exception e) {
+ onTriggerExecutionError("restore", e);
+ }
+ }
+
public boolean fire(Tablet tablet, TriggerEvent event) throws TriggerExecutionException {
if (event.equals(triggerInformation.getEvent())) {
try {
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 8f471ff405..9c2ed6d3df 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
@@ -85,7 +85,7 @@ public class TriggerManagementService {
try {
acquireLock();
checkIfRegistered(triggerInformation);
- doRegister(triggerInformation);
+ doRegister(triggerInformation, false);
} finally {
releaseLock();
}
@@ -164,7 +164,8 @@ public class TriggerManagementService {
new TriggerExecutor(
triggerInformation,
constructTriggerInstance(
- triggerInformation.getClassName(), currentActiveClassLoader));
+ triggerInformation.getClassName(), currentActiveClassLoader),
+ true);
executorMap.put(triggerName, newExecutor);
}
}
@@ -272,7 +273,8 @@ public class TriggerManagementService {
* Only call this method directly for registering new data node, otherwise you need to call
* register().
*/
- public void doRegister(TriggerInformation triggerInformation) throws IOException {
+ public void doRegister(TriggerInformation triggerInformation, boolean isRestoring)
+ throws IOException {
try (TriggerClassLoader currentActiveClassLoader =
TriggerClassLoaderManager.getInstance().updateAndGetActiveClassLoader()) {
String triggerName = triggerInformation.getTriggerName();
@@ -287,7 +289,8 @@ public class TriggerManagementService {
Trigger trigger =
constructTriggerInstance(triggerInformation.getClassName(), currentActiveClassLoader);
// construct and save TriggerExecutor after successfully creating trigger instance
- TriggerExecutor triggerExecutor = new TriggerExecutor(triggerInformation, trigger);
+ TriggerExecutor triggerExecutor =
+ new TriggerExecutor(triggerInformation, trigger, isRestoring);
executorMap.put(triggerName, triggerExecutor);
}
} catch (Exception e) {