Skip to content

Commit 0a02522

Browse files
authored
Fix registry table field (#14043)
1 parent 3bad68a commit 0a02522

File tree

7 files changed

+33
-46
lines changed

7 files changed

+33
-46
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public Long insertOrUpdateEphemeralData(String key, String value) throws SQLExce
7070
return id;
7171
}
7272
jdbcRegistryData = JdbcRegistryData.builder()
73-
.key(key)
74-
.data(value)
75-
.type(DataType.EPHEMERAL.getTypeValue())
73+
.dataKey(key)
74+
.dataValue(value)
75+
.dataType(DataType.EPHEMERAL.getTypeValue())
7676
.lastTerm(System.currentTimeMillis())
7777
.build();
7878
jdbcRegistryDataMapper.insert(jdbcRegistryData);
@@ -89,9 +89,9 @@ public long insertOrUpdatePersistentData(String key, String value) throws SQLExc
8989
return id;
9090
}
9191
jdbcRegistryData = JdbcRegistryData.builder()
92-
.key(key)
93-
.data(value)
94-
.type(DataType.PERSISTENT.getTypeValue())
92+
.dataKey(key)
93+
.dataValue(value)
94+
.dataType(DataType.PERSISTENT.getTypeValue())
9595
.lastTerm(System.currentTimeMillis())
9696
.build();
9797
jdbcRegistryDataMapper.insert(jdbcRegistryData);
@@ -122,7 +122,7 @@ public JdbcRegistryData getData(String key) throws SQLException {
122122
public List<String> getChildren(String key) throws SQLException {
123123
return jdbcRegistryDataMapper.fuzzyQueryByKey(key)
124124
.stream()
125-
.map(JdbcRegistryData::getKey)
125+
.map(JdbcRegistryData::getDataKey)
126126
.filter(fullPath -> fullPath.length() > key.length())
127127
.map(fullPath -> StringUtils.substringBefore(fullPath.substring(key.length() + 1), "/"))
128128
.collect(Collectors.toList());
@@ -139,7 +139,7 @@ public boolean existKey(String key) throws SQLException {
139139
@SuppressWarnings("checkstyle:IllegalCatch")
140140
public JdbcRegistryLock tryToAcquireLock(String key) throws SQLException {
141141
JdbcRegistryLock jdbcRegistryLock = JdbcRegistryLock.builder()
142-
.key(key)
142+
.lockKey(key)
143143
.lockOwner(JdbcRegistryConstant.LOCK_OWNER)
144144
.lastTerm(System.currentTimeMillis())
145145
.build();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public interface JdbcRegistryDataMapper extends BaseMapper<JdbcRegistryData> {
3434
@Select("select * from t_ds_jdbc_registry_data")
3535
List<JdbcRegistryData> selectAll();
3636

37-
@Select("select * from t_ds_jdbc_registry_data where key = #{key}")
37+
@Select("select * from t_ds_jdbc_registry_data where data_key = #{key}")
3838
JdbcRegistryData selectByKey(@Param("key") String key);
3939

40-
@Select("select * from t_ds_jdbc_registry_data where key like CONCAT (#{key}, '%')")
40+
@Select("select * from t_ds_jdbc_registry_data where data_key like CONCAT (#{key}, '%')")
4141
List<JdbcRegistryData> fuzzyQueryByKey(@Param("key") String key);
4242

43-
@Update("update t_ds_jdbc_registry_data set data = #{data}, last_term = #{term} where id = #{id}")
43+
@Update("update t_ds_jdbc_registry_data set data_value = #{data}, last_term = #{term} where id = #{id}")
4444
int updateDataAndTermById(@Param("id") long id, @Param("data") String data, @Param("term") long term);
4545

46-
@Delete("delete from t_ds_jdbc_registry_data where key = #{key}")
46+
@Delete("delete from t_ds_jdbc_registry_data where data_key = #{key}")
4747
void deleteByKey(@Param("key") String key);
4848

49-
@Delete("delete from t_ds_jdbc_registry_data where last_term < #{term} and type = #{type}")
49+
@Delete("delete from t_ds_jdbc_registry_data where last_term < #{term} and data_type = #{type}")
5050
void clearExpireEphemeralDate(@Param("term") long term, @Param("type") int type);
5151

5252
@Update({"<script>",

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import lombok.NoArgsConstructor;
2626

2727
import com.baomidou.mybatisplus.annotation.IdType;
28-
import com.baomidou.mybatisplus.annotation.TableField;
2928
import com.baomidou.mybatisplus.annotation.TableId;
3029
import com.baomidou.mybatisplus.annotation.TableName;
3130

@@ -38,17 +37,11 @@ public class JdbcRegistryData {
3837

3938
@TableId(value = "id", type = IdType.AUTO)
4039
private Long id;
41-
@TableField(value = "key")
42-
private String key;
43-
@TableField(value = "data")
44-
private String data;
45-
@TableField(value = "type")
46-
private int type;
47-
@TableField(value = "last_term")
40+
private String dataKey;
41+
private String dataValue;
42+
private int dataType;
4843
private long lastTerm;
49-
@TableField(value = "create_time")
5044
private Date createTime;
51-
@TableField(value = "last_time")
5245
private Date lastUpdateTime;
5346

5447
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import lombok.NoArgsConstructor;
2626

2727
import com.baomidou.mybatisplus.annotation.IdType;
28-
import com.baomidou.mybatisplus.annotation.TableField;
2928
import com.baomidou.mybatisplus.annotation.TableId;
3029
import com.baomidou.mybatisplus.annotation.TableName;
3130

@@ -41,26 +40,21 @@ public class JdbcRegistryLock {
4140
/**
4241
* The lock key.
4342
*/
44-
@TableField(value = "key")
45-
private String key;
43+
private String lockKey;
4644
/**
4745
* acquire lock host.
4846
*/
49-
@TableField(value = "lock_owner")
5047
private String lockOwner;
5148
/**
5249
* The last term, if the (currentTime - lastTerm) > termExpire time, the lock will be expired.
5350
*/
54-
@TableField(value = "last_term")
5551
private Long lastTerm;
5652
/**
5753
* The lock last update time.
5854
*/
59-
@TableField(value = "last_update_time")
6055
private Date lastUpdateTime;
6156
/**
6257
* The lock create time.
6358
*/
64-
@TableField(value = "create_time")
6559
private Date createTime;
6660
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public String getData(String path) {
8080
if (jdbcRegistryData == null) {
8181
return null;
8282
}
83-
return jdbcRegistryData.getData();
83+
return jdbcRegistryData.getDataValue();
8484
}
8585

8686
@Override
@@ -102,7 +102,7 @@ public void run() {
102102
try {
103103
Map<String, JdbcRegistryData> currentJdbcDataMap = jdbcOperator.queryAllJdbcRegistryData()
104104
.stream()
105-
.collect(Collectors.toMap(JdbcRegistryData::getKey, Function.identity()));
105+
.collect(Collectors.toMap(JdbcRegistryData::getDataKey, Function.identity()));
106106
// find the different
107107
List<JdbcRegistryData> addedData = new ArrayList<>();
108108
List<JdbcRegistryData> deletedData = new ArrayList<>();
@@ -143,9 +143,9 @@ private void triggerListener(List<JdbcRegistryData> dataList,
143143
List<SubscribeListener> subscribeListeners,
144144
Event.Type type) {
145145
for (JdbcRegistryData data : dataList) {
146-
if (data.getKey().startsWith(subscribeKey)) {
146+
if (data.getDataKey().startsWith(subscribeKey)) {
147147
subscribeListeners.forEach(subscribeListener -> subscribeListener
148-
.notify(new Event(data.getKey(), data.getKey(), data.getData(), type)));
148+
.notify(new Event(data.getDataKey(), data.getDataKey(), data.getDataValue(), type)));
149149
}
150150
}
151151
}

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/resources/mysql_registry_init.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ DROP TABLE IF EXISTS `t_ds_jdbc_registry_data`;
2121
CREATE TABLE `t_ds_jdbc_registry_data`
2222
(
2323
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
24-
`key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path',
25-
`data` text NOT NULL COMMENT 'data, like zookeeper node value',
26-
`type` tinyint(4) NOT NULL COMMENT '1: ephemeral node, 2: persistent node',
24+
`data_key` varchar(256) NOT NULL COMMENT 'key, like zookeeper node path',
25+
`data_value` text NOT NULL COMMENT 'data, like zookeeper node value',
26+
`data_type` tinyint(4) NOT NULL COMMENT '1: ephemeral node, 2: persistent node',
2727
`last_term` bigint NOT NULL COMMENT 'last term time',
2828
`last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last update time',
2929
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
3030
PRIMARY KEY (`id`),
31-
unique (`key`)
31+
unique (`data_key`)
3232
) ENGINE = InnoDB
3333
DEFAULT CHARSET = utf8;
3434

@@ -37,12 +37,12 @@ DROP TABLE IF EXISTS `t_ds_jdbc_registry_lock`;
3737
CREATE TABLE `t_ds_jdbc_registry_lock`
3838
(
3939
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
40-
`key` varchar(256) NOT NULL COMMENT 'lock path',
40+
`lock_key` varchar(256) NOT NULL COMMENT 'lock path',
4141
`lock_owner` varchar(256) NOT NULL COMMENT 'the lock owner, ip_processId',
4242
`last_term` bigint NOT NULL COMMENT 'last term time',
4343
`last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last update time',
4444
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
4545
PRIMARY KEY (`id`),
46-
unique (`key`)
46+
unique (`lock_key`)
4747
) ENGINE = InnoDB
4848
DEFAULT CHARSET = utf8;

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/resources/postgresql_registry_init.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ create table t_ds_jdbc_registry_data
2020
(
2121
id serial
2222
constraint t_ds_jdbc_registry_data_pk primary key,
23-
key varchar not null,
24-
data text not null,
25-
type int4 not null,
23+
data_key varchar not null,
24+
data_value text not null,
25+
data_type int4 not null,
2626
last_term bigint not null,
2727
last_update_time timestamp default current_timestamp not null,
2828
create_time timestamp default current_timestamp not null
2929
);
3030

31-
create unique index t_ds_jdbc_registry_data_key_uindex on t_ds_jdbc_registry_data (key);
31+
create unique index t_ds_jdbc_registry_data_key_uindex on t_ds_jdbc_registry_data (data_key);
3232

3333

3434
DROP TABLE IF EXISTS t_ds_jdbc_registry_lock;
3535
create table t_ds_jdbc_registry_lock
3636
(
3737
id serial
3838
constraint t_ds_jdbc_registry_lock_pk primary key,
39-
key varchar not null,
39+
lock_key varchar not null,
4040
lock_owner varchar not null,
4141
last_term bigint not null,
4242
last_update_time timestamp default current_timestamp not null,
4343
create_time timestamp default current_timestamp not null
4444
);
45-
create unique index t_ds_jdbc_registry_lock_key_uindex on t_ds_jdbc_registry_lock (key);
45+
create unique index t_ds_jdbc_registry_lock_key_uindex on t_ds_jdbc_registry_lock (lock_key);

0 commit comments

Comments
 (0)