@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 SafetyNetCloseableRegistry |
getSafetyNetCloseableRegistryForThread()
Deprecated.
This method should be removed after FLINK-6684 is implemented.
|
static void |
initializeSafetyNetForThread()
Activates the safety net for a thread.
|
static void |
setSafetyNetCloseableRegistryForThread(SafetyNetCloseableRegistry registry)
Sets the active safety-net registry for the current 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.
@Deprecated @Internal public static SafetyNetCloseableRegistry getSafetyNetCloseableRegistryForThread()
@Internal public static void setSafetyNetCloseableRegistryForThread(SafetyNetCloseableRegistry registry)
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.