@@ -54,10 +54,10 @@ public class AutoForceMergeManager extends AbstractLifecycleComponent {
5454 private final JvmService jvmService ;
5555 private final IndicesService indicesService ;
5656 private final ClusterService clusterService ;
57- private AsyncForceMergeTask task ;
58- private ConfigurationValidator configurationValidator ;
59- private NodeValidator nodeValidator ;
60- private ShardValidator shardValidator ;
57+ private final AsyncForceMergeTask task ;
58+ private final ConfigurationValidator configurationValidator ;
59+ private final NodeValidator nodeValidator ;
60+ private final ShardValidator shardValidator ;
6161 private final ForceMergeManagerSettings forceMergeManagerSettings ;
6262 private final AtomicBoolean initialCheckDone = new AtomicBoolean (false );
6363
@@ -92,20 +92,18 @@ protected void doClose() {
9292 }
9393
9494 private void triggerForceMerge () {
95- if (! forceMergeManagerSettings .isAutoForceMergeFeatureEnabled ()) {
96- logger .info ("Cluster configuration shows auto force merge feature is disabled. Closing task." );
95+ if (forceMergeManagerSettings .isAutoForceMergeFeatureEnabled () == false ) {
96+ logger .debug ("Cluster configuration shows auto force merge feature is disabled. Closing task." );
9797 return ;
9898 }
99- if (! configurationValidator .hasWarmNodes ()) {
99+ if (configurationValidator .hasWarmNodes () == false ) {
100100 logger .debug ("No warm nodes found. Skipping Auto Force merge." );
101101 return ;
102102 }
103-
104- if (!(nodeValidator .validate ().isAllowed ())) {
103+ if (nodeValidator .validate ().isAllowed () == false ) {
105104 logger .debug ("Node capacity constraints are not allowing to trigger auto ForceMerge" );
106105 return ;
107106 }
108-
109107 List <IndexShard > shards = new ArrayList <>();
110108 for (IndexService indexService : indicesService ) {
111109 for (IndexShard shard : indexService ) {
@@ -116,28 +114,23 @@ private void triggerForceMerge() {
116114 }
117115 }
118116 }
119-
120117 List <IndexShard > sortedShards = getSortedShardsByTranslogAge (shards );
121118 int iteration = nodeValidator .getMaxConcurrentForceMerges ();
122119 for (IndexShard shard : sortedShards ) {
123- if (! nodeValidator .validate ().isAllowed ()) {
120+ if (iteration == 0 || nodeValidator .validate ().isAllowed () == false ) {
124121 logger .debug ("Node conditions no longer suitable for force merge" );
125122 break ;
126123 }
127- if (iteration == 0 ) {
128- break ;
129- }
130124 iteration --;
131125 CompletableFuture .runAsync (() -> {
132126 try {
133127 shard .forceMerge (new ForceMergeRequest ()
134128 .maxNumSegments (forceMergeManagerSettings .getSegmentCountThreshold ()));
135- logger .info ("Merging is completed successfully for the shard {}" , shard .shardId ());
129+ logger .debug ("Merging is completed successfully for the shard {}" , shard .shardId ());
136130 } catch (IOException e ) {
137131 logger .error ("Error during force merge for shard {}" , shard .shardId (), e );
138132 }
139133 }, threadPool .executor (ThreadPool .Names .FORCE_MERGE ));
140-
141134 logger .debug ("Successfully triggered force merge for shard {}" , shard .shardId ());
142135 try {
143136 Thread .sleep (forceMergeManagerSettings .getForcemergeDelay ().getMillis ());
@@ -159,13 +152,13 @@ private List<IndexShard> getSortedShardsByTranslogAge(List<IndexShard> shards) {
159152 private class ShardAgeComparator implements Comparator <IndexShard > {
160153 @ Override
161154 public int compare (IndexShard s1 , IndexShard s2 ) {
162- long age1 = getTranslogAge (s1 );
163- long age2 = getTranslogAge (s2 );
155+ long age1 = getEarliestLastModifiedAge (s1 );
156+ long age2 = getEarliestLastModifiedAge (s2 );
164157 return Long .compare (age1 , age2 );
165158 }
166159 }
167160
168- private long getTranslogAge (IndexShard shard ) {
161+ private long getEarliestLastModifiedAge (IndexShard shard ) {
169162 CommonStatsFlags flags = new CommonStatsFlags (CommonStatsFlags .Flag .Translog );
170163 CommonStats stats = new CommonStats (indicesService .getIndicesQueryCache (), shard , flags );
171164 return stats .getTranslog () != null ? stats .getTranslog ().getEarliestLastModifiedAge () : 0 ;
@@ -194,16 +187,16 @@ protected class ConfigurationValidator implements ValidationStrategy {
194187 */
195188 @ Override
196189 public ValidationResult validate () {
197- if (! forceMergeManagerSettings .isAutoForceMergeFeatureEnabled ()) {
190+ if (forceMergeManagerSettings .isAutoForceMergeFeatureEnabled () == false ) {
198191 logger .debug ("Cluster configuration shows auto force merge feature is disabled. Closing task." );
199192 return new ValidationResult (false );
200193 }
201194 initializeIfNeeded ();
202- if (! isRemoteStoreEnabled ) {
195+ if (isRemoteStoreEnabled == false ) {
203196 logger .debug ("Cluster configuration is not meeting the criteria. Closing task." );
204197 return new ValidationResult (false );
205198 }
206- if (! isOnlyDataNode ) {
199+ if (isOnlyDataNode == false ) {
207200 logger .debug ("Node configuration doesn't meet requirements. Closing task." );
208201 task .close ();
209202 return new ValidationResult (false );
@@ -220,7 +213,7 @@ public ValidationResult validate() {
220213 * Thread-safe through atomic operation on initialCheckDone.
221214 */
222215 private void initializeIfNeeded () {
223- if (! initialCheckDone .get ()) {
216+ if (initialCheckDone .get () == false ) {
224217 DiscoveryNode localNode = clusterService .localNode ();
225218 isOnlyDataNode = localNode .isDataNode () && !localNode .isWarmNode ();
226219 isRemoteStoreEnabled = isRemoteStorageEnabled ();
@@ -239,7 +232,7 @@ private boolean isRemoteStorageEnabled() {
239232 * Checks if cluster has warm nodes.
240233 */
241234 private boolean hasWarmNodes () {
242- if (hasWarmNodes ) return true ;
235+ if (hasWarmNodes == true ) return true ;
243236 ClusterState clusterState = clusterService .state ();
244237 return hasWarmNodes = clusterState .getNodes ().getNodes ()
245238 .values ()
@@ -270,8 +263,8 @@ public ValidationResult validate() {
270263 logger .debug ("JVM memory usage too high: {}%" , jvmUsedPercent );
271264 return new ValidationResult (false );
272265 }
273- if (! areForceMergeThreadsAvailable ()) {
274- logger .info ("No force merge threads available" );
266+ if (areForceMergeThreadsAvailable () == false ) {
267+ logger .debug ("No force merge threads available" );
275268 return new ValidationResult (false );
276269 }
277270 return new ValidationResult (true );
@@ -309,8 +302,8 @@ public ValidationResult validate(IndexShard shard) {
309302 logger .debug ("No shard found." );
310303 return new ValidationResult (false );
311304 }
312- if (! isIndexWarmCandidate (shard )) {
313- logger .info ("Shard {} doesn't belong to a warm candidate index" , shard .shardId ());
305+ if (isIndexWarmCandidate (shard ) == false ) {
306+ logger .debug ("Shard {} doesn't belong to a warm candidate index" , shard .shardId ());
314307 return new ValidationResult (false );
315308 }
316309 CommonStats stats = new CommonStats (indicesService .getIndicesQueryCache (), shard , flags );
@@ -331,6 +324,10 @@ private boolean isIndexWarmCandidate(IndexShard shard) {
331324 IndexSettings indexSettings = shard .indexSettings ();
332325 return indexSettings .getScopedSettings ().get (IndexSettings .INDEX_IS_WARM_CANDIDATE_INDEX );
333326 }
327+
328+ private boolean isRelocating (IndexShard shard ){
329+ return false ;
330+ }
334331 }
335332
336333 /**
@@ -396,7 +393,7 @@ protected boolean mustReschedule() {
396393 */
397394 @ Override
398395 protected void runInternal () {
399- if (! initialCheckDone .get () && !( configurationValidator .validate ().isAllowed ()) ) {
396+ if (initialCheckDone .get () == false && configurationValidator .validate ().isAllowed () == false ) {
400397 return ;
401398 }
402399 triggerForceMerge ();
0 commit comments