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 17:19:55 UTC

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

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