Skip to content

Commit b9d0241

Browse files
committed
PartitionedNodeSorter -> NodeSorters
1 parent bfdc214 commit b9d0241

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public static class Balancer {
248248
private final double avgDiskUsageInBytesPerNode;
249249
private final Map<String, ModelNode> nodes;
250250
private final BalancingWeights balancingWeights;
251-
private final PartitionedNodeSorter partitionedNodeSorter;
251+
private final NodeSorters nodeSorters;
252252

253253
private Balancer(
254254
WriteLoadForecaster writeLoadForecaster,
@@ -265,8 +265,8 @@ private Balancer(
265265
avgWriteLoadPerNode = WeightFunction.avgWriteLoadPerNode(writeLoadForecaster, metadata, routingNodes);
266266
avgDiskUsageInBytesPerNode = WeightFunction.avgDiskUsageInBytesPerNode(allocation.clusterInfo(), metadata, routingNodes);
267267
nodes = Collections.unmodifiableMap(buildModelFromAssigned());
268+
this.nodeSorters = balancingWeights.createNodeSorters(nodesArray(), this);
268269
this.balancingWeights = balancingWeights;
269-
this.partitionedNodeSorter = balancingWeights.createPartitionedNodeSorter(nodesArray(), this);
270270
}
271271

272272
private static long getShardDiskUsageInBytes(ShardRouting shardRouting, IndexMetadata indexMetadata, ClusterInfo clusterInfo) {
@@ -384,7 +384,7 @@ private void balance() {
384384
}
385385

386386
// Balance each partition
387-
for (NodeSorter nodeSorter : partitionedNodeSorter.allNodeSorters()) {
387+
for (NodeSorter nodeSorter : nodeSorters.allNodeSorters()) {
388388
balanceByWeights(nodeSorter);
389389
}
390390
}
@@ -395,7 +395,7 @@ private void balance() {
395395
* explain API only.
396396
*/
397397
private MoveDecision decideRebalance(final ProjectIndex index, final ShardRouting shard, Decision canRemain) {
398-
final NodeSorter sorter = partitionedNodeSorter.sorterForShard(shard);
398+
final NodeSorter sorter = nodeSorters.sorterForShard(shard);
399399
index.assertMatch(shard);
400400
if (shard.started() == false) {
401401
// we can only rebalance started shards
@@ -765,7 +765,7 @@ public void moveShards() {
765765
* {@link MoveDecision#getNodeDecisions} will have a non-null value.
766766
*/
767767
public MoveDecision decideMove(final ProjectIndex index, final ShardRouting shardRouting) {
768-
NodeSorter sorter = partitionedNodeSorter.sorterForShard(shardRouting);
768+
NodeSorter sorter = nodeSorters.sorterForShard(shardRouting);
769769
index.assertMatch(shardRouting);
770770

771771
if (shardRouting.started() == false) {

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancingWeights.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ public interface BalancingWeights {
3535
WeightFunction weightFunctionForNode(RoutingNode node);
3636

3737
/**
38-
* Create a partitioned node sorter for the cluster
38+
* Create the node sorters for the cluster
3939
*
4040
* @param modelNodes The full set of cluster nodes
4141
* @param balancer The balancer
42-
* @return a {@link PartitionedNodeSorter}
42+
* @return a {@link NodeSorters} instance
4343
*/
44-
PartitionedNodeSorter createPartitionedNodeSorter(
45-
BalancedShardsAllocator.ModelNode[] modelNodes,
46-
BalancedShardsAllocator.Balancer balancer
47-
);
44+
NodeSorters createNodeSorters(BalancedShardsAllocator.ModelNode[] modelNodes, BalancedShardsAllocator.Balancer balancer);
4845
}

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/GlobalBalancingWeightsFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ public WeightFunction weightFunctionForNode(RoutingNode node) {
5151
return weightFunction;
5252
}
5353

54-
public PartitionedNodeSorter createPartitionedNodeSorter(
55-
BalancedShardsAllocator.ModelNode[] modelNodes,
56-
BalancedShardsAllocator.Balancer balancer
57-
) {
58-
return new GlobalPartitionedNodeSorter(new BalancedShardsAllocator.NodeSorter(modelNodes, weightFunction, balancer));
54+
@Override
55+
public NodeSorters createNodeSorters(BalancedShardsAllocator.ModelNode[] modelNodes, BalancedShardsAllocator.Balancer balancer) {
56+
return new GlobalNodeSorters(new BalancedShardsAllocator.NodeSorter(modelNodes, weightFunction, balancer));
5957
}
6058

61-
private record GlobalPartitionedNodeSorter(BalancedShardsAllocator.NodeSorter nodeSorter) implements PartitionedNodeSorter {
59+
private record GlobalNodeSorters(BalancedShardsAllocator.NodeSorter nodeSorter) implements NodeSorters {
6260

6361
@Override
6462
public Collection<BalancedShardsAllocator.NodeSorter> allNodeSorters() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import java.util.Collection;
1515

1616
/**
17-
* Partitioned node sorter is just a cache of
17+
* NodeSorters is just a cache of
1818
* {@link org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.NodeSorter}
1919
* instances for each cluster partition
2020
*/
21-
public interface PartitionedNodeSorter {
21+
public interface NodeSorters {
2222

2323
/**
2424
* Get the {@link BalancedShardsAllocator.NodeSorter}s for all partitions

0 commit comments

Comments
 (0)