K - Type of the key by which state is keyed.public abstract class AbstractKeyedStateBackend<K> extends Object implements KeyedStateBackend<K>, Snapshotable<SnapshotResult<KeyedStateHandle>,Collection<KeyedStateHandle>>, Closeable, CheckpointListener
Snapshotable.snapshot(long, long, CheckpointStreamFactory, CheckpointOptions).| Modifier and Type | Field and Description |
|---|---|
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
|
protected K |
currentKey
The currently active key.
|
protected StreamCompressionDecorator |
keyGroupCompressionDecorator
Decorates the input and output streams to write key-groups compressed.
|
protected KeyGroupRange |
keyGroupRange
Range of key-groups for which this backend is responsible
|
protected org.apache.flink.api.common.typeutils.TypeSerializer<K> |
keySerializer
TypeSerializer for our key. |
protected HashMap<String,InternalKvState<K,?,?>> |
keyValueStatesByName
So that we can give out state when the user uses the same key.
|
protected TaskKvStateRegistry |
kvStateRegistry
KvStateRegistry helper for this task
|
protected int |
numberOfKeyGroups
The number of key-groups aka max parallelism
|
protected ClassLoader |
userCodeClassLoader |
| Constructor and Description |
|---|
AbstractKeyedStateBackend(TaskKvStateRegistry kvStateRegistry,
org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
ClassLoader userCodeClassLoader,
int numberOfKeyGroups,
KeyGroupRange keyGroupRange,
org.apache.flink.api.common.ExecutionConfig executionConfig) |
| Modifier and Type | Method and Description |
|---|---|
<N,S extends org.apache.flink.api.common.state.State,T> |
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)
Applies the provided
KeyedStateFunction to the state with the provided
StateDescriptor of all the currently active keys. |
void |
close() |
protected abstract <N,T,ACC,R> |
createAggregatingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.AggregatingStateDescriptor<T,ACC,R> stateDesc)
Creates and returns a new
AggregatingState. |
protected abstract <N,T,ACC> InternalFoldingState<K,N,T,ACC> |
createFoldingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.FoldingStateDescriptor<T,ACC> stateDesc)
Deprecated.
will be removed in a future version
|
protected abstract <N,T> InternalListState<K,N,T> |
createListState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ListStateDescriptor<T> stateDesc)
Creates and returns a new
ListState. |
protected abstract <N,UK,UV> InternalMapState<K,N,UK,UV> |
createMapState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.MapStateDescriptor<UK,UV> stateDesc)
Creates and returns a new
MapState. |
protected abstract <N,T> InternalReducingState<K,N,T> |
createReducingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ReducingStateDescriptor<T> stateDesc)
Creates and returns a new
ReducingState. |
protected abstract <N,T> InternalValueState<K,N,T> |
createValueState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ValueStateDescriptor<T> stateDesc)
Creates and returns a new
ValueState. |
void |
dispose()
Closes the state backend, releasing all internal resources, but does not delete any persistent
checkpoint data.
|
K |
getCurrentKey()
Used by states to access the current key.
|
int |
getCurrentKeyGroupIndex()
Returns the key-group to which the current key belongs.
|
StreamCompressionDecorator |
getKeyGroupCompressionDecorator() |
KeyGroupRange |
getKeyGroupRange()
Returns the key groups for this backend.
|
org.apache.flink.api.common.typeutils.TypeSerializer<K> |
getKeySerializer()
TypeSerializer for the state backend key type. |
int |
getNumberOfKeyGroups()
Returns the number of key-groups aka max parallelism.
|
<N,S extends org.apache.flink.api.common.state.State,V> |
getOrCreateKeyedState(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> |
getPartitionedState(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.
|
abstract int |
numStateEntries()
Returns the total number of state entries across all keys/namespaces.
|
void |
setCurrentKey(K newKey)
Sets the current key that is used for partitioned state.
|
boolean |
supportsAsynchronousSnapshots() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetKeysrestore, snapshotnotifyCheckpointCompleteprotected final org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer
TypeSerializer for our key.protected K currentKey
protected final HashMap<String,InternalKvState<K,?,?>> keyValueStatesByName
protected final int numberOfKeyGroups
protected final KeyGroupRange keyGroupRange
protected final TaskKvStateRegistry kvStateRegistry
protected org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry
protected final ClassLoader userCodeClassLoader
protected final StreamCompressionDecorator keyGroupCompressionDecorator
public AbstractKeyedStateBackend(TaskKvStateRegistry kvStateRegistry, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, ClassLoader userCodeClassLoader, int numberOfKeyGroups, KeyGroupRange keyGroupRange, org.apache.flink.api.common.ExecutionConfig executionConfig)
public void dispose()
dispose in interface KeyedStateBackend<K>dispose in interface org.apache.flink.util.Disposableprotected abstract <N,T> InternalValueState<K,N,T> createValueState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ValueStateDescriptor<T> stateDesc) throws Exception
ValueState.N - The type of the namespace.T - The type of the value that the ValueState can store.namespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exceptionprotected abstract <N,T> InternalListState<K,N,T> createListState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ListStateDescriptor<T> stateDesc) throws Exception
ListState.N - The type of the namespace.T - The type of the values that the ListState can store.namespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exceptionprotected abstract <N,T> InternalReducingState<K,N,T> createReducingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ReducingStateDescriptor<T> stateDesc) throws Exception
ReducingState.N - The type of the namespace.T - The type of the values that the ListState can store.namespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exceptionprotected abstract <N,T,ACC,R> InternalAggregatingState<K,N,T,ACC,R> createAggregatingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.AggregatingStateDescriptor<T,ACC,R> stateDesc) throws Exception
AggregatingState.N - The type of the namespace.T - The type of the values that the ListState can store.namespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exception@Deprecated protected abstract <N,T,ACC> InternalFoldingState<K,N,T,ACC> createFoldingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.FoldingStateDescriptor<T,ACC> stateDesc) throws Exception
FoldingState.N - The type of the namespace.T - Type of the values folded into the stateACC - Type of the value in the statenamespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exceptionprotected abstract <N,UK,UV> InternalMapState<K,N,UK,UV> createMapState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.MapStateDescriptor<UK,UV> stateDesc) throws Exception
MapState.N - The type of the namespace.UK - Type of the keys in the stateUV - Type of the values in the state *namespaceSerializer - TypeSerializer for the state namespace.stateDesc - The StateDescriptor that contains the name of the state.Exceptionpublic void setCurrentKey(K newKey)
KeyedStateBackendsetCurrentKey in interface KeyedStateBackend<K>newKey - The new current key.KeyedStateBackendpublic org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
InternalKeyContextTypeSerializer for the state backend key type.getKeySerializer in interface InternalKeyContext<K>KeyedStateBackendpublic K getCurrentKey()
InternalKeyContextgetCurrentKey in interface InternalKeyContext<K>KeyedStateBackendpublic int getCurrentKeyGroupIndex()
InternalKeyContextgetCurrentKeyGroupIndex in interface InternalKeyContext<K>KeyedStateBackendpublic int getNumberOfKeyGroups()
InternalKeyContextgetNumberOfKeyGroups in interface InternalKeyContext<K>KeyedStateBackendpublic KeyGroupRange getKeyGroupRange()
InternalKeyContextgetKeyGroupRange in interface InternalKeyContext<K>KeyedStateBackendpublic <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 Exception
KeyedStateBackendKeyedStateFunction to the state with the provided
StateDescriptor of all the currently active keys.applyToAllKeys in interface KeyedStateBackend<K>N - The type of the namespace.S - The type of the state.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.ExceptionKeyedStateBackendpublic <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 Exception
KeyedStateBackendgetOrCreateKeyedState in interface KeyedStateBackend<K>N - The type of the namespace.S - The type of the state.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.Exception - Exceptions may occur during initialization of the state and should be forwarded.KeyedStateBackendpublic <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 Exception
getPartitionedState in interface KeyedStateBackend<K>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.Exception - Exceptions may occur during initialization of the state and should be forwarded.KeyedStateBackendpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException@VisibleForTesting public boolean supportsAsynchronousSnapshots()
@VisibleForTesting public StreamCompressionDecorator getKeyGroupCompressionDecorator()
@VisibleForTesting public abstract int numStateEntries()
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.