Class CleanerChore<T extends FileCleanerDelegate>
java.lang.Object
org.apache.hadoop.hbase.ScheduledChore
org.apache.hadoop.hbase.master.cleaner.CleanerChore<T>
- Type Parameters:
T- Cleaner delegate class that is dynamically loaded from configuration
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
HFileCleaner,LogCleaner
Abstract Cleaner that uses a chain of delegates to clean a directory of files
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intstatic final StringConfigures the threadpool used for scanning the archive directory for the HFileCleaner If it is an integer and >= 1, it would be the size; if 0.0 < size <= 1.0, size would be available processors * size.private final org.apache.hadoop.conf.Configuration(package private) static final String(package private) static final boolean(package private) static final Stringprivate final AtomicBooleanprivate booleanprotected final org.apache.hadoop.fs.FileSystemprivate CompletableFuture<Boolean>private static final org.slf4j.Loggerstatic final StringEnable the CleanerChore to sort the subdirectories by consumed space and start the cleaning with the largest subdirectory.static final StringConfigures the threadpool used for scanning the Old logs directory for the LogCleaner Follows the same configuration mechanism as CHORE_POOL_SIZE, but has a default of 1 thread.private final org.apache.hadoop.fs.Pathprivate final DirScanPoolprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionCleanerChore(String name, int sleepPeriod, Stoppable s, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path oldFileDir, String confKey, DirScanPool pool) CleanerChore(String name, int sleepPeriod, Stoppable s, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path oldFileDir, String confKey, DirScanPool pool, Map<String, Object> params, List<org.apache.hadoop.fs.Path> excludePaths) -
Method Summary
Modifier and TypeMethodDescription(package private) static intcalculatePoolSize(String poolSize) Calculate size for cleaner pool.private booleancheckAndDeleteFiles(List<org.apache.hadoop.fs.FileStatus> files) Run the given files through each of the cleaners to see if it should be deleted, deleting it if necessary.protected voidchore()The task to execute on each scheduled execution of the Chorevoidcleanup()Override to run cleanup tasks when the Chore encounters an error and must stop runningprivate booleandeleteAction(CleanerChore.Action<Boolean> deletion, String type, org.apache.hadoop.fs.Path dir) Perform a delete on a specified type.protected intdeleteFiles(Iterable<org.apache.hadoop.fs.FileStatus> filesToDelete) Delete the given files(package private) intbooleanprivate voidinitCleanerChain(String confKey) Instantiate and initialize all the file cleaners set in the configurationprotected booleanOverride to run a task before we start looping.private booleanisEmptyDirDeletable(org.apache.hadoop.fs.Path dir) Check if a empty directory with no subdirs or subfiles can be deletedprivate TnewFileCleaner(String className, org.apache.hadoop.conf.Configuration conf) A utility method to create new instances of LogCleanerDelegate based on the class name of the LogCleanerDelegate.private voidprivate voidbooleansetEnabled(boolean enabled) private booleanshouldExclude(org.apache.hadoop.fs.FileStatus f) Check if a path should not perform clearprivate voidsortByConsumedSpace(List<org.apache.hadoop.fs.FileStatus> dirs) Sort the given list in (descending) order of the space each element takesprivate voidtraverseAndDelete(org.apache.hadoop.fs.Path dir, boolean root, CompletableFuture<Boolean> result) Attempts to clean up a directory(its subdirectories, and files) in aThreadPoolExecutorconcurrently.Trigger the cleaner immediately and return a CompletableFuture for getting the result.protected abstract booleanvalidate(org.apache.hadoop.fs.Path file) Validate the file to see if it even belongs in the directory.Methods inherited from class org.apache.hadoop.hbase.ScheduledChore
cancel, cancel, choreForTesting, getInitialDelay, getName, getPeriod, getStopper, getTimeUnit, isInitialChoreComplete, isScheduled, run, shutdown, shutdown, toString, triggerNow
-
Field Details
-
LOG
-
AVAIL_PROCESSORS
-
CHORE_POOL_SIZE
Configures the threadpool used for scanning the archive directory for the HFileCleaner If it is an integer and >= 1, it would be the size; if 0.0 < size <= 1.0, size would be available processors * size. Pay attention that 1.0 is different from 1, former indicates it will use 100% of cores, while latter will use only 1 thread for chore to scan dir.- See Also:
-
DEFAULT_CHORE_POOL_SIZE
- See Also:
-
LOG_CLEANER_CHORE_SIZE
Configures the threadpool used for scanning the Old logs directory for the LogCleaner Follows the same configuration mechanism as CHORE_POOL_SIZE, but has a default of 1 thread.- See Also:
-
DEFAULT_LOG_CLEANER_CHORE_POOL_SIZE
- See Also:
-
LOG_CLEANER_CHORE_DIRECTORY_SORTING
Enable the CleanerChore to sort the subdirectories by consumed space and start the cleaning with the largest subdirectory. Enabled by default.- See Also:
-
DEFAULT_LOG_CLEANER_CHORE_DIRECTORY_SORTING
- See Also:
-
pool
-
fs
-
oldFileDir
-
conf
-
params
-
enabled
-
cleanersChain
-
excludeDirs
-
future
-
forceRun
-
sortDirectories
-
-
Constructor Details
-
CleanerChore
public CleanerChore(String name, int sleepPeriod, Stoppable s, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path oldFileDir, String confKey, DirScanPool pool) -
CleanerChore
public CleanerChore(String name, int sleepPeriod, Stoppable s, org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path oldFileDir, String confKey, DirScanPool pool, Map<String, Object> params, List<org.apache.hadoop.fs.Path> excludePaths) - Parameters:
name- name of the chore being runsleepPeriod- the period of time to sleep between each runs- the stopperconf- configuration to usefs- handle to the FSoldFileDir- the path to the archived filesconfKey- configuration key for the classes to instantiatepool- the thread pool used to scan directoriesparams- members could be used in cleaner
-
-
Method Details
-
calculatePoolSize
Calculate size for cleaner pool.- Parameters:
poolSize- size from configuration- Returns:
- size of pool after calculation
-
validate
Validate the file to see if it even belongs in the directory. If it is valid, then the file will go through the cleaner delegates, but otherwise the file is just deleted.- Parameters:
file- fullPathof the file to be checked- Returns:
- true if the file is valid, false otherwise
-
initCleanerChain
Instantiate and initialize all the file cleaners set in the configuration- Parameters:
confKey- key to get the file cleaner classes from the configuration
-
newFileCleaner
A utility method to create new instances of LogCleanerDelegate based on the class name of the LogCleanerDelegate.- Parameters:
className- fully qualified class name of the LogCleanerDelegateconf- used configuration- Returns:
- the new instance
-
initialChore
Description copied from class:ScheduledChoreOverride to run a task before we start looping.- Overrides:
initialChorein classScheduledChore- Returns:
- true if initial chore was successful
-
chore
Description copied from class:ScheduledChoreThe task to execute on each scheduled execution of the Chore- Specified by:
chorein classScheduledChore
-
preRunCleaner
-
postRunCleaner
-
triggerCleanerNow
Trigger the cleaner immediately and return a CompletableFuture for getting the result. Returntruemeans all the old files have been deleted, otherwisefalse.- Throws:
InterruptedException
-
sortByConsumedSpace
Sort the given list in (descending) order of the space each element takes- Parameters:
dirs- the list to sort, element in it should be directory (not file)
-
checkAndDeleteFiles
Run the given files through each of the cleaners to see if it should be deleted, deleting it if necessary.- Parameters:
files- List of FileStatus for the files to check (and possibly delete)- Returns:
- true iff successfully deleted all files
-
isEmptyDirDeletable
Check if a empty directory with no subdirs or subfiles can be deleted- Parameters:
dir- Path of the directory- Returns:
- True if the directory can be deleted, otherwise false
-
deleteFiles
Delete the given files- Parameters:
filesToDelete- files to delete- Returns:
- number of deleted files
-
cleanup
Description copied from class:ScheduledChoreOverride to run cleanup tasks when the Chore encounters an error and must stop running- Overrides:
cleanupin classScheduledChore
-
getChorePoolSize
int getChorePoolSize() -
setEnabled
-
getEnabled
-
traverseAndDelete
private void traverseAndDelete(org.apache.hadoop.fs.Path dir, boolean root, CompletableFuture<Boolean> result) Attempts to clean up a directory(its subdirectories, and files) in aThreadPoolExecutorconcurrently. We can get the final result by calling result.get(). -
shouldExclude
Check if a path should not perform clear -
deleteAction
private boolean deleteAction(CleanerChore.Action<Boolean> deletion, String type, org.apache.hadoop.fs.Path dir) Perform a delete on a specified type.- Parameters:
deletion- a deletetype- possible values are 'files', 'subdirs', 'dirs'- Returns:
- true if it deleted successfully, false otherwise
-