@Internal public class FileSystemSafetyNet extends Object
FileSystem
stream resource
leaks. When activated for a thread, it tracks all streams that are opened by FileSystems that the
thread obtains. The safety net has a global cleanup hook that will close all streams that were
not properly closed.
The main thread of each Flink task, as well as the checkpointing thread are automatically guarded by this safety net.
Important: This safety net works only for streams created by Flink's FileSystem
abstraction, i.e., for FileSystem
instances obtained via FileSystem.get(URI)
or
through Path.getFileSystem()
.
Important: When a guarded thread obtains a FileSystem
or a stream and passes
them to another thread, the safety net will close those resources once the former thread
finishes.
The safety net can be used as follows:
class GuardedThread extends Thread {
public void run() {
FileSystemSafetyNet.initializeSafetyNetForThread();
try {
// do some heavy stuff where you are unsure whether it closes all streams
// like some untrusted user code or library code
}
finally {
FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread();
}
}
}
Constructor and Description |
---|
FileSystemSafetyNet() |
Modifier and Type | Method and Description |
---|---|
static void |
closeSafetyNetAndGuardedResourcesForThread()
Closes the safety net for a thread.
|
static void |
initializeSafetyNetForThread()
Activates the safety net for a thread.
|
@Internal public static void initializeSafetyNetForThread()
FileSystem
instances obtained by the thread
that called this method will be guarded, meaning that their created streams are tracked and
can be closed via the safety net closing hook.
This method should be called at the beginning of a thread that should be guarded.
IllegalStateException
- Thrown, if a safety net was already registered for the thread.@Internal public static void closeSafetyNetAndGuardedResourcesForThread()
This method should be called at the very end of a guarded thread.
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.