From 748adbd1b7389962542e6acdfcea710ea6015eaa Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Thu, 19 Jan 2023 11:20:03 +0100 Subject: [PATCH 1/3] delegate calls to the same service constructor --- .../allocator/BalancedShardsAllocator.java | 3 +- .../allocation/BalanceConfigurationTests.java | 5 ++- .../allocation/ThrottlingAllocationTests.java | 11 +++++- .../EnableAllocationShortCircuitTests.java | 9 ++--- .../cluster/ESAllocationTestCase.java | 34 ++++++++++++------- 5 files changed, 40 insertions(+), 22 deletions(-) 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 43ddcaac64d7f..f11d5acf197e3 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 @@ -59,6 +59,7 @@ import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; /** * The {@link BalancedShardsAllocator} re-balances the nodes allocations @@ -128,7 +129,7 @@ public BalancedShardsAllocator() { } public BalancedShardsAllocator(Settings settings) { - this(new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), WriteLoadForecaster.DEFAULT); + this(createBuiltInClusterSettings(settings), WriteLoadForecaster.DEFAULT); } public BalancedShardsAllocator(ClusterSettings clusterSettings) { 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 ebec7140de28e..1649a9556740c 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 @@ -26,7 +26,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.gateway.TestGatewayAllocator; import org.hamcrest.Matchers; import java.util.stream.Collectors; @@ -61,7 +60,7 @@ public void testIndexBalance() { settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), replicaBalance); settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), balanceThreshold); - AllocationService strategy = createAllocationService(settings.build(), new TestGatewayAllocator()); + AllocationService strategy = createAllocationService(settings.build()); ClusterState clusterState = initCluster(strategy); assertIndexBalance( @@ -112,7 +111,7 @@ public void testReplicaBalance() { settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), replicaBalance); settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), balanceThreshold); - AllocationService strategy = createAllocationService(settings.build(), new TestGatewayAllocator()); + AllocationService strategy = createAllocationService(settings.build()); ClusterState clusterState = initCluster(strategy); assertReplicaBalance( diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java index c766d44b8f66d..05ab419c2b993 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ESAllocationTestCase; +import org.elasticsearch.cluster.EmptyClusterInfoService; import org.elasticsearch.cluster.RestoreInProgress; import org.elasticsearch.cluster.TestShardRoutingRoleStrategies; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -70,6 +71,7 @@ public void testPrimaryRecoveryThrottling() { .put("cluster.routing.allocation.node_initial_primaries_recoveries", 3) .build(), gatewayAllocator, + EmptyClusterInfoService.INSTANCE, snapshotsInfoService ); @@ -128,6 +130,7 @@ public void testReplicaAndPrimaryRecoveryThrottling() { .put("cluster.routing.allocation.node_initial_primaries_recoveries", 3) .build(), gatewayAllocator, + EmptyClusterInfoService.INSTANCE, snapshotsInfoService ); @@ -191,7 +194,12 @@ public void testThrottleIncomingAndOutgoing() { .put("cluster.routing.allocation.node_initial_primaries_recoveries", 5) .put("cluster.routing.allocation.cluster_concurrent_rebalance", 5) .build(); - AllocationService strategy = createAllocationService(settings, gatewayAllocator, snapshotsInfoService); + AllocationService strategy = createAllocationService( + settings, + gatewayAllocator, + EmptyClusterInfoService.INSTANCE, + snapshotsInfoService + ); logger.info("Building initial routing table"); Metadata metadata = Metadata.builder() @@ -250,6 +258,7 @@ public void testOutgoingThrottlesAllocation() { AllocationService strategy = createAllocationService( Settings.builder().put("cluster.routing.allocation.node_concurrent_outgoing_recoveries", 1).build(), gatewayAllocator, + EmptyClusterInfoService.INSTANCE, snapshotsInfoService ); 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 46f03dffbccc7..38d5ef8c57b75 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 @@ -198,15 +198,16 @@ public void testAllocationSkippedIfDisabled() { assertThat(plugin.canAllocateAttempts, equalTo(0)); } - private static AllocationService createAllocationService(Settings.Builder settings, ClusterPlugin plugin) { - final ClusterSettings emptyClusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + private static AllocationService createAllocationService(Settings.Builder settingsBuilder, ClusterPlugin plugin) { + var settings = settingsBuilder.build(); + var clusterSettings = ClusterSettings.createBuiltInClusterSettings(settings); List deciders = new ArrayList<>( - ClusterModule.createAllocationDeciders(settings.build(), emptyClusterSettings, Collections.singletonList(plugin)) + ClusterModule.createAllocationDeciders(settings, clusterSettings, Collections.singletonList(plugin)) ); return new MockAllocationService( new AllocationDeciders(deciders), new TestGatewayAllocator(), - new BalancedShardsAllocator(Settings.EMPTY), + new BalancedShardsAllocator(clusterSettings), 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 0b29e0536566d..f849114bd103d 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -89,7 +89,7 @@ public static MockAllocationService createAllocationService() { } public static MockAllocationService createAllocationService(Settings settings) { - return createAllocationService(settings, EMPTY_CLUSTER_SETTINGS); + return createAllocationService(settings, createBuiltInClusterSettings(settings)); } public static MockAllocationService createAllocationService(Settings settings, ClusterSettings clusterSettings) { @@ -141,34 +141,35 @@ protected void submitReconcileTask(DesiredBalance desiredBalance) { }; } - public static MockAllocationService createAllocationService(Settings settings, ClusterInfoService clusterInfoService) { - return new MockAllocationService( - randomAllocationDeciders(settings, EMPTY_CLUSTER_SETTINGS), - new TestGatewayAllocator(), - new BalancedShardsAllocator(settings), - clusterInfoService, + public static MockAllocationService createAllocationService(Settings settings, GatewayAllocator gatewayAllocator) { + return createAllocationService( + settings, + gatewayAllocator, + EmptyClusterInfoService.INSTANCE, SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES ); } - public static MockAllocationService createAllocationService(Settings settings, GatewayAllocator gatewayAllocator) { - return createAllocationService(settings, gatewayAllocator, SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES); + public static MockAllocationService createAllocationService(Settings settings, ClusterInfoService clusterInfoService) { + return createAllocationService(settings, new TestGatewayAllocator(), clusterInfoService, SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES); } public static MockAllocationService createAllocationService(Settings settings, SnapshotsInfoService snapshotsInfoService) { - return createAllocationService(settings, new TestGatewayAllocator(), snapshotsInfoService); + return createAllocationService(settings, new TestGatewayAllocator(), EmptyClusterInfoService.INSTANCE, snapshotsInfoService); } public static MockAllocationService createAllocationService( Settings settings, GatewayAllocator gatewayAllocator, + ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService ) { + var clusterSettings = createBuiltInClusterSettings(settings); return new MockAllocationService( - randomAllocationDeciders(settings, EMPTY_CLUSTER_SETTINGS), + randomAllocationDeciders(settings, clusterSettings), gatewayAllocator, - new BalancedShardsAllocator(settings), - EmptyClusterInfoService.INSTANCE, + new BalancedShardsAllocator(clusterSettings, WriteLoadForecaster.DEFAULT), + clusterInfoService, snapshotsInfoService ); } @@ -352,6 +353,8 @@ protected static class MockAllocationService extends AllocationService { private volatile long nanoTimeOverride = -1L; + private final GatewayAllocator gatewayAllocator; + public MockAllocationService( AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, @@ -367,6 +370,7 @@ public MockAllocationService( snapshotsInfoService, TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY ); + this.gatewayAllocator = gatewayAllocator; } public void setNanoTimeOverride(long nanoTime) { @@ -377,6 +381,10 @@ public void setNanoTimeOverride(long nanoTime) { protected long currentNanoTime() { return nanoTimeOverride == -1L ? super.currentNanoTime() : nanoTimeOverride; } + + public GatewayAllocator getGatewayAllocator() { + return gatewayAllocator; + } } /** From 9740a02e5ef2658c9a5900a564a6c69c7a2f521d Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Thu, 19 Jan 2023 11:45:30 +0100 Subject: [PATCH 2/3] watch setting in allocation deciders --- .../elasticsearch/cluster/ClusterModule.java | 12 +++---- .../ClusterRebalanceAllocationDecider.java | 6 ++-- .../ConcurrentRebalanceAllocationDecider.java | 8 ++--- .../decider/EnableAllocationDecider.java | 8 ++--- .../decider/SameShardAllocationDecider.java | 6 ++-- .../decider/ShardsLimitAllocationDecider.java | 6 ++-- .../decider/ThrottlingAllocationDecider.java | 14 +++----- .../fieldcaps/RequestDispatcherTests.java | 7 ++-- .../cluster/ClusterModuleTests.java | 2 +- .../allocation/AllocationServiceTests.java | 8 ++--- .../RandomAllocationDeciderTests.java | 7 ++-- .../allocation/SameShardRoutingTests.java | 12 ++----- .../DesiredBalanceReconcilerTests.java | 32 +++++++++---------- .../decider/DiskThresholdDeciderTests.java | 7 ++-- .../decider/FilterAllocationDeciderTests.java | 5 +-- ...NodeReplacementAllocationDeciderTests.java | 5 +-- .../NodeShutdownAllocationDeciderTests.java | 9 ++---- .../gateway/ReplicaShardAllocatorTests.java | 7 ++-- .../indices/cluster/ClusterStateChanges.java | 5 +-- .../cluster/ESAllocationTestCase.java | 16 ++-------- .../DataTierAllocationDeciderTests.java | 5 +-- 21 files changed, 74 insertions(+), 113 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index 67c3472221100..d6e8c2ed8b9c3 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -343,19 +343,19 @@ public static Collection createAllocationDeciders( addAllocationDecider(deciders, new ResizeAllocationDecider()); addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider()); addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider()); - addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings)); - addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings)); - addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings)); + addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(clusterSettings)); + addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(clusterSettings)); + addAllocationDecider(deciders, new EnableAllocationDecider(clusterSettings)); addAllocationDecider(deciders, new NodeVersionAllocationDecider()); addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider()); addAllocationDecider(deciders, new RestoreInProgressAllocationDecider()); addAllocationDecider(deciders, new NodeShutdownAllocationDecider()); addAllocationDecider(deciders, new NodeReplacementAllocationDecider()); addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings)); - addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings)); + addAllocationDecider(deciders, new SameShardAllocationDecider(clusterSettings)); addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings)); - addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings)); - addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings)); + addAllocationDecider(deciders, new ThrottlingAllocationDecider(clusterSettings)); + addAllocationDecider(deciders, new ShardsLimitAllocationDecider(clusterSettings)); addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings)); clusterPlugins.stream() diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java index 9d22bbd20385c..88d4a652a5a39 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java @@ -16,7 +16,6 @@ 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; import java.util.Locale; @@ -89,10 +88,9 @@ public String toString() { private volatile ClusterRebalanceType type; - public ClusterRebalanceAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - type = CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.get(settings); + public ClusterRebalanceAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch(CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING, this::setType); logger.debug("using [{}] with [{}]", CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, type); - clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING, this::setType); } private void setType(ClusterRebalanceType type) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java index bd32f670e226a..fd3ce510a1055 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java @@ -15,7 +15,6 @@ 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; /** * Similar to the {@link ClusterRebalanceAllocationDecider} this @@ -44,13 +43,12 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider { ); private volatile int clusterConcurrentRebalance; - public ConcurrentRebalanceAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.clusterConcurrentRebalance = CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING.get(settings); - logger.debug("using [cluster_concurrent_rebalance] with [{}]", clusterConcurrentRebalance); - clusterSettings.addSettingsUpdateConsumer( + public ConcurrentRebalanceAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch( CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING, this::setClusterConcurrentRebalance ); + logger.debug("using [cluster_concurrent_rebalance] with [{}]", clusterConcurrentRebalance); } private void setClusterConcurrentRebalance(int concurrentRebalance) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java index 19b2e3d986ebd..11624e39d1764 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java @@ -84,11 +84,9 @@ public class EnableAllocationDecider extends AllocationDecider { private volatile Rebalance enableRebalance; private volatile Allocation enableAllocation; - public EnableAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.enableAllocation = CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.get(settings); - this.enableRebalance = CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING, this::setEnableAllocation); - clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING, this::setEnableRebalance); + public EnableAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch(CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING, this::setEnableAllocation); + clusterSettings.initializeAndWatch(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING, this::setEnableRebalance); } private void setEnableRebalance(Rebalance enableRebalance) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java index 44ec04a3e1ae0..7f34150f26748 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java @@ -16,7 +16,6 @@ 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; /** * An allocation decider that prevents multiple instances of the same shard to @@ -46,9 +45,8 @@ public class SameShardAllocationDecider extends AllocationDecider { private volatile boolean sameHost; - public SameShardAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.sameHost = CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING, this::setSameHost); + public SameShardAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch(CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING, this::setSameHost); } /** diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java index e53688654e64b..c43fd599df133 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java @@ -16,7 +16,6 @@ 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; import java.util.function.BiPredicate; @@ -70,9 +69,8 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { Property.NodeScope ); - public ShardsLimitAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.clusterShardLimit = CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, this::setClusterShardLimit); + public ShardsLimitAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, this::setClusterShardLimit); } private void setClusterShardLimit(int clusterShardLimit) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java index 3952330ba8299..7011258e61a62 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java @@ -18,7 +18,6 @@ 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; import static org.elasticsearch.cluster.routing.allocation.decider.Decision.THROTTLE; import static org.elasticsearch.cluster.routing.allocation.decider.Decision.YES; @@ -81,24 +80,19 @@ public class ThrottlingAllocationDecider extends AllocationDecider { private volatile int concurrentIncomingRecoveries; private volatile int concurrentOutgoingRecoveries; - public ThrottlingAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.primariesInitialRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING.get(settings); - concurrentIncomingRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.get(settings); - concurrentOutgoingRecoveries = CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING.get(settings); - - clusterSettings.addSettingsUpdateConsumer( + public ThrottlingAllocationDecider(ClusterSettings clusterSettings) { + clusterSettings.initializeAndWatch( CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING, this::setPrimariesInitialRecoveries ); - clusterSettings.addSettingsUpdateConsumer( + clusterSettings.initializeAndWatch( CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING, this::setConcurrentIncomingRecoverries ); - clusterSettings.addSettingsUpdateConsumer( + clusterSettings.initializeAndWatch( CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING, this::setConcurrentOutgoingRecoverries ); - logger.debug( "using node_concurrent_outgoing_recoveries [{}], node_concurrent_incoming_recoveries [{}], " + "node_initial_primaries_recoveries [{}]", diff --git a/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java b/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java index 978a518a1ae25..2ed62b52bddcc 100644 --- a/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java +++ b/server/src/test/java/org/elasticsearch/action/fieldcaps/RequestDispatcherTests.java @@ -78,6 +78,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.equalTo; @@ -904,10 +905,10 @@ private ClusterState newClusterState(Metadata metadata, DiscoveryNodes discovery .routingTable(routingTable.build()) .build(); final Settings settings = Settings.EMPTY; - final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + final ClusterSettings clusterSettings = createBuiltInClusterSettings(settings); final ArrayList deciders = new ArrayList<>(); - deciders.add(new EnableAllocationDecider(settings, clusterSettings)); - deciders.add(new SameShardAllocationDecider(settings, clusterSettings)); + deciders.add(new EnableAllocationDecider(clusterSettings)); + deciders.add(new SameShardAllocationDecider(clusterSettings)); deciders.add(new ReplicaAfterPrimaryActiveAllocationDecider()); Collections.shuffle(deciders, random()); final MockAllocationService allocationService = new MockAllocationService( diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 45bd2a86d6f76..3abc91dbac04a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -153,7 +153,7 @@ public void testRegisterAllocationDeciderDuplicate() { () -> new ClusterModule(Settings.EMPTY, clusterService, Collections.singletonList(new ClusterPlugin() { @Override public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { - return Collections.singletonList(new EnableAllocationDecider(settings, clusterSettings)); + return Collections.singletonList(new EnableAllocationDecider(clusterSettings)); } }), clusterInfoService, null, threadPool, EmptySystemIndices.INSTANCE, WriteLoadForecaster.DEFAULT) ); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java index 73def08329313..68eaf2911f8fa 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java @@ -50,6 +50,7 @@ import static org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING; import static org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING; import static org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -109,13 +110,10 @@ public void testAssignsPrimariesInPriorityOrderThenReplicas() { .put(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.getKey(), 1) .put(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING.getKey(), Integer.MAX_VALUE) .build(); - final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + final ClusterSettings clusterSettings = createBuiltInClusterSettings(settings); final AllocationService allocationService = new AllocationService( new AllocationDeciders( - Arrays.asList( - new SameShardAllocationDecider(settings, clusterSettings), - new ThrottlingAllocationDecider(settings, clusterSettings) - ) + Arrays.asList(new SameShardAllocationDecider(clusterSettings), new ThrottlingAllocationDecider(clusterSettings)) ), new ShardsAllocator() { @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java index 8020a74a8364a..2bc63eb190e6f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.snapshots.EmptySnapshotsInfoService; import org.elasticsearch.test.gateway.TestGatewayAllocator; @@ -41,6 +40,7 @@ import static org.elasticsearch.cluster.routing.RoutingNodesHelper.shardsWithState; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.equalTo; public class RandomAllocationDeciderTests extends ESAllocationTestCase { @@ -55,10 +55,7 @@ public void testRandomDecisions() { new AllocationDeciders( new HashSet<>( Arrays.asList( - new SameShardAllocationDecider( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ), + new SameShardAllocationDecider(createBuiltInClusterSettings()), new ReplicaAfterPrimaryActiveAllocationDecider(), randomAllocationDecider ) diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java index 5e84c1953f80d..1125df5e18e57 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.Strings; import org.elasticsearch.index.Index; @@ -43,6 +42,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED; import static org.elasticsearch.cluster.routing.allocation.RoutingNodesUtils.numberOfShardsOfType; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -206,10 +206,7 @@ public void testSameHostCheckWithExplain() { } else { final ShardRouting unassignedShard = unassignedShards.get(0); - final SameShardAllocationDecider decider = new SameShardAllocationDecider( - sameHostSetting, - new ClusterSettings(sameHostSetting, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ); + final SameShardAllocationDecider decider = new SameShardAllocationDecider(createBuiltInClusterSettings(sameHostSetting)); final RoutingNode emptyNode = clusterState.getRoutingNodes() .stream() @@ -308,10 +305,7 @@ public void testSameHostCheckDisabledByAutoExpandReplicas() { } public void testForceAllocatePrimaryOnSameNodeNotAllowed() { - SameShardAllocationDecider decider = new SameShardAllocationDecider( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ); + SameShardAllocationDecider decider = new SameShardAllocationDecider(createBuiltInClusterSettings()); ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomIntBetween(2, 4), 1); Index index = clusterState.getMetadata().index("idx").getIndex(); ShardRouting primaryShard = clusterState.routingTable().index(index).shard(0).primaryShard(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java index 9a56a0753ab16..6d3b7a707dad7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java @@ -227,9 +227,9 @@ public void testUnassignedPrimariesBeforeUnassignedReplicas() { final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings), + new ThrottlingAllocationDecider(clusterSettings), new AllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { @@ -310,9 +310,9 @@ public void testUnassignedShardsInterleaving() { final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings) + new ThrottlingAllocationDecider(clusterSettings) ); final var stateWithInitializingPrimaries = startInitializingShardsAndReroute(allocationService, clusterState); @@ -400,9 +400,9 @@ public void testUnassignedShardsPriority() { final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings), + new ThrottlingAllocationDecider(clusterSettings), new AllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { @@ -508,7 +508,7 @@ public void testUnassignedRespectsDesiredBalance() { final var desiredBalance = desiredBalance(clusterState, (shardId, nodeId) -> true); final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider() ); @@ -601,7 +601,7 @@ public void testUnassignedAllocationPredictsDiskUsage() { routingAllocation -> reconcile(routingAllocation, desiredBalance), () -> clusterInfo, () -> snapshotShardSizeInfo, - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider() ); @@ -639,7 +639,7 @@ public void testUnassignedSkipsEquivalentReplicas() { final var desiredBalance = desiredBalance(clusterState, (shardId, nodeId) -> true); final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new AllocationDecider() { @Override @@ -698,7 +698,7 @@ public void testUnassignedSetsAllocationStatusOnUnassignedShards() { final var desiredBalance = desiredBalance(clusterState, (shardId, nodeId) -> true); final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new AllocationDecider() { @Override @@ -756,9 +756,9 @@ public void testUnassignedPrimariesThrottlingAndFallback() { final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings), + new ThrottlingAllocationDecider(clusterSettings), new AllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { @@ -834,9 +834,9 @@ public void testMoveShards() { final var desiredBalance = new AtomicReference<>(desiredBalance(clusterState, (shardId, nodeId) -> true)); final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance.get()), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings), + new ThrottlingAllocationDecider(clusterSettings), new FilterAllocationDecider(settings, clusterSettings), new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider(), @@ -955,9 +955,9 @@ public void testRebalance() { ); final var allocationService = createTestAllocationService( routingAllocation -> reconcile(routingAllocation, desiredBalance.get()), - new SameShardAllocationDecider(settings, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new ThrottlingAllocationDecider(settings, clusterSettings), + new ThrottlingAllocationDecider(clusterSettings), new AllocationDecider() { @Override public Decision canRebalance(RoutingAllocation allocation) { diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index caa22bc7b3789..863169d34432f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -73,6 +73,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED; import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -1273,15 +1274,15 @@ private AllocationService createAllocationService( } private DiskThresholdDecider createDiskThresholdDecider(Settings settings) { - return new DiskThresholdDecider(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + return new DiskThresholdDecider(settings, createBuiltInClusterSettings(settings)); } private SameShardAllocationDecider createSameShardAllocationDecider(Settings settings) { - return new SameShardAllocationDecider(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + return new SameShardAllocationDecider(createBuiltInClusterSettings(settings)); } private EnableAllocationDecider createEnableAllocationDecider(Settings settings) { - return new EnableAllocationDecider(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + return new EnableAllocationDecider(createBuiltInClusterSettings(settings)); } /** diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java index a3bc52fae5eb7..72d7650ad72de 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java @@ -45,17 +45,18 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.equalTo; public class FilterAllocationDeciderTests extends ESAllocationTestCase { public void testFilterInitialRecovery() { - ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + ClusterSettings clusterSettings = createBuiltInClusterSettings(); FilterAllocationDecider filterAllocationDecider = new FilterAllocationDecider(Settings.EMPTY, clusterSettings); AllocationDeciders allocationDeciders = new AllocationDeciders( Arrays.asList( filterAllocationDecider, - new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider() ) ); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java index 1d653afcfbfc9..ec3463ddf8d60 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.HashMap; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -53,12 +54,12 @@ public class NodeReplacementAllocationDeciderTests extends ESAllocationTestCase new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), ShardRouting.Role.DEFAULT ); - private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + private final ClusterSettings clusterSettings = createBuiltInClusterSettings(); private NodeReplacementAllocationDecider decider = new NodeReplacementAllocationDecider(); private final AllocationDeciders allocationDeciders = new AllocationDeciders( Arrays.asList( decider, - new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new NodeShutdownAllocationDecider() ) diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java index 5e309f95e1aa2..0cdfc6609e291 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.HashMap; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.equalTo; public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase { @@ -50,14 +51,10 @@ public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase { new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), ShardRouting.Role.DEFAULT ); - private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + private final ClusterSettings clusterSettings = createBuiltInClusterSettings(); private final NodeShutdownAllocationDecider decider = new NodeShutdownAllocationDecider(); private final AllocationDeciders allocationDeciders = new AllocationDeciders( - Arrays.asList( - decider, - new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), - new ReplicaAfterPrimaryActiveAllocationDecider() - ) + Arrays.asList(decider, new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider()) ); private final AllocationService service = new AllocationService( allocationDeciders, diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index b257edb8f1785..12ea5490028ea 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -33,7 +33,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; -import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; @@ -60,6 +59,7 @@ import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.cluster.routing.RoutingNodesHelper.shardsWithState; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -369,10 +369,7 @@ public void testThrottleWhenAllocatingToMatchingNode() { new AllocationDeciders( Arrays.asList( new TestAllocateDecision(Decision.YES), - new SameShardAllocationDecider( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ), + new SameShardAllocationDecider(createBuiltInClusterSettings()), new AllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { diff --git a/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java index 93808f94c57aa..8ccd7d75e944a 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java @@ -113,6 +113,7 @@ import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom; import static java.util.stream.Collectors.toMap; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.elasticsearch.env.Environment.PATH_HOME_SETTING; import static org.elasticsearch.test.CheckedFunctionUtils.anyCheckedFunction; import static org.elasticsearch.test.ESTestCase.between; @@ -142,12 +143,12 @@ public class ClusterStateChanges { @SuppressWarnings("unchecked") public ClusterStateChanges(NamedXContentRegistry xContentRegistry, ThreadPool threadPool) { - ClusterSettings clusterSettings = new ClusterSettings(SETTINGS, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + ClusterSettings clusterSettings = createBuiltInClusterSettings(SETTINGS); allocationService = new AllocationService( new AllocationDeciders( new HashSet<>( Arrays.asList( - new SameShardAllocationDecider(SETTINGS, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new RandomAllocationDeciderTests.RandomAllocationDecider(getRandom()) ) 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 f849114bd103d..c8fd861628ff7 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -218,13 +218,7 @@ protected static ClusterState startRandomInitializingShard(ClusterState clusterS protected static AllocationDeciders yesAllocationDeciders() { return new AllocationDeciders( - Arrays.asList( - new TestAllocateDecision(Decision.YES), - new SameShardAllocationDecider( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ) - ) + Arrays.asList(new TestAllocateDecision(Decision.YES), new SameShardAllocationDecider(createBuiltInClusterSettings())) ); } @@ -234,13 +228,7 @@ protected static AllocationDeciders noAllocationDeciders() { protected static AllocationDeciders throttleAllocationDeciders() { return new AllocationDeciders( - Arrays.asList( - new TestAllocateDecision(Decision.THROTTLE), - new SameShardAllocationDecider( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) - ) - ) + Arrays.asList(new TestAllocateDecision(Decision.THROTTLE), new SameShardAllocationDecider(createBuiltInClusterSettings())) ); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java index 6d2b5b530f22b..f897caf2a529c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java @@ -51,6 +51,7 @@ import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_COLD; import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_FROZEN; +import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings; import static org.elasticsearch.node.Node.NODE_EXTERNAL_ID_SETTING; import static org.elasticsearch.node.NodeRoleSettings.NODE_ROLES_SETTING; import static org.hamcrest.Matchers.containsString; @@ -73,11 +74,11 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { private static final DesiredNode CONTENT_DESIRED_NODE = newDesiredNode("node-content", DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE); private static final DesiredNode DATA_DESIRED_NODE = newDesiredNode("node-data", DiscoveryNodeRole.DATA_ROLE); - private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); + private final ClusterSettings clusterSettings = createBuiltInClusterSettings(); private final AllocationDeciders allocationDeciders = new AllocationDeciders( Arrays.asList( DataTierAllocationDecider.INSTANCE, - new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), + new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider() ) ); From 5b188ad5d1818956a5a5cd4693885292b5c46a48 Mon Sep 17 00:00:00 2001 From: "ievgen.degtiarenko" Date: Thu, 19 Jan 2023 12:11:12 +0100 Subject: [PATCH 3/3] delegate settings --- .../java/org/elasticsearch/cluster/ESAllocationTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c8fd861628ff7..6c294502de5cc 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -113,7 +113,7 @@ private static ShardsAllocator createShardsAllocator(Settings settings) { private static DesiredBalanceShardsAllocator createDesiredBalanceShardsAllocator(Settings settings) { var queue = new DeterministicTaskQueue(); return new DesiredBalanceShardsAllocator( - createBuiltInClusterSettings(), + createBuiltInClusterSettings(settings), new BalancedShardsAllocator(settings), queue.getThreadPool(), null,