Package org.apache.flink.runtime.state
Class AbstractKeyedStateBackend<K>
java.lang.Object
org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>
- Type Parameters:
K- Type of 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
- Direct Known Subclasses:
HeapKeyedStateBackend
public abstract class AbstractKeyedStateBackend<K>
extends Object
implements CheckpointableKeyedStateBackend<K>, org.apache.flink.api.common.state.InternalCheckpointListener, TestableKeyedStateBackend<K>, InternalKeyContext<K>
Base implementation of KeyedStateBackend. The state can be checkpointed to streams using
Snapshotable.snapshot(long, long, CheckpointStreamFactory, CheckpointOptions).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceNested classes/interfaces inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
KeyedStateBackend.KeySelectionListener<K> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.flink.core.fs.CloseableRegistryRegistry for all opened streams, so they can be closed if the task using this backend is closed.protected final InternalKeyContext<K>The key context for this backend.protected final StreamCompressionDecoratorDecorates the input and output streams to write key-groups compressed.protected final KeyGroupRangeRange of key-groups for which this backend is responsible.protected final org.apache.flink.api.common.typeutils.TypeSerializer<K>The key serializer.protected final TaskKvStateRegistryKvStateRegistry helper for this task.protected final LatencyTrackingStateConfigprotected final intThe number of key-groups aka max parallelism.protected final TtlTimeProviderprotected final ClassLoader -
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractKeyedStateBackend(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, InternalKeyContext<K> keyContext) AbstractKeyedStateBackend(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, InternalKeyContext<K> keyContext) protectedAbstractKeyedStateBackend(AbstractKeyedStateBackend<K> abstractKeyedStateBackend) -
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.<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) voidclose()booleanStop calling listener registered inKeyedStateBackend.registerKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K>).voiddispose()Closes the state backend, releasing all internal resources, but does not delete any persistent checkpoint data.Used by states to access the current key.intReturns the key-group to which the current key belongs.Returns the key groups which this state backend is responsible for.org.apache.flink.api.common.typeutils.TypeSerializer<K>intReturns the number of key-groups aka max parallelism.<N,S extends org.apache.flink.api.common.state.State, V>
SgetOrCreateKeyedState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, V> 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) TODO: NOTE: This method does a lot of work caching / retrieving states just to update the namespace.voidnotifyCheckpointSubsumed(long checkpointId) intvoidpublishQueryableStateIfEnabled(org.apache.flink.api.common.state.StateDescriptor<?, ?> stateDescriptor, InternalKvState<?, ?, ?> kvState) voidState backend will callKeyedStateBackend.KeySelectionListener.keySelected(K)when key context is switched if supported.booleanrequiresLegacySynchronousTimerSnapshots(SnapshotType checkpointType) 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.voidsetCurrentKeyGroupIndex(int currentKeyGroupIndex) Set current key group index of the context.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.CheckpointableKeyedStateBackend
savepointMethods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAborted, notifyCheckpointCompleteMethods inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
getKeys, getKeysAndNamespaces, isSafeToReuseKVStateMethods inherited from interface org.apache.flink.runtime.state.KeyedStateFactory
createOrUpdateInternalState, createOrUpdateInternalState, createOrUpdateInternalStateMethods inherited from interface org.apache.flink.runtime.state.PriorityQueueSetFactory
create, createMethods inherited from interface org.apache.flink.runtime.state.Snapshotable
snapshotMethods inherited from interface org.apache.flink.runtime.state.TestableKeyedStateBackend
getDelegatedKeyedStateBackend, numKeyValueStateEntries
-
Field Details
-
keySerializer
The key serializer. -
numberOfKeyGroups
protected final int numberOfKeyGroupsThe number of key-groups aka max parallelism. -
keyGroupRange
Range of key-groups for which this backend is responsible. -
kvStateRegistry
KvStateRegistry helper for this task. -
cancelStreamRegistry
protected org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistryRegistry for all opened streams, so they can be closed if the task using this backend is closed. -
userCodeClassLoader
-
ttlTimeProvider
-
latencyTrackingStateConfig
-
keyGroupCompressionDecorator
Decorates the input and output streams to write key-groups compressed. -
keyContext
The key context for this backend.
-
-
Constructor Details
-
AbstractKeyedStateBackend
public AbstractKeyedStateBackend(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, InternalKeyContext<K> keyContext) -
AbstractKeyedStateBackend
public AbstractKeyedStateBackend(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, InternalKeyContext<K> keyContext) -
AbstractKeyedStateBackend
-
-
Method Details
-
notifyCheckpointSubsumed
- Specified by:
notifyCheckpointSubsumedin interfaceorg.apache.flink.api.common.state.InternalCheckpointListener- Throws:
Exception
-
dispose
public void dispose()Closes the state backend, releasing all internal resources, but does not delete any persistent checkpoint data.- Specified by:
disposein interfaceorg.apache.flink.util.Disposable- Specified by:
disposein interfaceKeyedStateBackend<K>
-
setCurrentKey
Description copied from interface:KeyedStateBackendSets the current key that is used for partitioned state.- Specified by:
setCurrentKeyin interfaceInternalKeyContext<K>- Specified by:
setCurrentKeyin interfaceKeyedStateBackend<K>- Parameters:
newKey- The new current key.- See Also:
-
setCurrentKeyAndKeyGroup
Description copied from interface:KeyedStateBackendAct as a fast path forKeyedStateBackend.setCurrentKey(K)when the key group is known.- Specified by:
setCurrentKeyAndKeyGroupin 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.
-
getKeySerializer
- Specified by:
getKeySerializerin interfaceKeyedStateBackend<K>- Returns:
- Serializer of the key.
- See Also:
-
getCurrentKey
Description copied from interface:InternalKeyContextUsed by states to access the current key.- Specified by:
getCurrentKeyin interfaceInternalKeyContext<K>- Specified by:
getCurrentKeyin interfaceKeyedStateBackend<K>- Returns:
- Current key.
- See Also:
-
getCurrentKeyGroupIndex
public int getCurrentKeyGroupIndex()Description copied from interface:InternalKeyContextReturns the key-group to which the current key belongs.- Specified by:
getCurrentKeyGroupIndexin interfaceInternalKeyContext<K>- See Also:
-
getNumberOfKeyGroups
public int getNumberOfKeyGroups()Description copied from interface:InternalKeyContextReturns the number of key-groups aka max parallelism.- Specified by:
getNumberOfKeyGroupsin interfaceInternalKeyContext<K>- See Also:
-
getKeyGroupRange
Description copied from interface:CheckpointableKeyedStateBackendReturns the key groups which this state backend is responsible for.- Specified by:
getKeyGroupRangein interfaceCheckpointableKeyedStateBackend<K>- Specified by:
getKeyGroupRangein interfaceInternalKeyContext<K>- See Also:
-
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) 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.- Throws:
Exception- See Also:
-
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) - Throws:
Exception
-
getOrCreateKeyedState
public <N,S extends org.apache.flink.api.common.state.State, S getOrCreateKeyedStateV> (org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S, V> 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.- See Also:
-
publishQueryableStateIfEnabled
public void publishQueryableStateIfEnabled(org.apache.flink.api.common.state.StateDescriptor<?, ?> stateDescriptor, InternalKvState<?, ?, ?> kvState) -
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 ExceptionTODO: 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.- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getLatencyTrackingStateConfig
-
getKeyGroupCompressionDecorator
-
numKeyValueStatesByName
@VisibleForTesting public int numKeyValueStatesByName() -
requiresLegacySynchronousTimerSnapshots
-
getKeyContext
-
setCurrentKeyGroupIndex
public void setCurrentKeyGroupIndex(int currentKeyGroupIndex) Description copied from interface:InternalKeyContextSet current key group index of the context.- Specified by:
setCurrentKeyGroupIndexin interfaceInternalKeyContext<K>- Parameters:
currentKeyGroupIndex- the current key group index to set to.
-