You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "Cyrill (via GitHub)" <gi...@apache.org> on 2025/08/12 10:03:46 UTC

[PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Cyrill opened a new pull request, #6408:
URL: https://github.com/apache/ignite-3/pull/6408

   https://issues.apache.org/jira/browse/IGNITE-22818


-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287455318


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -317,6 +337,15 @@ void testNoConfigurationReordering() throws Exception {
         // Wait for the initial cluster reconfiguration to complete.
         assertLearnerSize(2);
 
+        // Same as above, but check the all 5 nodes see the same number of learners (which is 2 actually).
+        assertTrue(waitForCondition(() ->
+                        configs.size() == 5 && configs.values().stream()
+                                .map(list -> list.get(list.size() - 1))
+                                .mapToInt(raftGroupConfiguration -> raftGroupConfiguration.learners().size())
+                                .min().orElseThrow() == 2,

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284922090


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);

Review Comment:
   fixed



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284917181


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283013924


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))
+                        );
+            }
         }
     }
 
+    private static CompletableFuture<Void> updateLearnersOnLeader(CmgRaftService service, long term) {

Review Comment:
   I read `maybeUpdateLearnersOnLeader` as "even we are on a leader, there is a chance we are not willing to update learners". While in reality we want to execute this request on a leader only.
   So I would either stick to the current notation or change it to something like "maybeUpdateLearners", which highlights the conditional nature of the body.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283033200


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +282,27 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a set of consistent IDs of the learners nodes of the CMG.
+     */
+    public CompletableFuture<Set<String>> learners() {
+        Peer leader = raftService.leader();

Review Comment:
   Changed that. Thanks



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287803486


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -979,10 +1024,10 @@ private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, l
                             return service.updateLearners(term);
                         }
                     })
