@@ -70,6 +70,13 @@ public abstract class CleanerChore<T extends FileCleanerDelegate> extends Schedu
7070 */
7171 public static final String LOG_CLEANER_CHORE_SIZE = "hbase.log.cleaner.scan.dir.concurrent.size" ;
7272 static final String DEFAULT_LOG_CLEANER_CHORE_POOL_SIZE = "1" ;
73+ /**
74+ * Enable the CleanerChore to sort the subdirectories by consumed space and start the cleaning
75+ * with the largest subdirectory. Enabled by default.
76+ */
77+ public static final String LOG_CLEANER_CHORE_DIRECTORY_SORTING =
78+ "hbase.cleaner.directory.sorting" ;
79+ static final boolean DEFAULT_LOG_CLEANER_CHORE_DIRECTORY_SORTING = true ;
7380
7481 private final DirScanPool pool ;
7582
@@ -82,6 +89,7 @@ public abstract class CleanerChore<T extends FileCleanerDelegate> extends Schedu
8289 protected List <String > excludeDirs ;
8390 private CompletableFuture <Boolean > future ;
8491 private boolean forceRun ;
92+ private boolean sortDirectories ;
8593
8694 public CleanerChore (String name , final int sleepPeriod , final Stoppable s , Configuration conf ,
8795 FileSystem fs , Path oldFileDir , String confKey , DirScanPool pool ) {
@@ -123,6 +131,8 @@ public CleanerChore(String name, final int sleepPeriod, final Stoppable s, Confi
123131 if (excludeDirs != null ) {
124132 LOG .info ("Cleaner {} excludes sub dirs: {}" , name , excludeDirs );
125133 }
134+ sortDirectories = conf .getBoolean (LOG_CLEANER_CHORE_DIRECTORY_SORTING ,
135+ DEFAULT_LOG_CLEANER_CHORE_DIRECTORY_SORTING );
126136 initCleanerChain (confKey );
127137 }
128138
@@ -475,7 +485,9 @@ private void traverseAndDelete(Path dir, boolean root, CompletableFuture<Boolean
475485 // Step.3: Start to traverse and delete the sub-directories.
476486 List <CompletableFuture <Boolean >> futures = new ArrayList <>();
477487 if (!subDirs .isEmpty ()) {
478- sortByConsumedSpace (subDirs );
488+ if (sortDirectories ) {
489+ sortByConsumedSpace (subDirs );
490+ }
479491 // Submit the request of sub-directory deletion.
480492 subDirs .forEach (subDir -> {
481493 if (!shouldExclude (subDir )) {
0 commit comments