1818import org .elasticsearch .cluster .routing .ShardRouting ;
1919import org .elasticsearch .cluster .routing .allocation .RoutingAllocation ;
2020import org .elasticsearch .cluster .routing .allocation .WriteLoadConstraintSettings ;
21+ import org .elasticsearch .common .FrequencyCappedAction ;
2122import org .elasticsearch .common .settings .ClusterSettings ;
2223import org .elasticsearch .core .Strings ;
24+ import org .elasticsearch .core .TimeValue ;
2325import org .elasticsearch .threadpool .ThreadPool ;
2426
2527/**
@@ -31,10 +33,16 @@ public class WriteLoadConstraintDecider extends AllocationDecider {
3133
3234 public static final String NAME = "write_load" ;
3335
36+ private final FrequencyCappedAction logInterventionMessage ;
3437 private final WriteLoadConstraintSettings writeLoadConstraintSettings ;
3538
3639 public WriteLoadConstraintDecider (ClusterSettings clusterSettings ) {
3740 this .writeLoadConstraintSettings = new WriteLoadConstraintSettings (clusterSettings );
41+ logInterventionMessage = new FrequencyCappedAction (System ::currentTimeMillis , TimeValue .ZERO );
42+ clusterSettings .initializeAndWatch (
43+ WriteLoadConstraintSettings .WRITE_LOAD_DECIDER_MINIMUM_LOGGING_INTERVAL ,
44+ logInterventionMessage ::setMinInterval
45+ );
3846 }
3947
4048 @ Override
@@ -77,7 +85,9 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
7785 nodeWriteThreadPoolLoadThreshold ,
7886 shardRouting .shardId ()
7987 );
80- logger .debug (explain );
88+ if (logger .isDebugEnabled ()) {
89+ logInterventionMessage .maybeExecute (() -> logger .debug (explain ));
90+ }
8191 return Decision .single (Decision .Type .NOT_PREFERRED , NAME , explain );
8292 }
8393
@@ -97,7 +107,9 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
97107 shardWriteLoad ,
98108 nodeWriteThreadPoolStats .totalThreadPoolThreads ()
99109 );
100- logger .debug (explain );
110+ if (logger .isDebugEnabled ()) {
111+ logInterventionMessage .maybeExecute (() -> logger .debug (explain ));
112+ }
101113 return Decision .single (Decision .Type .NOT_PREFERRED , NAME , explain );
102114 }
103115
@@ -108,7 +120,6 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
108120 node .nodeId (),
109121 newWriteThreadPoolUtilization
110122 );
111- logger .trace (explanation );
112123 return allocation .decision (Decision .YES , NAME , explanation );
113124 }
114125
@@ -146,7 +157,9 @@ public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting
146157 nodeWriteThreadPoolQueueLatencyThreshold .toHumanReadableString (2 ),
147158 nodeWriteThreadPoolStats .averageThreadPoolUtilization ()
148159 );
149- logger .debug (explain );
160+ if (logger .isDebugEnabled ()) {
161+ logInterventionMessage .maybeExecute (() -> logger .debug (explain ));
162+ }
150163 return Decision .single (Decision .Type .NOT_PREFERRED , NAME , explain );
151164 }
152165
@@ -156,7 +169,6 @@ public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting
156169 nodeWriteThreadPoolStats .maxThreadPoolQueueLatencyMillis (),
157170 nodeWriteThreadPoolQueueLatencyThreshold .toHumanReadableString (2 )
158171 );
159- logger .trace (explanation );
160172 return allocation .decision (Decision .YES , NAME , explanation );
161173 }
162174
0 commit comments