Shard Allocation: Closed indices are not properly taken into account when rebalancing, closes #858.

This commit is contained in:
kimchy 2011-04-14 15:00:54 +03:00
parent 7550fc570e
commit 1e84c439e5
1 changed files with 9 additions and 1 deletions

View File

@ -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<RoutingNode> {
}
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() {