HDFS-12984. BlockPoolSlice can leak in a mini dfs cluster. Contributed by Ajay Kumar.
This commit is contained in:
parent
128d773a23
commit
b278f7b293
@ -84,6 +84,7 @@ class BlockPoolSlice {
|
||||
private final int ioFileBufferSize;
|
||||
@VisibleForTesting
|
||||
public static final String DU_CACHE_FILE = "dfsUsed";
|
||||
private final Runnable shutdownHook;
|
||||
private volatile boolean dfsUsedSaved = false;
|
||||
private static final int SHUTDOWN_HOOK_PRIORITY = 30;
|
||||
private final boolean deleteDuplicateReplicas;
|
||||
@ -162,15 +163,16 @@ class BlockPoolSlice {
|
||||
.build();
|
||||
|
||||
// Make the dfs usage to be saved during shutdown.
|
||||
ShutdownHookManager.get().addShutdownHook(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!dfsUsedSaved) {
|
||||
saveDfsUsed();
|
||||
}
|
||||
shutdownHook = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!dfsUsedSaved) {
|
||||
saveDfsUsed();
|
||||
}
|
||||
}, SHUTDOWN_HOOK_PRIORITY);
|
||||
}
|
||||
};
|
||||
ShutdownHookManager.get().addShutdownHook(shutdownHook,
|
||||
SHUTDOWN_HOOK_PRIORITY);
|
||||
}
|
||||
|
||||
File getDirectory() {
|
||||
@ -756,6 +758,11 @@ void shutdown(BlockListAsLongs blocksListToPersist) {
|
||||
saveDfsUsed();
|
||||
dfsUsedSaved = true;
|
||||
|
||||
// Remove the shutdown hook to avoid any memory leak
|
||||
if (shutdownHook != null) {
|
||||
ShutdownHookManager.get().removeShutdownHook(shutdownHook);
|
||||
}
|
||||
|
||||
if (dfsUsage instanceof CachingGetSpaceUsed) {
|
||||
IOUtils.cleanup(LOG, ((CachingGetSpaceUsed) dfsUsage));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user