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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org