Skip to content

Commit 3ba31a0

Browse files
committed
Remove rate-limiting
1 parent ce79281 commit 3ba31a0

3 files changed

Lines changed: 16 additions & 48 deletions

File tree

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,13 @@ private static ShardsAllocator createShardsAllocator(
531531
Map<String, Supplier<ShardsAllocator>> allocators = new HashMap<>();
532532
allocators.put(
533533
BALANCED_ALLOCATOR,
534-
() -> new BalancedShardsAllocator(
535-
balancerSettings,
536-
writeLoadForecaster,
537-
balancingWeightsFactory,
538-
threadPool.relativeTimeInMillisSupplier()
539-
)
534+
() -> new BalancedShardsAllocator(balancerSettings, writeLoadForecaster, balancingWeightsFactory)
540535
);
541536
allocators.put(
542537
DESIRED_BALANCE_ALLOCATOR,
543538
() -> new DesiredBalanceShardsAllocator(
544539
clusterSettings,
545-
new BalancedShardsAllocator(
546-
balancerSettings,
547-
writeLoadForecaster,
548-
balancingWeightsFactory,
549-
threadPool.relativeTimeInMillisSupplier()
550-
),
540+
new BalancedShardsAllocator(balancerSettings, writeLoadForecaster, balancingWeightsFactory),
551541
threadPool,
552542
clusterService,
553543
reconciler,

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
3636
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
3737
import org.elasticsearch.cluster.routing.allocation.decider.Decision.Type;
38-
import org.elasticsearch.common.FrequencyCappedAction;
3938
import org.elasticsearch.common.settings.Setting;
4039
import org.elasticsearch.common.settings.Setting.Property;
4140
import org.elasticsearch.common.settings.Settings;
@@ -58,7 +57,6 @@
5857
import java.util.Map;
5958
import java.util.Set;
6059
import java.util.function.BiFunction;
61-
import java.util.function.LongSupplier;
6260
import java.util.function.Predicate;
6361

6462
import static org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata.Type.REPLACE;
@@ -128,7 +126,6 @@ public class BalancedShardsAllocator implements ShardsAllocator {
128126
private final BalancerSettings balancerSettings;
129127
private final WriteLoadForecaster writeLoadForecaster;
130128
private final BalancingWeightsFactory balancingWeightsFactory;
131-
private final FrequencyCappedAction logMoveNotPreferred;
132129

133130
public BalancedShardsAllocator() {
134131
this(Settings.EMPTY);
@@ -139,22 +136,18 @@ public BalancedShardsAllocator(Settings settings) {
139136
}
140137

141138
public BalancedShardsAllocator(BalancerSettings balancerSettings, WriteLoadForecaster writeLoadForecaster) {
142-
this(balancerSettings, writeLoadForecaster, new GlobalBalancingWeightsFactory(balancerSettings), System::currentTimeMillis);
139+
this(balancerSettings, writeLoadForecaster, new GlobalBalancingWeightsFactory(balancerSettings));
143140
}
144141

145142
@Inject
146143
public BalancedShardsAllocator(
147144
BalancerSettings balancerSettings,
148145
WriteLoadForecaster writeLoadForecaster,
149-
BalancingWeightsFactory balancingWeightsFactory,
150-
LongSupplier relativeTimeInMillisProvider
146+
BalancingWeightsFactory balancingWeightsFactory
151147
) {
152148
this.balancerSettings = balancerSettings;
153149
this.writeLoadForecaster = writeLoadForecaster;
154150
this.balancingWeightsFactory = balancingWeightsFactory;
155-
this.logMoveNotPreferred = new FrequencyCappedAction(relativeTimeInMillisProvider, TimeValue.ZERO);
156-
balancerSettings.getClusterSettings()
157-
.initializeAndWatch(MOVE_NOT_PREFERRED_MINIMUM_LOGGING_INTERVAL, logMoveNotPreferred::setMinInterval);
158151
}
159152

160153
@Override
@@ -186,8 +179,7 @@ public void allocate(RoutingAllocation allocation) {
186179
allocation,
187180
balancerSettings.getThreshold(),
188181
balancingWeights,
189-
balancerSettings.completeEarlyOnShardAssignmentChange(),
190-
logMoveNotPreferred
182+
balancerSettings.completeEarlyOnShardAssignmentChange()
191183
);
192184

193185
boolean shardAssigned = false, shardMoved = false, shardBalanced = false;
@@ -266,8 +258,7 @@ public ShardAllocationDecision explainShardAllocation(final ShardRouting shard,
266258
allocation,
267259
balancerSettings.getThreshold(),
268260
balancingWeightsFactory.create(),
269-
balancerSettings.completeEarlyOnShardAssignmentChange(),
270-
logMoveNotPreferred
261+
balancerSettings.completeEarlyOnShardAssignmentChange()
271262
);
272263
AllocateUnassignedDecision allocateUnassignedDecision = AllocateUnassignedDecision.NOT_TAKEN;
273264
MoveDecision moveDecision = MoveDecision.NOT_TAKEN;
@@ -328,15 +319,13 @@ public static class Balancer {
328319
private final BalancingWeights balancingWeights;
329320
private final NodeSorters nodeSorters;
330321
private final boolean completeEarlyOnShardAssignmentChange;
331-
private final FrequencyCappedAction logMoveNotPreferred;
332322

333323
private Balancer(
334324
WriteLoadForecaster writeLoadForecaster,
335325
RoutingAllocation allocation,
336326
float threshold,
337327
BalancingWeights balancingWeights,
338-
boolean completeEarlyOnShardAssignmentChange,
339-
FrequencyCappedAction logMoveNotPreferred
328+
boolean completeEarlyOnShardAssignmentChange
340329
) {
341330
this.writeLoadForecaster = writeLoadForecaster;
342331
this.allocation = allocation;
@@ -352,7 +341,6 @@ private Balancer(
352341
this.nodeSorters = balancingWeights.createNodeSorters(nodesArray(), this);
353342
this.balancingWeights = balancingWeights;
354343
this.completeEarlyOnShardAssignmentChange = completeEarlyOnShardAssignmentChange;
355-
this.logMoveNotPreferred = logMoveNotPreferred;
356344
}
357345

358346
private static long getShardDiskUsageInBytes(ShardRouting shardRouting, IndexMetadata indexMetadata, ClusterInfo clusterInfo) {
@@ -888,13 +876,11 @@ public boolean moveShards() {
888876
final var moveDecision = shardMoved ? decideMove(index, shardRouting) : storedShardMovement.moveDecision();
889877
if (moveDecision.isDecisionTaken() && moveDecision.cannotRemainAndCanMove()) {
890878
if (notPreferredLogger.isDebugEnabled()) {
891-
logMoveNotPreferred.maybeExecute(
892-
() -> notPreferredLogger.debug(
893-
"Moving shard [{}] to [{}] from a NOT_PREFERRED allocation, explanation is [{}]",
894-
shardRouting,
895-
moveDecision.getTargetNode().getName(),
896-
moveDecision.getCanRemainDecision().getExplanation()
897-
)
879+
notPreferredLogger.debug(
880+
"Moving shard [{}] to [{}] from a NOT_PREFERRED allocation, explanation is [{}]",
881+
shardRouting,
882+
moveDecision.getTargetNode().getName(),
883+
moveDecision.getCanRemainDecision().getExplanation()
898884
);
899885
}
900886
executeMove(shardRouting, index, moveDecision, "move-non-preferred");

server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,7 @@ public void testPartitionedClusterWithSeparateWeights() {
643643
TEST_WRITE_LOAD_FORECASTER,
644644
new PrefixBalancingWeightsFactory(
645645
Map.of("shardsOnly", new WeightFunction(1, 0, 0, 0), "weightsOnly", new WeightFunction(0, 0, 1, 0))
646-
),
647-
System::currentTimeMillis
646+
)
648647
),
649648
EmptyClusterInfoService.INSTANCE,
650649
SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES
@@ -748,8 +747,7 @@ public Iterator<BalancedShardsAllocator.NodeSorter> iterator() {
748747
public boolean diskUsageIgnored() {
749748
return true; // This makes the computation ignore disk usage
750749
}
751-
},
752-
System::currentTimeMillis
750+
}
753751
);
754752

755753
final String indexName = randomIdentifier();
@@ -1025,8 +1023,7 @@ public void testNotPreferredMovementIsLoggedAtDebugLevel() {
10251023
final var balancedShardsAllocator = new BalancedShardsAllocator(
10261024
balancerSettings,
10271025
TEST_WRITE_LOAD_FORECASTER,
1028-
new GlobalBalancingWeightsFactory(balancerSettings),
1029-
relativeTimeMillis::get
1026+
new GlobalBalancingWeightsFactory(balancerSettings)
10301027
);
10311028

10321029
final var allocation = new RoutingAllocation(new AllocationDeciders(List.<AllocationDecider>of(new AllocationDecider() {
@@ -1204,12 +1201,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
12041201
final var allocationService = new MockAllocationService(
12051202
new AllocationDeciders(List.of(notPreferredDecider)),
12061203
new TestGatewayAllocator(),
1207-
new BalancedShardsAllocator(
1208-
BalancerSettings.DEFAULT,
1209-
TEST_WRITE_LOAD_FORECASTER,
1210-
new NodeNameDrivenBalancingWeightsFactory(),
1211-
System::currentTimeMillis
1212-
),
1204+
new BalancedShardsAllocator(BalancerSettings.DEFAULT, TEST_WRITE_LOAD_FORECASTER, new NodeNameDrivenBalancingWeightsFactory()),
12131205
() -> ClusterInfo.EMPTY,
12141206
SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES
12151207
);

0 commit comments

Comments
 (0)