Browse Source

let quartz use the same datasource (#2137)

pull/2/head
Tboy 5 years ago committed by GitHub
parent
commit
7f72df4ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java
  2. 11
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java
  3. 190
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/DruidConnectionProvider.java
  4. 16
      dolphinscheduler-service/src/main/resources/quartz.properties

3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java

@ -70,7 +70,7 @@ public class SpringConnectionFactory {
* get the data source
* @return druid dataSource
*/
@Bean
@Bean(destroyMethod="")
public DruidDataSource dataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
@ -98,7 +98,6 @@ public class SpringConnectionFactory {
druidDataSource.setValidationQueryTimeout(conf.getInt(Constants.SPRING_DATASOURCE_VALIDATION_QUERY_TIMEOUT));
//auto commit
druidDataSource.setDefaultAutoCommit(conf.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT));
return druidDataSource;
}

11
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java

@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.concurrent.ThreadPoolExecutor;
/**
@ -59,9 +60,6 @@ public class MasterSchedulerService extends Thread {
@Autowired
private ZKMasterClient zkMasterClient;
@Autowired
private MasterConfig masterConfig;
/**
* master config
*/
@ -71,17 +69,18 @@ public class MasterSchedulerService extends Thread {
/**
* netty remoting client
*/
private final NettyRemotingClient nettyRemotingClient;
private NettyRemotingClient nettyRemotingClient;
/**
* master exec service
*/
private final ThreadPoolExecutor masterExecService;
private ThreadPoolExecutor masterExecService;
/**
* constructor of MasterSchedulerThread
*/
public MasterSchedulerService(){
@PostConstruct
public void init(){
this.masterExecService = (ThreadPoolExecutor)ThreadUtils.newDaemonFixedThreadExecutor("Master-Exec-Thread", masterConfig.getMasterExecThreads());
NettyClientConfig clientConfig = new NettyClientConfig();
this.nettyRemotingClient = new NettyRemotingClient(clientConfig);

190
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/quartz/DruidConnectionProvider.java

@ -17,7 +17,7 @@
package org.apache.dolphinscheduler.service.quartz;
import com.alibaba.druid.pool.DruidDataSource;
import org.quartz.SchedulerException;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.quartz.utils.ConnectionProvider;
import java.sql.Connection;
@ -28,196 +28,24 @@ import java.sql.SQLException;
*/
public class DruidConnectionProvider implements ConnectionProvider {
/**
* JDBC driver
*/
public String driver;
private final DruidDataSource dataSource;
/**
* JDBC URL
*/
public String URL;
/**
* Database user name
*/
public String user;
/**
* Database password
*/
public String password;
/**
* Maximum number of database connections
*/
public int maxConnections;
/**
* The query that validates the database connection
*/
public String validationQuery;
/**
* Whether the database sql query to validate connections should be executed every time
* a connection is retrieved from the pool to ensure that it is still valid. If false,
* then validation will occur on check-in. Default is false.
*/
private boolean validateOnCheckout;
/**
* The number of seconds between tests of idle connections - only enabled
* if the validation query property is set. Default is 50 seconds.
*/
private int idleConnectionValidationSeconds;
/**
* The maximum number of prepared statements that will be cached per connection in the pool.
* Depending upon your JDBC Driver this may significantly help performance, or may slightly
* hinder performance.
* Default is 120, as Quartz uses over 100 unique statements. 0 disables the feature.
*/
public String maxCachedStatementsPerConnection;
/**
* Discard connections after they have been idle this many seconds. 0 disables the feature. Default is 0.
*/
private String discardIdleConnectionsSeconds;
/**
* Default maximum number of database connections in the pool.
*/
public static final int DEFAULT_DB_MAX_CONNECTIONS = 10;
/**
* The maximum number of prepared statements that will be cached per connection in the pool.
*/
public static final int DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION = 120;
/**
* Druid connection pool
*/
private DruidDataSource datasource;
public DruidConnectionProvider(){
this.dataSource = SpringApplicationContext.getBean(DruidDataSource.class);
}
/**
* get connection
* @return Connection
* @throws SQLException sql exception
*/
@Override
public Connection getConnection() throws SQLException {
return datasource.getConnection();
return dataSource.getConnection();
}
/**
* shutdown data source
* @throws SQLException sql exception
*/
@Override
public void shutdown() throws SQLException {
datasource.close();
dataSource.close();
}
/**
* data source initialize
* @throws SQLException sql exception
*/
@Override
public void initialize() throws SQLException{
if (this.URL == null) {
throw new SQLException("DBPool could not be created: DB URL cannot be null");
}
if (this.driver == null) {
throw new SQLException("DBPool driver could not be created: DB driver class name cannot be null!");
}
if (this.maxConnections < 0) {
throw new SQLException("DBPool maxConnectins could not be created: Max connections must be greater than zero!");
}
datasource = new DruidDataSource();
try{
datasource.setDriverClassName(this.driver);
} catch (Exception e) {
try {
throw new SchedulerException("Problem setting driver class name on datasource", e);
} catch (SchedulerException e1) {
}
}
datasource.setUrl(this.URL);
datasource.setUsername(this.user);
datasource.setPassword(this.password);
datasource.setMaxActive(this.maxConnections);
datasource.setMinIdle(1);
datasource.setMaxWait(0);
datasource.setMaxPoolPreparedStatementPerConnectionSize(DEFAULT_DB_MAX_CONNECTIONS);
if (this.validationQuery != null) {
datasource.setValidationQuery(this.validationQuery);
if(!this.validateOnCheckout){
datasource.setTestOnReturn(true);
} else {
datasource.setTestOnBorrow(true);
}
datasource.setValidationQueryTimeout(this.idleConnectionValidationSeconds);
}
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getURL() {
return URL;
}
public void setURL(String URL) {
this.URL = URL;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getMaxConnections() {
return maxConnections;
}
public void setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public boolean isValidateOnCheckout() {
return validateOnCheckout;
}
public void setValidateOnCheckout(boolean validateOnCheckout) {
this.validateOnCheckout = validateOnCheckout;
}
public int getIdleConnectionValidationSeconds() {
return idleConnectionValidationSeconds;
}
public void setIdleConnectionValidationSeconds(int idleConnectionValidationSeconds) {
this.idleConnectionValidationSeconds = idleConnectionValidationSeconds;
}
public DruidDataSource getDatasource() {
return datasource;
}
public void setDatasource(DruidDataSource datasource) {
this.datasource = datasource;
}
public String getDiscardIdleConnectionsSeconds() {
return discardIdleConnectionsSeconds;
}
public void setDiscardIdleConnectionsSeconds(String discardIdleConnectionsSeconds) {
this.discardIdleConnectionsSeconds = discardIdleConnectionsSeconds;
public void initialize() throws SQLException {
//NOP
}
}

16
dolphinscheduler-service/src/main/resources/quartz.properties

@ -18,16 +18,16 @@
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
# postgre
org.quartz.dataSource.myDs.driver = org.postgresql.Driver
org.quartz.dataSource.myDs.URL = jdbc:postgresql://localhost:5432/dolphinscheduler?characterEncoding=utf8
#org.quartz.dataSource.myDs.driver = org.postgresql.Driver
#org.quartz.dataSource.myDs.URL = jdbc:postgresql://localhost:5432/dolphinscheduler?characterEncoding=utf8
# mysql
#org.quartz.dataSource.myDs.driver = com.mysql.jdbc.Driver
#org.quartz.dataSource.myDs.URL = jdbc:mysql://localhost:3306/dolphinscheduler?characterEncoding=utf8
org.quartz.dataSource.myDs.user = test
org.quartz.dataSource.myDs.password = test
#org.quartz.dataSource.myDs.user = root
#org.quartz.dataSource.myDs.password = 123456
org.quartz.scheduler.instanceName = DolphinScheduler
org.quartz.scheduler.instanceId = AUTO
@ -59,6 +59,4 @@ org.quartz.jobStore.dataSource = myDs
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.myDs.connectionProvider.class = org.apache.dolphinscheduler.service.quartz.DruidConnectionProvider
org.quartz.dataSource.myDs.maxConnections = 10
org.quartz.dataSource.myDs.validationQuery = select 1
org.quartz.dataSource.myDs.connectionProvider.class = org.apache.dolphinscheduler.service.quartz.DruidConnectionProvider
Loading…
Cancel
Save