K
- Type of the key by which state is keyed.public abstract class AbstractKeyedStateBackend<K> extends Object implements KeyedStateBackend<K>, Snapshotable<KeyGroupsStateHandle>, Closeable, InternalKeyContext<K>
Snapshotable.snapshot(long, long, CheckpointStreamFactory)
.Modifier and Type | Field and Description |
---|---|
protected 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 KeyGroupRange |
keyGroupRange
Range of key-groups for which this backend is responsible
|
protected TypeSerializer<K> |
keySerializer
TypeSerializer for our key. |
protected HashMap<String,KvState<?>> |
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,
TypeSerializer<K> keySerializer,
ClassLoader userCodeClassLoader,
int numberOfKeyGroups,
KeyGroupRange keyGroupRange) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected abstract <N,T,ACC> FoldingState<T,ACC> |
createFoldingState(TypeSerializer<N> namespaceSerializer,
FoldingStateDescriptor<T,ACC> stateDesc)
Creates and returns a new
FoldingState . |
protected abstract <N,T> ListState<T> |
createListState(TypeSerializer<N> namespaceSerializer,
ListStateDescriptor<T> stateDesc)
Creates and returns a new
ListState . |
protected abstract <N,T> ReducingState<T> |
createReducingState(TypeSerializer<N> namespaceSerializer,
ReducingStateDescriptor<T> stateDesc)
Creates and returns a new
ReducingState . |
protected abstract <N,T> ValueState<T> |
createValueState(TypeSerializer<N> namespaceSerializer,
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.
|
KeyGroupRange |
getKeyGroupRange()
Returns the key groups for this backend.
|
TypeSerializer<K> |
getKeySerializer()
TypeSerializer for the state backend key type. |
int |
getNumberOfKeyGroups()
Returns the number of key-groups aka max parallelism.
|
<N,S extends State> |
getPartitionedState(N namespace,
TypeSerializer<N> namespaceSerializer,
StateDescriptor<S,?> stateDescriptor)
Creates or retrieves a partitioned state backed by this state backend.
|
<N,S extends MergingState<?,?>> |
mergePartitionedStates(N target,
Collection<N> sources,
TypeSerializer<N> namespaceSerializer,
StateDescriptor<S,?> stateDescriptor) |
void |
setCurrentKey(K newKey)
Sets the current key that is used for partitioned state.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
restore, snapshot
protected final TypeSerializer<K> keySerializer
TypeSerializer
for our key.protected K currentKey
protected HashMap<String,KvState<?>> keyValueStatesByName
protected final int numberOfKeyGroups
protected final KeyGroupRange keyGroupRange
protected final TaskKvStateRegistry kvStateRegistry
protected CloseableRegistry cancelStreamRegistry
protected final ClassLoader userCodeClassLoader
public AbstractKeyedStateBackend(TaskKvStateRegistry kvStateRegistry, TypeSerializer<K> keySerializer, ClassLoader userCodeClassLoader, int numberOfKeyGroups, KeyGroupRange keyGroupRange)
public void dispose()
dispose
in interface KeyedStateBackend<K>
protected abstract <N,T> ValueState<T> createValueState(TypeSerializer<N> namespaceSerializer, 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.Exception
protected abstract <N,T> ListState<T> createListState(TypeSerializer<N> namespaceSerializer, 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.Exception
protected abstract <N,T> ReducingState<T> createReducingState(TypeSerializer<N> namespaceSerializer, 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.Exception
protected abstract <N,T,ACC> FoldingState<T,ACC> createFoldingState(TypeSerializer<N> namespaceSerializer, 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 state *namespaceSerializer
- TypeSerializer for the state namespace.stateDesc
- The StateDescriptor
that contains the name of the state.Exception
public void setCurrentKey(K newKey)
KeyedStateBackend
setCurrentKey
in interface KeyedStateBackend<K>
newKey
- The new current key.KeyedStateBackend
public TypeSerializer<K> getKeySerializer()
KeyedStateBackend
TypeSerializer
for the state backend key type.getKeySerializer
in interface InternalKeyContext<K>
getKeySerializer
in interface KeyedStateBackend<K>
KeyedStateBackend
public K getCurrentKey()
KeyedStateBackend
getCurrentKey
in interface InternalKeyContext<K>
getCurrentKey
in interface KeyedStateBackend<K>
KeyedStateBackend
public int getCurrentKeyGroupIndex()
KeyedStateBackend
getCurrentKeyGroupIndex
in interface InternalKeyContext<K>
getCurrentKeyGroupIndex
in interface KeyedStateBackend<K>
KeyedStateBackend
public int getNumberOfKeyGroups()
KeyedStateBackend
getNumberOfKeyGroups
in interface InternalKeyContext<K>
getNumberOfKeyGroups
in interface KeyedStateBackend<K>
KeyedStateBackend
public KeyGroupRange getKeyGroupRange()
KeyedStateBackend
getKeyGroupRange
in interface InternalKeyContext<K>
getKeyGroupRange
in interface KeyedStateBackend<K>
KeyedStateBackend
public <N,S extends State> S getPartitionedState(N namespace, TypeSerializer<N> namespaceSerializer, StateDescriptor<S,?> stateDescriptor) throws Exception
KeyedStateBackend
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.KeyedStateBackend
public <N,S extends MergingState<?,?>> void mergePartitionedStates(N target, Collection<N> sources, TypeSerializer<N> namespaceSerializer, StateDescriptor<S,?> stateDescriptor) throws Exception
mergePartitionedStates
in interface KeyedStateBackend<K>
Exception
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.