Skip to content

Commit 1c9a39c

Browse files
authored
Skip ancient closed indices in desired balance (elastic#91765)
This assertion fails in the presence of pre-7.2.0 closed indices because such indices don't even have routing table entries. Relates elastic#33888 Closes elastic#91470
1 parent 642a77f commit 1c9a39c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
1313
import org.apache.lucene.util.ArrayUtil;
14+
import org.elasticsearch.Version;
15+
import org.elasticsearch.cluster.metadata.IndexMetadata;
16+
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
1417
import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata;
1518
import org.elasticsearch.cluster.node.DiscoveryNode;
1619
import org.elasticsearch.cluster.routing.RoutingNode;
@@ -95,8 +98,11 @@ private boolean allocateUnassignedInvariant() {
9598

9699
assert routingNodes.unassigned().isEmpty();
97100

98-
final var shardCounts = allocation.metadata()
99-
.stream()
101+
final var shardCounts = allocation.metadata().stream().filter(indexMetadata ->
102+
// skip any pre-7.2 closed indices which have no routing table entries at all
103+
indexMetadata.getCreationVersion().onOrAfter(Version.V_7_2_0)
104+
|| indexMetadata.getState() == IndexMetadata.State.OPEN
105+
|| MetadataIndexStateService.isIndexVerifiedBeforeClosed(indexMetadata))
100106
.flatMap(
101107
indexMetadata -> IntStream.range(0, indexMetadata.getNumberOfShards())
102108
.mapToObj(
@@ -151,7 +157,7 @@ private void failAllocationOfNewPrimaries(RoutingAllocation allocation) {
151157
private void allocateUnassigned() {
152158
RoutingNodes.UnassignedShards unassigned = routingNodes.unassigned();
153159
if (logger.isTraceEnabled()) {
154-
logger.trace("Start allocating unassigned shards");
160+
logger.trace("Start allocating unassigned shards: {}", routingNodes.toString());
155161
}
156162
if (unassigned.isEmpty()) {
157163
return;

0 commit comments

Comments
 (0)