K
- type of key.N
- type of namespace.S
- type of state.@Internal public class NestedMapsStateTable<K,N,S> extends StateTable<K,N,S>
StateTable
uses nested HashMap
objects. It is also maintaining a partitioning
by key-group.
In contrast to CopyOnWriteStateTable
, this implementation does not support asynchronous snapshots. However,
it might have a better memory footprint for some use-cases, e.g. it is naturally de-duplicating namespace objects.
keyContext, metaInfo
Constructor and Description |
---|
NestedMapsStateTable(InternalKeyContext<K> keyContext,
RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo)
Creates a new
NestedMapsStateTable for the given key context and meta info. |
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.
|
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.
|
java.util.stream.Stream<K> |
getKeys(N namespace) |
Map<N,Map<K,S>>[] |
getState()
Returns the internal data structure.
|
void |
put(K key,
int keyGroupIndex,
N namespace,
S value) |
void |
put(N namespace,
S state)
Maps the composite of active key and given namespace to the specified state.
|
S |
putAndGetOld(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.
|
int |
size()
Returns the total number of entries in this
StateTable . |
int |
sizeOfNamespace(Object namespace) |
org.apache.flink.runtime.state.heap.NestedMapsStateTable.NestedMapsStateTableSnapshot<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. |
getMetaInfo, getNamespaceSerializer, getStateSerializer, isEmpty, keyGroupReader, setMetaInfo
public NestedMapsStateTable(InternalKeyContext<K> keyContext, RegisteredKeyValueStateBackendMetaInfo<N,S> metaInfo)
NestedMapsStateTable
for the given key context and meta info.keyContext
- the key context.metaInfo
- the meta information for this state table.@VisibleForTesting public Map<N,Map<K,S>>[] getState()
public int size()
StateTable
StateTable
. This is the sum of both sub-tables.size
in class StateTable<K,N,S>
StateTable
.public S get(N namespace)
StateTable
get
in class StateTable<K,N,S>
namespace
- the namespace. Not null.null
if no mapping for the specified key is found.public boolean containsKey(N namespace)
StateTable
containsKey
in class StateTable<K,N,S>
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)
StateTable
#putAndGetOld(N, S)
(Namespace, State)} when the caller is not interested in the old state.put
in class StateTable<K,N,S>
namespace
- the namespace. Not null.state
- the state. Can be null.public S putAndGetOld(N namespace, S state)
StateTable
putAndGetOld
in class StateTable<K,N,S>
namespace
- the namespace. Not null.state
- the state. Can be null.null
if there was no such mapping.public void remove(N namespace)
StateTable
#removeAndGetOld(N)
when the caller is not interested in the old state.remove
in class StateTable<K,N,S>
namespace
- the namespace of the mapping to remove. Not null.public S removeAndGetOld(N namespace)
StateTable
removeAndGetOld
in class StateTable<K,N,S>
namespace
- the namespace of the mapping to remove. Not null.null
if no mapping
for the specified key was found.public S get(K key, N namespace)
StateTable
get
in class StateTable<K,N,S>
key
- the key. Not null.namespace
- the namespace. Not null.null
if no mapping for the specified key is found.public java.util.stream.Stream<K> getKeys(N namespace)
getKeys
in class StateTable<K,N,S>
public void put(K key, int keyGroupIndex, N namespace, S value)
put
in class StateTable<K,N,S>
public int sizeOfNamespace(Object namespace)
sizeOfNamespace
in class StateTable<K,N,S>
public <T> void transform(N namespace, T value, StateTransformationFunction<S,T> transformation) throws Exception
StateTable
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.@Nonnull public org.apache.flink.runtime.state.heap.NestedMapsStateTable.NestedMapsStateTableSnapshot<K,N,S> stateSnapshot()
StateSnapshotRestore
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.