Class StateTable<K,N,S>
java.lang.Object
org.apache.flink.runtime.state.heap.StateTable<K,N,S>
- Type Parameters:
K- type of keyN- type of namespaceS- type of state
- All Implemented Interfaces:
Iterable<StateEntry<K,,N, S>> StateSnapshotRestore
- Direct Known Subclasses:
CopyOnWriteStateTable
public abstract class StateTable<K,N,S>
extends Object
implements StateSnapshotRestore, Iterable<StateEntry<K,N,S>>
Base class for state tables. Accesses to state are typically scoped by the currently active key,
as provided through the
InternalKeyContext.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InternalKeyContext<K>The key context view on the backend.Map for holding the actual state objects.protected final KeyGroupRangeThe current key group range.protected final org.apache.flink.api.common.typeutils.TypeSerializer<K>The serializer of the key.protected RegisteredKeyValueStateBackendMetaInfo<N,S> Combined meta information such as name and serializers for this state. -
Constructor Summary
ConstructorsConstructorDescriptionStateTable(InternalKeyContext<K> keyContext, RegisteredKeyValueStateBackendMetaInfo<N, S> metaInfo, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer) -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(N namespace) Returns whether this table contains a mapping for the composite of active key and given namespace.Returns the state for the composite of active key and given namespace.Returns the state of the mapping for the composite of active key and given namespace.intorg.apache.flink.api.common.typeutils.TypeSerializer<K>getMapForKeyGroup(int keyGroupIndex) org.apache.flink.api.common.typeutils.TypeSerializer<N>getState()Returns the internal data structure.getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) org.apache.flink.api.common.typeutils.TypeSerializer<S>booleanisEmpty()Returns whether thisStateTableis empty.Iterator<StateEntry<K,N, S>> iterator()keyGroupReader(int readVersion) This method returns aStateSnapshotKeyGroupReaderthat can be used to restore the state on a per-key-group basis.voidvoidMaps the composite of active key and given namespace to the specified state.voidRemoves the mapping for the composite of active key and given namespace.removeAndGetOld(N namespace) Removes the mapping for the composite of active key and given namespace, returning the state that was found under the entry.voidsetMetaInfo(RegisteredKeyValueStateBackendMetaInfo<N, S> metaInfo) intsize()Returns the total number of entries in thisStateTable.intsizeOfNamespace(Object namespace) abstract IterableStateSnapshot<K,N, S> Returns a snapshot of the state.<T> voidtransform(N namespace, T value, StateTransformationFunction<S, T> transformation) Applies the givenStateTransformationFunctionto the state (1st input argument), using the given value as second input argument.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
keyContext
The key context view on the backend. This provides information, such as the currently active key. -
metaInfo
Combined meta information such as name and serializers for this state. -
keySerializer
The serializer of the key. -
keyGroupRange
The current key group range. -
keyGroupedStateMaps
Map for holding the actual state objects. The outer array represents the key-groups. All array positions will be initialized with an empty state map.
-
-
Constructor Details
-
StateTable
public StateTable(InternalKeyContext<K> keyContext, RegisteredKeyValueStateBackendMetaInfo<N, S> metaInfo, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer) - Parameters:
keyContext- the key context provides the key scope for all put/get/delete operations.metaInfo- the meta information, including the type serializer for state copy-on-write.keySerializer- the serializer of the key.
-
-
Method Details
-
createStateMap
-
stateSnapshot
Description copied from interface:StateSnapshotRestoreReturns a snapshot of the state.- Specified by:
stateSnapshotin interfaceStateSnapshotRestore
-
isEmpty
public boolean isEmpty()Returns whether thisStateTableis empty.- Returns:
trueif thisStateTablehas no elements,falseotherwise.- See Also:
-
size
public int size()Returns the total number of entries in thisStateTable. This is the sum of both sub-tables.- Returns:
- the number of entries in this
StateTable.
-
get
Returns the state of the mapping for the composite of active key and given namespace.- Parameters:
namespace- the namespace. Not null.- Returns:
- the states of the mapping with the specified key/namespace composite key, or
nullif no mapping for the specified key is found.
-
containsKey
Returns whether this table contains a mapping for the composite of active key and given namespace.- Parameters:
namespace- the namespace in the composite key to search for. Not null.- Returns:
trueif this map contains the specified key/namespace composite key,falseotherwise.
-
put
Maps the composite of active key and given namespace to the specified state.- Parameters:
namespace- the namespace. Not null.state- the state. Can be null.
-
remove
Removes the mapping for the composite of active key and given namespace. This method should be preferred overremoveAndGetOld(N)when the caller is not interested in the old state.- Parameters:
namespace- the namespace of the mapping to remove. Not null.
-
removeAndGetOld
Removes the mapping for the composite of active key and given namespace, returning the state that was found under the entry.- Parameters:
namespace- the namespace of the mapping to remove. Not null.- Returns:
- the state of the removed mapping or
nullif no mapping for the specified key was found.
-
transform
public <T> void transform(N namespace, T value, StateTransformationFunction<S, T> transformation) throws ExceptionApplies the givenStateTransformationFunctionto the state (1st input argument), using the given value as second input argument. The result ofStateTransformationFunction.apply(Object, Object)is then stored as the new state. This function is basically an optimization for get-update-put pattern.- Parameters:
namespace- the namespace. Not null.value- the value to use in transforming the state. Can be null.transformation- the transformation function.- Throws:
Exception- if some exception happens in the transformation function.
-
get
Returns the state for the composite of active key and given namespace. This is typically used by queryable state.- Parameters:
key- the key. Not null.namespace- the namespace. Not null.- Returns:
- the state of the mapping with the specified key/namespace composite key, or
nullif no mapping for the specified key is found.
-
getKeys
-
getKeysAndNamespaces
-
getStateIncrementalVisitor
public InternalKvState.StateIncrementalVisitor<K,N, getStateIncrementalVisitorS> (int recommendedMaxNumberOfReturnedRecords) -
getState
Returns the internal data structure. -
getKeyGroupOffset
public int getKeyGroupOffset() -
getMapForKeyGroup
-
getKeySerializer
-
getStateSerializer
-
getNamespaceSerializer
-
getMetaInfo
-
setMetaInfo
-
put
-
iterator
-
sizeOfNamespace
-
keyGroupReader
Description copied from interface:StateSnapshotRestoreThis method returns aStateSnapshotKeyGroupReaderthat can be used to restore the state on a per-key-group basis. This method tries to return a reader for the given version hint.- Specified by:
keyGroupReaderin interfaceStateSnapshotRestore- Parameters:
readVersion- the required version of the state to read.- Returns:
- a reader that reads state by key-groups, for the given read version.
-