diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index 421ea3ca96734..e0c78780c3b3f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -37,6 +37,7 @@ import org.elasticsearch.cluster.routing.allocation.NodeAllocationStatsAndWeightsCalculator; import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; +import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator.DesiredBalanceReconcilerAction; import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator; @@ -144,13 +145,12 @@ public ClusterModule( this.clusterPlugins = clusterPlugins; this.deciderList = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins); this.allocationDeciders = new AllocationDeciders(deciderList); - var nodeAllocationStatsAndWeightsCalculator = new NodeAllocationStatsAndWeightsCalculator( - writeLoadForecaster, - clusterService.getClusterSettings() - ); + final BalancerSettings balancerSettings = new BalancerSettings(clusterService.getClusterSettings()); + var nodeAllocationStatsAndWeightsCalculator = new NodeAllocationStatsAndWeightsCalculator(writeLoadForecaster, balancerSettings); this.shardsAllocator = createShardsAllocator( settings, clusterService.getClusterSettings(), + balancerSettings, threadPool, clusterPlugins, clusterService, @@ -438,6 +438,7 @@ private static void addAllocationDecider(Map, AllocationDecider> decide private static ShardsAllocator createShardsAllocator( Settings settings, ClusterSettings clusterSettings, + BalancerSettings balancerSettings, ThreadPool threadPool, List clusterPlugins, ClusterService clusterService, @@ -447,12 +448,12 @@ private static ShardsAllocator createShardsAllocator( NodeAllocationStatsAndWeightsCalculator nodeAllocationStatsAndWeightsCalculator ) { Map> allocators = new HashMap<>(); - allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(clusterSettings, writeLoadForecaster)); + allocators.put(BALANCED_ALLOCATOR, () -> new BalancedShardsAllocator(balancerSettings, writeLoadForecaster)); allocators.put( DESIRED_BALANCE_ALLOCATOR, () -> new DesiredBalanceShardsAllocator( clusterSettings, - new BalancedShardsAllocator(clusterSettings, writeLoadForecaster), + new BalancedShardsAllocator(balancerSettings, writeLoadForecaster), threadPool, clusterService, reconciler, diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocationStatsAndWeightsCalculator.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocationStatsAndWeightsCalculator.java index 6466736e1e8ab..f85b97125ceba 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocationStatsAndWeightsCalculator.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeAllocationStatsAndWeightsCalculator.java @@ -15,10 +15,9 @@ 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.BalancerSettings; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalance; 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 +28,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 BalancerSettings balancerSettings; /** * Node shard allocation stats and the total node weight. @@ -47,18 +42,9 @@ public record NodeAllocationStatsAndWeight( float currentNodeWeight ) {} - public NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster writeLoadForecaster, ClusterSettings clusterSettings) { + public NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster writeLoadForecaster, BalancerSettings balancerSettings) { 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.balancerSettings = balancerSettings; } /** @@ -74,7 +60,12 @@ public Map nodesAllocationStatsAndWeights( // must not use licensed features when just starting up writeLoadForecaster.refreshLicense(); } - var weightFunction = new WeightFunction(shardBalanceFactor, indexBalanceFactor, writeLoadBalanceFactor, diskUsageBalanceFactor); + var weightFunction = new WeightFunction( + balancerSettings.getShardBalanceFactor(), + balancerSettings.getIndexBalanceFactor(), + balancerSettings.getWriteLoadBalanceFactor(), + balancerSettings.getDiskUsageBalanceFactor() + ); var avgShardsPerNode = WeightFunction.avgShardPerNode(metadata, routingNodes); var avgWriteLoadPerNode = WeightFunction.avgWriteLoadPerNode(writeLoadForecaster, metadata, routingNodes); var avgDiskUsageInBytesPerNode = WeightFunction.avgDiskUsageInBytesPerNode(clusterInfo, metadata, routingNodes); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index cc6f1bcbf3477..4173ff930cfef 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -35,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.routing.allocation.decider.Decision.Type; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; @@ -60,7 +59,6 @@ import static org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata.Type.REPLACE; import static org.elasticsearch.cluster.routing.ExpectedShardSizeEstimator.getExpectedShardSize; import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING; -import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; /** * The {@link BalancedShardsAllocator} allocates and balances shards on the cluster nodes using {@link WeightFunction}. @@ -114,13 +112,7 @@ public class BalancedShardsAllocator implements ShardsAllocator { Property.NodeScope ); - // TODO: deduplicate these fields, use the fields in NodeAllocationStatsAndWeightsCalculator instead. - private volatile float indexBalanceFactor; - private volatile float shardBalanceFactor; - private volatile float writeLoadBalanceFactor; - private volatile float diskUsageBalanceFactor; - private volatile float threshold; - + private final BalancerSettings balancerSettings; private final WriteLoadForecaster writeLoadForecaster; public BalancedShardsAllocator() { @@ -128,20 +120,12 @@ public BalancedShardsAllocator() { } public BalancedShardsAllocator(Settings settings) { - this(createBuiltInClusterSettings(settings), WriteLoadForecaster.DEFAULT); - } - - public BalancedShardsAllocator(ClusterSettings clusterSettings) { - this(clusterSettings, WriteLoadForecaster.DEFAULT); + this(new BalancerSettings(settings), WriteLoadForecaster.DEFAULT); } @Inject - public BalancedShardsAllocator(ClusterSettings clusterSettings, WriteLoadForecaster writeLoadForecaster) { - clusterSettings.initializeAndWatch(SHARD_BALANCE_FACTOR_SETTING, value -> this.shardBalanceFactor = value); - clusterSettings.initializeAndWatch(INDEX_BALANCE_FACTOR_SETTING, value -> this.indexBalanceFactor = value); - clusterSettings.initializeAndWatch(WRITE_LOAD_BALANCE_FACTOR_SETTING, value -> this.writeLoadBalanceFactor = value); - clusterSettings.initializeAndWatch(DISK_USAGE_BALANCE_FACTOR_SETTING, value -> this.diskUsageBalanceFactor = value); - clusterSettings.initializeAndWatch(THRESHOLD_SETTING, value -> this.threshold = value); + public BalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster) { + this.balancerSettings = balancerSettings; this.writeLoadForecaster = writeLoadForecaster; } @@ -159,12 +143,12 @@ public void allocate(RoutingAllocation allocation) { return; } final WeightFunction weightFunction = new WeightFunction( - shardBalanceFactor, - indexBalanceFactor, - writeLoadBalanceFactor, - diskUsageBalanceFactor + balancerSettings.getShardBalanceFactor(), + balancerSettings.getIndexBalanceFactor(), + balancerSettings.getWriteLoadBalanceFactor(), + balancerSettings.getDiskUsageBalanceFactor() ); - final Balancer balancer = new Balancer(writeLoadForecaster, allocation, weightFunction, threshold); + final Balancer balancer = new Balancer(writeLoadForecaster, allocation, weightFunction, balancerSettings.getThreshold()); balancer.allocateUnassigned(); balancer.moveShards(); balancer.balance(); @@ -196,12 +180,12 @@ private void collectAndRecordNodeWeightStats(Balancer balancer, WeightFunction w @Override public ShardAllocationDecision decideShardAllocation(final ShardRouting shard, final RoutingAllocation allocation) { WeightFunction weightFunction = new WeightFunction( - shardBalanceFactor, - indexBalanceFactor, - writeLoadBalanceFactor, - diskUsageBalanceFactor + balancerSettings.getShardBalanceFactor(), + balancerSettings.getIndexBalanceFactor(), + balancerSettings.getWriteLoadBalanceFactor(), + balancerSettings.getDiskUsageBalanceFactor() ); - Balancer balancer = new Balancer(writeLoadForecaster, allocation, weightFunction, threshold); + Balancer balancer = new Balancer(writeLoadForecaster, allocation, weightFunction, balancerSettings.getThreshold()); AllocateUnassignedDecision allocateUnassignedDecision = AllocateUnassignedDecision.NOT_TAKEN; MoveDecision moveDecision = MoveDecision.NOT_TAKEN; final ProjectIndex index = new ProjectIndex(allocation, shard); @@ -244,27 +228,6 @@ private void failAllocationOfNewPrimaries(RoutingAllocation allocation) { } } - /** - * Returns the currently configured delta threshold - */ - public float getThreshold() { - return threshold; - } - - /** - * Returns the index related weight factor. - */ - public float getIndexBalance() { - return indexBalanceFactor; - } - - /** - * Returns the shard related weight factor. - */ - public float getShardBalance() { - return shardBalanceFactor; - } - /** * A {@link Balancer} */ diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancerSettings.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancerSettings.java new file mode 100644 index 0000000000000..31932bc1c2079 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancerSettings.java @@ -0,0 +1,70 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.cluster.routing.allocation.allocator; + +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.Settings; + +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.DISK_USAGE_BALANCE_FACTOR_SETTING; +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING; +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING; +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.THRESHOLD_SETTING; +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.WRITE_LOAD_BALANCE_FACTOR_SETTING; + +public class BalancerSettings { + public static final BalancerSettings DEFAULT = new BalancerSettings(ClusterSettings.createBuiltInClusterSettings()); + + private volatile float indexBalanceFactor; + private volatile float shardBalanceFactor; + private volatile float writeLoadBalanceFactor; + private volatile float diskUsageBalanceFactor; + private volatile float threshold; + + public BalancerSettings(Settings settings) { + this(ClusterSettings.createBuiltInClusterSettings(settings)); + } + + public BalancerSettings(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch(SHARD_BALANCE_FACTOR_SETTING, value -> this.shardBalanceFactor = value); + clusterSettings.initializeAndWatch(INDEX_BALANCE_FACTOR_SETTING, value -> this.indexBalanceFactor = value); + clusterSettings.initializeAndWatch(WRITE_LOAD_BALANCE_FACTOR_SETTING, value -> this.writeLoadBalanceFactor = value); + clusterSettings.initializeAndWatch(DISK_USAGE_BALANCE_FACTOR_SETTING, value -> this.diskUsageBalanceFactor = value); + clusterSettings.initializeAndWatch(THRESHOLD_SETTING, value -> this.threshold = value); + } + + /** + * Returns the index related weight factor. + */ + public float getIndexBalanceFactor() { + return indexBalanceFactor; + } + + /** + * Returns the shard related weight factor. + */ + public float getShardBalanceFactor() { + return shardBalanceFactor; + } + + public float getWriteLoadBalanceFactor() { + return writeLoadBalanceFactor; + } + + public float getDiskUsageBalanceFactor() { + return diskUsageBalanceFactor; + } + + /** + * Returns the currently configured delta threshold + */ + public float getThreshold() { + return threshold; + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationStatsServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationStatsServiceTests.java index 2a4d91437df0b..756f29384ec5c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationStatsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationStatsServiceTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; +import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalance; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator; import org.elasticsearch.cluster.routing.allocation.allocator.ShardAssignment; @@ -84,7 +85,7 @@ public void testShardStats() { clusterService, () -> clusterInfo, createShardAllocator(), - new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, ClusterSettings.createBuiltInClusterSettings()) + new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, BalancerSettings.DEFAULT) ); assertThat( service.stats(), @@ -125,7 +126,7 @@ public void testRelocatingShardIsOnlyCountedOnceOnTargetNode() { clusterService, EmptyClusterInfoService.INSTANCE, createShardAllocator(), - new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, ClusterSettings.createBuiltInClusterSettings()) + new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, BalancerSettings.DEFAULT) ); assertThat( service.stats(), @@ -182,7 +183,7 @@ public DesiredBalance getDesiredBalance() { ); } }, - new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, ClusterSettings.createBuiltInClusterSettings()) + new NodeAllocationStatsAndWeightsCalculator(TEST_WRITE_LOAD_FORECASTER, BalancerSettings.DEFAULT) ); assertThat( service.stats(), diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java index 6b6c439d7c43b..6ad85864a2417 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; +import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings; import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; @@ -285,11 +286,11 @@ public void testPersistedSettings() { settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2); settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.3); settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 2.0); - ClusterSettings service = new ClusterSettings(settings.build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); - BalancedShardsAllocator allocator = new BalancedShardsAllocator(service, WriteLoadForecaster.DEFAULT); - assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f)); - assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f)); - assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f)); + ClusterSettings clusterSettings = new ClusterSettings(settings.build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + BalancerSettings balancerSettings = new BalancerSettings(clusterSettings); + assertThat(balancerSettings.getIndexBalanceFactor(), Matchers.equalTo(0.2f)); + assertThat(balancerSettings.getShardBalanceFactor(), Matchers.equalTo(0.3f)); + assertThat(balancerSettings.getThreshold(), Matchers.equalTo(2.0f)); settings = Settings.builder(); settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2); @@ -299,18 +300,18 @@ public void testPersistedSettings() { ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString() ); - service.applySettings(settings.build()); - assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f)); - assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f)); - assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f)); + clusterSettings.applySettings(settings.build()); + assertThat(balancerSettings.getIndexBalanceFactor(), Matchers.equalTo(0.2f)); + assertThat(balancerSettings.getShardBalanceFactor(), Matchers.equalTo(0.3f)); + assertThat(balancerSettings.getThreshold(), Matchers.equalTo(2.0f)); settings = Settings.builder(); settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.5); settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.1); settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 3.0); - service.applySettings(settings.build()); - assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.5f)); - assertThat(allocator.getShardBalance(), Matchers.equalTo(0.1f)); - assertThat(allocator.getThreshold(), Matchers.equalTo(3.0f)); + clusterSettings.applySettings(settings.build()); + assertThat(balancerSettings.getIndexBalanceFactor(), Matchers.equalTo(0.5f)); + assertThat(balancerSettings.getShardBalanceFactor(), Matchers.equalTo(0.1f)); + assertThat(balancerSettings.getThreshold(), Matchers.equalTo(3.0f)); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java index b32621e62ab58..92171b75b5181 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java @@ -38,7 +38,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.elasticsearch.common.UUIDs; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; @@ -225,7 +224,7 @@ public void testBalanceByForecastWriteLoad() { var allocationService = new MockAllocationService( yesAllocationDeciders(), new TestGatewayAllocator(), - new BalancedShardsAllocator(ClusterSettings.createBuiltInClusterSettings(), TEST_WRITE_LOAD_FORECASTER), + new BalancedShardsAllocator(BalancerSettings.DEFAULT, TEST_WRITE_LOAD_FORECASTER), EmptyClusterInfoService.INSTANCE, SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES ); @@ -558,13 +557,13 @@ public void testThresholdLimit() { final var badValue = (float) randomDoubleBetween(0.0, Math.nextDown(1.0f), true); expectThrows( IllegalArgumentException.class, - () -> new BalancedShardsAllocator(Settings.builder().put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), badValue).build()) + () -> new BalancerSettings(Settings.builder().put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), badValue).build()) ); final var goodValue = (float) randomDoubleBetween(1.0, 10.0, true); assertEquals( goodValue, - new BalancedShardsAllocator(Settings.builder().put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), goodValue).build()) + new BalancerSettings(Settings.builder().put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), goodValue).build()) .getThreshold(), 0.0f ); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java index 38ea9e65d8280..c75912fda27e3 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java @@ -484,10 +484,7 @@ private Map.Entry createNewAllocationSer var strategyRef = new SetOnce(); var desiredBalanceShardsAllocator = new DesiredBalanceShardsAllocator( createBuiltInClusterSettings(), - new BalancedShardsAllocator( - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - TEST_WRITE_LOAD_FORECASTER - ), + new BalancedShardsAllocator(BalancerSettings.DEFAULT, TEST_WRITE_LOAD_FORECASTER), threadPool, clusterService, (clusterState, routingAllocationAction) -> strategyRef.get() diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java index 87cd74d11a0e1..ba0c431493f57 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java @@ -24,7 +24,9 @@ import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; +import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; +import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexVersion; @@ -210,7 +212,7 @@ private static AllocationService createAllocationService(Settings.Builder settin return new MockAllocationService( new AllocationDeciders(deciders), new TestGatewayAllocator(), - new BalancedShardsAllocator(clusterSettings), + new BalancedShardsAllocator(new BalancerSettings(clusterSettings), WriteLoadForecaster.DEFAULT), EmptyClusterInfoService.INSTANCE, EmptySnapshotsInfoService.INSTANCE ); diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java index a6d18a46016e9..d2f6c05a5d3f6 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; +import org.elasticsearch.cluster.routing.allocation.allocator.BalancerSettings; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalance; import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator; import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator; @@ -442,7 +443,7 @@ public void allocateUnassigned( } protected static final NodeAllocationStatsAndWeightsCalculator EMPTY_NODE_ALLOCATION_STATS = - new NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster.DEFAULT, createBuiltInClusterSettings()) { + new NodeAllocationStatsAndWeightsCalculator(WriteLoadForecaster.DEFAULT, BalancerSettings.DEFAULT) { @Override public Map nodesAllocationStatsAndWeights( Metadata metadata,