2525import java .util .Map ;
2626import java .util .stream .Collectors ;
2727
28+ import static org .elasticsearch .core .TimeValue .ONE_MINUTE ;
29+ import static org .elasticsearch .core .TimeValue .ZERO ;
30+ import static org .elasticsearch .core .TimeValue .timeValueMillis ;
31+ import static org .elasticsearch .core .TimeValue .timeValueMinutes ;
32+
2833/**
2934 * Keeps track of a limited number of shards that are currently in undesired allocations. If the
3035 * shards remain in undesired allocations for longer than a configurable threshold, it will log
@@ -34,12 +39,14 @@ public class UndesiredAllocationsTracker {
3439
3540 private static final Logger logger = LogManager .getLogger (UndesiredAllocationsTracker .class );
3641
42+ private static final TimeValue FIVE_MINUTES = timeValueMinutes (5 );
43+
3744 /**
3845 * Warning logs will be periodically written if we see a shard that's been in an undesired allocation for this long
3946 */
4047 public static final Setting <TimeValue > UNDESIRED_ALLOCATION_DURATION_LOG_THRESHOLD_SETTING = Setting .timeSetting (
4148 "cluster.routing.allocation.desired_balance.undesired_duration_logging.threshold" ,
42- TimeValue . timeValueMinutes ( 5 ) ,
49+ FIVE_MINUTES ,
4350 Setting .Property .Dynamic ,
4451 Setting .Property .NodeScope
4552 );
@@ -49,8 +56,8 @@ public class UndesiredAllocationsTracker {
4956 */
5057 public static final Setting <TimeValue > UNDESIRED_ALLOCATION_DURATION_LOG_INTERVAL_SETTING = Setting .timeSetting (
5158 "cluster.routing.allocation.desired_balance.undesired_duration_logging.interval" ,
52- TimeValue . timeValueMinutes ( 5 ) ,
53- TimeValue . timeValueMinutes ( 1 ) ,
59+ FIVE_MINUTES ,
60+ ONE_MINUTE ,
5461 Setting .Property .Dynamic ,
5562 Setting .Property .NodeScope
5663 );
@@ -75,7 +82,7 @@ public class UndesiredAllocationsTracker {
7582
7683 UndesiredAllocationsTracker (ClusterSettings clusterSettings , TimeProvider timeProvider ) {
7784 this .timeProvider = timeProvider ;
78- this .undesiredAllocationDurationLogInterval = new FrequencyCappedAction (timeProvider ::relativeTimeInMillis , TimeValue . ZERO );
85+ this .undesiredAllocationDurationLogInterval = new FrequencyCappedAction (timeProvider ::relativeTimeInMillis , ZERO );
7986 clusterSettings .initializeAndWatch (
8087 UNDESIRED_ALLOCATION_DURATION_LOG_INTERVAL_SETTING ,
8188 undesiredAllocationDurationLogInterval ::setMinInterval
@@ -172,7 +179,7 @@ private void logDecisionsForUndesiredShardsOverThreshold(
172179 if (shardRouting != null ) {
173180 logUndesiredShardDetails (
174181 shardRouting ,
175- TimeValue . timeValueMillis (currentTimeMillis - undesiredAllocation .undesiredSince ()),
182+ timeValueMillis (currentTimeMillis - undesiredAllocation .undesiredSince ()),
176183 routingNodes ,
177184 routingAllocation ,
178185 desiredBalance
0 commit comments