Skip to content

Commit f36bfd5

Browse files
committed
Different approach at allowing separate weights per tier
1 parent 58c8f4a commit f36bfd5

File tree

11 files changed

+422
-94
lines changed

11 files changed

+422
-94
lines changed

server/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
import org.elasticsearch.cluster.routing.allocation.NodeAllocationStatsAndWeightsCalculator;
3838
import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster;
3939
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
40+
import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings;
4041
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator;
4142
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator.DesiredBalanceReconcilerAction;
43+
import org.elasticsearch.cluster.routing.allocation.allocator.GlobalNodeSorterFactory;
44+
import org.elasticsearch.cluster.routing.allocation.allocator.NodeSorterFactory;
4245
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
4346
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider;
4447
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
@@ -145,13 +148,12 @@ public ClusterModule(
145148
this.clusterPlugins = clusterPlugins;
146149
this.deciderList = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins);
147150
this.allocationDeciders = new AllocationDeciders(deciderList);
148-
var nodeAllocationStatsAndWeightsCalculator = new NodeAllocationStatsAndWeightsCalculator(
149-
writeLoadForecaster,
150-
clusterService.getClusterSettings()
151-
);
151+
final BalancerSettings balancerSettings = new BalancerSettings(clusterService.getClusterSettings());
152+
var nodeAllocationStatsAndWeightsCalculator = new NodeAllocationStatsAndWeightsCalculator(writeLoadForecaster, balancerSettings);
152153
this.shardsAllocator = createShardsAllocator(
153154
settings,
154155
clusterService.getClusterSettings(),
156+
balancerSettings,
155157
threadPool,
156158
clusterPlugins,
157159
clusterService,
@@ -440,6 +442,7 @@ private static void addAllocationDecider(Map<Class<?>, AllocationDecider> decide
440442
private static ShardsAllocator createShardsAllocator(
441443
Settings settings,
442444
ClusterSettings clusterSettings,
445+
BalancerSettings balancerSettings,
443446
ThreadPool threadPool,
444447
List<ClusterPlugin> clusterPlugins,
445448
ClusterService clusterService,
@@ -449,12 +452,13 @@ private static ShardsAllocator createShardsAllocator(
449452
NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator
450453
) {
451454
Map<String, Supplier<ShardsAllocator>> allocators = new HashMap<>();
452-
allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(clusterSettings, writeLoadForecaster));
455+
final NodeSorterFactory nodeSorterFactory = new GlobalNodeSorterFactory(balancerSettings);
456+
allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(balancerSettings, writeLoadForecaster, nodeSorterFactory));
453457
allocators.put(
454458
DESIRED_BALANCE_ALLOCATOR,
455459
() -> new DesiredBalanceShardsAllocator(
456460
clusterSettings,
457-
new BalancedShardsAllocator(clusterSettings, writeLoadForecaster),
461+
new BalancedShardsAllocator(balancerSettings, writeLoadForecaster, nodeSorterFactory),
458462
threadPool,
459463
clusterService,
460464
reconciler,

server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocationStatsAndWeightsCalculator.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
import org.elasticsearch.cluster.routing.RoutingNode;
1616
import org.elasticsearch.cluster.routing.RoutingNodes;
1717
import org.elasticsearch.cluster.routing.ShardRouting;
18-
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
18+
import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings;
1919
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalance;
2020
import org.elasticsearch.cluster.routing.allocation.allocator.WeightFunction;
21-
import org.elasticsearch.common.settings.ClusterSettings;
2221
import org.elasticsearch.common.util.Maps;
2322
import org.elasticsearch.core.Nullable;
2423

@@ -30,10 +29,7 @@
3029
public class NodeAllocationStatsAndWeightsCalculator {
3130
private final WriteLoadForecaster writeLoadForecaster;
3231

33-
private volatile float indexBalanceFactor;
34-
private volatile float shardBalanceFactor;
35-
private volatile float writeLoadBalanceFactor;
36-
private volatile float diskUsageBalanceFactor;
32+
private final BalancerSettings balancerSettings;
3733

3834
/**
3935
* Node shard allocation stats and the total node weight.
@@ -47,18 +43,9 @@ public record NodeAllocationStatsAndWeight(
4743
float currentNodeWeight
4844
) {}
4945

50-
public NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster writeLoadForecaster, ClusterSettings clusterSettings) {
46+
public NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster writeLoadForecaster, BalancerSettings balancerSettings) {
5147
this.writeLoadForecaster = writeLoadForecaster;
52-
clusterSettings.initializeAndWatch(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, value -> this.shardBalanceFactor = value);
53-
clusterSettings.initializeAndWatch(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, value -> this.indexBalanceFactor = value);
54-
clusterSettings.initializeAndWatch(
55-
BalancedShardsAllocator.WRITE_LOAD_BALANCE_FACTOR_SETTING,
56-
value -> this.writeLoadBalanceFactor = value
57-
);
58-
clusterSettings.initializeAndWatch(
59-
BalancedShardsAllocator.DISK_USAGE_BALANCE_FACTOR_SETTING,
60-
value -> this.diskUsageBalanceFactor = value
61-
);
48+
this.balancerSettings = balancerSettings;
6249
}
6350

6451
/**
@@ -74,7 +61,12 @@ public Map<String, NodeAllocationStatsAndWeight> nodesAllocationStatsAndWeights(
7461
// must not use licensed features when just starting up
7562
writeLoadForecaster.refreshLicense();
7663
}
77-
var weightFunction = new WeightFunction(shardBalanceFactor, indexBalanceFactor, writeLoadBalanceFactor, diskUsageBalanceFactor);
64+
var weightFunction = new WeightFunction(
65+
balancerSettings.getShardBalanceFactor(),
66+
balancerSettings.getIndexBalanceFactor(),
67+
balancerSettings.getWriteLoadBalanceFactor(),
68+
balancerSettings.getDiskUsageBalanceFactor()
69+
);
7870
var avgShardsPerNode = WeightFunction.avgShardPerNode(metadata, routingNodes);
7971
var avgWriteLoadPerNode = WeightFunction.avgWriteLoadPerNode(writeLoadForecaster, metadata, routingNodes);
8072
var avgDiskUsageInBytesPerNode = WeightFunction.avgDiskUsageInBytesPerNode(clusterInfo, metadata, routingNodes);

0 commit comments

Comments
 (0)