smengcl commented on code in PR #1630:
URL: https://github.com/apache/ratis/pull/1630#discussion_r4223912931


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftConfigurationImpl.java:
##########
@@ -303,6 +303,13 @@ public String toString() {
   }
 
   boolean hasNoChange(Collection<RaftPeer> newMembers, Collection<RaftPeer> 
newListeners) {
+    return hasNoChange(newMembers, newListeners, false);
+  }
+
+  /**
+   * @param checkAddresses Should a peer with the same id but different 
addresses be considered as a change?
+   */
+  boolean hasNoChange(Collection<RaftPeer> newMembers, Collection<RaftPeer> 
newListeners, boolean checkAddresses) {

Review Comment:
   Replaced the boolean overload with a named method, 
`hasNoChangeIncludingAddresses`. The flag is now private.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -1492,7 +1492,7 @@ public CompletableFuture<RaftClientReply> 
setConfigurationAsync(SetConfiguration
       }
 
       // return success with a null message if the new conf is the same as the 
current
-      if (current.hasNoChange(serversInNewConf, listenersInNewConf)) {
+      if (current.hasNoChange(serversInNewConf, listenersInNewConf, true)) {

Review Comment:
   The call site now uses `hasNoChangeIncludingAddresses(...)` instead of a 
boolean literal.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java:
##########
@@ -663,6 +666,51 @@ void runTestNoChangeRequest(CLUSTER cluster) throws 
Exception {
     }
   }
 
+  /**
+   * When a request changes only the addresses of the existing peers,
+   * make sure the new configuration is committed and persisted.
+   */
+  @Test
+  public void testAddressChangeRequest() throws Exception {
+    runWithNewCluster(3, this::runTestAddressChangeRequest);
+  }
+
+  void runTestAddressChangeRequest(CLUSTER cluster) throws Exception {
+    final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
+    final long confIndex = leader.getRaftConf().getLogEntryIndex();
+
+    // the same peers with an equivalent address
+    final List<RaftPeer> newPeers = 
leader.getRaftConf().getCurrentPeers().stream()
+        .map(p -> 
RaftPeer.newBuilder(p).setAddress(p.getAddress().replace(NetUtils.LOCALHOST, 
"127.0.0.1")).build())
+        .collect(Collectors.toList());

Review Comment:
   Added `TestRaftConfiguration.testHasNoChangeIncludingAddresses`, which 
covers each address field for members and listeners.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java:
##########
@@ -663,6 +666,51 @@ void runTestNoChangeRequest(CLUSTER cluster) throws 
Exception {
     }
   }
 
+  /**
+   * When a request changes only the addresses of the existing peers,
+   * make sure the new configuration is committed and persisted.
+   */
+  @Test
+  public void testAddressChangeRequest() throws Exception {
+    runWithNewCluster(3, this::runTestAddressChangeRequest);
+  }
+
+  void runTestAddressChangeRequest(CLUSTER cluster) throws Exception {
+    final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
+    final long confIndex = leader.getRaftConf().getLogEntryIndex();
+
+    // the same peers with an equivalent address
+    final List<RaftPeer> newPeers = 
leader.getRaftConf().getCurrentPeers().stream()
+        .map(p -> 
RaftPeer.newBuilder(p).setAddress(p.getAddress().replace(NetUtils.LOCALHOST, 
"127.0.0.1")).build())
+        .collect(Collectors.toList());
+    try (RaftClient client = cluster.createClient(leader.getId())) {
+      assertTrue(client.admin().setConfiguration(newPeers).isSuccess());
+      assertTrue(leader.getRaftConf().getLogEntryIndex() > confIndex);
+      assertAddresses(newPeers, cluster);
+
+      // the same request again has no change
+      final RaftConfiguration conf = leader.getRaftConf();
+      assertTrue(client.admin().setConfiguration(newPeers).isSuccess());
+      Assertions.assertSame(conf, leader.getRaftConf());
+    }
+
+    cluster.restart(false);
+    RaftTestUtil.waitForLeader(cluster);
+    assertAddresses(newPeers, cluster);
+  }
+
+  void assertAddresses(List<RaftPeer> expected, MiniRaftCluster cluster) 
throws Exception {
+    JavaUtils.attempt(() -> {
+      for (RaftServer.Division d : cluster.iterateDivisions()) {
+        final RaftConfiguration persisted = ((RaftStorageImpl) 
d.getRaftStorage()).readRaftConfiguration();

Review Comment:
   Not changed. `ServerState` is typed to `RaftStorageImpl`, so the cast cannot 
fail in the test cluster.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



-- 
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]

Reply via email to