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.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
RocksDBKeyedStateBackend.RocksDbKvStateInfo
Rocks DB specific information about the k/v states.
|
| 限定符和类型 | 字段和说明 |
|---|---|
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.
|
| 构造器和说明 |
|---|
RocksDBKeyedStateBackend(ClassLoader userCodeClassLoader,
File instanceBasePath,
org.rocksdb.DBOptions dbOptions,
java.util.function.Function<String,org.rocksdb.ColumnFamilyOptions> columnFamilyOptionsFactory,
org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry,
org.apache.flink.runtime.state.StateSerializerProvider<K> keySerializerProvider,
int numberOfKeyGroups,
org.apache.flink.runtime.state.KeyGroupRange keyGroupRange,
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) |
| 限定符和类型 | 方法和说明 |
|---|---|
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.WriteOptions |
getWriteOptions() |
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, 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, org.rocksdb.DBOptions dbOptions, java.util.function.Function<String,org.rocksdb.ColumnFamilyOptions> columnFamilyOptionsFactory, org.apache.flink.runtime.query.TaskKvStateRegistry kvStateRegistry, org.apache.flink.runtime.state.StateSerializerProvider<K> keySerializerProvider, int numberOfKeyGroups, org.apache.flink.runtime.state.KeyGroupRange keyGroupRange, 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)
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()
@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
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 在类中 org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>@VisibleForTesting public int numKeyValueStateEntries()
numKeyValueStateEntries 在类中 org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>public boolean requiresLegacySynchronousTimerSnapshots()
requiresLegacySynchronousTimerSnapshots 在类中 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–2019 The Apache Software Foundation. All rights reserved.