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

zihaoxiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new e3b97e6213 [Improvement-17467][Master] Support set a separate 
dataSource for quartz (#17468)
e3b97e6213 is described below

commit e3b97e6213548462c5c72d789d96c51759d60016
Author: Wenjun Ruan <[email protected]>
AuthorDate: Tue Sep 16 15:22:40 2025 +0800

    [Improvement-17467][Master] Support set a separate dataSource for quartz 
(#17468)
---
 .../src/main/resources/application.yaml            |  7 ++
 .../dolphinscheduler-scheduler-quartz/README.md    | 46 ++++++++++++
 .../quartz/QuartzSchedulerAutoConfiguration.java   |  2 +
 ...QuartzSchedulerDataSourceAutoConfiguration.java | 84 ++++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  1 +
 .../src/main/resources/application.yaml            |  8 +++
 6 files changed, 148 insertions(+)

diff --git a/dolphinscheduler-master/src/main/resources/application.yaml 
b/dolphinscheduler-master/src/main/resources/application.yaml
index 8e4b7ae0e0..0c56d4c81e 100644
--- a/dolphinscheduler-master/src/main/resources/application.yaml
+++ b/dolphinscheduler-master/src/main/resources/application.yaml
@@ -67,6 +67,13 @@ mybatis-plus:
       id-type: auto
     banner: false
 
+scheduler-plugin:
+  quartz:
+    # By default, will not use a separate datasource for quartz
+    # If you want to use a separate datasource, set it to true and configure 
the datasource below
+    # If set true, and you do not configure hikari below, it will use the same 
configuration as spring.datasource.hikari
+    using-separate-datasource: false
+    # hikari:
 
 registry:
   type: zookeeper
diff --git 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/README.md 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/README.md
new file mode 100644
index 0000000000..acf88a96d5
--- /dev/null
+++ 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/README.md
@@ -0,0 +1,46 @@
+# Introduction
+
+This module is the quartz-scheduler plugin module, this plugin will use quartz 
as the scheduler.
+
+# How to use
+
+By default, you don't need to do any configuration, the quartz-scheduler use 
the same datasource with master.
+
+```yaml
+scheduler-plugin:
+  quartz:
+    # By default, will not use a separate datasource for quartz
+    # If you want to use a separate datasource, set it to true and configure 
the datasource below
+    # If set true and you do not configure hikari below, it will use the same 
configuration as spring.datasource.hikari
+    using-separate-datasource: false
+    # hikari:
+```
+
+## Use a separate datasource for quartz-scheduler
+
+If your have a lot of workflow to be scheduled, it is better to set a separate 
datasource for quartz-scheduler,
+otherwise the performance of quartz thread may be affected. After set 
`using-separate-datasource` to true, the
+quartz-scheduler will use a new datasource, and the datasource configuration 
is same with the master datasource
+configuration.
+
+```yaml
+scheduler-plugin:
+  quartz:
+    using-separate-datasource: true
+```
+
+If you want to use a separate datasource for quartz-scheduler, and set the 
configuration, you need to configure the
+hikari configuration like below:
+
+```yaml
+scheduler-plugin:
+  quartz:
+    using-separate-datasource: true
+    hikari:
+      jdbc-url: jdbc:mysql://localhost:3306/dolphinscheduler
+      username: root
+      password: root
+      minimum-idle: 8
+      maximum-pool-size: 8
+```
+
diff --git 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerAutoConfiguration.java
 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerAutoConfiguration.java
index 34fb782587..7387342634 100644
--- 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerAutoConfiguration.java
+++ 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerAutoConfiguration.java
@@ -26,6 +26,8 @@ import 
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
 import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 
+// Right now we only have one implementation of SchedulerApi: QuartzScheduler
+// If we have more implementations in the future, we can use 
@ConditionalOnProperty to distinguish them, rather than using 
@ConditionalOnClass
 @AutoConfiguration(after = {QuartzAutoConfiguration.class})
 @ConditionalOnClass(value = Scheduler.class)
 public class QuartzSchedulerAutoConfiguration {
diff --git 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerDataSourceAutoConfiguration.java
 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerDataSourceAutoConfiguration.java
new file mode 100644
index 0000000000..2c6e10c441
--- /dev/null
+++ 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/java/org/apache/dolphinscheduler/scheduler/quartz/QuartzSchedulerDataSourceAutoConfiguration.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.scheduler.quartz;
+
+import java.util.Optional;
+
+import javax.sql.DataSource;
+
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+import org.quartz.Scheduler;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
+import 
org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.annotation.Order;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+@Slf4j
+@AutoConfiguration(after = {DataSourceAutoConfiguration.class}, before = 
QuartzSchedulerAutoConfiguration.class)
+@ConditionalOnClass(value = Scheduler.class)
+@ConditionalOnProperty(prefix = "scheduler-plugin.quartz", name = 
"using-separate-datasource", havingValue = "true")
+@EnableConfigurationProperties(QuartzSchedulerDataSourceAutoConfiguration.QuartzDataSourceConfig.class)
+public class QuartzSchedulerDataSourceAutoConfiguration {
+
+    /**
+     * Initialize After {@link 
QuartzAutoConfiguration.JdbcStoreTypeConfiguration#dataSourceCustomizer}
+     */
+    @Bean
+    @Order(1)
+    public SchedulerFactoryBeanCustomizer 
schedulerFactoryBeanCustomizer(QuartzDataSourceConfig quartzDataSourceConfig,
+                                                                         
DataSource defaultDataSource) {
+        return schedulerFactoryBean -> {
+            if (!quartzDataSourceConfig.isUsingSeparateDatasource()) {
+                return;
+            }
+            final HikariConfig quartzHikariConfig = 
Optional.ofNullable(quartzDataSourceConfig.getHikari())
+                    
.orElse(generateQuartzHikariConfigFromDataSource((HikariDataSource) 
defaultDataSource));
+            final HikariDataSource quartzDataSource = new 
HikariDataSource(quartzHikariConfig);
+            schedulerFactoryBean.setDataSource(quartzDataSource);
+            schedulerFactoryBean.setTransactionManager(new 
DataSourceTransactionManager(quartzDataSource));
+        };
+    }
+
+    @Data
+    @ConfigurationProperties(prefix = "scheduler-plugin.quartz")
+    public static class QuartzDataSourceConfig {
+
+        private boolean usingSeparateDatasource = false;
+        private HikariConfig hikari;
+    }
+
+    private HikariConfig 
generateQuartzHikariConfigFromDataSource(HikariDataSource hikariDataSource) {
+        HikariConfig defaultQuartzHikariConfig = new HikariConfig();
+        hikariDataSource.copyStateTo(defaultQuartzHikariConfig);
+        defaultQuartzHikariConfig.setPoolName("QuartzHikariCP");
+        return defaultQuartzHikariConfig;
+    }
+
+}
diff --git 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/resources/META-INF/spring.factories
 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/resources/META-INF/spring.factories
index b34f896b84..2540e56b03 100644
--- 
a/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/resources/META-INF/spring.factories
+++ 
b/dolphinscheduler-scheduler-plugin/dolphinscheduler-scheduler-quartz/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,5 @@
 #
 
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+  
org.apache.dolphinscheduler.scheduler.quartz.QuartzSchedulerDataSourceAutoConfiguration,\
   org.apache.dolphinscheduler.scheduler.quartz.QuartzSchedulerAutoConfiguration
diff --git 
a/dolphinscheduler-standalone-server/src/main/resources/application.yaml 
b/dolphinscheduler-standalone-server/src/main/resources/application.yaml
index bec892599f..a659d5d284 100644
--- a/dolphinscheduler-standalone-server/src/main/resources/application.yaml
+++ b/dolphinscheduler-standalone-server/src/main/resources/application.yaml
@@ -32,6 +32,9 @@ spring:
       url: 
jdbc:h2:mem:dolphinscheduler;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true
       username: sa
       password: ""
+      hikari:
+        connection-test-query: select 1
+        pool-name: DolphinSchedulerDataSource
   quartz:
     job-store-type: jdbc
     jdbc:
@@ -67,6 +70,11 @@ spring:
       matching-strategy: ANT_PATH_MATCHER
   cloud.discovery.client.composite-indicator.enabled: false
 
+scheduler-plugin:
+  quartz:
+    using-separate-datasource: false
+    # hikari:
+
 mybatis-plus:
   mapper-locations: 
classpath:org/apache/dolphinscheduler/dao/mapper/*Mapper.xml
   type-aliases-package: org.apache.dolphinscheduler.dao.entity

Reply via email to