You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2023/11/14 07:57:52 UTC

(ignite-3) branch main updated: IGNITE-20831 Make all nodes SWIM seeds in Cluster.startAndInit()

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

sergeychugunov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 8dc319f2cf IGNITE-20831 Make all nodes SWIM seeds in Cluster.startAndInit()
8dc319f2cf is described below

commit 8dc319f2cf3d983ae632b258d068a99726917e5b
Author: Roman Puchkovskiy <ro...@gmail.com>
AuthorDate: Tue Nov 14 11:54:10 2023 +0400

    IGNITE-20831 Make all nodes SWIM seeds in Cluster.startAndInit()
    
    Signed-off-by: Sergey Chugunov <se...@gmail.com>
---
 .../java/org/apache/ignite/internal/Cluster.java     | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
index 58a03e8987..f69509742c 100644
--- a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
+++ b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal;
 
+import static java.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.toList;
 import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
 import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
@@ -87,8 +88,6 @@ public class Cluster {
 
     private static final int BASE_HTTPS_PORT = 10400;
 
-    private static final String CONNECT_NODE_ADDR = "\"localhost:" + BASE_PORT + '\"';
-
     /** Timeout for SQL queries (in milliseconds). */
     private static final int QUERY_TIMEOUT_MS = 10_000;
 
@@ -120,6 +119,9 @@ public class Cluster {
 
     private volatile boolean stopped = false;
 
+    /** Number of nodes in the cluster on first startAndInit() [if it was invoked]. */
+    private volatile int initialClusterSize;
+
     /** Indices of nodes that have been knocked out. */
     private final Set<Integer> knockedOutNodesIndices = new ConcurrentHashSet<>();
 
@@ -209,6 +211,8 @@ public class Cluster {
             throw new IllegalStateException("The cluster is already started");
         }
 
+        initialClusterSize = nodeCount;
+
         List<CompletableFuture<IgniteImpl>> futures = IntStream.range(0, nodeCount)
                 .mapToObj(nodeIndex -> startNodeAsync(nodeIndex, nodeBootstrapConfigTemplate))
                 .collect(toList());
@@ -254,7 +258,7 @@ public class Cluster {
         String config = IgniteStringFormatter.format(
                 nodeBootstrapConfigTemplate,
                 BASE_PORT + nodeIndex,
-                CONNECT_NODE_ADDR,
+                seedAddressesString(),
                 BASE_CLIENT_PORT + nodeIndex,
                 BASE_HTTP_PORT + nodeIndex,
                 BASE_HTTPS_PORT + nodeIndex
@@ -285,6 +289,16 @@ public class Cluster {
                 });
     }
 
+    private String seedAddressesString() {
+        // We do this maxing because in some scenarios startAndInit() is not invoked, instead startNode() is used directly.
+        int seedsCount = Math.max(Math.max(initialClusterSize, nodes.size()), 1);
+
+        return IntStream.range(0, seedsCount)
+                .map(index -> BASE_PORT + index)
+                .mapToObj(port -> "\"localhost:" + port + '\"')
+                .collect(joining(", "));
+    }
+
     /**
      * Returns an Ignite node (a member of the cluster) by its index.
      */