SbloodyS commented on code in PR #16352:
URL: 
https://github.com/apache/dolphinscheduler/pull/16352#discussion_r1685430568


##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/test/resources/application.yaml:
##########
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+registry:
+  type: raft
+  module: master
+  clusterName: dolphinscheduler
+  serverAddressList: 127.0.0.1:8082
+  serverAddress: 127.0.0.1
+  serverPort: 8082
+  logStorageDir: raft-data/
+  distributedLockTimeout: 3s
+  distributedLockRetryInterval: 3s
+  listenerCheckInterval: 3s

Review Comment:
   Same here.



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/README.md:
##########
@@ -0,0 +1,56 @@
+# Introduction
+
+This module is the RAFT consensus algorithm registry plugin module, this 
plugin will use raft cluster as the registry center.
+The Raft registration plugin consists of two parts: 
+the server and the client. The Master module of DolphinScheduler will form a 
Raft server cluster
+, while the Worker modules and API modules will interact with the Raft server 
using the Raft client.
+
+# How to use
+
+If you want to set the registry center as raft, 
+
+you need to set the registry properties in master/worker/api's 
appplication.yml,
+
+
+`please remember change the server-port in appplication.yml`.
+
+NOTE: In production environment, in order to achieve high availability, the 
master must be an odd number e.g 3 or 5.
+
+master's properties example
+```yaml
+registry:
+  type: raft
+  cluster-name: dolphinscheduler
+  server-address-list: 127.0.0.1:8181,127.0.0.1:8182,127.0.0.1:8183
+  server-address: 127.0.0.1
+  server-port: 8181
+  log-storage-dir: raft-data/
+  listener-check-interval: 3s
+  distributed-lock-timeout: 3s
+  distributedLockRetryInterval: 3s
+  module: master

Review Comment:
   Please keep 4 indent in yaml file.



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftRegistry.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.raft;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import 
org.apache.dolphinscheduler.plugin.registry.raft.client.IRaftRegisterClient;
+import 
org.apache.dolphinscheduler.plugin.registry.raft.client.RaftRegisterClient;
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.time.Duration;
+import java.util.Collection;
+
+import lombok.NonNull;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class RaftRegistry implements Registry {
+
+    private final IRaftRegisterClient raftRegisterClient;
+    public RaftRegistry(RaftRegistryProperties raftRegistryProperties) {
+        this.raftRegisterClient = new 
RaftRegisterClient(raftRegistryProperties);
+    }
+
+    @Override
+    public void start() {
+        log.info("starting raft registry...");
+        raftRegisterClient.start();
+        log.info("raft registry started successfully");
+    }
+
+    @Override
+    public boolean isConnected() {
+        return raftRegisterClient.isConnectivity();
+    }
+
+    @Override
+    public void connectUntilTimeout(@NonNull Duration timeout) throws 
RegistryException {
+        try {
+            long startTimeMillis = System.currentTimeMillis();
+            long endTimeMillis = timeout.toMillis() > 0 ? startTimeMillis + 
timeout.toMillis() : Long.MAX_VALUE;
+
+            while (System.currentTimeMillis() < endTimeMillis) {
+                if (raftRegisterClient.isConnectivity()) {
+                    return;
+                }
+            }
+            ThreadUtils.sleep(50);

Review Comment:
   Please avoid using magic number. Adding it to constant.



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftSubscribeDataManager.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.raft;
+
+import static com.alipay.sofa.jraft.util.BytesUtil.readUtf8;
+
+import org.apache.dolphinscheduler.common.constants.Constants;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import lombok.extern.slf4j.Slf4j;
+
+import com.alipay.sofa.jraft.rhea.client.RheaKVStore;
+import com.alipay.sofa.jraft.rhea.storage.KVEntry;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+@Slf4j
+public class RaftSubscribeDataManager implements IRaftSubscribeDataManager {
+
+    private final Map<String, List<SubscribeListener>> dataSubScribeMap = new 
ConcurrentHashMap<>();
+
+    private final RaftRegistryProperties properties;
+
+    private final RheaKVStore kvStore;
+
+    public RaftSubscribeDataManager(RaftRegistryProperties properties, 
RheaKVStore kvStore) {
+        this.properties = properties;
+        this.kvStore = kvStore;
+    }
+
+    private final ScheduledExecutorService scheduledExecutorService = 
Executors.newScheduledThreadPool(
+            1,

Review Comment:
   Avoid magic number here.



-- 
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