Package org.apache.flink.runtime.state
Class AsyncSnapshotCallable<T>
- java.lang.Object
-
- org.apache.flink.runtime.state.AsyncSnapshotCallable<T>
-
- Type Parameters:
T
- type of the result.
- All Implemented Interfaces:
Callable<T>
public abstract class AsyncSnapshotCallable<T> extends Object implements Callable<T>
Base class that outlines the strategy for asynchronous snapshots. Implementations of this class are typically instantiated with resources that have been created in the synchronous part of a snapshot. Then, the implementation ofcallInternal()
is invoked in the asynchronous part. All resources created by this methods should be released by the end of the method. If the created resources areCloseable
objects and can block in calls (e.g. in/output streams), they should be registered with the snapshot'sCloseableRegistry
so that the can be closed and unblocked on cancellation. AftercallInternal()
ended,logAsyncSnapshotComplete(long)
is called. In that method, implementations can emit log statements about the duration. At the very end, this class callscleanupProvidedResources()
. The implementation of this method should release all provided resources that have been passed into the snapshot from the synchronous part of the snapshot.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AsyncSnapshotCallable.AsyncSnapshotTask
FutureTask
that wraps aAsyncSnapshotCallable
and connects it with cancellation and closing.
-
Field Summary
Fields Modifier and Type Field Description protected CloseableRegistry
snapshotCloseableRegistry
Registers streams that can block in I/O during snapshot.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AsyncSnapshotCallable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
call()
protected abstract T
callInternal()
This method implements the (async) snapshot logic.protected void
cancel()
protected abstract void
cleanupProvidedResources()
This method implements the cleanup of resources that have been passed in (from the sync part).protected void
logAsyncSnapshotComplete(long startTime)
This method is invoked after completion of the snapshot and can be overridden to output a logging about the duration of the async part.AsyncSnapshotCallable.AsyncSnapshotTask
toAsyncSnapshotFutureTask(CloseableRegistry taskRegistry)
Creates a future task from this and registers it with the givenCloseableRegistry
.
-
-
-
Field Detail
-
snapshotCloseableRegistry
@Nonnull protected final CloseableRegistry snapshotCloseableRegistry
Registers streams that can block in I/O during snapshot. Forwards close from taskCancelCloseableRegistry.
-
-
Method Detail
-
cancel
@VisibleForTesting protected void cancel()
-
toAsyncSnapshotFutureTask
public AsyncSnapshotCallable.AsyncSnapshotTask toAsyncSnapshotFutureTask(@Nonnull CloseableRegistry taskRegistry) throws IOException
Creates a future task from this and registers it with the givenCloseableRegistry
. The task is unregistered again inFutureTask.done()
.- Throws:
IOException
-
callInternal
protected abstract T callInternal() throws Exception
This method implements the (async) snapshot logic. Resources aquired within this method should be released at the end of the method.- Throws:
Exception
-
cleanupProvidedResources
protected abstract void cleanupProvidedResources()
This method implements the cleanup of resources that have been passed in (from the sync part). Called after the end ofcallInternal()
.
-
logAsyncSnapshotComplete
protected void logAsyncSnapshotComplete(long startTime)
This method is invoked after completion of the snapshot and can be overridden to output a logging about the duration of the async part.
-
-