2323import org .elasticsearch .common .lucene .store .IndexOutputOutputStream ;
2424import org .elasticsearch .common .lucene .store .InputStreamIndexInput ;
2525import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
26- import org .elasticsearch .core .CheckedFunction ;
2726import org .elasticsearch .core .IOUtils ;
2827import org .elasticsearch .core .Nullable ;
2928import org .elasticsearch .core .Tuple ;
@@ -351,28 +350,11 @@ protected Directory newDirectory(Path dir) throws IOException {
351350 * @param locations state paths.
352351 */
353352 public void cleanupOldFiles (final long currentGeneration , final Path [] locations ) {
354- cleanupOldFiles (prefix , currentGeneration , locations , this ::newDirectory );
355- }
356-
357- /**
358- * Clean ups all state files not matching passed generation.
359- *
360- * @param prefix filename prefix for filtering state files.
361- * @param currentGeneration state generation to keep.
362- * @param locations state paths.
363- * @param directoryFunc function to create a {@link Directory} for the given path.
364- */
365- public static void cleanupOldFiles (
366- final String prefix ,
367- final long currentGeneration ,
368- final Path [] locations ,
369- final CheckedFunction <Path , Directory , IOException > directoryFunc
370- ) {
371- final String fileNameToKeep = getStateFileName (prefix , currentGeneration );
353+ final String fileNameToKeep = getStateFileName (currentGeneration );
372354 for (Path location : locations ) {
373355 logger .trace ("cleanupOldFiles: cleaning up {}" , location );
374356 Path stateLocation = location .resolve (STATE_DIR_NAME );
375- try (Directory stateDir = directoryFunc . apply (stateLocation )) {
357+ try (Directory stateDir = newDirectory (stateLocation )) {
376358 for (String file : stateDir .listAll ()) {
377359 if (file .startsWith (prefix ) && file .equals (fileNameToKeep ) == false ) {
378360 deleteFileIgnoreExceptions (stateLocation , stateDir , file );
@@ -384,14 +366,6 @@ public static void cleanupOldFiles(
384366 }
385367 }
386368
387- /**
388- * Finds state file with maximum id.
389- *
390- * @param prefix - filename prefix
391- * @param locations - paths to directories with state folder
392- * @return maximum id of state file or -1 if no such files are found
393- * @throws IOException if IOException occurs
394- */
395369 long findMaxGenerationId (final String prefix , Path ... locations ) throws IOException {
396370 long maxId = -1 ;
397371 for (Path dataLocation : locations ) {
@@ -430,10 +404,6 @@ List<Path> findStateFilesByGeneration(final long generation, Path... locations)
430404 }
431405
432406 public String getStateFileName (long generation ) {
433- return getStateFileName (prefix , generation );
434- }
435-
436- public static String getStateFileName (String prefix , long generation ) {
437407 return prefix + generation + STATE_FILE_EXTENSION ;
438408 }
439409
0 commit comments