-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Allow balancing weights to be set per tier #126091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicktindall
merged 34 commits into
elastic:main
from
nicktindall:separate_weights_per_tier_v2
Apr 28, 2025
+481
−65
Merged
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f36bfd5
Different approach at allowing separate weights per tier
nicktindall 45f8c44
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall b40f3a4
Compiling without errors
nicktindall 91b2072
Minimised
nicktindall 4807773
Hack in tiered partitions for serverless
nicktindall 05a27b6
Merge branch 'main' into separate_weights_per_tier_v2
nicktindall 539499f
Register settings
nicktindall 2db4d2e
Use the same PartitionedClusterFactory for NodeAllocationStatsAndWeig…
nicktindall 8bc0aba
Use the same PartitionedClusterFactory for NodeAllocationStatsAndWeig…
nicktindall 6e7d2e0
Move balancer settings testing to use BalancerSettings
nicktindall 453e819
Tidy
nicktindall daff958
Add assertion around tiering
nicktindall 5fbf544
Handle case when there are no search nodes
nicktindall f8f579c
Handle zero nodes in NodeSorter
nicktindall afea2ef
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall 2f87308
Update docs/changelog/126091.yaml
nicktindall 321ce06
Rename PartitionedCluster(Factory), add javadoc
nicktindall 3557b54
[CI] Auto commit changes from spotless
f186c56
TieredBalancingWeightsFactory -> StatelessBalancingWeightsFactory
nicktindall 0679990
Allow balancer weights factory to be provided by ClusterPlugin
nicktindall 0dbd4ca
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall 49429f1
Move stateless parts to a separate PR
nicktindall 6952169
Fix changelog message
nicktindall 2d1ec90
Make ModelNode and NodeSorter public
nicktindall 9e7f13d
Merge branch 'main' into separate_weights_per_tier_v2
nicktindall 99c9144
Merge branch 'main' into separate_weights_per_tier_v2
nicktindall bfdc214
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall b9d0241
PartitionedNodeSorter -> NodeSorters
nicktindall 218901f
Add tests for weights-by-partition
nicktindall da8a69e
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall e50bd1b
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall 3361bbe
Make NodeSorters iterable
nicktindall b9403bb
Javadoc on NodeSorter
nicktindall da14071
Merge remote-tracking branch 'origin/main' into separate_weights_per_…
nicktindall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,10 +15,10 @@ | |||||
| import org.elasticsearch.cluster.routing.RoutingNode; | ||||||
| import org.elasticsearch.cluster.routing.RoutingNodes; | ||||||
| import org.elasticsearch.cluster.routing.ShardRouting; | ||||||
| import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; | ||||||
| import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalance; | ||||||
| import org.elasticsearch.cluster.routing.allocation.allocator.PartitionedCluster; | ||||||
| import org.elasticsearch.cluster.routing.allocation.allocator.PartitionedClusterFactory; | ||||||
| import org.elasticsearch.cluster.routing.allocation.allocator.WeightFunction; | ||||||
| import org.elasticsearch.common.settings.ClusterSettings; | ||||||
| import org.elasticsearch.common.util.Maps; | ||||||
| import org.elasticsearch.core.Nullable; | ||||||
|
|
||||||
|
|
@@ -29,11 +29,7 @@ | |||||
| */ | ||||||
| public class NodeAllocationStatsAndWeightsCalculator { | ||||||
| private final WriteLoadForecaster writeLoadForecaster; | ||||||
|
|
||||||
| private volatile float indexBalanceFactor; | ||||||
| private volatile float shardBalanceFactor; | ||||||
| private volatile float writeLoadBalanceFactor; | ||||||
| private volatile float diskUsageBalanceFactor; | ||||||
| private final PartitionedClusterFactory partitionedClusterFactory; | ||||||
|
|
||||||
| /** | ||||||
| * Node shard allocation stats and the total node weight. | ||||||
|
|
@@ -47,18 +43,12 @@ public record NodeAllocationStatsAndWeight( | |||||
| float currentNodeWeight | ||||||
| ) {} | ||||||
|
|
||||||
| public NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster writeLoadForecaster, ClusterSettings clusterSettings) { | ||||||
| public NodeAllocationStatsAndWeightsCalculator( | ||||||
| WriteLoadForecaster writeLoadForecaster, | ||||||
| PartitionedClusterFactory partitionedClusterFactory | ||||||
| ) { | ||||||
| this.writeLoadForecaster = writeLoadForecaster; | ||||||
| clusterSettings.initializeAndWatch(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, value -> this.shardBalanceFactor = value); | ||||||
| clusterSettings.initializeAndWatch(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, value -> this.indexBalanceFactor = value); | ||||||
| clusterSettings.initializeAndWatch( | ||||||
| BalancedShardsAllocator.WRITE_LOAD_BALANCE_FACTOR_SETTING, | ||||||
| value -> this.writeLoadBalanceFactor = value | ||||||
| ); | ||||||
| clusterSettings.initializeAndWatch( | ||||||
| BalancedShardsAllocator.DISK_USAGE_BALANCE_FACTOR_SETTING, | ||||||
| value -> this.diskUsageBalanceFactor = value | ||||||
| ); | ||||||
| this.partitionedClusterFactory = partitionedClusterFactory; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -74,13 +64,14 @@ public Map<String, NodeAllocationStatsAndWeight> nodesAllocationStatsAndWeights( | |||||
| // must not use licensed features when just starting up | ||||||
| writeLoadForecaster.refreshLicense(); | ||||||
| } | ||||||
| var weightFunction = new WeightFunction(shardBalanceFactor, indexBalanceFactor, writeLoadBalanceFactor, diskUsageBalanceFactor); | ||||||
| final PartitionedCluster partitionedCluster = partitionedClusterFactory.create(); | ||||||
| var avgShardsPerNode = WeightFunction.avgShardPerNode(metadata, routingNodes); | ||||||
| var avgWriteLoadPerNode = WeightFunction.avgWriteLoadPerNode(writeLoadForecaster, metadata, routingNodes); | ||||||
| var avgDiskUsageInBytesPerNode = WeightFunction.avgDiskUsageInBytesPerNode(clusterInfo, metadata, routingNodes); | ||||||
|
|
||||||
| var nodeAllocationStatsAndWeights = Maps.<String, NodeAllocationStatsAndWeight>newMapWithExpectedSize(routingNodes.size()); | ||||||
| for (RoutingNode node : routingNodes) { | ||||||
| WeightFunction weightFunction = partitionedCluster.weightFunctionForNode(node); | ||||||
|
||||||
| WeightFunction weightFunction = partitionedCluster.weightFunctionForNode(node); | |
| WeightFunction nodeWeightFunction = partitionedCluster.weightFunctionForNode(node); |
Nit. Since it's per node now, might be nice to reflect that.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't change from call to call -- maybe it did once upon a time? Or does it somehow?
Shouldn't the PartitionedCluster (a global or tiered instance) be created once and locally save in the constructor, and then repeatedly use the saved PartitionedCluster instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned above it's just about capturing the weights at this point so they remain static throughout the balancing. If we kept a single long-lived instance it would have to keep a reference to the dynamic weights and they may be updated mid-balance. It's probably not the end of the world but I was trying to keep the behaviour consistent with the existing implementation.