-                    .whenComplete((unused, throwable) -> {
-                        if (throwable != null) {
-                            LOG.error("Failed to reset learners", throwable);
-                        }
+                    .exceptionally(e -> {
+                        LOG.warn("Failed to update learners for term {}", e, term);

Review Comment:
   Does this deserve a TODO in 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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2281999248


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +282,27 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a set of consistent IDs of the learners nodes of the CMG.
+     */
+    public CompletableFuture<Set<String>> learners() {
+        Peer leader = raftService.leader();

Review Comment:
   Why do you need to retrieve or refresh raft leader prior to retrieving learners?



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +282,27 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a set of consistent IDs of the learners nodes of the CMG.

Review Comment:
   No, it's not. It will return known set of learners of the corresponding raftService.



##########
modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/BaseItClusterManagementTest.java:
##########
@@ -44,7 +44,7 @@
 public abstract class BaseItClusterManagementTest extends IgniteAbstractTest {
     private static final int PORT_BASE = 10000;
 
-    @InjectConfiguration
+    @InjectConfiguration("mock.retryTimeoutMillis = 60000")

Review Comment:
   Why?



##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java:
##########
@@ -52,21 +53,16 @@ public void handleRequest(final RpcContext rpcCtx, final T request) {
             if (msg != null) {
                 rpcCtx.sendResponse(msg);
             }
+        } catch (NotLeaderException t) {
+            // It is ok if we lost leadership while a request to us was in flight, there is no need to clutter up the log.
+            LOG.debug("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(t.leaderId(), msgFactory, RaftError.EPERM, t.getMessage()));
+        } catch (Throwable t) {
+            LOG.error("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(msgFactory, RaftError.UNKNOWN.getNumber(), "handleRequest internal error"));
         }
-        catch (final Throwable t) {
-            if (isIgnorable(t)) {
-                LOG.debug("handleRequest {} failed", t, request);
-            } else {
-                LOG.error("handleRequest {} failed", t, request);
-            }
-            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT //

Review Comment:
   Do you mean that prior to your changes in case of NotLeaderException we've responded with "handleRequest internal error" that triggers request retry to the same node?



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))
+                        );
+            }
         }
     }
 
+    private static CompletableFuture<Void> updateLearnersOnLeader(CmgRaftService service, long term) {

Review Comment:
   I'd rather name it maybeUpdateLearnersOnLeader since in case of !IsLeader we won't do an update.



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))

Review Comment:
   busyLocks are likely missing in theCompose clauses.



##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java:
##########
@@ -448,7 +447,7 @@ public Ignite startNode(int index) {
      */
     public Ignite startNode(int index, String nodeBootstrapConfigTemplate) {
         ServerRegistration registration = startEmbeddedNode(index, nodeBootstrapConfigTemplate);
-        assertThat("nodeIndex=" + index, registration.registrationFuture(), willSucceedIn(20, SECONDS));
+        assertThat("nodeIndex=" + index, registration.registrationFuture(), willCompleteSuccessfully());

Review Comment:
   As far as I remember willCompleteSuccessfully waits for 10 seconds. If it's true, why it's now enough to wait 10 instead of 20 seconds?



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2282989517


##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java:
##########
@@ -448,7 +447,7 @@ public Ignite startNode(int index) {
      */
     public Ignite startNode(int index, String nodeBootstrapConfigTemplate) {
         ServerRegistration registration = startEmbeddedNode(index, nodeBootstrapConfigTemplate);
-        assertThat("nodeIndex=" + index, registration.registrationFuture(), willSucceedIn(20, SECONDS));
+        assertThat("nodeIndex=" + index, registration.registrationFuture(), willCompleteSuccessfully());

Review Comment:
   `willCompleteSuccessfully()` delegates to 
   ```
   private CompletableFutureMatcher(Matcher<T> matcher) {
       this(matcher, DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
   }
   ```
   and DEFAULT_TIMEOUT_SECONDS=30,
   in other words I increased the timeout from 20 to 30
   



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284919822


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .mapToInt(node -> {
+                                    try {
+                                        return node.clusterManager().learnerNodes().get().size();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .min().orElseThrow() == size,
+                30_000
+        ));
+    }
+
+    private void blockMessage(BiPredicate<String, NetworkMessage> predicate) {
+        cluster.stream().map(node -> node.clusterService().messagingService()).forEach(msg -> {

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284916058


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285071921


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +281,21 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a known set of consistent IDs of the learners nodes of the CMG.
+     */
+    public CompletableFuture<Set<String>> learners() {
+        List<Peer> currentLearners = raftService.learners();
+
+        if (currentLearners == null) {
+            return raftService.refreshMembers(true).thenCompose(v -> learners());
+        }
+
+        return completedFuture(currentLearners.stream()
+                .map(Peer::consistentId)
+                .collect(toCollection(HashSet::new)));

Review Comment:
   fixed



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285098797


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -132,6 +132,12 @@ public class ClusterManagementGroupManager extends AbstractEventProducer<Cluster
     /** Lock for the {@code raftService} field. */
     private final Object raftServiceLock = new Object();
 
+    /** Current updateLearners operation to ensure linearization of updates. */
+    private volatile CompletableFuture<Void> currentUpdateLearners = nullCompletedFuture();

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2286165335


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+

Review Comment:
   Okay, I added configuration changes history analysis, should be fine now.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc merged PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408


-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284642128


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +282,27 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a set of consistent IDs of the learners nodes of the CMG.

Review Comment:
   changed



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284912798


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java:
##########
@@ -52,21 +53,16 @@ public void handleRequest(final RpcContext rpcCtx, final T request) {
             if (msg != null) {
                 rpcCtx.sendResponse(msg);
             }
+        } catch (NotLeaderException t) {

Review Comment:
   The test I created would be flaky without this fix - it will pass only when the leader is not changed during the whole test run. If it did, the test would fail.
   



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287464341


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -979,10 +1024,10 @@ private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, l
                             return service.updateLearners(term);
                         }
                     })
-                    .whenComplete((unused, throwable) -> {
-                        if (throwable != null) {
-                            LOG.error("Failed to reset learners", throwable);
-                        }
+                    .exceptionally(e -> {
+                        LOG.warn("Failed to update learners for term {}", e, term);

Review Comment:
   Before this change we neither waited on nor checked the status of this future. Now we wait for the the previous one to finish but again, ignoring the result. In other words, this behavior is left intact.
   The future is likely to fail if the majority is down, otherwise we expect the happy path. And the 'majority down' is going to be addressed in a separate topic.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2282992865


##########
modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/BaseItClusterManagementTest.java:
##########
@@ -44,7 +44,7 @@
 public abstract class BaseItClusterManagementTest extends IgniteAbstractTest {
     private static final int PORT_BASE = 10000;
 
-    @InjectConfiguration
+    @InjectConfiguration("mock.retryTimeoutMillis = 60000")

Review Comment:
   It is to be able to slow down ResetLearnersRequest without the risk of receiving a timeout on sendWithRetry.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283034081


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))
+                        );
+            }
         }
     }
 
+    private static CompletableFuture<Void> updateLearnersOnLeader(CmgRaftService service, long term) {

Review Comment:
   Yep, make sense, let's stick with current one.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283040422


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);

Review Comment:
    Is `service.updateLearners(term);` still called within onElectedAsLeader? If true how it's linearized with `service.updateLearners(term);` calls in onLogicalTopologyChanged?



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284906359


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..

Review Comment:
   Imagine we have learner nodes 3 and 4 and stop node 4, then the message will be ResetLearnersRequest(to node3).
   If there are 0 learners and we add node 3 as a learner, the message will be again ResetLearnersRequest(to node3).



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285275986


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -950,23 +956,49 @@ private static RaftNodeId raftNodeId(Peer serverPeer) {
         return new RaftNodeId(CmgGroupId.INSTANCE, serverPeer);
     }
 
+    /**
+     * Serializes calls to updateLearners to prevent race conditions between multiple topology changes
+     * and leader election callbacks.
+     *
+     * @param service CMG Raft service.
+     * @param term RAFT term.
+     * @param checkLeadership Whether to check leadership before updating learners.
+     */
+    private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, long term, boolean checkLeadership) {
+        synchronized (updateLearnersLock) {
+            currentUpdateLearners = currentUpdateLearners
+                    .thenCompose(v -> {
+                        if (checkLeadership) {
+                            return service.isCurrentNodeLeader().thenCompose(isLeader -> {
+                                if (!isLeader) {
+                                    return nullCompletedFuture();
+                                }
+                                return service.updateLearners(term);
+                            });
+                        } else {
+                            return service.updateLearners(term);
+                        }
+                    })
+                    .whenComplete((unused, throwable) -> {
+                        if (throwable != null) {
+                            LOG.error("Failed to reset learners", throwable);

Review Comment:
   Fixed as per #2



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2288005441


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -979,10 +1024,10 @@ private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, l
                             return service.updateLearners(term);
                         }
                     })
-                    .whenComplete((unused, throwable) -> {
-                        if (throwable != null) {
-                            LOG.error("Failed to reset learners", throwable);
-                        }
+                    .exceptionally(e -> {
+                        LOG.warn("Failed to update learners for term {}", e, term);

Review Comment:
   Proposed solution looks fine to me. 
   
   > Does this deserve a TODO in code?
   
   I don't think that there's an epic. We may create it though.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2286166204


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);

Review Comment:
   Added final configuration history analysis, should be fine now



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2282998742


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java:
##########
@@ -52,21 +53,16 @@ public void handleRequest(final RpcContext rpcCtx, final T request) {
             if (msg != null) {
                 rpcCtx.sendResponse(msg);
             }
+        } catch (NotLeaderException t) {
+            // It is ok if we lost leadership while a request to us was in flight, there is no need to clutter up the log.
+            LOG.debug("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(t.leaderId(), msgFactory, RaftError.EPERM, t.getMessage()));
+        } catch (Throwable t) {
+            LOG.error("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(msgFactory, RaftError.UNKNOWN.getNumber(), "handleRequest internal error"));
         }
-        catch (final Throwable t) {
-            if (isIgnorable(t)) {
-                LOG.debug("handleRequest {} failed", t, request);
-            } else {
-                LOG.error("handleRequest {} failed", t, request);
-            }
-            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT //

Review Comment:
   Correct. 
   The return code -1 translates to RaftError.UNKNOWN. What we had were constant retries until sendWithRetry failed with a timeout.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285232579


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283041147


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +282,27 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a set of consistent IDs of the learners nodes of the CMG.

Review Comment:
   isn't raftService that we have here handling cmg?



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287447503


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -317,6 +337,15 @@ void testNoConfigurationReordering() throws Exception {
         // Wait for the initial cluster reconfiguration to complete.
         assertLearnerSize(2);
 
+        // Same as above, but check the all 5 nodes see the same number of learners (which is 2 actually).

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283013924


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))
+                        );
+            }
         }
     }
 
+    private static CompletableFuture<Void> updateLearnersOnLeader(CmgRaftService service, long term) {

Review Comment:
   I read `maybeUpdateLearnersOnLeader` as "even we are on a leader, there is a chance we are not willing to update learners".  
   So I would either stick to the current notation or change it to something like "maybeUpdateLearners", which highlights the conditional nature of the body.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283023948


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);
-            }));
+        synchronized (raftServiceLock) {
+            if (topologyReconfigurationFuture == null) {
+                topologyReconfigurationFuture =
+                        serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term));
+            } else {
+                topologyReconfigurationFuture =
+                        // At the moment topology reconfiguration will stop if the previous one fails (see how thenCompose works).
+                        // This is going to change in the future when cmg/mg majority loss is handled properly.
+                        topologyReconfigurationFuture.thenCompose(v ->
+                                serviceFuture.thenCompose(service -> updateLearnersOnLeader(service, term))

Review Comment:
   Fixed. Thanks



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285222418


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();

Review Comment:
   We are blocking the message that changes cmg learners so there exist nodes that will be unable to respond correctly



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284925404


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());

Review Comment:
   fixed



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285226195


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .mapToInt(node -> {
+                                    try {
+                                        return node.clusterManager().learnerNodes().get().size();

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285230448


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -957,18 +960,39 @@ private void onLogicalTopologyChanged(long term) {
 
         // If the future is not here yet, this means we are still starting, so learners will be updated after start
         // (if we happen to become a leader).
+        if (serviceFuture == null) {
+            return;
+        }
 
-        if (serviceFuture != null) {
-            serviceFuture.thenCompose(service -> service.isCurrentNodeLeader().thenCompose(isLeader -> {
-                if (!isLeader) {
-                    return nullCompletedFuture();
-                }
-
-                return service.updateLearners(term);

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287247201


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -979,10 +1024,10 @@ private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, l
                             return service.updateLearners(term);
                         }
                     })
-                    .whenComplete((unused, throwable) -> {
-                        if (throwable != null) {
-                            LOG.error("Failed to reset learners", throwable);
-                        }
+                    .exceptionally(e -> {
+                        LOG.warn("Failed to update learners for term {}", e, term);

Review Comment:
   Are we ok with proceeding after a failed update? Should we fail the node?
   
   @sanpwc I would also want to hear your opinion



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -317,6 +337,15 @@ void testNoConfigurationReordering() throws Exception {
         // Wait for the initial cluster reconfiguration to complete.
         assertLearnerSize(2);
 
+        // Same as above, but check the all 5 nodes see the same number of learners (which is 2 actually).

Review Comment:
   ```suggestion
           // Same as above, but check that all 5 nodes see the same number of learners (which is 2 actually).
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -317,6 +337,15 @@ void testNoConfigurationReordering() throws Exception {
         // Wait for the initial cluster reconfiguration to complete.
         assertLearnerSize(2);
 
+        // Same as above, but check the all 5 nodes see the same number of learners (which is 2 actually).
+        assertTrue(waitForCondition(() ->
+                        configs.size() == 5 && configs.values().stream()
+                                .map(list -> list.get(list.size() - 1))
+                                .mapToInt(raftGroupConfiguration -> raftGroupConfiguration.learners().size())
+                                .min().orElseThrow() == 2,

Review Comment:
   It's not the most obvious way to check that every node sees exactly 2 learners. Would it make sense to switch to `allMatch()`?



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -340,60 +369,91 @@ void testNoConfigurationReordering() throws Exception {
             return false;
         });
 
-        logger().info("Stop last node [4].");
-        MockNode last = cluster.remove(cluster.size() - 1);
-        stopNodes(List.of(last));
+        logger().info("Stop the node [4].");
+        MockNode node4 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(node4));
 
-        logger().info("Stop last node [3].");
-        MockNode last2 = cluster.remove(cluster.size() - 1);
-        stopNodes(List.of(last2));
+        logger().info("Stop the node [3].");
+        MockNode node3 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(node3));
 
         // There should be still two learner nodes since the previous reconfiguration was blocked.
         assertLearnerSize(2);
 
+        // The configs will be properly updated when new 3 and 4 are started, so remove the history for the stopped nodes.
+        configs.remove(3);
+        configs.remove(4);
+
         // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
         logger().info("Start nodes [3] and [4].");
-        // Start node 4 first to avoid clashing with the earlier blocked message..
-        startNode(4, 5);
-        startNode(3, 5);
-
-        logger().info("Nodes started.");
+        // Start node 4 first to avoid clashing with the earlier blocked message (as we get ResetLearnersRequest(3)
+        // both when we move from [3, 4] to [3] and when we move from [] to [3]).
+        startNode(4, 5, config ->
+                configs.computeIfAbsent(4, k -> new CopyOnWriteArrayList<>()).add(config)
+        );
+        startNode(3, 5, config ->
+                configs.computeIfAbsent(3, k -> new CopyOnWriteArrayList<>()).add(config)
+        );
 
-        // Waif for the nodes 3 and 4 to start.
+        // Wait for the nodes 3 and 4 to start.
         for (MockNode node : cluster) {
             assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
         }
 
+        logger().info("Nodes started.");
         assertLearnerSize(2);
 
-        for (MockNode node : cluster) {
-            Boolean leader = node.clusterManager().isCmgLeader().get();
-            if (leader) {
-                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
-            }
-        }
-
         // Unblock the first reconfiguration.
         logger().info("Unblock message.");
         blockMessage.set(false);
 
-        assertLearnerSize(2);
+        // Now we need to wait for the reconfiguration to complete.
+        // To check it we will look through the raft configuration history and verify that all nodes have same transition history
+        // with regards to the learner nodes: [] -> [3] -> [3, 4] -> [4] -> [3, 4].
+        // Basically should be enough to check learners size only.
+        int[] count = {0, 1, 2, 1, 2};

Review Comment:
   ```suggestion
           int[] counts = {0, 1, 2, 1, 2};
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2287449565


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -340,60 +369,91 @@ void testNoConfigurationReordering() throws Exception {
             return false;
         });
 
-        logger().info("Stop last node [4].");
-        MockNode last = cluster.remove(cluster.size() - 1);
-        stopNodes(List.of(last));
+        logger().info("Stop the node [4].");
+        MockNode node4 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(node4));
 
-        logger().info("Stop last node [3].");
-        MockNode last2 = cluster.remove(cluster.size() - 1);
-        stopNodes(List.of(last2));
+        logger().info("Stop the node [3].");
+        MockNode node3 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(node3));
 
         // There should be still two learner nodes since the previous reconfiguration was blocked.
         assertLearnerSize(2);
 
+        // The configs will be properly updated when new 3 and 4 are started, so remove the history for the stopped nodes.
+        configs.remove(3);
+        configs.remove(4);
+
         // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
         logger().info("Start nodes [3] and [4].");
-        // Start node 4 first to avoid clashing with the earlier blocked message..
-        startNode(4, 5);
-        startNode(3, 5);
-
-        logger().info("Nodes started.");
+        // Start node 4 first to avoid clashing with the earlier blocked message (as we get ResetLearnersRequest(3)
+        // both when we move from [3, 4] to [3] and when we move from [] to [3]).
+        startNode(4, 5, config ->
+                configs.computeIfAbsent(4, k -> new CopyOnWriteArrayList<>()).add(config)
+        );
+        startNode(3, 5, config ->
+                configs.computeIfAbsent(3, k -> new CopyOnWriteArrayList<>()).add(config)
+        );
 
-        // Waif for the nodes 3 and 4 to start.
+        // Wait for the nodes 3 and 4 to start.
         for (MockNode node : cluster) {
             assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
         }
 
+        logger().info("Nodes started.");
         assertLearnerSize(2);
 
-        for (MockNode node : cluster) {
-            Boolean leader = node.clusterManager().isCmgLeader().get();
-            if (leader) {
-                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
-            }
-        }
-
         // Unblock the first reconfiguration.
         logger().info("Unblock message.");
         blockMessage.set(false);
 
-        assertLearnerSize(2);
+        // Now we need to wait for the reconfiguration to complete.
+        // To check it we will look through the raft configuration history and verify that all nodes have same transition history
+        // with regards to the learner nodes: [] -> [3] -> [3, 4] -> [4] -> [3, 4].
+        // Basically should be enough to check learners size only.
+        int[] count = {0, 1, 2, 1, 2};

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2288195504


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -979,10 +1024,10 @@ private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, l
                             return service.updateLearners(term);
                         }
                     })
-                    .whenComplete((unused, throwable) -> {
-                        if (throwable != null) {
-                            LOG.error("Failed to reset learners", throwable);
-                        }
+                    .exceptionally(e -> {
+                        LOG.warn("Failed to update learners for term {}", e, term);

Review Comment:
   Thank you guys. Feel free to close this discussion



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2283035062


##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java:
##########
@@ -448,7 +447,7 @@ public Ignite startNode(int index) {
      */
     public Ignite startNode(int index, String nodeBootstrapConfigTemplate) {
         ServerRegistration registration = startEmbeddedNode(index, nodeBootstrapConfigTemplate);
-        assertThat("nodeIndex=" + index, registration.registrationFuture(), willSucceedIn(20, SECONDS));
+        assertThat("nodeIndex=" + index, registration.registrationFuture(), willCompleteSuccessfully());

Review Comment:
   Ahh, ok.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2282998742


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java:
##########
@@ -52,21 +53,16 @@ public void handleRequest(final RpcContext rpcCtx, final T request) {
             if (msg != null) {
                 rpcCtx.sendResponse(msg);
             }
+        } catch (NotLeaderException t) {
+            // It is ok if we lost leadership while a request to us was in flight, there is no need to clutter up the log.
+            LOG.debug("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(t.leaderId(), msgFactory, RaftError.EPERM, t.getMessage()));
+        } catch (Throwable t) {
+            LOG.error("handleRequest {} failed", t, request);
+            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT
+                .newResponse(msgFactory, RaftError.UNKNOWN.getNumber(), "handleRequest internal error"));
         }
-        catch (final Throwable t) {
-            if (isIgnorable(t)) {
-                LOG.debug("handleRequest {} failed", t, request);
-            } else {
-                LOG.error("handleRequest {} failed", t, request);
-            }
-            rpcCtx.sendResponse(RaftRpcFactory.DEFAULT //

Review Comment:
   Correct. 
   The return code -1 translates to RaftError.UNKNOWN. What we had were constant retries until sendWithRetry failed with a timeout.
   
   `UNKNOWN` handler looks like:
   ```
   NetworkMessage request = retryContext.request();
   
                   Peer newTargetPeer;
   
                   // If changing peers or requesting a leader and something is not found
                   // probably target peer is doing rebalancing, try another peer.
                   if (request instanceof GetLeaderRequest || request instanceof ChangePeersAndLearnersAsyncRequest) {
                       newTargetPeer = randomNode(retryContext);
                   } else {
                       newTargetPeer = retryContext.targetPeer();
                   }
   
                   scheduleRetry(fut, retryContext.nextAttempt(newTargetPeer, getShortReasonMessage(retryContext, error, resp)));
   
   ```
   
   Since the request I faced this issue with was ResetLearnersRequest, the code always falls into the else branch without changing the target node. 
   And I don't think adding one more request here is a good design.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2282989517


##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java:
##########
@@ -448,7 +447,7 @@ public Ignite startNode(int index) {
      */
     public Ignite startNode(int index, String nodeBootstrapConfigTemplate) {
         ServerRegistration registration = startEmbeddedNode(index, nodeBootstrapConfigTemplate);
-        assertThat("nodeIndex=" + index, registration.registrationFuture(), willSucceedIn(20, SECONDS));
+        assertThat("nodeIndex=" + index, registration.registrationFuture(), willCompleteSuccessfully());

Review Comment:
   `willCompleteSuccessfully()` delegates to 
   ```
   private CompletableFutureMatcher(Matcher<T> matcher) {
       this(matcher, DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
   }
   ```
   and DEFAULT_TIMEOUT_SECONDS=30
   



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2284776705


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());

Review Comment:
   Let's import `Collectors.toList` statically so that it reads `collect(toList())`, close to plain English



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();

Review Comment:
   Why do we need to find the leader explicitly to get learners from CMG? Can't we get them from any node?



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);

Review Comment:
   ```suggestion
           MockNode penult = cluster.remove(cluster.size() - 1);
   ```



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -132,6 +132,12 @@ public class ClusterManagementGroupManager extends AbstractEventProducer<Cluster
     /** Lock for the {@code raftService} field. */
     private final Object raftServiceLock = new Object();
 
+    /** Current updateLearners operation to ensure linearization of updates. */
+    private volatile CompletableFuture<Void> currentUpdateLearners = nullCompletedFuture();

Review Comment:
   `currentUpdateLearners` is always accessed under the corresponding lock, so `volatile` is excessive



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..

Review Comment:
   What kind of a clash is this?



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());

Review Comment:
   ```suggestion
           List<String> votingNodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .mapToInt(node -> {
+                                    try {
+                                        return node.clusterManager().learnerNodes().get().size();

Review Comment:
   ```suggestion
                                           return node.clusterManager().learnerNodes().get(10, SECONDS).size();
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();

Review Comment:
   ```suggestion
                                           return node.clusterManager().isCmgLeader().get(10, SECONDS);
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..

Review Comment:
   ```suggestion
           // Start node 4 first to avoid clashing with the earlier blocked message.
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+
+        assertLearnerSize(2);
+    }
+
+    private void assertLearnerSize(int size) throws InterruptedException {
+        assertTrue(waitForCondition(() ->
+                        cluster.stream()
+                                .filter(node -> {
+                                    try {
+                                        return node.clusterManager().isCmgLeader().get();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .mapToInt(node -> {
+                                    try {
+                                        return node.clusterManager().learnerNodes().get().size();
+                                    } catch (InterruptedException | ExecutionException e) {
+                                        throw new RuntimeException(e);
+                                    }
+                                })
+                                .min().orElseThrow() == size,
+                30_000
+        ));
+    }
+
+    private void blockMessage(BiPredicate<String, NetworkMessage> predicate) {
+        cluster.stream().map(node -> node.clusterService().messagingService()).forEach(msg -> {

Review Comment:
   ```suggestion
           cluster.stream().map(node -> node.clusterService().messagingService()).forEach(messagingService -> {
   ```



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);

Review Comment:
   Should we give the test some time to remove a learner (if the production code works incorrectly and DOES remove a learner)? Otherwise, we might just miss the removal because we check the number of learners immediately after stopping the two nodes.



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -950,23 +956,49 @@ private static RaftNodeId raftNodeId(Peer serverPeer) {
         return new RaftNodeId(CmgGroupId.INSTANCE, serverPeer);
     }
 
+    /**
+     * Serializes calls to updateLearners to prevent race conditions between multiple topology changes
+     * and leader election callbacks.
+     *
+     * @param service CMG Raft service.
+     * @param term RAFT term.
+     * @param checkLeadership Whether to check leadership before updating learners.
+     */
+    private CompletableFuture<Void> updateLearnersSerially(CmgRaftService service, long term, boolean checkLeadership) {
+        synchronized (updateLearnersLock) {
+            currentUpdateLearners = currentUpdateLearners
+                    .thenCompose(v -> {
+                        if (checkLeadership) {
+                            return service.isCurrentNodeLeader().thenCompose(isLeader -> {
+                                if (!isLeader) {
+                                    return nullCompletedFuture();
+                                }
+                                return service.updateLearners(term);
+                            });
+                        } else {
+                            return service.updateLearners(term);
+                        }
+                    })
+                    .whenComplete((unused, throwable) -> {
+                        if (throwable != null) {
+                            LOG.error("Failed to reset learners", throwable);

Review Comment:
   If we have an exception here, all subsequent attempts to update learners will fail with the same exception. Hence, a few points:
   
   1. If we care much about learners set consistency, we should probably call the FailureProcessor here as the learners will not be consistent if one update is failed
   2. If we don't care about learners set consistency (and can just miss an update), we should translate the exception (for example, with `exceptionally()`) to make it possible for subsequent updates to be applied
   3. If we don't translate it and leave the chain forever broken, we should think about only logging the error message + exception just for the first time, noting in the log message that no more learner updates will be applied (like we did in WatchProcessor). The subsequent attempts (which will also fail) should either not log this at all, or just log a brief message, without the exception



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());

Review Comment:
   ```suggestion
                   logger().info("Learner nodes {}", node.clusterManager().learnerNodes().get(10, SECONDS));
   ```



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -281,6 +281,21 @@ private ClusterNodeMessage nodeMessage(ClusterNode node) {
                 .build();
     }
 
+    /**
+     * Returns a known set of consistent IDs of the learners nodes of the CMG.
+     */
+    public CompletableFuture<Set<String>> learners() {
+        List<Peer> currentLearners = raftService.learners();
+
+        if (currentLearners == null) {
+            return raftService.refreshMembers(true).thenCompose(v -> learners());
+        }
+
+        return completedFuture(currentLearners.stream()
+                .map(Peer::consistentId)
+                .collect(toCollection(HashSet::new)));

Review Comment:
   Why is it collected to a `HashMap`?



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();
+            if (leader) {
+                logger().info("lerner nodes {}", node.clusterManager().learnerNodes().get());
+            }
+        }
+
+        // Unblock the first reconfiguration.
+        logger().info("Unblock message.");
+        blockMessage.set(false);
+

Review Comment:
   Again, no time is given to the async message exchanges to be done. Also, this test will pass even if learners cannot be changed at all, right?
   
   It seems to be more reliable to collect all configuration changes and then analyze them.



##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();

Review Comment:
   ```suggestion
               Boolean leader = node.clusterManager().isCmgLeader().get(10, SECONDS);
   ```



##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java:
##########
@@ -52,21 +53,16 @@ public void handleRequest(final RpcContext rpcCtx, final T request) {
             if (msg != null) {
                 rpcCtx.sendResponse(msg);
             }
+        } catch (NotLeaderException t) {

Review Comment:
   Is this fix required for this CMG learner updates linearization? If not, would it make sense to split it out to another PR? It, by itself, looks like an important fix, and it will be weird to see it squashed into an unrelated change.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


Re: [PR] IGNITE-22818 Fix cmg reordering [ignite-3]

Posted by "Cyrill (via GitHub)" <gi...@apache.org>.
Cyrill commented on code in PR #6408:
URL: https://github.com/apache/ignite-3/pull/6408#discussion_r2285229437


##########
modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java:
##########
@@ -290,6 +296,126 @@ void testInitInvalidNodesAsync() throws Exception {
         );
     }
 
+    @Test
+    void testNoConfigurationReordering() throws Exception {
+        startCluster(5);
+
+        ClusterManagementGroupManager clusterManager = cluster.get(0).clusterManager();
+
+        List<String> nodes = cluster.stream().map(MockNode::name).limit(3).collect(Collectors.toList());
+
+        // successful init
+        assertThat(
+                clusterManager.initClusterAsync(nodes, List.of(), "cluster"),
+                willCompleteSuccessfully()
+        );
+
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        // Wait for the initial cluster reconfiguration to complete.
+        assertLearnerSize(2);
+
+        String node3Name = cluster.get(3).name();
+
+        AtomicBoolean blockMessage = new AtomicBoolean(true);
+
+        // Block the first reconfiguration to simulate network issues.
+        // We stop node 4, that should produce a ResetLearnersRequest with only one learner - node 3.
+        blockMessage((recipientName, networkMessage) -> {
+            if (!blockMessage.get()) {
+                return false;
+            }
+
+            if (networkMessage instanceof ResetLearnersRequest) {
+                ResetLearnersRequest rlr = (ResetLearnersRequest) networkMessage;
+
+                if (rlr.learnersList().contains(node3Name) &&  rlr.learnersList().size() == 1) {
+                    logger().info("Block message {} to {}", networkMessage, recipientName);
+                    return true;
+                }
+            }
+
+            return false;
+        });
+
+        logger().info("Stop last node [4].");
+        MockNode last = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last));
+
+        logger().info("Stop last node [3].");
+        MockNode last2 = cluster.remove(cluster.size() - 1);
+        stopNodes(List.of(last2));
+
+        // There should be still two learner nodes since the previous reconfiguration was blocked.
+        assertLearnerSize(2);
+
+        // Start nodes 3 and 4 back, so that the topology is back to normal and no node availability issues are expected.
+        logger().info("Start nodes [3] and [4].");
+        // Start node 4 first to avoid clashing with the earlier blocked message..
+        startNode(4, 5);
+        startNode(3, 5);
+
+        logger().info("Nodes started.");
+
+        // Waif for the nodes 3 and 4 to start.
+        for (MockNode node : cluster) {
+            assertThat(node.clusterManager().joinFuture(), willCompleteSuccessfully());
+        }
+
+        assertLearnerSize(2);
+
+        for (MockNode node : cluster) {
+            Boolean leader = node.clusterManager().isCmgLeader().get();

Review Comment:
   fixed



-- 
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: notifications-unsubscribe@ignite.apache.org

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