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

[GitHub] [ignite-3] sashapolo commented on a diff in pull request #2152: IGNITE-19522 Modify deploy unit command

sashapolo commented on code in PR #2152:
URL: https://github.com/apache/ignite-3/pull/2152#discussion_r1226309820


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -228,6 +228,38 @@ public Set<String> nodeNames() {
                 .collect(toSet());
     }
 
+    /**
+     * Returns a set of consistent IDs of the majority of the voting nodes of the CMG, including a leader.
+     *
+     * @return Set of consistent IDs of the majority of the voting nodes of the CMG, including a leader.
+     */
+    public CompletableFuture<Set<String>> majority() {
+        Peer leader = raftService.leader();
+
+        if (leader == null) {
+            return raftService.refreshLeader().thenCompose(v -> majority());
+        }
+
+        List<Peer> peers = raftService.peers();
+
+        assert peers != null;
+
+        int peersCount = peers.size();
+        String leaderId = leader.consistentId();
+
+        // Take half of the voting peers without the leader.
+        Set<String> result = peers.stream()
+                .map(Peer::consistentId)
+                .filter(consistentId -> !consistentId.equals(leaderId))
+                .limit(peersCount / 2)
+                .collect(toSet());

Review Comment:
   Also, why is it a set and not a list? 



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/CmgRaftService.java:
##########
@@ -228,6 +228,38 @@ public Set<String> nodeNames() {
                 .collect(toSet());
     }
 
+    /**
+     * Returns a set of consistent IDs of the majority of the voting nodes of the CMG, including a leader.
+     *
+     * @return Set of consistent IDs of the majority of the voting nodes of the CMG, including a leader.
+     */
+    public CompletableFuture<Set<String>> majority() {
+        Peer leader = raftService.leader();
+
+        if (leader == null) {
+            return raftService.refreshLeader().thenCompose(v -> majority());
+        }
+
+        List<Peer> peers = raftService.peers();
+
+        assert peers != null;
+
+        int peersCount = peers.size();
+        String leaderId = leader.consistentId();
+
+        // Take half of the voting peers without the leader.
+        Set<String> result = peers.stream()
+                .map(Peer::consistentId)
+                .filter(consistentId -> !consistentId.equals(leaderId))
+                .limit(peersCount / 2)
+                .collect(toSet());

Review Comment:
   It is generally a bad idea to modify a set, returned by `toSet()`, there's no guarantee on its mutability



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