3535import org .elasticsearch .cluster .routing .allocation .decider .AllocationDeciders ;
3636import org .elasticsearch .cluster .routing .allocation .decider .Decision ;
3737import org .elasticsearch .cluster .routing .allocation .decider .Decision .Type ;
38- import org .elasticsearch .common .FrequencyCappedAction ;
3938import org .elasticsearch .common .settings .Setting ;
4039import org .elasticsearch .common .settings .Setting .Property ;
4140import org .elasticsearch .common .settings .Settings ;
5857import java .util .Map ;
5958import java .util .Set ;
6059import java .util .function .BiFunction ;
61- import java .util .function .LongSupplier ;
6260import java .util .function .Predicate ;
6361
6462import 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" );
0 commit comments