K
- The type of the key.N
- The type of the namespace.UK
- The type of the keys in the map state.UV
- The type of the values in the map state.public class RocksDBMapState<K,N,UK,UV> extends AbstractRocksDBState<K,N,Map<UK,UV>,MapState<UK,UV>> implements InternalMapState<K,N,UK,UV>
MapState
implementation that stores state in RocksDB.
RocksDBStateBackend
must ensure that we set the
StringAppendOperator
on the column family that we use for our state since
we use the merge()
call.
backend, columnFamily, defaultValue, keySerializationDataOutputView, keySerializationStream, writeOptions
Constructor and Description |
---|
RocksDBMapState(org.rocksdb.ColumnFamilyHandle columnFamily,
TypeSerializer<N> namespaceSerializer,
TypeSerializer<Map<UK,UV>> valueSerializer,
Map<UK,UV> defaultValue,
RocksDBKeyedStateBackend<K> backend)
Creates a new
RocksDBMapState . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes the value mapped under the current key.
|
boolean |
contains(UK userKey)
Returns whether there exists the given mapping.
|
Iterable<Map.Entry<UK,UV>> |
entries()
Returns all the mappings in the state.
|
UV |
get(UK userKey)
Returns the current value associated with the given key.
|
TypeSerializer<K> |
getKeySerializer()
Returns the
TypeSerializer for the type of key this state is associated to. |
TypeSerializer<N> |
getNamespaceSerializer()
Returns the
TypeSerializer for the type of namespace this state is associated to. |
byte[] |
getSerializedValue(byte[] serializedKeyAndNamespace,
TypeSerializer<K> safeKeySerializer,
TypeSerializer<N> safeNamespaceSerializer,
TypeSerializer<Map<UK,UV>> safeValueSerializer)
Returns the serialized value for the given key and namespace.
|
TypeSerializer<Map<UK,UV>> |
getValueSerializer()
Returns the
TypeSerializer for the type of value this state holds. |
Iterator<Map.Entry<UK,UV>> |
iterator()
Iterates over all the mappings in the state.
|
Iterable<UK> |
keys()
Returns all the keys in the state.
|
void |
put(UK userKey,
UV userValue)
Associates a new value with the given key.
|
void |
putAll(Map<UK,UV> map)
Copies all of the mappings from the given map into the state.
|
void |
remove(UK userKey)
Deletes the mapping of the given key.
|
Iterable<UV> |
values()
Returns all the values in the state.
|
getDefaultValue, setCurrentNamespace, writeCurrentKeyWithGroupAndNamespace, writeKeyWithGroupAndNamespace, writeKeyWithGroupAndNamespace
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setCurrentNamespace
public RocksDBMapState(org.rocksdb.ColumnFamilyHandle columnFamily, TypeSerializer<N> namespaceSerializer, TypeSerializer<Map<UK,UV>> valueSerializer, Map<UK,UV> defaultValue, RocksDBKeyedStateBackend<K> backend)
RocksDBMapState
.columnFamily
- The RocksDB column family that this state is associated to.namespaceSerializer
- The serializer for the namespace.valueSerializer
- The serializer for the state.defaultValue
- The default value for the state.backend
- The backend for which this state is bind to.public TypeSerializer<K> getKeySerializer()
InternalKvState
TypeSerializer
for the type of key this state is associated to.getKeySerializer
in interface InternalKvState<K,N,Map<UK,UV>>
public TypeSerializer<N> getNamespaceSerializer()
InternalKvState
TypeSerializer
for the type of namespace this state is associated to.getNamespaceSerializer
in interface InternalKvState<K,N,Map<UK,UV>>
public TypeSerializer<Map<UK,UV>> getValueSerializer()
InternalKvState
TypeSerializer
for the type of value this state holds.getValueSerializer
in interface InternalKvState<K,N,Map<UK,UV>>
public UV get(UK userKey) throws IOException, org.rocksdb.RocksDBException
MapState
get
in interface MapState<UK,UV>
userKey
- The key of the mappingIOException
org.rocksdb.RocksDBException
public void put(UK userKey, UV userValue) throws IOException, org.rocksdb.RocksDBException
MapState
put
in interface MapState<UK,UV>
userKey
- The key of the mappinguserValue
- The new value of the mappingIOException
org.rocksdb.RocksDBException
public void putAll(Map<UK,UV> map) throws IOException, org.rocksdb.RocksDBException
MapState
putAll
in interface MapState<UK,UV>
map
- The mappings to be stored in this stateIOException
org.rocksdb.RocksDBException
public void remove(UK userKey) throws IOException, org.rocksdb.RocksDBException
MapState
remove
in interface MapState<UK,UV>
userKey
- The key of the mappingIOException
org.rocksdb.RocksDBException
public boolean contains(UK userKey) throws IOException, org.rocksdb.RocksDBException
MapState
contains
in interface MapState<UK,UV>
userKey
- The key of the mappingIOException
org.rocksdb.RocksDBException
public Iterable<Map.Entry<UK,UV>> entries() throws IOException, org.rocksdb.RocksDBException
MapState
entries
in interface MapState<UK,UV>
IOException
org.rocksdb.RocksDBException
public Iterable<UK> keys() throws IOException, org.rocksdb.RocksDBException
MapState
keys
in interface MapState<UK,UV>
IOException
org.rocksdb.RocksDBException
public Iterable<UV> values() throws IOException, org.rocksdb.RocksDBException
MapState
values
in interface MapState<UK,UV>
IOException
org.rocksdb.RocksDBException
public Iterator<Map.Entry<UK,UV>> iterator() throws IOException, org.rocksdb.RocksDBException
MapState
iterator
in interface MapState<UK,UV>
IOException
org.rocksdb.RocksDBException
public void clear()
State
public byte[] getSerializedValue(byte[] serializedKeyAndNamespace, TypeSerializer<K> safeKeySerializer, TypeSerializer<N> safeNamespaceSerializer, TypeSerializer<Map<UK,UV>> safeValueSerializer) throws Exception
InternalKvState
If no value is associated with key and namespace, null
is returned.
TO IMPLEMENTERS: This method is called by multiple threads. Anything stateful (e.g. serializers) should be either duplicated or protected from undesired consequences of concurrent invocations.
getSerializedValue
in interface InternalKvState<K,N,Map<UK,UV>>
getSerializedValue
in class AbstractRocksDBState<K,N,Map<UK,UV>,MapState<UK,UV>>
serializedKeyAndNamespace
- Serialized key and namespacesafeKeySerializer
- A key serializer which is safe to be used even in multi-threaded contextsafeNamespaceSerializer
- A namespace serializer which is safe to be used even in multi-threaded contextsafeValueSerializer
- A value serializer which is safe to be used even in multi-threaded contextnull
if no value is associated with the key and namespace.Exception
- Exceptions during serialization are forwardedCopyright © 2014–2019 The Apache Software Foundation. All rights reserved.