From a7b8e071b5265ae84c2361f36d426daf5243b63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=BA=E9=98=B3?= Date: Sat, 24 Jun 2023 22:10:58 +0800 Subject: [PATCH] [Improvement][Registry][Jdbc] Add option can use ds database directly (#14369) --- .../dolphinscheduler-registry-jdbc/README.md | 59 +++++++++++-------- .../jdbc/JdbcRegistryConfiguration.java | 1 + 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/README.md b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/README.md index 305714ad9b..f311c20b07 100644 --- a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/README.md +++ b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/README.md @@ -1,20 +1,48 @@ # Introduction -This module is the mysql registry plugin module, this plugin will use mysql as the registry center. +This module is the jdbc registry plugin module, this plugin will use jdbc as the registry center. Will use the database configuration same as DolphinScheduler in api'yaml default. # How to use -## Use Mysql as registry center -If you want to set mysql as the registry center, you need to do the below two steps: +1. Initialize the database table -1. Initialize the mysql table +- If you use Mysql you can directly execute the sql script `src/main/resources/mysql_registry_init.sql`. -You can directly execute the sql script `src/main/resources/mysql_registry_init.sql`. +- If you use Postgresql you can directly execute the sql script `src/main/resources/postgresql_registry_init.sql`. -2. Open the config +2. Change the config You need to set the registry properties in master/worker/api's appplication.yml +```yaml +registry: + type: jdbc +``` + +After do this two steps, you can start your DolphinScheduler cluster, your cluster will use mysql as registry center to +store server metadata. + +NOTE: You need to add `mysql-connector-java.jar` into DS classpath if you use mysql database, since this plugin will not bundle this driver in distribution. +You can get the detail about Initialize the Database. + +## Optional configuration + +```yaml +registry: + type: jdbc + # Used to schedule refresh the ephemeral data/ lock. + term-refresh-interval: 2s + # Used to calculate the expire time, + # e.g. if you set 2, and latest two refresh error, then the ephemeral data/lock will be expire. + term-expire-times: 3 +``` + +## Use different database configuration for jdbc registry center + +You need to set the registry properties in master/worker/api's appplication.yml + +### Use Mysql as registry center + ```yaml registry: type: jdbc @@ -29,22 +57,7 @@ registry: idle-timeout: 600000 ``` -After do this two steps, you can start your DolphinScheduler cluster, your cluster will use mysql as registry center to -store server metadata. - -NOTE: You need to add `mysql-connector-java.jar` into DS classpath, since this plugin will not bundle this driver in distribution. -You can get the detail about Initialize the Database - -## Use Postgresql as registry center -If you want to set Postgresql as the registry center, you need to do the below two steps: - -1. Initialize the PostgreSQL table - -You can directly execute the sql script `src/main/resources/postgresql_registry_init.sql`. - -2. Open the config - -You need to set the registry properties in master/worker/api's appplication.yml +### Use Postgresql as registry center ```yaml registry: @@ -60,5 +73,3 @@ registry: idle-timeout: 600000 ``` -After do this two steps, you can start your DolphinScheduler cluster, your cluster will use postgresql as registry center to -store server metadata. diff --git a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryConfiguration.java b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryConfiguration.java index ced09380f6..7b37749ab7 100644 --- a/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryConfiguration.java +++ b/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryConfiguration.java @@ -35,6 +35,7 @@ import com.zaxxer.hikari.HikariDataSource; public class JdbcRegistryConfiguration { @Bean + @ConditionalOnProperty(prefix = "registry.hikari-config", name = "jdbc-url") public SqlSessionFactory jdbcRegistrySqlSessionFactory(JdbcRegistryProperties jdbcRegistryProperties) throws Exception { MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(new HikariDataSource(jdbcRegistryProperties.getHikariConfig()));