Class BatchExecutionKeyedStateBackend<K>
java.lang.Object
org.apache.flink.streaming.api.operators.sorted.state.BatchExecutionKeyedStateBackend<K>
- All Implemented Interfaces:
Closeable,AutoCloseable,CheckpointableKeyedStateBackend<K>,KeyedStateBackend<K>,KeyedStateFactory,PriorityQueueSetFactory,Snapshotable<SnapshotResult<KeyedStateHandle>>,org.apache.flink.util.Disposable
public class BatchExecutionKeyedStateBackend<K>
extends Object
implements CheckpointableKeyedStateBackend<K>
A
CheckpointableKeyedStateBackend which keeps values for a single key at a time.
IMPORTANT: Requires the incoming records to be sorted/grouped by the key. Used in a BATCH style execution.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
KeyedStateBackend.KeySelectionListener<K> -
Constructor Summary
ConstructorsConstructorDescriptionBatchExecutionKeyedStateBackend(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, KeyGroupRange keyGroupRange, org.apache.flink.api.common.ExecutionConfig executionConfig) -
Method Summary
Modifier and TypeMethodDescription<N,S extends org.apache.flink.api.common.state.State, T>
voidapplyToAllKeys(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, T> stateDescriptor, KeyedStateFunction<K, S> function) Applies the providedKeyedStateFunctionto the state with the providedStateDescriptorof all the currently active keys.voidclose()<T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>>
KeyGroupedInternalPriorityQueue<T>create(String stateName, org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer) Creates aKeyGroupedInternalPriorityQueue.<N,SV, SEV, S extends org.apache.flink.api.common.state.State, IS extends S>
IScreateOrUpdateInternalState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, SV> stateDesc, StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory) Creates or updates internal state and returns a newInternalKvState.booleanStop calling listener registered inKeyedStateBackend.registerKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K>).voiddispose()Returns the key groups which this state backend is responsible for.getKeysAndNamespaces(String state) org.apache.flink.api.common.typeutils.TypeSerializer<K><N,S extends org.apache.flink.api.common.state.State, T>
SgetOrCreateKeyedState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, T> stateDescriptor) Creates or retrieves a keyed state backed by this state backend.<N,S extends org.apache.flink.api.common.state.State>
SgetPartitionedState(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, ?> stateDescriptor) Creates or retrieves a partitioned state backed by this state backend.voidState backend will callKeyedStateBackend.KeySelectionListener.keySelected(K)when key context is switched if supported.Returns aSavepointResourcesthat can be used bySavepointSnapshotStrategyto write out a savepoint in the common/unified format.voidsetCurrentKey(K newKey) Sets the current key that is used for partitioned state.voidsetCurrentKeyAndKeyGroup(K newKey, int newKeyGroupIndex) Act as a fast path forKeyedStateBackend.setCurrentKey(K)when the key group is known.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
isSafeToReuseKVStateMethods inherited from interface org.apache.flink.runtime.state.KeyedStateFactory
createOrUpdateInternalState, createOrUpdateInternalStateMethods inherited from interface org.apache.flink.runtime.state.PriorityQueueSetFactory
create
-
Constructor Details
-
BatchExecutionKeyedStateBackend
public BatchExecutionKeyedStateBackend(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, KeyGroupRange keyGroupRange, org.apache.flink.api.common.ExecutionConfig executionConfig)
-
-
Method Details
-
setCurrentKey
Description copied from interface:KeyedStateBackendSets the current key that is used for partitioned state.- Specified by:
setCurrentKeyin interfaceKeyedStateBackend<K>- Parameters:
newKey- The new current key.
-
getCurrentKey
- Specified by:
getCurrentKeyin interfaceKeyedStateBackend<K>- Returns:
- Current key.
-
setCurrentKeyAndKeyGroup
Description copied from interface:KeyedStateBackendAct as a fast path forKeyedStateBackend.setCurrentKey(K)when the key group is known.- Specified by:
setCurrentKeyAndKeyGroupin interfaceKeyedStateBackend<K>
-
getKeySerializer
- Specified by:
getKeySerializerin interfaceKeyedStateBackend<K>- Returns:
- Serializer of the key.
-
applyToAllKeys
public <N,S extends org.apache.flink.api.common.state.State, void applyToAllKeysT> (N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, T> stateDescriptor, KeyedStateFunction<K, S> function) Description copied from interface:KeyedStateBackendApplies the providedKeyedStateFunctionto the state with the providedStateDescriptorof all the currently active keys.- Specified by:
applyToAllKeysin interfaceKeyedStateBackend<K>- Type Parameters:
N- The type of the namespace.S- The type of the state.- Parameters:
namespace- the namespace of the state.namespaceSerializer- the serializer for the namespace.stateDescriptor- the descriptor of the state to which the function is going to be applied.function- the function to be applied to the keyed state.
-
getKeys
- Specified by:
getKeysin interfaceKeyedStateBackend<K>- Parameters:
state- State variable for which existing keys will be returned.namespace- Namespace for which existing keys will be returned.- Returns:
- A stream of all keys for the given state and namespace. Modifications to the state during iterating over it keys are not supported.
-
getKeysAndNamespaces
- Specified by:
getKeysAndNamespacesin interfaceKeyedStateBackend<K>- Parameters:
state- State variable for which existing keys will be returned.- Returns:
- A stream of all keys for the given state and namespace. Modifications to the state during iterating over it keys are not supported. Implementations go not make any ordering guarantees about the returned tupes. Two records with the same key or namespace may not be returned near each other in the stream.
-
getOrCreateKeyedState
public <N,S extends org.apache.flink.api.common.state.State, S getOrCreateKeyedStateT> (org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, T> stateDescriptor) throws ExceptionDescription copied from interface:KeyedStateBackendCreates or retrieves a keyed state backed by this state backend.- Specified by:
getOrCreateKeyedStatein interfaceKeyedStateBackend<K>- Type Parameters:
N- The type of the namespace.S- The type of the state.- Parameters:
namespaceSerializer- The serializer used for the namespace type of the statestateDescriptor- The identifier for the state. This contains name and can create a default state value.- Returns:
- A new key/value state backed by this backend.
- Throws:
Exception- Exceptions may occur during initialization of the state and should be forwarded.
-
getPartitionedState
public <N,S extends org.apache.flink.api.common.state.State> S getPartitionedState(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, ?> stateDescriptor) throws ExceptionDescription copied from interface:KeyedStateBackendCreates or retrieves a partitioned state backed by this state backend.TODO: NOTE: This method does a lot of work caching / retrieving states just to update the namespace. This method should be removed for the sake of namespaces being lazily fetched from the keyed state backend, or being set on the state directly.
- Specified by:
getPartitionedStatein interfaceKeyedStateBackend<K>- Type Parameters:
N- The type of the namespace.S- The type of the state.stateDescriptor- The identifier for the state. This contains name and can create a default state value.- Returns:
- A new key/value state backed by this backend.
- Throws:
Exception- Exceptions may occur during initialization of the state and should be forwarded.
-
dispose
public void dispose()- Specified by:
disposein interfaceorg.apache.flink.util.Disposable- Specified by:
disposein interfaceKeyedStateBackend<K>
-
registerKeySelectionListener
Description copied from interface:KeyedStateBackendState backend will callKeyedStateBackend.KeySelectionListener.keySelected(K)when key context is switched if supported.- Specified by:
registerKeySelectionListenerin interfaceKeyedStateBackend<K>
-
deregisterKeySelectionListener
Description copied from interface:KeyedStateBackendStop calling listener registered inKeyedStateBackend.registerKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K>).- Specified by:
deregisterKeySelectionListenerin interfaceKeyedStateBackend<K>- Returns:
- returns true iff listener was registered before.
-
createOrUpdateInternalState
@Nonnull public <N,SV, IS createOrUpdateInternalStateSEV, S extends org.apache.flink.api.common.state.State, IS extends S> (@Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, @Nonnull org.apache.flink.api.common.state.StateDescriptor<S, SV> stateDesc, @Nonnull StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory) throws ExceptionDescription copied from interface:KeyedStateFactoryCreates or updates internal state and returns a newInternalKvState.- Specified by:
createOrUpdateInternalStatein interfaceKeyedStateFactory- Type Parameters:
N- The type of the namespace.SV- The type of the stored state value.SEV- The type of the stored state value or entry for collection types (list or map).S- The type of the public API state.IS- The type of internal state.- Parameters:
namespaceSerializer- TypeSerializer for the state namespace.stateDesc- TheStateDescriptorthat contains the name of the state.snapshotTransformFactory- factory of state snapshot transformer.- 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.
-
getKeyGroupRange
Description copied from interface:CheckpointableKeyedStateBackendReturns the key groups which this state backend is responsible for.- Specified by:
getKeyGroupRangein interfaceCheckpointableKeyedStateBackend<K>
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
snapshot
@Nonnull public RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot(long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) 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.
-
savepoint
Description copied from interface:CheckpointableKeyedStateBackendReturns aSavepointResourcesthat can be used bySavepointSnapshotStrategyto write out a savepoint in the common/unified format.- Specified by:
savepointin interfaceCheckpointableKeyedStateBackend<K>- Throws:
Exception
-