You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/08/02 13:26:45 UTC

[GitHub] [dolphinscheduler] leo-lao commented on a diff in pull request #11144: [DSIP-9][Feature][Server] Add Raft consensus algorithm registry, remove zookeeper dependency

leo-lao commented on code in PR #11144:
URL: https://github.com/apache/dolphinscheduler/pull/11144#discussion_r935333423


##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftConnectionStateListener.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import com.alipay.sofa.jraft.Status;
+import com.alipay.sofa.jraft.core.Replicator;
+import com.alipay.sofa.jraft.entity.PeerId;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class RaftConnectionStateListener implements Replicator.ReplicatorStateListener {
+    private final ConnectionListener connectionListener;
+    private ConnectionState connectionState;
+
+    public RaftConnectionStateListener(ConnectionListener connectionListener) {
+        this.connectionListener = connectionListener;
+    }
+
+    @Override
+    public void onCreated(PeerId peerId) {
+        log.info("{}:{} created...", peerId.getIp(), peerId.getPort());
+    }
+
+    @Override
+    public void onError(PeerId peerId, Status status) {
+        log.error("{}:{} an error occurred, {}", peerId.getIp(), peerId.getPort(), status.getErrorMsg());
+    }
+
+    @Override
+    public void onDestroyed(PeerId peerId) {
+        log.info("{}:{} destroyed...", peerId.getIp(), peerId.getPort());
+    }
+
+    @Override
+    public void stateChanged(PeerId peer, ReplicatorState newState) {
+        switch (newState) {

Review Comment:
   Is it possible to get state change event of other peers?
   If so you cannot grant `connectionState` values from `newState` directly.



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-raft/src/main/java/org/apache/dolphinscheduler/plugin/registry/raft/RaftConnectionStateListener.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import com.alipay.sofa.jraft.Status;
+import com.alipay.sofa.jraft.core.Replicator;
+import com.alipay.sofa.jraft.entity.PeerId;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class RaftConnectionStateListener implements Replicator.ReplicatorStateListener {
+    private final ConnectionListener connectionListener;
+    private ConnectionState connectionState;
+
+    public RaftConnectionStateListener(ConnectionListener connectionListener) {
+        this.connectionListener = connectionListener;
+    }
+
+    @Override
+    public void onCreated(PeerId peerId) {
+        log.info("{}:{} created...", peerId.getIp(), peerId.getPort());
+    }
+
+    @Override
+    public void onError(PeerId peerId, Status status) {
+        log.error("{}:{} an error occurred, {}", peerId.getIp(), peerId.getPort(), status.getErrorMsg());
+    }
+
+    @Override
+    public void onDestroyed(PeerId peerId) {
+        log.info("{}:{} destroyed...", peerId.getIp(), peerId.getPort());
+    }
+
+    @Override
+    public void stateChanged(PeerId peer, ReplicatorState newState) {
+        switch (newState) {
+            case CREATED:
+                connectionState = ConnectionState.CONNECTED;
+                break;
+            case ONLINE:
+                if (connectionState == ConnectionState.DISCONNECTED || connectionState == ConnectionState.SUSPENDED) {
+                    connectionState = ConnectionState.RECONNECTED;
+                }
+                break;
+            case OFFLINE:
+                connectionState = ConnectionState.SUSPENDED;
+                break;
+            case DESTROYED:
+                connectionState = ConnectionState.DISCONNECTED;
+                break;
+            default:
+        }
+        connectionListener.onUpdate(connectionState);
+    }

Review Comment:
   Here I am confused by `stateChanged` method and still I cannot figure out how  statuses of raft node switch and how the master path on KVStore gets removed.
   
   Suppose Peer A(master) is down, and it is evicted from the raft cluster, then its `stateChanged` method gets invoked, but here only connectionState changed, then `MasterConnectionStateListener` invoked.
   till now I haven't seen any logic about how the path on KVStore got deleted. 
   
   I don't think the path of dead master will be deleted automaticaly unless you make the path on KVStore `one object with TTL` feature, that is, something like temporary nodes on Zookeeper.
   
   So to conclude, in order to get correct statemachine, there are two methods:
   1. `one object with TTL` to represent the master status(refreshed by HeatBeat)
   2. periodic checking logic(like MySQL registry)
   
   But In Raft Registry I see none of above.



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org