public class DirectoryCleaner extends Object
Provide methods to help Logviewer to clean up files in directories and to get a list of files without worrying about excessive memory usage.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_NUMBER_OF_FILES_FOR_DIR |
Constructor and Description |
---|
DirectoryCleaner(StormMetricsRegistry metricsRegistry) |
Modifier and Type | Method and Description |
---|---|
org.apache.storm.daemon.logviewer.utils.DeletionMeta |
deleteOldestWhileTooLarge(List<Path> dirs,
long quota,
boolean forPerDir,
Set<Path> activeDirs)
If totalSize of files exceeds the either the per-worker quota or global quota, Logviewer deletes oldest inactive log files in a worker directory or in all worker dirs.
|
List<Path> |
getFilesForDir(Path dir)
Lists files in directory.
|
DirectoryStream<Path> |
getStreamForDirectory(Path dir)
Creates DirectoryStream for give directory.
|
public static final int MAX_NUMBER_OF_FILES_FOR_DIR
public DirectoryCleaner(StormMetricsRegistry metricsRegistry)
public DirectoryStream<Path> getStreamForDirectory(Path dir) throws IOException
Creates DirectoryStream for give directory.
dir
- File instance representing specific directoryIOException
public org.apache.storm.daemon.logviewer.utils.DeletionMeta deleteOldestWhileTooLarge(List<Path> dirs, long quota, boolean forPerDir, Set<Path> activeDirs) throws IOException
If totalSize of files exceeds the either the per-worker quota or global quota, Logviewer deletes oldest inactive log files in a worker directory or in all worker dirs. We use the parameter forPerDir to switch between the two deletion modes.
dirs
- the list of directories to be scanned for deletionquota
- the per-dir quota or the total quota for the all directoriesforPerDir
- if true, deletion happens for a single dir; otherwise, for all directories globallyactiveDirs
- only for global deletion, we want to skip the active logs in activeDirsIOException
public List<Path> getFilesForDir(Path dir) throws IOException
Lists files in directory. Note that to avoid memory problem, we only return the first 1024 files in a directory.
dir
- directory to get file listIOException
Copyright © 2022 The Apache Software Foundation. All rights reserved.