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
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final int
static final String
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.private final org.apache.hadoop.conf.Configuration
(package private) static final String
(package private) static final boolean
(package private) static final String
private final AtomicBoolean
private boolean
protected final org.apache.hadoop.fs.FileSystem
private CompletableFuture<Boolean>
private static final org.slf4j.Logger
static final String
Enable the CleanerChore to sort the subdirectories by consumed space and start the cleaning with the largest subdirectory.static final String
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.private final org.apache.hadoop.fs.Path
private final DirScanPool
private boolean
-
Constructor Summary
ConstructorDescriptionCleanerChore
(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 int
calculatePoolSize
(String poolSize) Calculate size for cleaner pool.private boolean
checkAndDeleteFiles
(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 void
chore()
The task to execute on each scheduled execution of the Chorevoid
cleanup()
Override to run cleanup tasks when the Chore encounters an error and must stop runningprivate boolean
deleteAction
(CleanerChore.Action<Boolean> deletion, String type, org.apache.hadoop.fs.Path dir) Perform a delete on a specified type.protected int
deleteFiles
(Iterable<org.apache.hadoop.fs.FileStatus> filesToDelete) Delete the given files(package private) int
boolean
private void
initCleanerChain
(String confKey) Instantiate and initialize all the file cleaners set in the configurationprotected boolean
Override to run a task before we start looping.private boolean
isEmptyDirDeletable
(org.apache.hadoop.fs.Path dir) Check if a empty directory with no subdirs or subfiles can be deletedprivate T
newFileCleaner
(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 void
private void
boolean
setEnabled
(boolean enabled) private boolean
shouldExclude
(org.apache.hadoop.fs.FileStatus f) Check if a path should not perform clearprivate void
sortByConsumedSpace
(List<org.apache.hadoop.fs.FileStatus> dirs) Sort the given list in (descending) order of the space each element takesprivate void
traverseAndDelete
(org.apache.hadoop.fs.Path dir, boolean root, CompletableFuture<Boolean> result) Attempts to clean up a directory(its subdirectories, and files) in aThreadPoolExecutor
concurrently.Trigger the cleaner immediately and return a CompletableFuture for getting the result.protected abstract boolean
validate
(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
- fullPath
of 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:ScheduledChore
Override to run a task before we start looping.- Overrides:
initialChore
in classScheduledChore
- Returns:
- true if initial chore was successful
-
chore
Description copied from class:ScheduledChore
The task to execute on each scheduled execution of the Chore- Specified by:
chore
in classScheduledChore
-
preRunCleaner
-
postRunCleaner
-
triggerCleanerNow
Trigger the cleaner immediately and return a CompletableFuture for getting the result. Returntrue
means 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:ScheduledChore
Override to run cleanup tasks when the Chore encounters an error and must stop running- Overrides:
cleanup
in 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 aThreadPoolExecutor
concurrently. 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
-