Skip to content

Commit cb40ebf

Browse files
committed
[Improvement-17646][JdbcRegistry] Using transaction in JdbcRegistryDataManager
1 parent 4505d4b commit cb40ebf

File tree

9 files changed

+88
-220
lines changed

9 files changed

+88
-220
lines changed

docs/docs/en/guide/installation/registry-plugins/jdbc.md

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,13 @@ configuration same as DolphinScheduler in api'yaml default.
1111

1212
- If you use Postgresql you can directly execute the sql script `src/main/resources/postgresql_registry_init.sql`.
1313

14-
2. Change the config
15-
16-
You need to set the registry properties in master/worker/api's application.yml
17-
18-
```yaml
19-
registry:
20-
type: jdbc
21-
```
22-
23-
After do this two steps, you can start your DolphinScheduler cluster, your cluster will use mysql as registry center to
24-
store server metadata.
25-
2614
NOTE: You need to add `mysql-connector-java.jar` into DS classpath if you use mysql database, since this plugin will not
2715
bundle this driver in distribution.
2816
You can get the detail
2917
about <a href="https://dolphinscheduler.apache.org/en-us/docs/3.1.2/guide/installation/pseudo-cluster">Initialize the
3018
Database</a>.
3119

32-
## Optional configuration
20+
2. Change the config
3321

3422
```yaml
3523
registry:
@@ -38,49 +26,5 @@ registry:
3826
heartbeat-refresh-interval: 3s
3927
# Once the client's heartbeat is not refresh in this time, the server will consider the client is offline.
4028
session-timeout: 60s
41-
# The hikari configuration, default will use the same datasource pool as DolphinScheduler.
42-
hikari-config:
43-
jdbc-url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler
44-
username: root
45-
password: root
46-
maximum-pool-size: 5
47-
connection-timeout: 9000
48-
idle-timeout: 600000
49-
```
50-
51-
## Use different database configuration for jdbc registry center
52-
53-
You need to set the registry properties in master/worker/api's application.yml
54-
55-
### Use Mysql as registry center
56-
57-
```yaml
58-
registry:
59-
type: jdbc
60-
heartbeat-refresh-interval: 3s
61-
session-timeout: 60s
62-
hikari-config:
63-
jdbc-url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler
64-
username: root
65-
password: root
66-
maximum-pool-size: 5
67-
connection-timeout: 9000
68-
idle-timeout: 600000
69-
```
70-
71-
### Use Postgresql as registry center
72-
73-
```yaml
74-
registry:
75-
type: jdbc
76-
heartbeat-refresh-interval: 3s
77-
session-timeout: 60s
78-
hikari-config:
79-
jdbc-url: jdbc:postgresql://localhost:5432/dolphinscheduler
80-
username: root
81-
password: root
82-
maximum-pool-size: 5
83-
connection-timeout: 9000
84-
idle-timeout: 600000
8529
```
8630

docs/docs/zh/guide/installation/registry-plugins/jdbc.md

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,71 +10,18 @@
1010

1111
- 如果你使用 PostgreSQL,你可以直接执行 SQL 脚本 `src/main/resources/postgresql_registry_init.sql`.
1212

13+
注意: 如果您使用mysql数据库,您需要将 `mysql-connector-java.jar` 添加到 DS 的类路径中,因为这个插件不会在发行版中捆绑此驱动程序。
14+
1315
2. 修改配置
1416

1517
需要在 master/worker/api 的 application.yml 中设置属性
1618

17-
```yaml
18-
registry:
19-
type: jdbc
20-
```
21-
22-
完成这两步后,你就可以启动你的 DolphinScheduler 集群了,你的集群将使用 MySQL 作为注册中心来存储服务器元数据。
23-
24-
注意: 如果您使用mysql数据库,您需要将 `mysql-connector-java.jar` 添加到 DS 的类路径中,因为这个插件不会在发行版中捆绑此驱动程序。
25-
26-
## 可选配置
27-
2819
```yaml
2920
registry:
3021
type: jdbc
3122
# Used to schedule refresh the heartbeat.
3223
heartbeat-refresh-interval: 3s
3324
# Once the client's heartbeat is not refresh in this time, the server will consider the client is offline.
3425
session-timeout: 60s
35-
# The hikari configuration, default will use the same datasource pool as DolphinScheduler.
36-
hikari-config:
37-
jdbc-url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler
38-
username: root
39-
password: root
40-
maximum-pool-size: 5
41-
connection-timeout: 9000
42-
idle-timeout: 600000
43-
```
44-
45-
## 对 JDBC 注册中心使用不同的数据库配置
46-
47-
需要在 master/worker/api 的 application.yml 中设置属性
48-
49-
### 使用 MySQL 作为注册中心
50-
51-
```yaml
52-
registry:
53-
type: jdbc
54-
heartbeat-refresh-interval: 3s
55-
session-timeout: 60s
56-
hikari-config:
57-
jdbc-url: jdbc:mysql://127.0.0.1:3306/dolphinscheduler
58-
username: root
59-
password: root
60-
maximum-pool-size: 5
61-
connection-timeout: 9000
62-
idle-timeout: 600000
63-
```
64-
65-
### 使用 PostgreSQL 作为注册中心
66-
67-
```yaml
68-
registry:
69-
type: jdbc
70-
heartbeat-refresh-interval: 3s
71-
session-timeout: 60s
72-
hikari-config:
73-
jdbc-url: jdbc:postgresql://localhost:5432/dolphinscheduler
74-
username: root
75-
password: root
76-
maximum-pool-size: 5
77-
connection-timeout: 9000
78-
idle-timeout: 600000
7926
```
8027

