szetszwo commented on code in PR #1060:
URL: https://github.com/apache/ratis/pull/1060#discussion_r1552274990
##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +70,35 @@ public int run(CommandLine cl) throws IOException {
printf("peers or path can't be empty.");
return -1;
}
+ Set<String> addresses = new HashSet<>();
List<RaftPeerProto> raftPeerProtos = new ArrayList<>();
- for (String address : peersStr.split(",")) {
- String peerId =
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+ for (String idWithAddress : peersStr.split(",")) {
+ String[] peerIdWithAddressArray = idWithAddress.split(SEPARATOR);
+
+ if (peerIdWithAddressArray.length < 1 || peerIdWithAddressArray.length >
2) {
+ printf("Please make sure to provide list of peers in format
<P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT>, "
+ + "or
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT>");
+ return -1;
+ }
+ String address =
parseInetSocketAddress(peerIdWithAddressArray[peerIdWithAddressArray.length -
1]).toString();
+ if (addresses.contains(address)) {
+ printf("Please make sure the addresses of peers have no duplicated
value.");
+ return -1;
+ }
+ addresses.add(address);
+
+ String peerId;
+ if (peerIdWithAddressArray.length == 2) {
+ // Peer ID is provided
+ peerId =
RaftPeerId.getRaftPeerId(peerIdWithAddressArray[0]).toString();
+ } else {
+ // If peer ID is not provided, use host address as peerId value
+ peerId =
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+ }
+
raftPeerProtos.add(RaftPeerProto.newBuilder()
-
.setId(ByteString.copyFrom(peerId.getBytes(StandardCharsets.UTF_8))).setAddress(address)
+ .setId(ByteString.copyFrom(peerId.getBytes(StandardCharsets.UTF_8)))
+
.setAddress(parseInetSocketAddress(peerIdWithAddressArray[1]).toString())
Review Comment:
Use `address`.
How come the test not getting `ArrayIndexOutOfBounds` for
`"host1:9872,host2:9872,host3:9872"`?
--
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]