From 166247f2abab1104ba043d2907638e5f6f4f968b Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 21 Nov 2022 16:17:33 +0000 Subject: [PATCH] Skip ancient closed indices in desired balance (#91765) (#91768) This assertion fails in the presence of pre-7.2.0 closed indices because such indices don't even have routing table entries. Relates #33888 Closes #91470 --- .../allocator/DesiredBalanceReconciler.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java index 6bf0ed8eeba05..19a388964feab 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java @@ -11,6 +11,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.ArrayUtil; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.metadata.MetadataIndexStateService; import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RoutingNode; @@ -95,8 +98,11 @@ private boolean allocateUnassignedInvariant() { assert routingNodes.unassigned().isEmpty(); - final var shardCounts = allocation.metadata() - .stream() + final var shardCounts = allocation.metadata().stream().filter(indexMetadata -> + // skip any pre-7.2 closed indices which have no routing table entries at all + indexMetadata.getCreationVersion().onOrAfter(Version.V_7_2_0) + || indexMetadata.getState() == IndexMetadata.State.OPEN + || MetadataIndexStateService.isIndexVerifiedBeforeClosed(indexMetadata)) .flatMap( indexMetadata -> IntStream.range(0, indexMetadata.getNumberOfShards()) .mapToObj( @@ -151,7 +157,7 @@ private void failAllocationOfNewPrimaries(RoutingAllocation allocation) { private void allocateUnassigned() { RoutingNodes.UnassignedShards unassigned = routingNodes.unassigned(); if (logger.isTraceEnabled()) { - logger.trace("Start allocating unassigned shards"); + logger.trace("Start allocating unassigned shards: {}", routingNodes.toString()); } if (unassigned.isEmpty()) { return;