4343import java .time .temporal .ChronoUnit ;
4444import java .util .*;
4545import java .util .stream .Collectors ;
46+ import java .util .concurrent .TimeUnit ;
4647
4748/**
4849 * @author Leonardo M. López
@@ -278,6 +279,11 @@ private void deleteOldestIndices() {
278279
279280 // Indices are returned from oldest to newest ordered by creation.date asc
280281 for (IndicesRecord index : indices ) {
282+ Optional <ElasticCluster > opt = getClusterStatus ();
283+
284+ if (opt .isEmpty () || opt .get ().getResume ().getDiskUsedPercent () < 70 )
285+ break ;
286+
281287 try {
282288 // Delete oldest indices
283289 deleteIndex (Collections .singletonList (index .index ()));
@@ -286,15 +292,12 @@ private void deleteOldestIndices() {
286292 "Docs Count: %3$s\n " +
287293 "Size: %4$s" ,
288294 index .index (), index .creationDateString (), index .docsCount (), index .storeSize ()), ApplicationEventType .INFO );
295+ TimeUnit .SECONDS .sleep (10 );
289296 } catch (Exception e ) {
290297 String msg = String .format ("%1$s: Fail to delete index: %2$s with message: %3$s" , ctx , index .index (), e .getMessage ());
291298 eventService .createEvent (msg , ApplicationEventType .WARNING );
292299 }
293300
294- Optional <ElasticCluster > opt = getClusterStatus ();
295-
296- if (opt .isEmpty () || opt .get ().getResume ().getDiskUsedPercent () < 70 )
297- break ;
298301 }
299302 } catch (Exception e ) {
300303 String msg = String .format ("%1$s: %2$s" , ctx , e .getMessage ());
@@ -407,4 +410,4 @@ public <T> SearchSqlResponse<T> searchBySql(SqlQueryRequest request, Class<T> re
407410 throw new RuntimeException (ctx + ": " + e .getMessage ());
408411 }
409412 }
410- }
413+ }
0 commit comments