Precalculate avgShardsPerNode

This commit is contained in:
Yannick Welsch 2015-12-28 10:04:57 +01:00
parent 507bb11345
commit 0fd19008b1
1 changed files with 3 additions and 1 deletions

View File

@ -228,6 +228,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
private final float threshold;
private final MetaData metaData;
private final float avgShardsPerNode;
private final Predicate<ShardRouting> assignedFilter = shard -> shard.assignedToNode();
@ -241,6 +242,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
nodes.put(node.nodeId(), new ModelNode(node.nodeId()));
}
metaData = routingNodes.metaData();
avgShardsPerNode = ((float) metaData.totalNumberOfShards()) / nodes.size();
}
/**
@ -261,7 +263,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
* Returns the global average of shards per node
*/
public float avgShardsPerNode() {
return ((float) metaData.totalNumberOfShards()) / nodes.size();
return avgShardsPerNode;
}
/**