elastic/elasticsearch · error · TestClustersException
Ran out of nodes to take to the next version
Error message
Ran out of nodes to take to the next version
What it means
Thrown by ElasticsearchCluster.nextNodeToNextVersion when nodeIndex + 1 exceeds the cluster's node count. nextNodeToNextVersion rolls nodes one at a time to the next version during rolling-upgrade BWC tests; once every node has been advanced, there are no more to advance.
Source
Thrown at build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java:491
}
}
}
@Override
public void restart() {
nodes.forEach(ElasticsearchNode::restart);
}
public void goToNextVersion() {
stop(false);
nodes.all(ElasticsearchNode::goToNextVersion);
start();
writeUnicastHostsFiles();
}
public void nextNodeToNextVersion() {
if (nodeIndex + 1 > nodes.size()) {
throw new TestClustersException("Ran out of nodes to take to the next version");
}
ElasticsearchNode node = nodes.getByName(clusterName + "-" + nodeIndex);
node.stop(false);
node.goToNextVersion();
commonNodeConfig();
nodeIndex += 1;
if (node.getTestDistribution().equals(TestDistribution.DEFAULT)) {
if (hasDeprecationIndexing(node)) {
node.setting("cluster.deprecation_indexing.enabled", "false");
}
}
node.start();
}
private static boolean hasDeprecationIndexing(ElasticsearchNode node) {
return node.getVersion().onOrAfter("7.16.0") && node.getSettingKeys().contains("stateless.enabled") == false;
}
View on GitHub (pinned to db6a809a66)
Solutions
- Guard the loop: `while (cluster.nodeIndex < cluster.nodes.size()) cluster.nextNodeToNextVersion()`.
- Ensure the cluster's numberOfNodes matches the number of rolling steps the test performs.
- If using nextNodeToNextVersion in a parameterized test, cap iterations at nodes.size().
Example fix
// before
for (int i = 0; i < 5; i++) {
cluster.nextNodeToNextVersion(); // throws when i exceeds node count
}
// after
while (cluster.getNodes().size() > 0 && cluster.nodeIndex < cluster.getNodes().size()) {
cluster.nextNodeToNextVersion();
} Defensive patterns
Strategy: validation
Validate before calling
while (cluster.getNodes().size() > 0
&& cluster.nodeIndex < cluster.getNodes().size()) {
cluster.nextNodeToNextVersion();
} Prevention
- Cap rolling iterations at the node count, not a hardcoded constant.
- Sync the cluster's numberOfNodes with the test's expected rolling steps.
- Add an assertion before the loop: nodeCount == rollingStepCount.
When it happens
Trigger: Calling nextNodeToNextVersion() more times than there are nodes in the cluster (each call increments nodeIndex and stops at nodes.size()).
Common situations: A rolling-upgrade test loop iterates one step too many, or the node count was reduced after the loop bound was computed. Also when an upgrade test assumes N nodes but the cluster has fewer.
Related errors
- Number of nodes should be >= 1 but was {} for {}
- Cannot shrink {} to have {} nodes as it already has {}
- Can't treat {} as single node as it has {} nodes
- unrecognized classpath entry: {}
- Cannot add nodes to test cluster after is has been frozen
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/3da7dddf17071b26.
Report an issue: GitHub.