dolphinscheduler-master/src/test/resources/application.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ mybatis-plus:
4343

4444
registry:
4545
type: jdbc
46+
# Used to schedule refresh the heartbeat.
47+
heartbeat-refresh-interval: 3s
48+
# Once the client's heartbeat is not refresh in this time, the server will consider the client is offline.
49+
session-timeout: 60s
4650

4751
master:
4852
listen-port: 5678

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/JdbcRegistryAutoConfiguration.java

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,24 @@
1717

1818
package org.apache.dolphinscheduler.plugin.registry.jdbc;
1919

20-
import org.apache.dolphinscheduler.plugin.registry.jdbc.mapper.JdbcRegistryClientHeartbeatMapper;
21-
import org.apache.dolphinscheduler.plugin.registry.jdbc.mapper.JdbcRegistryDataChangeEventMapper;
22-
import org.apache.dolphinscheduler.plugin.registry.jdbc.mapper.JdbcRegistryDataMapper;
23-
import org.apache.dolphinscheduler.plugin.registry.jdbc.mapper.JdbcRegistryLockMapper;
2420
import org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryClientRepository;
2521
import org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataChangeEventRepository;
2622
import org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataRepository;
2723
import org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryLockRepository;
2824
import org.apache.dolphinscheduler.plugin.registry.jdbc.server.IJdbcRegistryServer;
2925
import org.apache.dolphinscheduler.plugin.registry.jdbc.server.JdbcRegistryServer;
3026

31-
import org.apache.ibatis.session.SqlSessionFactory;
32-
3327
import lombok.extern.slf4j.Slf4j;
3428

35-
import org.mybatis.spring.SqlSessionTemplate;
3629
import org.mybatis.spring.annotation.MapperScan;
3730
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
38-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3931
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4032
import org.springframework.context.annotation.Bean;
4133
import org.springframework.context.annotation.ComponentScan;
4234
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.transaction.support.TransactionTemplate;
4336

4437
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
45-
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
46-
import com.zaxxer.hikari.HikariDataSource;
4738

4839
@Slf4j
4940
@ComponentScan
@@ -62,13 +53,15 @@ public IJdbcRegistryServer jdbcRegistryServer(JdbcRegistryDataRepository jdbcReg
6253
JdbcRegistryLockRepository jdbcRegistryLockRepository,
6354
JdbcRegistryClientRepository jdbcRegistryClientRepository,
6455
JdbcRegistryDataChangeEventRepository jdbcRegistryDataChangeEventRepository,
65-
JdbcRegistryProperties jdbcRegistryProperties) {
56+
JdbcRegistryProperties jdbcRegistryProperties,
57+
TransactionTemplate transactionTemplate) {
6658
return new JdbcRegistryServer(
6759
jdbcRegistryDataRepository,
6860
jdbcRegistryLockRepository,
6961
jdbcRegistryClientRepository,
7062
jdbcRegistryDataChangeEventRepository,
71-
jdbcRegistryProperties);
63+
jdbcRegistryProperties,
64+
transactionTemplate);
7265
}
7366

7467
@Bean
@@ -79,44 +72,4 @@ public JdbcRegistry jdbcRegistry(JdbcRegistryProperties jdbcRegistryProperties,
7972
return jdbcRegistry;
8073
}
8174

82-
@Bean
83-
@ConditionalOnMissingBean
84-
public SqlSessionFactory sqlSessionFactory(JdbcRegistryProperties jdbcRegistryProperties) throws Exception {
85-
log.info("Initialize jdbcRegistrySqlSessionFactory");
86-
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
87-
sqlSessionFactoryBean.setDataSource(new HikariDataSource(jdbcRegistryProperties.getHikariConfig()));
88-
return sqlSessionFactoryBean.getObject();
89-
}
90-
91-
@Bean
92-
@ConditionalOnMissingBean
93-
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory jdbcRegistrySqlSessionFactory) {
94-
log.info("Initialize jdbcRegistrySqlSessionTemplate");
95-
return new SqlSessionTemplate(jdbcRegistrySqlSessionFactory);
96-
}
97-
98-
@Bean
99-
public JdbcRegistryDataMapper jdbcRegistryDataMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) {
100-
jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryDataMapper.class);
101-
return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryDataMapper.class);
102-
}
103-
104-
@Bean
105-
public JdbcRegistryLockMapper jdbcRegistryLockMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) {
106-
jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryLockMapper.class);
107-
return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryLockMapper.class);
108-
}
109-
110-
@Bean
111-
public JdbcRegistryDataChangeEventMapper jdbcRegistryDataChangeEventMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) {
112-
jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryDataChangeEventMapper.class);
113-
return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryDataChangeEventMapper.class);
114-
}
115-
116-
@Bean
117-
public JdbcRegistryClientHeartbeatMapper jdbcRegistryClientHeartbeatMapper(SqlSessionTemplate jdbcRegistrySqlSessionTemplate) {
118-
jdbcRegistrySqlSessionTemplate.getConfiguration().addMapper(JdbcRegistryClientHeartbeatMapper.class);
119-
return jdbcRegistrySqlSessionTemplate.getMapper(JdbcRegistryClientHeartbeatMapper.class);
120-
}
121-
12275
}

0 commit comments

Comments
 (0)