Class AsyncKeyedStateBackendAdaptor<K>
java.lang.Object
org.apache.flink.runtime.state.v2.adaptor.AsyncKeyedStateBackendAdaptor<K>
- Type Parameters:
K- The key by which state is keyed.
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.common.state.InternalCheckpointListener,AsyncExecutionController.SwitchContextListener<K>,AsyncKeyedStateBackend<K>,PriorityQueueSetFactory,Snapshotable<SnapshotResult<KeyedStateHandle>>,org.apache.flink.util.Disposable
A adaptor that transforms
KeyedStateBackend into AsyncKeyedStateBackend.-
Constructor Summary
ConstructorsConstructorDescriptionAsyncKeyedStateBackendAdaptor(CheckpointableKeyedStateBackend<K> keyedStateBackend) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()<T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>>
KeyGroupedInternalPriorityQueue<T>create(String stateName, org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer) Creates aKeyGroupedInternalPriorityQueue.<T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>>
KeyGroupedInternalPriorityQueue<T>create(String stateName, org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer, boolean allowFutureMetadataUpdates) Creates aKeyGroupedInternalPriorityQueue.Creates aStateExecutorwhich supports to execute a batch of state requests asynchronously.<N,S extends InternalKeyedState, SV>
ScreateStateInternal(N defaultNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) Creates and returns a new state for internal usage.voiddispose()Returns the key groups which this state backend is responsible for.<N,S extends org.apache.flink.api.common.state.v2.State, SV>
SgetOrCreateKeyedState(N defaultNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) Creates or retrieves a keyed state backed by this state backend.booleanWhether it's safe to reuse key-values from the state-backend, e.g for the purpose of optimization.voidnotifyCheckpointAborted(long checkpointId) voidnotifyCheckpointComplete(long checkpointId) voidnotifyCheckpointSubsumed(long checkpointId) booleanrequiresLegacySynchronousTimerSnapshots(SnapshotType checkpointType) Whether the keyed state backend requires legacy synchronous timer snapshots.voidsetup(StateRequestHandler stateRequestHandler) Initializes with some contexts.snapshot(long checkpointId, long timestamp, CheckpointStreamFactory streamFactory, CheckpointOptions checkpointOptions) Operation that writes a snapshot into a stream that is provided by the givenCheckpointStreamFactoryand returns a @RunnableFuturethat gives a state handle to the snapshot.voidswitchContext(RecordContext<K> context) By default, a state backend does nothing when a key is switched in async processing.
-
Constructor Details
-
AsyncKeyedStateBackendAdaptor
-
-
Method Details
-
setup
Description copied from interface:AsyncKeyedStateBackendInitializes with some contexts.- Specified by:
setupin interfaceAsyncKeyedStateBackend<K>- Parameters:
stateRequestHandler- which handles state request.
-
getOrCreateKeyedState
public <N,S extends org.apache.flink.api.common.state.v2.State, S getOrCreateKeyedStateSV> (N defaultNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) throws Exception Description copied from interface:AsyncKeyedStateBackendCreates or retrieves a keyed state backed by this state backend.- Specified by:
getOrCreateKeyedStatein interfaceAsyncKeyedStateBackend<K>- Type Parameters:
N- the type of namespace for partitioning.S- The type of the public API state.SV- The type of the stored state value.- Parameters:
defaultNamespace- the default namespace for this state.namespaceSerializer- the serializer for namespace.stateDesc- TheStateDescriptorthat contains the name of the state.- Returns:
- A new key/value state backed by this backend.
- Throws:
Exception- Exceptions may occur during initialization of the state and should be forwarded.
-
createStateInternal
@Nonnull public <N,S extends InternalKeyedState, S createStateInternalSV> (@Nonnull N defaultNamespace, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, @Nonnull org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) throws Exception Description copied from interface:AsyncKeyedStateBackendCreates and returns a new state for internal usage.- Specified by:
createStateInternalin interfaceAsyncKeyedStateBackend<K>- Type Parameters:
N- the type of namespace for partitioning.S- The type of the public API state.SV- The type of the stored state value.- Parameters:
defaultNamespace- the default namespace for this state.namespaceSerializer- the serializer for namespace.stateDesc- TheStateDescriptorthat contains the name of the state.- Throws:
Exception- Exceptions may occur during initialization of the state.
-
createStateExecutor
Description copied from interface:AsyncKeyedStateBackendCreates aStateExecutorwhich supports to execute a batch of state requests asynchronously.Notice that the
AsyncKeyedStateBackendis responsible for shutting down the StateExecutors created by itself when they are no longer in use.- Specified by:
createStateExecutorin interfaceAsyncKeyedStateBackend<K>- Returns:
- a
StateExecutorwhich supports to execute a batch of state requests asynchronously.
-
getKeyGroupRange
Description copied from interface:AsyncKeyedStateBackendReturns the key groups which this state backend is responsible for.- Specified by:
getKeyGroupRangein interfaceAsyncKeyedStateBackend<K>
-
switchContext
Description copied from interface:AsyncKeyedStateBackendBy default, a state backend does nothing when a key is switched in async processing.- Specified by:
switchContextin interfaceAsyncExecutionController.SwitchContextListener<K>- Specified by:
switchContextin interfaceAsyncKeyedStateBackend<K>
-
dispose
public void dispose()- Specified by:
disposein interfaceAsyncKeyedStateBackend<K>- Specified by:
disposein interfaceorg.apache.flink.util.Disposable
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
notifyCheckpointComplete
- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Throws:
Exception
-
notifyCheckpointAborted
- Specified by:
notifyCheckpointAbortedin interfaceorg.apache.flink.api.common.state.CheckpointListener- Throws:
Exception
-
notifyCheckpointSubsumed
- Specified by:
notifyCheckpointSubsumedin interfaceorg.apache.flink.api.common.state.InternalCheckpointListener- Throws:
Exception
-
snapshot
@Nonnull public RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot(long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception Description copied from interface:SnapshotableOperation that writes a snapshot into a stream that is provided by the givenCheckpointStreamFactoryand returns a @RunnableFuturethat gives a state handle to the snapshot. It is up to the implementation if the operation is performed synchronous or asynchronous. In the later case, the returned Runnable must be executed first before obtaining the handle.- Specified by:
snapshotin interfaceSnapshotable<K>- Parameters:
checkpointId- The ID of the checkpoint.timestamp- The timestamp of the checkpoint.streamFactory- The factory that we can use for writing our state to streams.checkpointOptions- Options for how to perform this checkpoint.- Returns:
- A runnable future that will yield a
StateObject. - Throws:
Exception
-
create
@Nonnull public <T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>> KeyGroupedInternalPriorityQueue<T> create(@Nonnull String stateName, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer) Description copied from interface:PriorityQueueSetFactoryCreates aKeyGroupedInternalPriorityQueue.- Specified by:
createin interfacePriorityQueueSetFactory- Type Parameters:
T- type of the stored elements.- Parameters:
stateName- unique name for associated with this queue.byteOrderedElementSerializer- a serializer that with a format that is lexicographically ordered in alignment with elementPriorityComparator.- Returns:
- the queue with the specified unique name.
-
create
public <T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>> KeyGroupedInternalPriorityQueue<T> create(@Nonnull String stateName, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer, boolean allowFutureMetadataUpdates) Description copied from interface:PriorityQueueSetFactoryCreates aKeyGroupedInternalPriorityQueue.- Specified by:
createin interfacePriorityQueueSetFactory- Type Parameters:
T- type of the stored elements.- Parameters:
stateName- unique name for associated with this queue.byteOrderedElementSerializer- a serializer that with a format that is lexicographically ordered in alignment with elementPriorityComparator.allowFutureMetadataUpdates- whether allow metadata to update in the future or not.- Returns:
- the queue with the specified unique name.
-
requiresLegacySynchronousTimerSnapshots
Description copied from interface:AsyncKeyedStateBackendWhether the keyed state backend requires legacy synchronous timer snapshots.- Specified by:
requiresLegacySynchronousTimerSnapshotsin interfaceAsyncKeyedStateBackend<K>- Returns:
- true as default in case of AsyncKeyedStateBackend
-
isSafeToReuseKVState
public boolean isSafeToReuseKVState()Description copied from interface:AsyncKeyedStateBackendWhether it's safe to reuse key-values from the state-backend, e.g for the purpose of optimization.NOTE: this method should not be used to check for
InternalPriorityQueue, as the priority queue could be stored on different locations, e.g ForSt state-backend could store that on JVM heap if configuring HEAP as the time-service factory.- Specified by:
isSafeToReuseKVStatein interfaceAsyncKeyedStateBackend<K>- Returns:
- returns ture if safe to reuse the key-values from the state-backend.
-
getKeyedStateBackend
-