From 8c5f3647963086f3a67aa5108d85a5733b355537 Mon Sep 17 00:00:00 2001 From: wind Date: Sat, 25 Dec 2021 21:00:48 +0800 Subject: [PATCH] [cherry-pick-2.0.2][BUG-7554] Fix database lose data in standalone (#7621) * [cherry-pick][BUG-7554] Fix database lose data in standalone * Fix thread starts too early Co-authored-by: caishunfeng <534328519@qq.com> Co-authored-by: kezhenxu94 --- .../alert/AlertPluginManager.java | 8 +++---- .../dolphinscheduler/alert/AlertServer.java | 8 +++---- .../api/aspect/AccessLogAnnotation.java | 2 +- .../src/main/resources/application-h2.yaml | 19 ++++++--------- .../server/master/MasterServer.java | 6 +++-- .../worker/plugin/TaskPluginManager.java | 23 ++++++++++++------- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java index ca882ca0e7..1ad06e261a 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java @@ -35,9 +35,9 @@ import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; -import javax.annotation.PostConstruct; - import org.slf4j.Logger; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @Component @@ -52,8 +52,8 @@ public final class AlertPluginManager { this.pluginDao = pluginDao; } - @PostConstruct - public void installPlugin() { + @EventListener + public void installPlugin(ApplicationReadyEvent readyEvent) { final Set names = new HashSet<>(); ServiceLoader.load(AlertChannelFactory.class).forEach(factory -> { diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java index d549ec91cf..2c41f31072 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -32,16 +32,16 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.event.EventListener; @EnableAutoConfiguration @ComponentScan(value = { @@ -73,8 +73,8 @@ public class AlertServer implements Closeable { .run(args); } - @PostConstruct - public void start() { + @EventListener + public void start(ApplicationReadyEvent readyEvent) { log.info("Starting Alert server"); checkTable(); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java index a7bee62a7e..db62bcda3a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/AccessLogAnnotation.java @@ -28,7 +28,7 @@ import java.lang.annotation.Target; @Documented public @interface AccessLogAnnotation { // ignore request args - String[] ignoreRequestArgs() default {}; + String[] ignoreRequestArgs() default {"loginUser"}; boolean ignoreRequest() default false; diff --git a/dolphinscheduler-dao/src/main/resources/application-h2.yaml b/dolphinscheduler-dao/src/main/resources/application-h2.yaml index 147892c350..d42a1032f4 100644 --- a/dolphinscheduler-dao/src/main/resources/application-h2.yaml +++ b/dolphinscheduler-dao/src/main/resources/application-h2.yaml @@ -16,19 +16,14 @@ # under the License. # spring: + sql: + init: + schema-locations: classpath:sql/dolphinscheduler_h2.sql datasource: driver-class-name: org.h2.Driver - url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript from 'classpath:sql/dolphinscheduler_h2.sql' + url: jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true username: sa password: "" - hikari: - connection-test-query: select 1 - minimum-idle: 5 - auto-commit: true - validation-timeout: 3000 - pool-name: DolphinScheduler - maximum-pool-size: 50 - connection-timeout: 30000 - idle-timeout: 600000 - leak-detection-threshold: 0 - initialization-fail-timeout: 1 + jpa: + hibernate: + ddl-auto: none diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java index e9d0cc5a4d..576fadd95a 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java @@ -50,8 +50,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; +import org.springframework.context.event.EventListener; import org.springframework.transaction.annotation.EnableTransactionManagement; /** @@ -127,8 +129,8 @@ public class MasterServer implements IStoppable { /** * run master server */ - @PostConstruct - public void run() { + @EventListener + public void run(ApplicationReadyEvent ignored) { PropertyUtils.setValue(SPRING_DATASOURCE_DRIVER_CLASS_NAME, driverClassName); // init remoting server diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/plugin/TaskPluginManager.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/plugin/TaskPluginManager.java index 7c35b13448..24d4603c8e 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/plugin/TaskPluginManager.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/plugin/TaskPluginManager.java @@ -17,6 +17,8 @@ package org.apache.dolphinscheduler.server.worker.plugin; +import static java.lang.String.format; + import org.apache.dolphinscheduler.common.enums.PluginType; import org.apache.dolphinscheduler.common.enums.TaskType; import org.apache.dolphinscheduler.dao.PluginDao; @@ -25,15 +27,20 @@ import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.PluginParams; import org.apache.dolphinscheduler.spi.task.TaskChannel; import org.apache.dolphinscheduler.spi.task.TaskChannelFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import java.util.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import static java.lang.String.format; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; @Component public class TaskPluginManager { @@ -56,8 +63,8 @@ public class TaskPluginManager { return Collections.unmodifiableMap(taskChannelMap); } - @PostConstruct - public void installPlugin() { + @EventListener + public void installPlugin(ApplicationReadyEvent readyEvent) { final Set names = new HashSet<>(); ServiceLoader.load(TaskChannelFactory.class).forEach(factory -> {