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/10/10 17:01:44 UTC

[GitHub] [iotdb] SzyWilliam commented on a diff in pull request #7531: [IOTDB-4550] Add NodeId to Peer

SzyWilliam commented on code in PR #7531:
URL: https://github.com/apache/iotdb/pull/7531#discussion_r991478517


##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/Utils.java:
##########
@@ -70,27 +70,36 @@ public static RaftPeerId fromTEndPointToRaftPeerId(TEndPoint endpoint) {
     return RaftPeerId.valueOf(fromTEndPointToString(endpoint));
   }
 
-  public static TEndPoint formRaftPeerIdToTEndPoint(RaftPeerId id) {
-    String[] items = id.toString().split("_");
+  public static RaftPeerId fromNodeIdToRaftPeerId(int nodeId) {
+    return RaftPeerId.valueOf(String.valueOf(nodeId));
+  }
+
+  public static TEndPoint formRaftPeerAddressToTEndPoint(String address) {
+    String[] items = address.split(":");
     return new TEndPoint(items[0], Integer.parseInt(items[1]));
   }
 
-  public static TEndPoint formRaftPeerProtoToTEndPoint(RaftPeerProto proto) {
+  public static int frommRaftPeerIdToNodeId(RaftPeerId id) {
+    return Integer.parseInt(id.toString());
+  }
+
+  public static TEndPoint fromRaftPeerProtoToTEndPoint(RaftPeerProto proto) {
     String[] items = proto.getAddress().split(":");
     return new TEndPoint(items[0], Integer.parseInt(items[1]));
   }
 
   // priority is used as ordinal of leader election
-  public static RaftPeer fromTEndPointAndPriorityToRaftPeer(TEndPoint endpoint, int priority) {
+  public static RaftPeer fromTEndPointAndPriorityToRaftPeer(

Review Comment:
   we should rename this function since now it includes NodeID & TEndPoint



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/Utils.java:
##########
@@ -70,27 +70,36 @@ public static RaftPeerId fromTEndPointToRaftPeerId(TEndPoint endpoint) {
     return RaftPeerId.valueOf(fromTEndPointToString(endpoint));
   }
 
-  public static TEndPoint formRaftPeerIdToTEndPoint(RaftPeerId id) {
-    String[] items = id.toString().split("_");
+  public static RaftPeerId fromNodeIdToRaftPeerId(int nodeId) {
+    return RaftPeerId.valueOf(String.valueOf(nodeId));
+  }
+
+  public static TEndPoint formRaftPeerAddressToTEndPoint(String address) {
+    String[] items = address.split(":");
     return new TEndPoint(items[0], Integer.parseInt(items[1]));
   }
 
-  public static TEndPoint formRaftPeerProtoToTEndPoint(RaftPeerProto proto) {
+  public static int frommRaftPeerIdToNodeId(RaftPeerId id) {

Review Comment:
   typo



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/Utils.java:
##########
@@ -70,27 +70,36 @@ public static RaftPeerId fromTEndPointToRaftPeerId(TEndPoint endpoint) {
     return RaftPeerId.valueOf(fromTEndPointToString(endpoint));
   }
 
-  public static TEndPoint formRaftPeerIdToTEndPoint(RaftPeerId id) {
-    String[] items = id.toString().split("_");
+  public static RaftPeerId fromNodeIdToRaftPeerId(int nodeId) {
+    return RaftPeerId.valueOf(String.valueOf(nodeId));
+  }
+
+  public static TEndPoint formRaftPeerAddressToTEndPoint(String address) {

Review Comment:
   I think it's my fault to use `form` instead of `from`🥵, can you fix it in this PR?



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/Utils.java:
##########
@@ -70,27 +70,36 @@ public static RaftPeerId fromTEndPointToRaftPeerId(TEndPoint endpoint) {
     return RaftPeerId.valueOf(fromTEndPointToString(endpoint));
   }
 
-  public static TEndPoint formRaftPeerIdToTEndPoint(RaftPeerId id) {
-    String[] items = id.toString().split("_");
+  public static RaftPeerId fromNodeIdToRaftPeerId(int nodeId) {
+    return RaftPeerId.valueOf(String.valueOf(nodeId));
+  }
+
+  public static TEndPoint formRaftPeerAddressToTEndPoint(String address) {
+    String[] items = address.split(":");
     return new TEndPoint(items[0], Integer.parseInt(items[1]));
   }
 
-  public static TEndPoint formRaftPeerProtoToTEndPoint(RaftPeerProto proto) {
+  public static int frommRaftPeerIdToNodeId(RaftPeerId id) {
+    return Integer.parseInt(id.toString());
+  }
+
+  public static TEndPoint fromRaftPeerProtoToTEndPoint(RaftPeerProto proto) {
     String[] items = proto.getAddress().split(":");
     return new TEndPoint(items[0], Integer.parseInt(items[1]));
   }
 
   // priority is used as ordinal of leader election
-  public static RaftPeer fromTEndPointAndPriorityToRaftPeer(TEndPoint endpoint, int priority) {
+  public static RaftPeer fromTEndPointAndPriorityToRaftPeer(
+      int nodeId, TEndPoint endpoint, int priority) {
     return RaftPeer.newBuilder()
-        .setId(fromTEndPointToRaftPeerId(endpoint))
+        .setId(fromNodeIdToRaftPeerId(nodeId))
         .setAddress(HostAddress(endpoint))
         .setPriority(priority)
         .build();
   }
 
   public static RaftPeer fromTEndPointAndPriorityToRaftPeer(Peer peer, int priority) {

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

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