public class RocksDBKeyedStateBackend<K>
extends org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>
AbstractKeyedStateBackend that stores its state in RocksDB and serializes state to
streams provided by a CheckpointStreamFactory upon
checkpointing. This state backend can store very large state that exceeds memory and spills
to disk. Except for the snapshotting, this class should be accessed as if it is not threadsafe.
This class follows the rules for closing/releasing native RocksDB resources as described in + this document.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RocksDBKeyedStateBackend.MergeIterator
Wraps a RocksDB iterator to cache it's current key and assigns an id for the key/value state to the iterator.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.rocksdb.RocksDB |
db
Our RocksDB database, this is used by the actual subclasses of
AbstractRocksDBState
to store state. |
static String |
MERGE_OPERATOR_NAME
The name of the merge operator in RocksDB.
|
| Constructor and Description |
|---|
RocksDBKeyedStateBackend(String operatorIdentifier,
ClassLoader userCodeClassLoader,
File instanceBasePath,
org.rocksdb.DBOptions dbOptions,
org.rocksdb.ColumnFamilyOptions columnFamilyOptions,
org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry,
org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
int numberOfKeyGroups,
org.apache.flink.runtime.state.KeyGroupRange keyGroupRange,
org.apache.flink.api.common.ExecutionConfig executionConfig,
boolean enableIncrementalCheckpointing,
org.apache.flink.runtime.state.LocalRecoveryConfig localRecoveryConfig,
RocksDBStateBackend.PriorityQueueStateType priorityQueueStateType,
org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider) |
| Modifier and Type | Method and Description |
|---|---|
<T extends org.apache.flink.runtime.state.heap.HeapPriorityQueueElement & org.apache.flink.runtime.state.PriorityComparable & org.apache.flink.runtime.state.Keyed> |
create(String stateName,
org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer) |
<N,SV,SEV,S extends org.apache.flink.api.common.state.State,IS extends S> |
createInternalState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.StateDescriptor<S,SV> stateDesc,
org.apache.flink.runtime.state.StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory) |
void |
dispose()
Should only be called by one thread, and only after all accesses to the DB happened.
|
File |
getInstanceBasePath()
Only visible for testing, DO NOT USE.
|
int |
getKeyGroupPrefixBytes() |
<N> java.util.stream.Stream<K> |
getKeys(String state,
N namespace) |
static RocksIteratorWrapper |
getRocksIterator(org.rocksdb.RocksDB db) |
static RocksIteratorWrapper |
getRocksIterator(org.rocksdb.RocksDB db,
org.rocksdb.ColumnFamilyHandle columnFamilyHandle) |
org.rocksdb.WriteOptions |
getWriteOptions() |
void |
notifyCheckpointComplete(long completedCheckpointId) |
int |
numKeyValueStateEntries() |
boolean |
requiresLegacySynchronousTimerSnapshots() |
void |
restore(Collection<org.apache.flink.runtime.state.KeyedStateHandle> restoreState) |
RunnableFuture<org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle>> |
snapshot(long checkpointId,
long timestamp,
org.apache.flink.runtime.state.CheckpointStreamFactory streamFactory,
org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions)
Triggers an asynchronous snapshot of the keyed state backend from RocksDB.
|
boolean |
supportsAsynchronousSnapshots() |
applyToAllKeys, close, getCurrentKey, getCurrentKeyGroupIndex, getKeyGroupRange, getKeySerializer, getNumberOfKeyGroups, getOrCreateKeyedState, getPartitionedState, setCurrentKeypublic static final String MERGE_OPERATOR_NAME
protected org.rocksdb.RocksDB db
AbstractRocksDBState
to store state. The different k/v states that we have don't each have their own RocksDB
instance. They all write to this instance but to their own column family.public RocksDBKeyedStateBackend(String operatorIdentifier, ClassLoader userCodeClassLoader, File instanceBasePath, org.rocksdb.DBOptions dbOptions, org.rocksdb.ColumnFamilyOptions columnFamilyOptions, org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, int numberOfKeyGroups, org.apache.flink.runtime.state.KeyGroupRange keyGroupRange, org.apache.flink.api.common.ExecutionConfig executionConfig, boolean enableIncrementalCheckpointing, org.apache.flink.runtime.state.LocalRecoveryConfig localRecoveryConfig, RocksDBStateBackend.PriorityQueueStateType priorityQueueStateType, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider) throws IOException
IOExceptionpublic <N> java.util.stream.Stream<K> getKeys(String state, N namespace)
public void dispose()
@Nonnull public <T extends org.apache.flink.runtime.state.heap.HeapPriorityQueueElement & org.apache.flink.runtime.state.PriorityComparable & org.apache.flink.runtime.state.Keyed> org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<T> create(@Nonnull String stateName, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer)
public int getKeyGroupPrefixBytes()
public org.rocksdb.WriteOptions getWriteOptions()
public RunnableFuture<org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle>> snapshot(long checkpointId, long timestamp, org.apache.flink.runtime.state.CheckpointStreamFactory streamFactory, org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions) throws Exception
dispose(). For each backend, this method must always
be called by the same thread.checkpointId - The Id of the checkpoint.timestamp - The timestamp of the checkpoint.streamFactory - The factory that we can use for writing our state to streams.checkpointOptions - Options for how to perform this checkpoint.Exception - indicating a problem in the synchronous part of the checkpoint.public void restore(Collection<org.apache.flink.runtime.state.KeyedStateHandle> restoreState) throws Exception
Exceptionpublic void notifyCheckpointComplete(long completedCheckpointId)
@Nonnull public <N,SV,SEV,S extends org.apache.flink.api.common.state.State,IS extends S> IS createInternalState(@Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, @Nonnull org.apache.flink.api.common.state.StateDescriptor<S,SV> stateDesc, @Nonnull org.apache.flink.runtime.state.StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory) throws Exception
Exceptionpublic File getInstanceBasePath()
public boolean supportsAsynchronousSnapshots()
supportsAsynchronousSnapshots in class org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>@VisibleForTesting public int numKeyValueStateEntries()
numKeyValueStateEntries in class org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>public static RocksIteratorWrapper getRocksIterator(org.rocksdb.RocksDB db)
public static RocksIteratorWrapper getRocksIterator(org.rocksdb.RocksDB db, org.rocksdb.ColumnFamilyHandle columnFamilyHandle)
public boolean requiresLegacySynchronousTimerSnapshots()
requiresLegacySynchronousTimerSnapshots in class org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.