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 usingSnapshotable.snapshot(long, long, CheckpointStreamFactory, CheckpointOptions).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractKeyedStateBackend.PartitionStateFactory-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
KeyedStateBackend.KeySelectionListener<K>
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.flink.core.fs.CloseableRegistrycancelStreamRegistryRegistry for all opened streams, so they can be closed if the task using this backend is closed.protected InternalKeyContext<K>keyContextThe key context for this backend.protected StreamCompressionDecoratorkeyGroupCompressionDecoratorDecorates the input and output streams to write key-groups compressed.protected KeyGroupRangekeyGroupRangeRange of key-groups for which this backend is responsible.protected org.apache.flink.api.common.typeutils.TypeSerializer<K>keySerializerThe key serializer.protected TaskKvStateRegistrykvStateRegistryKvStateRegistry helper for this task.protected LatencyTrackingStateConfiglatencyTrackingStateConfigprotected intnumberOfKeyGroupsThe number of key-groups aka max parallelism.protected TtlTimeProviderttlTimeProviderprotected ClassLoaderuserCodeClassLoader
-
Constructor Summary
Constructors Modifier Constructor Description 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(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <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()booleanderegisterKeySelectionListener(KeyedStateBackend.KeySelectionListener<K> listener)Stop 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.KgetCurrentKey()Used by states to access the current key.intgetCurrentKeyGroupIndex()Returns the key-group to which the current key belongs.InternalKeyContext<K>getKeyContext()StreamCompressionDecoratorgetKeyGroupCompressionDecorator()KeyGroupRangegetKeyGroupRange()Returns the key groups which this state backend is responsible for.org.apache.flink.api.common.typeutils.TypeSerializer<K>getKeySerializer()LatencyTrackingStateConfiggetLatencyTrackingStateConfig()intgetNumberOfKeyGroups()Returns 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)intnumKeyValueStatesByName()voidpublishQueryableStateIfEnabled(org.apache.flink.api.common.state.StateDescriptor<?,?> stateDescriptor, InternalKvState<?,?,?> kvState)voidregisterKeySelectionListener(KeyedStateBackend.KeySelectionListener<K> listener)State 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, wait
-
Methods inherited from interface org.apache.flink.runtime.state.CheckpointableKeyedStateBackend
savepoint
-
Methods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAborted, notifyCheckpointComplete
-
Methods inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
getKeys, getKeysAndNamespaces, isSafeToReuseKVState
-
Methods inherited from interface org.apache.flink.runtime.state.KeyedStateFactory
createOrUpdateInternalState, createOrUpdateInternalState, createOrUpdateInternalState
-
Methods inherited from interface org.apache.flink.runtime.state.PriorityQueueSetFactory
create, create
-
Methods inherited from interface org.apache.flink.runtime.state.Snapshotable
snapshot
-
Methods inherited from interface org.apache.flink.runtime.state.TestableKeyedStateBackend
getDelegatedKeyedStateBackend, numKeyValueStateEntries
-
-
-
-
Field Detail
-
keySerializer
protected final org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer
The key serializer.
-
numberOfKeyGroups
protected final int numberOfKeyGroups
The number of key-groups aka max parallelism.
-
keyGroupRange
protected final KeyGroupRange keyGroupRange
Range of key-groups for which this backend is responsible.
-
kvStateRegistry
protected final TaskKvStateRegistry kvStateRegistry
KvStateRegistry helper for this task.
-
cancelStreamRegistry
protected org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry
Registry for all opened streams, so they can be closed if the task using this backend is closed.
-
userCodeClassLoader
protected final ClassLoader userCodeClassLoader
-
ttlTimeProvider
protected final TtlTimeProvider ttlTimeProvider
-
latencyTrackingStateConfig
protected final LatencyTrackingStateConfig latencyTrackingStateConfig
-
keyGroupCompressionDecorator
protected final StreamCompressionDecorator keyGroupCompressionDecorator
Decorates the input and output streams to write key-groups compressed.
-
keyContext
protected final InternalKeyContext<K> keyContext
The key context for this backend.
-
-
Constructor Detail
-
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
protected AbstractKeyedStateBackend(AbstractKeyedStateBackend<K> abstractKeyedStateBackend)
-
-
Method Detail
-
notifyCheckpointSubsumed
public void notifyCheckpointSubsumed(long checkpointId) throws Exception- 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
public void setCurrentKey(K newKey)
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:
KeyedStateBackend
-
setCurrentKeyAndKeyGroup
public void setCurrentKeyAndKeyGroup(K newKey, int newKeyGroupIndex)
Description copied from interface:KeyedStateBackendAct as a fast path forKeyedStateBackend.setCurrentKey(K)when the key group is known.- Specified by:
setCurrentKeyAndKeyGroupin interfaceKeyedStateBackend<K>
-
registerKeySelectionListener
public void registerKeySelectionListener(KeyedStateBackend.KeySelectionListener<K> listener)
Description copied from interface:KeyedStateBackendState backend will callKeyedStateBackend.KeySelectionListener.keySelected(K)when key context is switched if supported.- Specified by:
registerKeySelectionListenerin interfaceKeyedStateBackend<K>
-
deregisterKeySelectionListener
public boolean deregisterKeySelectionListener(KeyedStateBackend.KeySelectionListener<K> listener)
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
public org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
- Specified by:
getKeySerializerin interfaceKeyedStateBackend<K>- Returns:
- Serializer of the key.
- See Also:
KeyedStateBackend
-
getCurrentKey
public K 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:
KeyedStateBackend
-
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:
KeyedStateBackend
-
getNumberOfKeyGroups
public int getNumberOfKeyGroups()
Description copied from interface:InternalKeyContextReturns the number of key-groups aka max parallelism.- Specified by:
getNumberOfKeyGroupsin interfaceInternalKeyContext<K>- See Also:
KeyedStateBackend
-
getKeyGroupRange
public KeyGroupRange 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:
KeyedStateBackend
-
applyToAllKeys
public <N,S extends org.apache.flink.api.common.state.State,T> void applyToAllKeys(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) throws ExceptionDescription 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:
KeyedStateBackend
-
applyToAllKeys
public <N,S extends org.apache.flink.api.common.state.State,T> void applyToAllKeys(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) throws Exception- Throws:
Exception
-
getOrCreateKeyedState
public <N,S extends org.apache.flink.api.common.state.State,V> S getOrCreateKeyedState(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:
KeyedStateBackend
-
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:
KeyedStateBackend
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getLatencyTrackingStateConfig
public LatencyTrackingStateConfig getLatencyTrackingStateConfig()
-
getKeyGroupCompressionDecorator
@VisibleForTesting public StreamCompressionDecorator getKeyGroupCompressionDecorator()
-
numKeyValueStatesByName
@VisibleForTesting public int numKeyValueStatesByName()
-
requiresLegacySynchronousTimerSnapshots
public boolean requiresLegacySynchronousTimerSnapshots(SnapshotType checkpointType)
-
getKeyContext
public InternalKeyContext<K> 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.
-
-