You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/03/27 01:30:28 UTC

[GitHub] [iotdb] qiaojialin commented on a change in pull request #5347: [IOTDB-2780] Config node ratis consensus protocol implementation

qiaojialin commented on a change in pull request #5347:
URL: https://github.com/apache/iotdb/pull/5347#discussion_r835832146



##########
File path: confignode/src/main/java/org/apache/iotdb/confignode/consensus/ConsensusType.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.iotdb.confignode.consensus;
+
+import java.util.Arrays;
+
+public enum ConsensusType {

Review comment:
       put this to consensus module?

##########
File path: confignode/src/assembly/resources/conf/iotdb-confignode.properties
##########
@@ -57,6 +53,23 @@ config_node_rpc_port=22277
 # Datatype: int
 # thrift_init_buffer_size=1024
 
+####################
+### consensus protocol configuration
+####################
+
+# ConfigNodeGroup consensus protocol type
+# These consensus protocol are currently supported:
+# 1. standalone(No protocol, only supports stand-alone machine)
+# 2. ratis(Ratis protocol)
+# Datatype: String
+# consensus_type=standalone

Review comment:
       Default is Ratis?

##########
File path: confignode/src/assembly/resources/conf/iotdb-confignode.properties
##########
@@ -57,6 +53,23 @@ config_node_rpc_port=22277
 # Datatype: int
 # thrift_init_buffer_size=1024
 
+####################
+### consensus protocol configuration
+####################
+
+# ConfigNodeGroup consensus protocol type
+# These consensus protocol are currently supported:
+# 1. standalone(No protocol, only supports stand-alone machine)
+# 2. ratis(Ratis protocol)

Review comment:
       ```suggestion
   # 2. ratis(Raft protocol)
   ```
   
   Users only know Raft, they do not know Ratis

##########
File path: confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
##########
@@ -87,33 +89,80 @@ public int getDeviceGroupID(String device) {
   }
 
   /** Build ConfigNodeGroup ConsensusLayer */
-  private void setConsensusLayer(ConfigNodeConf config) {
-    // TODO: Support other consensus protocol
-    this.consensusImpl = new StandAloneConsensus(id -> new PartitionRegionStateMachine());
-    // TODO: handle the possible exception that cause the Consensus fail
-    try {
-      this.consensusImpl.start();
-    } catch (IOException e) {
-      e.printStackTrace();
+  private void setConsensusLayer() throws IOException {
+    // There is only one ConfigNodeGroup
+    consensusGroupId = new ConsensusGroupId(GroupType.PartitionRegion, 0);
+
+    // If consensusDir does not exist, create consensusDir
+    File consensusDir = new File(conf.getConsensusDir());
+    if (!consensusDir.exists()) {
+      if (consensusDir.mkdirs()) {
+        LOGGER.info("Make consensus dirs: {}", consensusDir);
+      } else {
+        throw new IOException(
+            String.format(
+                "Start ConfigNode failed, because couldn't make system dirs: %s.",
+                consensusDir.getAbsolutePath()));
+      }
     }
 
-    this.consensusGroupId = new ConsensusGroupId(GroupType.PartitionRegion, 0);
-    this.consensusImpl.addConsensusGroup(
-        this.consensusGroupId,
+    // Implement specific consensus
+    switch (conf.getConsensusType()) {
+      case STANDALONE:
+        constructStandAloneConsensus();
+        break;
+      case RATIS:
+        constructRatisConsensus();

Review comment:
       looks like the constructors of these two consensus are not consistent




-- 
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: reviews-unsubscribe@iotdb.apache.org

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