Skip to content

Commit

Permalink
Skip ancient closed indices in desired balance (#91765) (#91768)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DaveCTurner authored Nov 21, 2022
1 parent 4eeb574 commit 166247f
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 166247f

Please sign in to comment.