You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/08/16 10:36:07 UTC

[GitHub] [ratis] leo65535 opened a new pull request, #714: Patch

leo65535 opened a new pull request, #714:
URL: https://github.com/apache/ratis/pull/714

   ## What changes were proposed in this pull request?
   
   When run ratis example, the script still runs normally while the peerids are same.
   ```
   BIN=ratis-examples/src/main/bin
   PEERS=n0:127.0.0.1:6000,n0:127.0.0.1:6001,n0:127.0.0.1:6002
   ```
   
   After patch
   ```
   [dcadmin@dcadmin-work ratis]$     PEERS=n0:127.0.0.1:6000,n0:127.0.0.1:6001,n0:127.0.0.1:6002
   [dcadmin@dcadmin-work ratis]$ ID=n0; ${BIN}/server.sh arithmetic server --id ${ID} --storage /tmp/ratis/test/${ID} --peers ${PEERS}
   Found /work/projects/opensource/raft/ratis/ratis-examples/target/ratis-examples-3.0.0-SNAPSHOT.jar
   Exception in thread "main" java.lang.IllegalStateException: PeerId n0 has already appeared in this group.
           at org.apache.ratis.util.Preconditions.assertTrue(Preconditions.java:72)
           at org.apache.ratis.protocol.RaftGroup.lambda$new$2(RaftGroup.java:66)
           at java.util.Arrays$ArrayList.forEach(Arrays.java:3880)
           at org.apache.ratis.protocol.RaftGroup.<init>(RaftGroup.java:65)
           at org.apache.ratis.protocol.RaftGroup.valueOf(RaftGroup.java:38)
           at org.apache.ratis.examples.arithmetic.cli.Server.run(Server.java:77)
           at org.apache.ratis.examples.common.Runner.main(Runner.java:63)
   ```
   
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-1673
   
   ## How was this patch tested?
   
   (Please explain how this patch was tested. Ex: unit tests, manual tests)
   (If this patch involves UI changes, please attach a screen-shot; otherwise, remove this)
   


-- 
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: issues-unsubscribe@ratis.apache.org

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


[GitHub] [ratis] leo65535 commented on a diff in pull request #714: RATIS-1673. Verify duplicate peerid when init raft group

Posted by GitBox <gi...@apache.org>.
leo65535 commented on code in PR #714:
URL: https://github.com/apache/ratis/pull/714#discussion_r947364738


##########
ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java:
##########
@@ -62,7 +62,12 @@ private RaftGroup(RaftGroupId groupId, Iterable<RaftPeer> peers) {
       this.peers = Collections.emptyMap();
     } else {
       final Map<RaftPeerId, RaftPeer> map = new HashMap<>();
-      peers.forEach(p -> map.put(p.getId(), p));
+      peers.forEach(p -> {
+        Preconditions.assertTrue(!map.containsKey(p.getId()),
+            () -> "PeerId " + p.getId() + " has already appeared in this group.");

Review Comment:
   Make sense.



-- 
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: issues-unsubscribe@ratis.apache.org

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


[GitHub] [ratis] szetszwo merged pull request #714: RATIS-1673. Verify duplicate peerid when init raft group

Posted by GitBox <gi...@apache.org>.
szetszwo merged PR #714:
URL: https://github.com/apache/ratis/pull/714


-- 
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: issues-unsubscribe@ratis.apache.org

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


[GitHub] [ratis] szetszwo commented on a diff in pull request #714: RATIS-1673. Verify duplicate peerid when init raft group

Posted by GitBox <gi...@apache.org>.
szetszwo commented on code in PR #714:
URL: https://github.com/apache/ratis/pull/714#discussion_r947049950


##########
ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java:
##########
@@ -62,7 +62,12 @@ private RaftGroup(RaftGroupId groupId, Iterable<RaftPeer> peers) {
       this.peers = Collections.emptyMap();
     } else {
       final Map<RaftPeerId, RaftPeer> map = new HashMap<>();
-      peers.forEach(p -> map.put(p.getId(), p));
+      peers.forEach(p -> {
+        Preconditions.assertTrue(!map.containsKey(p.getId()),
+            () -> "PeerId " + p.getId() + " has already appeared in this group.");

Review Comment:
   Let's use assertUnique, i.e.
   ```java
   +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftGroup.java
   @@ -61,6 +61,7 @@ public final class RaftGroup {
        if (peers == null || !peers.iterator().hasNext()) {
          this.peers = Collections.emptyMap();
        } else {
   +      Preconditions.assertUnique(peers);
          final Map<RaftPeerId, RaftPeer> map = new HashMap<>();
          peers.forEach(p -> map.put(p.getId(), p));
          this.peers = Collections.unmodifiableMap(map);
   ```



-- 
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: issues-unsubscribe@ratis.apache.org

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