K
- The type of the key.N
- The type of the namespace.S
- The type of State
.SD
- The type of StateDescriptor
.public abstract class AbstractRocksDBState<K,N,S extends State,SD extends StateDescriptor<S,?>> extends Object implements KvState<K,N,S,SD,RocksDBStateBackend>, State
State
implementations that store state in a RocksDB database.
This base class is responsible for setting up the RocksDB database, for
checkpointing/restoring the database and for disposal in the dispose()
method. The
concrete subclasses just use the RocksDB handle to store/retrieve state.
State is checkpointed asynchronously. The synchronous part is drawing the actual backup
from RocksDB, this is done in snapshot(long, long)
. This will return a
AsyncRocksDBSnapshot
that will perform the copying of the backup to the remote
file system.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractRocksDBState.AbstractRocksDBSnapshot<K,N,S extends State,SD extends StateDescriptor<S,?>> |
Modifier and Type | Field and Description |
---|---|
protected File |
basePath
Store it so that we can clean up in dispose()
|
protected String |
checkpointPath
FileSystem path where checkpoints are stored
|
protected K |
currentKey
The current key, which the next value methods will refer to
|
protected N |
currentNamespace
The current namespace, which the next value methods will refer to
|
protected org.rocksdb.RocksDB |
db
Our RocksDB instance
|
protected TypeSerializer<K> |
keySerializer
Serializer for the keys
|
protected TypeSerializer<N> |
namespaceSerializer
Serializer for the namespace
|
protected File |
rocksDbPath
Directory in "basePath" where the actual RocksDB data base instance stores its files
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractRocksDBState(TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer,
File basePath,
String checkpointPath,
org.rocksdb.Options options)
Creates a new RocksDB backed state.
|
protected |
AbstractRocksDBState(TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer,
File basePath,
String checkpointPath,
String restorePath,
org.rocksdb.Options options)
Creates a new RocksDB backed state and restores from the given backup directory.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes the value mapped under the current key.
|
protected abstract AbstractRocksDBState.AbstractRocksDBSnapshot<K,N,S,SD> |
createRocksDBSnapshot(URI backupUri,
long checkpointId) |
void |
dispose()
Disposes the key/value state, releasing all occupied resources.
|
void |
setCurrentKey(K currentKey)
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.
|
KvStateSnapshot<K,N,S,SD,RocksDBStateBackend> |
snapshot(long checkpointId,
long timestamp)
Creates a snapshot of this state.
|
protected void |
writeKeyAndNamespace(DataOutputView out) |
protected final TypeSerializer<K> keySerializer
protected final TypeSerializer<N> namespaceSerializer
protected K currentKey
protected N currentNamespace
protected final File basePath
protected final String checkpointPath
protected final File rocksDbPath
protected final org.rocksdb.RocksDB db
protected AbstractRocksDBState(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, File basePath, String checkpointPath, org.rocksdb.Options options)
keySerializer
- The serializer for the keys.namespaceSerializer
- The serializer for the namespace.basePath
- The path on the local system where RocksDB data should be stored.protected AbstractRocksDBState(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, File basePath, String checkpointPath, String restorePath, org.rocksdb.Options options)
keySerializer
- The serializer for the keys.namespaceSerializer
- The serializer for the namespace.basePath
- The path on the local system where RocksDB data should be stored.restorePath
- The path to a backup directory from which to restore RocksDb database.public final void clear()
State
protected void writeKeyAndNamespace(DataOutputView out) throws IOException
IOException
public final void setCurrentKey(K currentKey)
KvState
setCurrentKey
in interface KvState<K,N,S extends State,SD extends StateDescriptor<S,?>,RocksDBStateBackend>
currentKey
- The key.public final void setCurrentNamespace(N namespace)
KvState
setCurrentNamespace
in interface KvState<K,N,S extends State,SD extends StateDescriptor<S,?>,RocksDBStateBackend>
namespace
- The namespace.protected abstract AbstractRocksDBState.AbstractRocksDBSnapshot<K,N,S,SD> createRocksDBSnapshot(URI backupUri, long checkpointId)
public final KvStateSnapshot<K,N,S,SD,RocksDBStateBackend> snapshot(long checkpointId, long timestamp) throws Exception
KvState
snapshot
in interface KvState<K,N,S extends State,SD extends StateDescriptor<S,?>,RocksDBStateBackend>
checkpointId
- The ID of the checkpoint for which the snapshot should be created.timestamp
- The timestamp of the checkpoint.Exception
- Exceptions during snapshotting the state should be forwarded, so the system
can react to failed snapshots.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.