K
- type of keyN
- type of namespaceS
- type of statepublic abstract class StateTable<K,N,S> extends Object implements StateSnapshotRestore, Iterable<StateEntry<K,N,S>>
InternalKeyContext
.Modifier and Type | Field and Description |
---|---|
protected InternalKeyContext<K> |
keyContext
The key context view on the backend.
|
protected StateMap<K,N,S>[] |
keyGroupedStateMaps
Map for holding the actual state objects.
|
protected KeyGroupRange |
keyGroupRange
The current key group range.
|
protected TypeSerializer<K> |
keySerializer
The serializer of the key.
|
protected RegisteredKeyValueStateBackendMetaInfo<N,S> |
metaInfo
Combined meta information such as name and serializers for this state.
|
Constructor and Description |
---|
StateTable(InternalKeyContext<K> keyContext,
RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo,
TypeSerializer<K> keySerializer) |
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(N namespace)
Returns whether this table contains a mapping for the composite of active key and given
namespace.
|
protected abstract StateMap<K,N,S> |
createStateMap() |
S |
get(K key,
N namespace)
Returns the state for the composite of active key and given namespace.
|
S |
get(N namespace)
Returns the state of the mapping for the composite of active key and given namespace.
|
int |
getKeyGroupOffset() |
Stream<K> |
getKeys(N namespace) |
Stream<Tuple2<K,N>> |
getKeysAndNamespaces() |
TypeSerializer<K> |
getKeySerializer() |
StateMap<K,N,S> |
getMapForKeyGroup(int keyGroupIndex) |
RegisteredKeyValueStateBackendMetaInfo<N,S> |
getMetaInfo() |
TypeSerializer<N> |
getNamespaceSerializer() |
StateMap<K,N,S>[] |
getState()
Returns the internal data structure.
|
InternalKvState.StateIncrementalVisitor<K,N,S> |
getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) |
TypeSerializer<S> |
getStateSerializer() |
boolean |
isEmpty()
Returns whether this
StateTable is empty. |
Iterator<StateEntry<K,N,S>> |
iterator() |
StateSnapshotKeyGroupReader |
keyGroupReader(int readVersion)
This method returns a
StateSnapshotKeyGroupReader that can be used to restore the
state on a per-key-group basis. |
void |
put(K key,
int keyGroup,
N namespace,
S state) |
void |
put(N namespace,
S state)
Maps the composite of active key and given namespace to the specified state.
|
void |
remove(N namespace)
Removes the mapping for the composite of active key and given namespace.
|
S |
removeAndGetOld(N namespace)
Removes the mapping for the composite of active key and given namespace, returning the state
that was found under the entry.
|
void |
setMetaInfo(RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo) |
int |
size()
Returns the total number of entries in this
StateTable . |
int |
sizeOfNamespace(Object namespace) |
abstract IterableStateSnapshot<K,N,S> |
stateSnapshot()
Returns a snapshot of the state.
|
<T> void |
transform(N namespace,
T value,
StateTransformationFunction<S,T> transformation)
Applies the given
StateTransformationFunction to the state (1st input argument),
using the given value as second input argument. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
protected final InternalKeyContext<K> keyContext
protected RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo
protected final TypeSerializer<K> keySerializer
protected final KeyGroupRange keyGroupRange
public StateTable(InternalKeyContext<K> keyContext, RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo, TypeSerializer<K> keySerializer)
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.@Nonnull public abstract IterableStateSnapshot<K,N,S> stateSnapshot()
StateSnapshotRestore
stateSnapshot
in interface StateSnapshotRestore
public boolean isEmpty()
StateTable
is empty.true
if this StateTable
has no elements, false
otherwise.size()
public int size()
StateTable
. This is the sum of both
sub-tables.StateTable
.public S get(N namespace)
namespace
- the namespace. Not null.null
if no mapping for the specified key is found.public boolean containsKey(N namespace)
namespace
- the namespace in the composite key to search for. Not null.true
if this map contains the specified key/namespace composite key, false
otherwise.public void put(N namespace, S state)
namespace
- the namespace. Not null.state
- the state. Can be null.public void remove(N namespace)
#removeAndGetOld(N)
when the caller is not interested in the old
state.namespace
- the namespace of the mapping to remove. Not null.public S removeAndGetOld(N namespace)
namespace
- the namespace of the mapping to remove. Not null.null
if no mapping for the specified key
was found.public <T> void transform(N namespace, T value, StateTransformationFunction<S,T> transformation) throws Exception
StateTransformationFunction
to the state (1st input argument),
using the given value as second input argument. The result of StateTransformationFunction.apply(Object, Object)
is then stored as the new state. This
function is basically an optimization for get-update-put pattern.namespace
- the namespace. Not null.value
- the value to use in transforming the state. Can be null.transformation
- the transformation function.Exception
- if some exception happens in the transformation function.public S get(K key, N namespace)
key
- the key. Not null.namespace
- the namespace. Not null.null
if no mapping for the specified key is found.public InternalKvState.StateIncrementalVisitor<K,N,S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords)
@VisibleForTesting public StateMap<K,N,S>[] getState()
public int getKeyGroupOffset()
@VisibleForTesting public StateMap<K,N,S> getMapForKeyGroup(int keyGroupIndex)
public TypeSerializer<K> getKeySerializer()
public TypeSerializer<S> getStateSerializer()
public TypeSerializer<N> getNamespaceSerializer()
public RegisteredKeyValueStateBackendMetaInfo<N,S> getMetaInfo()
public void setMetaInfo(RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo)
public Iterator<StateEntry<K,N,S>> iterator()
@VisibleForTesting public int sizeOfNamespace(Object namespace)
@Nonnull public StateSnapshotKeyGroupReader keyGroupReader(int readVersion)
StateSnapshotRestore
StateSnapshotKeyGroupReader
that 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.keyGroupReader
in interface StateSnapshotRestore
readVersion
- the required version of the state to read.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.