github-advanced-security[bot] commented on code in PR #16287:
URL: 
https://github.com/apache/dolphinscheduler/pull/16287#discussion_r1668101674


##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/model/DTO/JdbcRegistryClientHeartbeatDTO.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.plugin.registry.jdbc.model.DTO;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DO.JdbcRegistryClientHeartbeat;
+
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.With;
+
+@Data
+@With
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class JdbcRegistryClientHeartbeatDTO implements Cloneable {
+
+    private Long id;
+
+    // Connection name should be unique in the db.
+    private String clientName;
+
+    private Long lastHeartbeatTime;

Review Comment:
   ## Reference equality test of boxed types
   
   Suspicious reference comparison of boxed numerical values.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4223)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/model/DTO/JdbcRegistryClientHeartbeatDTO.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.plugin.registry.jdbc.model.DTO;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DO.JdbcRegistryClientHeartbeat;
+
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.With;
+
+@Data
+@With
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class JdbcRegistryClientHeartbeatDTO implements Cloneable {
+
+    private Long id;

Review Comment:
   ## Reference equality test of boxed types
   
   Suspicious reference comparison of boxed numerical values.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4222)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/model/DTO/JdbcRegistryClientHeartbeatDTO.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.plugin.registry.jdbc.model.DTO;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DO.JdbcRegistryClientHeartbeat;
