From 1e84c439e593999ae148a459e560380f59ca7124 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 14 Apr 2011 15:00:54 +0300 Subject: [PATCH] Shard Allocation: Closed indices are not properly taken into account when rebalancing, closes #858. --- .../elasticsearch/cluster/routing/RoutingNodes.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 6f51e058b99..5c84673400c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.util.concurrent.NotThreadSafe; @@ -113,7 +114,14 @@ public class RoutingNodes implements Iterable { } public int requiredAverageNumberOfShardsPerNode() { - return metaData.totalNumberOfShards() / nodesToShards.size(); + int totalNumberOfShards = 0; + // we need to recompute to take closed shards into account + for (IndexMetaData indexMetaData : metaData.indices().values()) { + if (indexMetaData.state() == IndexMetaData.State.OPEN) { + totalNumberOfShards += indexMetaData.totalNumberOfShards(); + } + } + return totalNumberOfShards / nodesToShards.size(); } public boolean hasUnassigned() {