Module org.elasticsearch.server
Class BalancedShardsAllocator.NodeSorter
java.lang.Object
org.apache.lucene.util.Sorter
org.apache.lucene.util.IntroSorter
org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.NodeSorter
- Enclosing class:
BalancedShardsAllocator
public static final class BalancedShardsAllocator.NodeSorter
extends org.apache.lucene.util.IntroSorter
A NodeSorter sorts the set of nodes for a single partition using the
WeightFunction
for that partition. In partitioned cluster topologies there will be one for each partition
(e.g. search/indexing in stateless). By default, there is a single partition containing
a single weight function that applies to all nodes and shards.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionNodeSorter(BalancedShardsAllocator.ModelNode[] modelNodes, WeightFunction function, BalancedShardsAllocator.Balancer balancer, float threshold) -
Method Summary
Modifier and TypeMethodDescriptionprotected intcompare(int i, int j) protected intcomparePivot(int j) floatdelta()floatfloatvoidrecalculateWeightsAndReSort(int... nodeIndices) Recalculate the weights of the nodes at the specified indices, incrementing the invalid count if any become invalid.voidvoidreset(BalancedShardsAllocator.ProjectIndex index, int to) Resets the sorter, recalculates the weights per node and sorts the nodes by weight, with minimal weight first.protected voidsetPivot(int i) protected voidswap(int i, int j) intIf the weight function returns an invalid weight (seeBalancedShardsAllocator.nodeWeightIsInvalid(float)).Methods inherited from class org.apache.lucene.util.IntroSorter
sort
-
Constructor Details
-
NodeSorter
public NodeSorter(BalancedShardsAllocator.ModelNode[] modelNodes, WeightFunction function, BalancedShardsAllocator.Balancer balancer, float threshold)
-
-
Method Details
-
validSortedCount
public int validSortedCount()If the weight function returns an invalid weight (seeBalancedShardsAllocator.nodeWeightIsInvalid(float)). We default the weight toFloat.MAX_VALUE. This method returns the number of nodes that returned valid weights last timereset(ProjectIndex)orreset(ProjectIndex, int)was called. This allows iteration of only those nodes that returned valid weights.- Returns:
- The count of nodes that returned valid weights the last time reset was called
-
reset
Resets the sorter, recalculates the weights per node and sorts the nodes by weight, with minimal weight first. -
recalculateWeightsAndReSort
public void recalculateWeightsAndReSort(int... nodeIndices) Recalculate the weights of the nodes at the specified indices, incrementing the invalid count if any become invalid.- Parameters:
nodeIndices- The indices of the nodes whose weights should be recalculated
-
reset
-
minWeightDelta
public float minWeightDelta() -
swap
protected void swap(int i, int j) - Specified by:
swapin classorg.apache.lucene.util.Sorter
-
compare
protected int compare(int i, int j) - Overrides:
comparein classorg.apache.lucene.util.IntroSorter
-
setPivot
protected void setPivot(int i) - Specified by:
setPivotin classorg.apache.lucene.util.IntroSorter
-
comparePivot
protected int comparePivot(int j) - Specified by:
comparePivotin classorg.apache.lucene.util.IntroSorter
-
delta
public float delta() -
getWeightFunction
-
getThreshold
public float getThreshold()
-