Class HeapKeyedStateBackend<K>
java.lang.Object
org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>
org.apache.flink.runtime.state.heap.HeapKeyedStateBackend<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,CheckpointableKeyedStateBackend<K>,InternalKeyContext<K>,KeyedStateBackend<K>,KeyedStateFactory,PriorityQueueSetFactory,Snapshotable<SnapshotResult<KeyedStateHandle>>,TestableKeyedStateBackend<K>,org.apache.flink.util.Disposable
A
AbstractKeyedStateBackend that keeps state on the Java Heap and will serialize state to
streams provided by a CheckpointStreamFactory upon checkpointing.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.flink.runtime.state.AbstractKeyedStateBackend
AbstractKeyedStateBackend.PartitionStateFactoryNested classes/interfaces inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
KeyedStateBackend.KeySelectionListener<K> -
Field Summary
Fields inherited from class org.apache.flink.runtime.state.AbstractKeyedStateBackend
cancelStreamRegistry, keyContext, keyGroupCompressionDecorator, keyGroupRange, keySerializer, kvStateRegistry, latencyTrackingStateConfig, numberOfKeyGroups, ttlTimeProvider, userCodeClassLoader -
Constructor Summary
ConstructorsConstructorDescriptionHeapKeyedStateBackend(TaskKvStateRegistry kvStateRegistry, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, ClassLoader userCodeClassLoader, org.apache.flink.api.common.ExecutionConfig executionConfig, TtlTimeProvider ttlTimeProvider, LatencyTrackingStateConfig latencyTrackingStateConfig, org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry, StreamCompressionDecorator keyGroupCompressionDecorator, Map<String, StateTable<K, ?, ?>> registeredKVStates, Map<String, HeapPriorityQueueSnapshotRestoreWrapper<?>> registeredPQStates, LocalRecoveryConfig localRecoveryConfig, HeapPriorityQueueSetFactory priorityQueueSetFactory, org.apache.flink.runtime.state.heap.HeapSnapshotStrategy<K> checkpointStrategy, SnapshotExecutionType snapshotExecutionType, org.apache.flink.runtime.state.heap.StateTableFactory<K> stateTableFactory, InternalKeyContext<K> keyContext) -
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, AbstractKeyedStateBackend.PartitionStateFactory partitionStateFactory) <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.<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.<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, boolean allowFutureMetadataUpdates) Creates or updates internal state and returns a newInternalKvState.getKeysAndNamespaces(String state) voidnotifyCheckpointAborted(long checkpointId) voidnotifyCheckpointComplete(long checkpointId) intReturns the total number of state entries across all keys/namespaces.intnumKeyValueStateEntries(Object namespace) Returns the total number of state entries across all keys for the given namespace.Returns aSavepointResourcesthat can be used bySavepointSnapshotStrategyto write out a savepoint in the common/unified format.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.toString()Methods inherited from class org.apache.flink.runtime.state.AbstractKeyedStateBackend
applyToAllKeys, close, deregisterKeySelectionListener, dispose, getCurrentKey, getCurrentKeyGroupIndex, getKeyContext, getKeyGroupCompressionDecorator, getKeyGroupRange, getKeySerializer, getLatencyTrackingStateConfig, getNumberOfKeyGroups, getOrCreateKeyedState, getPartitionedState, notifyCheckpointSubsumed, numKeyValueStatesByName, publishQueryableStateIfEnabled, registerKeySelectionListener, requiresLegacySynchronousTimerSnapshots, setCurrentKey, setCurrentKeyAndKeyGroup, setCurrentKeyGroupIndexMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
isSafeToReuseKVStateMethods inherited from interface org.apache.flink.runtime.state.KeyedStateFactory
createOrUpdateInternalStateMethods inherited from interface org.apache.flink.runtime.state.TestableKeyedStateBackend
getDelegatedKeyedStateBackend
-
Constructor Details
-
HeapKeyedStateBackend
public HeapKeyedStateBackend(TaskKvStateRegistry kvStateRegistry, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, ClassLoader userCodeClassLoader, org.apache.flink.api.common.ExecutionConfig executionConfig, TtlTimeProvider ttlTimeProvider, LatencyTrackingStateConfig latencyTrackingStateConfig, org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry, StreamCompressionDecorator keyGroupCompressionDecorator, Map<String, StateTable<K, ?, ?>> registeredKVStates, Map<String, HeapPriorityQueueSnapshotRestoreWrapper<?>> registeredPQStates, LocalRecoveryConfig localRecoveryConfig, HeapPriorityQueueSetFactory priorityQueueSetFactory, org.apache.flink.runtime.state.heap.HeapSnapshotStrategy<K> checkpointStrategy, SnapshotExecutionType snapshotExecutionType, org.apache.flink.runtime.state.heap.StateTableFactory<K> stateTableFactory, InternalKeyContext<K> keyContext)
-
-
Method Details
-
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.- 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.- 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.
-
getKeys
- 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
- 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.
-
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.- 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
-
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, boolean allowFutureMetadataUpdates) throws ExceptionDescription copied from interface:KeyedStateFactoryCreates or updates internal state and returns a newInternalKvState.- 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.allowFutureMetadataUpdates- whether allow metadata to update in the future or not.- 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.- 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
-
savepoint
Description copied from interface:CheckpointableKeyedStateBackendReturns aSavepointResourcesthat can be used bySavepointSnapshotStrategyto write out a savepoint in the common/unified format. -
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId) -
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) -
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, throws ExceptionS> function, AbstractKeyedStateBackend.PartitionStateFactory partitionStateFactory) - Overrides:
applyToAllKeysin classAbstractKeyedStateBackend<K>- Throws:
Exception
-
toString
-
numKeyValueStateEntries
@VisibleForTesting public int numKeyValueStateEntries()Returns the total number of state entries across all keys/namespaces. -
numKeyValueStateEntries
Returns the total number of state entries across all keys for the given namespace. -
getLocalRecoveryConfig
-