public class LazyDbValueState<K,N,V> extends Object implements KvState<K,N,ValueState<V>,ValueStateDescriptor<V>,DbStateBackend>, ValueState<V>, CheckpointListener
KvState
using a SQL backend. Key-value pairs are
cached on heap and are lazily retrieved on access.Constructor and Description |
---|
LazyDbValueState(String kvStateId,
boolean compact,
ShardedConnection cons,
DbBackendConfig conf,
TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer,
ValueStateDescriptor<V> stateDesc)
Constructor to initialize the
LazyDbValueState the first time the
job starts. |
LazyDbValueState(String kvStateId,
boolean compact,
ShardedConnection cons,
DbBackendConfig conf,
TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer,
ValueStateDescriptor<V> stateDesc,
long nextTs,
long lastCompactedTs)
Initialize the
LazyDbValueState from a snapshot. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes the value mapped under the current key.
|
void |
dispose()
Disposes the key/value state, releasing all occupied resources.
|
ExecutorService |
getExecutor()
Used for testing purposes
|
Map<Tuple2<K,N>,com.google.common.base.Optional<V>> |
getModified()
Return the Map of modified states that hasn't been written to the
database yet.
|
Map<Tuple2<K,N>,com.google.common.base.Optional<V>> |
getStateCache()
Return the Map of cached states.
|
boolean |
isCompactor()
Used for testing purposes
|
void |
notifyCheckpointComplete(long checkpointId)
This method is called as a notification once a distributed checkpoint has been completed.
|
void |
setCurrentKey(K key)
Sets the current key, which will be used when using the state access methods.
|
void |
setCurrentNamespace(N namespace)
Sets the current namespace, which will be used when using the state access methods.
|
int |
size()
Returns the number of elements currently stored in the task's cache.
|
org.apache.flink.contrib.streaming.state.LazyDbValueState.DbKvStateSnapshot<K,N,V> |
snapshot(long checkpointId,
long timestamp)
Creates a snapshot of this state.
|
void |
update(V value)
Updates the operator state accessible by
ValueState.value() to the given
value. |
V |
value()
Returns the current value for the state.
|
public LazyDbValueState(String kvStateId, boolean compact, ShardedConnection cons, DbBackendConfig conf, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, ValueStateDescriptor<V> stateDesc) throws IOException
LazyDbValueState
the first time the
job starts.IOException
public LazyDbValueState(String kvStateId, boolean compact, ShardedConnection cons, DbBackendConfig conf, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, ValueStateDescriptor<V> stateDesc, long nextTs, long lastCompactedTs) throws IOException
LazyDbValueState
from a snapshot.IOException
public void setCurrentKey(K key)
KvState
setCurrentKey
in interface KvState<K,N,ValueState<V>,ValueStateDescriptor<V>,DbStateBackend>
key
- The key.public void setCurrentNamespace(N namespace)
KvState
setCurrentNamespace
in interface KvState<K,N,ValueState<V>,ValueStateDescriptor<V>,DbStateBackend>
namespace
- The namespace.public void update(V value) throws IOException
ValueState
ValueState.value()
to the given
value. The next time ValueState.value()
is called (for the same state
partition) the returned state will represent the updated value. When a
partitioned state is updated with null, the state for the current key
will be removed and the default value is returned on the next access.update
in interface OperatorState<V>
update
in interface ValueState<V>
value
- The new value for the state.IOException
- Thrown if the system cannot access the state.public V value() throws IOException
ValueState
value
in interface OperatorState<V>
value
in interface ValueState<V>
IOException
- Thrown if the system cannot access the state.public void clear()
State
public org.apache.flink.contrib.streaming.state.LazyDbValueState.DbKvStateSnapshot<K,N,V> snapshot(long checkpointId, long timestamp) throws IOException
KvState
snapshot
in interface KvState<K,N,ValueState<V>,ValueStateDescriptor<V>,DbStateBackend>
checkpointId
- The ID of the checkpoint for which the snapshot should be created.timestamp
- The timestamp of the checkpoint.IOException
public int size()
public void notifyCheckpointComplete(long checkpointId)
CheckpointListener
notifyCheckpointComplete
in interface CheckpointListener
checkpointId
- The ID of the checkpoint that has been completed.public void dispose()
KvState
dispose
in interface KvState<K,N,ValueState<V>,ValueStateDescriptor<V>,DbStateBackend>
public Map<Tuple2<K,N>,com.google.common.base.Optional<V>> getStateCache()
public Map<Tuple2<K,N>,com.google.common.base.Optional<V>> getModified()
public boolean isCompactor()
public ExecutorService getExecutor()
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.