I’m setting up a two-node Apache Ignite 3 cluster programmatically in a Spring Boot app, but I’m facing issues with initialization and client connectivity. The server starts with localhost, but the client times out, and the cluster doesn’t stabilize. Seeking help from those who’ve done this successfully.
Context
Application: Spring Boot 3.4.8, Spring 6.2.9, Java 17.0.12, macOS.
Ignite Version: 3.0.0.
Goal: Two-node cluster (Ignite3ClusterNode1, Ignite3ClusterNode2) for a Person entity with SQL CRUD operations.
Approach: Programmatic initialization instead of CLI.
@Configuration
public class IgniteConfig {
private static final Logger LOG = LoggerFactory.getLogger(IgniteConfig.class);
@Bean
public IgniteServer igniteServer(@Value("${ignite.instance:1}") String instance) {
String configPath = "ignite-config-" + instance + ".yml";
String nodeName = "Ignite3ClusterNode" + instance;
IgniteServer node = IgniteServer.start(
nodeName,
Paths.get("src/main/resources/" + configPath),
Paths.get("target/ignite-work-" + instance)
);
LOG.info("Ignite server started successfully on node {}.", nodeName);
if ("1".equals(instance)) {
int maxRetries = 15;
int retryDelayMillis = 5000;
boolean initialized = false;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
try {
LOG.info("Attempt {} to initialize cluster...", attempt);
InitParameters initParams = InitParameters.builder()
.clusterName("ignite3Cluster")
.metaStorageNodeNames("Ignite3ClusterNode1", "Ignite3ClusterNode2")
.build();
node.initCluster(initParams);
LOG.info("Cluster initialized successfully on attempt {}.", attempt);
initialized = true;
break;
} catch (Exception e) {
LOG.warn("Cluster initialization attempt {} failed: {}. Full stack trace: {}", attempt, e.getMessage(), getStackTrace(e));
}
try {
Thread.sleep(retryDelayMillis);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException("Cluster init retry interrupted", ie);
}
}
if (!initialized) {
LOG.error("Failed to initialize cluster after {} attempts.", maxRetries);
throw new IllegalStateException("Failed to initialize cluster after " + maxRetries + " attempts.");
}
}
return node;
}
@Bean
public IgniteClient igniteClient(@Value("${ignite.instance:1}") String instance) {
String endpoint = "localhost:" + (instance.equals("1") ? "10800" : "10801");
IgniteClientConfiguration cfg = IgniteClientConfiguration.builder()
.endpoints(endpoint)
.reconnectThrottlingPeriod(5000)
.connectTimeout(10000)
.build();
int maxRetries = 12;
long retryDelayMs = 5000;
Exception lastException = null;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
try {
IgniteClient client = IgniteClient.builder()
.configuration(cfg)
.build();
LOG.info("Ignite client connected successfully to {} on attempt {}.", endpoint, attempt);
return client;
} catch (Exception e) {
lastException = e;
LOG.warn("Attempt {} to connect Ignite client to {} failed: {}. Retrying...", attempt, endpoint, e.getMessage());
if (attempt < maxRetries) {
try {
Thread.sleep(retryDelayMs);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException("Client connection retry interrupted", ie);
}
}
}
}
throw new IllegalStateException("Failed to connect Ignite client to " + endpoint + " after " + maxRetries + " attempts", lastException);
}
private String getStackTrace(Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
}
ignite-config-1.yml:
network:
port: 3344
membership:
syncTimeout: 10000
nodeFinder:
netClusterNodes: [ "localhost:3344", "localhost:3345" ]
client:
connector:
port: 10800
instance-config-2.yml :
network:
port: 3345
membership:
syncTimeout: 10000
nodeFinder:
netClusterNodes: [ "localhost:3344", "localhost:3345" ]
client:
connector:
port: 10801
----------
Startup Commands:
Instance 1: java -Dignite.node-name=Ignite3ClusterNode1 -Dignite.config-path=ignite-config-1.yml -Dignite.endpoint=localhost:10800 -Dignite.instance=1 -jar state-event-app.jar
Instance 2: java -Dignite.node-name=Ignite3ClusterNode2 -Dignite.config-path=ignite-config-2.yml -Dignite.endpoint=localhost:10801 -Dignite.instance=2 -jar state-event-app.jar
Question :
Has anyone successfully set up a two-node Apache Ignite 3 cluster with Spring Boot?
What might be causing the logical topology to fail and the client to time out?
If I comment out cluster initiation in the code and just start the servers, then at least I can see the physical topology from CLI command, however, when I cluster it from the CLI its says successful but actually not forming a cluster anyway. My main goal is to have Ignite Startup and clustering happening within the application itself, rather than clustering it CLI.
Should I adjust the
nodeFinderconfiguration (e.g., use IP instead of localhost despite server start failure), delay client initialization further, or is there a known issue with Ignite 3 clustering in this setup?
Any working examples or configuration tweaks would be greatly appreciated!