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 |
|---|---|
static class |
RocksDBKeyedStateBackend.RocksDbKvStateInfo
Rocks DB specific information about the k/v states.
|
| 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(ClassLoader userCodeClassLoader,
File instanceBasePath,
RocksDBResourceContainer optionsContainer,
java.util.function.Function<String,org.rocksdb.ColumnFamilyOptions> columnFamilyOptionsFactory,
org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry,
org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
org.apache.flink.api.common.ExecutionConfig executionConfig,
org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider,
org.rocksdb.RocksDB db,
LinkedHashMap<String,RocksDBKeyedStateBackend.RocksDbKvStateInfo> kvStateInformation,
int keyGroupPrefixBytes,
org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry,
org.apache.flink.runtime.state.StreamCompressionDecorator keyGroupCompressionDecorator,
org.apache.flink.util.ResourceGuard rocksDBResourceGuard,
RocksDBSnapshotStrategyBase<K> checkpointSnapshotStrategy,
RocksDBSnapshotStrategyBase<K> savepointSnapshotStrategy,
RocksDBWriteBatchWrapper writeBatchWrapper,
org.rocksdb.ColumnFamilyHandle defaultColumnFamilyHandle,
RocksDBNativeMetricMonitor nativeMetricMonitor,
org.apache.flink.contrib.streaming.state.RocksDBSerializedCompositeKeyBuilder<K> sharedRocksKeyBuilder,
org.apache.flink.runtime.state.PriorityQueueSetFactory priorityQueueFactory,
RocksDbTtlCompactFiltersManager ttlCompactFiltersManager,
org.apache.flink.runtime.state.heap.InternalKeyContext<K> keyContext,
long writeBatchSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
compactState(org.apache.flink.api.common.state.StateDescriptor<?,?> stateDesc) |
<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.
|
int |
getKeyGroupPrefixBytes() |
<N> java.util.stream.Stream<K> |
getKeys(String state,
N namespace) |
org.rocksdb.ReadOptions |
getReadOptions() |
org.rocksdb.WriteOptions |
getWriteOptions() |
void |
notifyCheckpointAborted(long checkpointId) |
void |
notifyCheckpointComplete(long completedCheckpointId) |
int |
numKeyValueStateEntries() |
boolean |
requiresLegacySynchronousTimerSnapshots() |
void |
setCurrentKey(K newKey) |
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, deregisterKeySelectionListener, getCurrentKey, getCurrentKeyGroupIndex, getKeyGroupCompressionDecorator, getKeyGroupRange, getKeySerializer, getNumberOfKeyGroups, getOrCreateKeyedState, getPartitionedState, numKeyValueStatesByName, registerKeySelectionListenerpublic static final String MERGE_OPERATOR_NAME
protected final 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(ClassLoader userCodeClassLoader, File instanceBasePath, RocksDBResourceContainer optionsContainer, java.util.function.Function<String,org.rocksdb.ColumnFamilyOptions> columnFamilyOptionsFactory, org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.ExecutionConfig executionConfig, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider, org.rocksdb.RocksDB db, LinkedHashMap<String,RocksDBKeyedStateBackend.RocksDbKvStateInfo> kvStateInformation, int keyGroupPrefixBytes, org.apache.flink.core.fs.CloseableRegistry cancelStreamRegistry, org.apache.flink.runtime.state.StreamCompressionDecorator keyGroupCompressionDecorator, org.apache.flink.util.ResourceGuard rocksDBResourceGuard, RocksDBSnapshotStrategyBase<K> checkpointSnapshotStrategy, RocksDBSnapshotStrategyBase<K> savepointSnapshotStrategy, RocksDBWriteBatchWrapper writeBatchWrapper, org.rocksdb.ColumnFamilyHandle defaultColumnFamilyHandle, RocksDBNativeMetricMonitor nativeMetricMonitor, org.apache.flink.contrib.streaming.state.RocksDBSerializedCompositeKeyBuilder<K> sharedRocksKeyBuilder, org.apache.flink.runtime.state.PriorityQueueSetFactory priorityQueueFactory, RocksDbTtlCompactFiltersManager ttlCompactFiltersManager, org.apache.flink.runtime.state.heap.InternalKeyContext<K> keyContext, @Nonnegative long writeBatchSize)
public <N> java.util.stream.Stream<K> getKeys(String state, N namespace)
public void setCurrentKey(K newKey)
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 org.rocksdb.ReadOptions getReadOptions()
@Nonnull public RunnableFuture<org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle>> snapshot(long checkpointId, long timestamp, @Nonnull org.apache.flink.runtime.state.CheckpointStreamFactory streamFactory, @Nonnull 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 notifyCheckpointComplete(long completedCheckpointId)
throws Exception
Exceptionpublic void notifyCheckpointAborted(long checkpointId)
throws Exception
Exception@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 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 boolean requiresLegacySynchronousTimerSnapshots()
requiresLegacySynchronousTimerSnapshots in class org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>@VisibleForTesting
public void compactState(org.apache.flink.api.common.state.StateDescriptor<?,?> stateDesc)
throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBExceptionCopyright © 2014–2020 The Apache Software Foundation. All rights reserved.