+
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.With;
+
+@Data
+@With
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class JdbcRegistryClientHeartbeatDTO implements Cloneable {
+
+    private Long id;
+
+    // Connection name should be unique in the db.
+    private String clientName;

Review Comment:
   ## Reference equality test on strings
   
   String values compared with  == .
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4228)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryLockManager.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.plugin.registry.jdbc.server;
+
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.LockUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryLockDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryLockRepository;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.dao.DuplicateKeyException;
+
+@Slf4j
+public class JdbcRegistryLockManager implements IJdbcRegistryLockManager {
+
+    private final JdbcRegistryProperties jdbcRegistryProperties;
+    private final JdbcRegistryLockRepository jdbcRegistryLockRepository;
+
+    // lockKey -> LockEntry
+    private final Map<String, LockEntry> jdbcRegistryLockHolderMap = new 
HashMap<>();
+
+    public JdbcRegistryLockManager(JdbcRegistryProperties 
jdbcRegistryProperties,
+                                   JdbcRegistryLockRepository 
jdbcRegistryLockRepository) {
+        this.jdbcRegistryProperties = jdbcRegistryProperties;
+        this.jdbcRegistryLockRepository = jdbcRegistryLockRepository;
+    }
+
+    @Override
+    public void acquireJdbcRegistryLock(Long clientId, String lockKey) throws 
InterruptedException {
+        String lockOwner = LockUtils.getLockOwner();
+        while (true) {
+            LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey);
+            if (lockEntry != null && 
lockOwner.equals(lockEntry.getLockOwner())) {
+                return;
+            }
+            JdbcRegistryLockDTO jdbcRegistryLock = 
JdbcRegistryLockDTO.builder()
+                    .lockKey(lockKey)
+                    .clientId(clientId)
+                    .lockOwner(lockOwner)
+                    .createTime(new Date())
+                    .build();
+            try {
+                jdbcRegistryLockRepository.insert(jdbcRegistryLock);
+                if (jdbcRegistryLock != null) {
+                    jdbcRegistryLockHolderMap.put(lockKey, LockEntry.builder()
+                            .lockKey(lockKey)
+                            .lockOwner(lockOwner)
+                            .jdbcRegistryLock(jdbcRegistryLock)
+                            .build());
+                    return;
+                }
+                log.debug("{} acquire the lock {} success", lockOwner, 
lockKey);
+            } catch (DuplicateKeyException duplicateKeyException) {
+                // The lock is already exist, wait it release.
+                continue;
+            }
+            log.debug("Acquire the lock {} failed try again", lockKey);
+            // acquire failed, wait and try again
+            
Thread.sleep(jdbcRegistryProperties.getHeartbeatRefreshInterval().toMillis());
+        }
+    }
+
+    @Override
+    public boolean acquireJdbcRegistryLock(Long clientId, String lockKey, long 
timeout) {
+        String lockOwner = LockUtils.getLockOwner();
+        long start = System.currentTimeMillis();
+        while (System.currentTimeMillis() - start <= timeout) {
+            LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey);
+            if (lockEntry != null && 
lockOwner.equals(lockEntry.getLockOwner())) {
+                return true;
+            }
+            JdbcRegistryLockDTO jdbcRegistryLock = 
JdbcRegistryLockDTO.builder()
+                    .lockKey(lockKey)
+                    .clientId(clientId)
+                    .lockOwner(lockOwner)
+                    .createTime(new Date())
+                    .build();
+            try {
+                jdbcRegistryLockRepository.insert(jdbcRegistryLock);
+                if (jdbcRegistryLock != null) {
+                    jdbcRegistryLockHolderMap.put(lockKey, LockEntry.builder()
+                            .lockKey(lockKey)
+                            .lockOwner(lockOwner)
+                            .jdbcRegistryLock(jdbcRegistryLock)
+                            .build());
+                    return true;
+                }
+                log.debug("{} acquire the lock {} success", lockOwner, 
lockKey);

Review Comment:
   ## Log Injection
   
   This log entry depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4227)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryDataManager.java:
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.plugin.registry.jdbc.server;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryThreadFactory;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.DataType;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataChanceEventDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataChanceEventRepository;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataRepository;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.time.DateUtils;
+
+import java.time.Duration;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import lombok.extern.slf4j.Slf4j;
+
+import com.google.common.collect.Lists;
+
+@Slf4j
+public class JdbcRegistryDataManager
+        implements
+            IRegistryRowChangeNotifier<JdbcRegistryDataDTO>,
+            IJdbcRegistryDataManager {
+
+    private final Integer keepJdbcRegistryDataChanceEventHours = 2;
+
+    private final JdbcRegistryProperties registryProperties;
+
+    private final JdbcRegistryDataRepository jdbcRegistryDataRepository;
+
+    private final JdbcRegistryDataChanceEventRepository 
jdbcRegistryDataChanceEventRepository;
+
+    private final List<RegistryRowChangeListener<JdbcRegistryDataDTO>> 
registryRowChangeListeners;
+
+    private long lastDetectedJdbcRegistryDataChangeEventId = -1;
+
+    public JdbcRegistryDataManager(JdbcRegistryProperties registryProperties,
+                                   JdbcRegistryDataRepository 
jdbcRegistryDataRepository,
+                                   JdbcRegistryDataChanceEventRepository 
jdbcRegistryDataChanceEventRepository) {
+        this.registryProperties = registryProperties;
+        this.jdbcRegistryDataChanceEventRepository = 
jdbcRegistryDataChanceEventRepository;
+        this.jdbcRegistryDataRepository = jdbcRegistryDataRepository;
+        this.registryRowChangeListeners = new CopyOnWriteArrayList<>();
+        this.lastDetectedJdbcRegistryDataChangeEventId =
+                
jdbcRegistryDataChanceEventRepository.getMaxJdbcRegistryDataChanceEventId();
+    }
+
+    @Override
+    public void start() {
+        
JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor().scheduleWithFixedDelay(
+                this::detectJdbcRegistryDataChangeEvent,
+                registryProperties.getHeartbeatRefreshInterval().toMillis(),
+                registryProperties.getHeartbeatRefreshInterval().toMillis(),
+                TimeUnit.MILLISECONDS);
+
+        
JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor().scheduleWithFixedDelay(
+                this::purgeHistoryJdbcRegistryDataChangeEvent,
+                0,
+                
Duration.ofHours(keepJdbcRegistryDataChanceEventHours).toHours(),
+                TimeUnit.HOURS);
+    }
+
+    private void detectJdbcRegistryDataChangeEvent() {
+        final List<JdbcRegistryDataChanceEventDTO> 
jdbcRegistryDataChanceEvents = jdbcRegistryDataChanceEventRepository
+                
.selectJdbcRegistryDataChangeEventWhereIdAfter(lastDetectedJdbcRegistryDataChangeEventId);
+        if (CollectionUtils.isEmpty(jdbcRegistryDataChanceEvents)) {
+            return;
+        }
+        for (JdbcRegistryDataChanceEventDTO jdbcRegistryDataChanceEvent : 
jdbcRegistryDataChanceEvents) {
+            switch (jdbcRegistryDataChanceEvent.getEventType()) {
+                case ADD:
+                    doTriggerJdbcRegistryDataAddedListener(
+                            
Lists.newArrayList(jdbcRegistryDataChanceEvent.getJdbcRegistryData()));
+                    break;
+                case UPDATE:
+                    doTriggerJdbcRegistryDataUpdatedListener(
+                            
Lists.newArrayList(jdbcRegistryDataChanceEvent.getJdbcRegistryData()));
+                    break;
+                case DELETE:
+                    doTriggerJdbcRegistryDataRemovedListener(
+                            
Lists.newArrayList(jdbcRegistryDataChanceEvent.getJdbcRegistryData()));
+                    break;
+                default:
+                    log.warn("Unknown event type: {}", 
jdbcRegistryDataChanceEvent.getEventType());
+                    break;
+            }
+            if (jdbcRegistryDataChanceEvent.getId() > 
lastDetectedJdbcRegistryDataChangeEventId) {
+                lastDetectedJdbcRegistryDataChangeEventId = 
jdbcRegistryDataChanceEvent.getId();
+            }
+        }
+    }
+
+    private void purgeHistoryJdbcRegistryDataChangeEvent() {
+        
jdbcRegistryDataChanceEventRepository.deleteJdbcRegistryDataChangeEventBeforeCreateTime(
+                DateUtils.addHours(new Date(), 
-keepJdbcRegistryDataChanceEventHours));
+    }
+
+    @Override
+    public void 
subscribeRegistryRowChange(RegistryRowChangeListener<JdbcRegistryDataDTO> 
registryRowChangeListener) {
+        
registryRowChangeListeners.add(checkNotNull(registryRowChangeListener));
+    }
+
+    @Override
+    public boolean existKey(String key) {
+        checkNotNull(key);
+        return jdbcRegistryDataRepository.selectByKey(key).isPresent();
+    }
+
+    public Optional<JdbcRegistryDataDTO> getRegistryDataByKey(String key) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [IJdbcRegistryDataManager.getRegistryDataByKey](1); it 
is advisable to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4224)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.plugin.registry.jdbc.server;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.plugin.registry.jdbc.IJdbcRegistryClient;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryThreadFactory;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.client.JdbcRegistryClientIdentify;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.DataType;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryClientHeartbeatDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryDataDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryClientRepository;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataChanceEventRepository;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryDataRepository;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryLockRepository;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+
+import com.google.common.collect.Lists;
+
+/**
+ * The JdbcRegistryServer will manage the client, once a client is 
disconnected, the server will remove the client from the registry, and remove 
it's related data and lock.
+ */
+@Slf4j
+public class JdbcRegistryServer implements IJdbcRegistryServer {
+
+    private final JdbcRegistryProperties jdbcRegistryProperties;
+
+    private final JdbcRegistryDataRepository jdbcRegistryDataRepository;
+
+    private final JdbcRegistryLockRepository jdbcRegistryLockRepository;
+
+    private final JdbcRegistryClientRepository jdbcRegistryClientRepository;
+
+    private final JdbcRegistryDataManager jdbcRegistryDataManager;
+
+    private final JdbcRegistryLockManager jdbcRegistryLockManager;
+
+    private JdbcRegistryServerState jdbcRegistryServerState;
+
+    private final List<IJdbcRegistryClient> jdbcRegistryClients = new 
CopyOnWriteArrayList<>();
+
+    private final List<ConnectionStateListener> connectionStateListeners = new 
CopyOnWriteArrayList<>();
+
+    private final Map<JdbcRegistryClientIdentify, 
JdbcRegistryClientHeartbeatDTO> jdbcRegistryClientDTOMap =
+            new ConcurrentHashMap<>();
+
+    private Long lastSuccessHeartbeat;
+
+    public JdbcRegistryServer(JdbcRegistryDataRepository 
jdbcRegistryDataRepository,
+                              JdbcRegistryLockRepository 
jdbcRegistryLockRepository,
+                              JdbcRegistryClientRepository 
jdbcRegistryClientRepository,
+                              JdbcRegistryDataChanceEventRepository 
jdbcRegistryDataChanceEventRepository,
+                              JdbcRegistryProperties jdbcRegistryProperties) {
+        this.jdbcRegistryDataRepository = 
checkNotNull(jdbcRegistryDataRepository);
+        this.jdbcRegistryLockRepository = 
checkNotNull(jdbcRegistryLockRepository);
+        this.jdbcRegistryClientRepository = 
checkNotNull(jdbcRegistryClientRepository);
+        this.jdbcRegistryProperties = checkNotNull(jdbcRegistryProperties);
+        this.jdbcRegistryDataManager = new JdbcRegistryDataManager(
+                jdbcRegistryProperties, jdbcRegistryDataRepository, 
jdbcRegistryDataChanceEventRepository);
+        this.jdbcRegistryLockManager = new JdbcRegistryLockManager(
+                jdbcRegistryProperties, jdbcRegistryLockRepository);
+        this.jdbcRegistryServerState = JdbcRegistryServerState.INIT;
+        lastSuccessHeartbeat = System.currentTimeMillis();
+    }
+
+    public void start() {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [IJdbcRegistryServer.start](1); it is advisable to add 
an Override annotation.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4225)



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryLockManager.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.plugin.registry.jdbc.server;
+
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.JdbcRegistryProperties;
+import org.apache.dolphinscheduler.plugin.registry.jdbc.LockUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.model.DTO.JdbcRegistryLockDTO;
+import 
org.apache.dolphinscheduler.plugin.registry.jdbc.repository.JdbcRegistryLockRepository;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.dao.DuplicateKeyException;
+
+@Slf4j
+public class JdbcRegistryLockManager implements IJdbcRegistryLockManager {
+
+    private final JdbcRegistryProperties jdbcRegistryProperties;
+    private final JdbcRegistryLockRepository jdbcRegistryLockRepository;
+
+    // lockKey -> LockEntry
+    private final Map<String, LockEntry> jdbcRegistryLockHolderMap = new 
HashMap<>();
+
+    public JdbcRegistryLockManager(JdbcRegistryProperties 
jdbcRegistryProperties,
+                                   JdbcRegistryLockRepository 
jdbcRegistryLockRepository) {
+        this.jdbcRegistryProperties = jdbcRegistryProperties;
+        this.jdbcRegistryLockRepository = jdbcRegistryLockRepository;
+    }
+
+    @Override
+    public void acquireJdbcRegistryLock(Long clientId, String lockKey) throws 
InterruptedException {
+        String lockOwner = LockUtils.getLockOwner();
+        while (true) {
+            LockEntry lockEntry = jdbcRegistryLockHolderMap.get(lockKey);
+            if (lockEntry != null && 
lockOwner.equals(lockEntry.getLockOwner())) {
+                return;
+            }
+            JdbcRegistryLockDTO jdbcRegistryLock = 
JdbcRegistryLockDTO.builder()
+                    .lockKey(lockKey)
+                    .clientId(clientId)
+                    .lockOwner(lockOwner)
+                    .createTime(new Date())
+                    .build();
+            try {
+                jdbcRegistryLockRepository.insert(jdbcRegistryLock);
+                if (jdbcRegistryLock != null) {
+                    jdbcRegistryLockHolderMap.put(lockKey, LockEntry.builder()
+                            .lockKey(lockKey)
+                            .lockOwner(lockOwner)
+                            .jdbcRegistryLock(jdbcRegistryLock)
+                            .build());
+                    return;
+                }
+                log.debug("{} acquire the lock {} success", lockOwner, 
lockKey);

Review Comment:
   ## Log Injection
   
   This log entry depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/4226)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to