This is an automated email from the ASF dual-hosted git repository.

williamsong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 526f678f746 [RatisConsensus] Prevent misuse of addRemotePeer (#14779)
526f678f746 is described below

commit 526f678f74610fa6134d91613bf6e36bcc396284
Author: William Song <[email protected]>
AuthorDate: Mon Jan 27 08:48:36 2025 +0800

    [RatisConsensus] Prevent misuse of addRemotePeer (#14779)
---
 .../java/org/apache/iotdb/consensus/ratis/RatisConsensus.java | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index 384730a9742..7a7bdc2f9c5 100644
--- 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++ 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -578,7 +578,16 @@ class RatisConsensus implements IConsensus {
 
     RaftPeer peerToAdd = Utils.fromPeerAndPriorityToRaftPeer(peer, 
DEFAULT_PRIORITY);
     // pre-condition: peer not in this group
-    if (group.getPeers().contains(peerToAdd)) {
+    if (group.getPeers().stream()
+        .anyMatch(
+            p ->
+                p.getId().equals(peerToAdd.getId())
+                    || p.getAddress().equals(peerToAdd.getAddress()))) {
+      logger.warn(
+          "{}: try to add a peer {} with conflicting id or address in {}",
+          this,
+          peerToAdd,
+          group.getPeers());
       throw new PeerAlreadyInConsensusGroupException(groupId, peer);
     }
 

Reply via email to