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 | 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) |
| Modifier and Type | Method and Description |
|---|---|
protected <N,T,ACC,R> |
createAggregatingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.AggregatingStateDescriptor<T,ACC,R> stateDesc) |
protected <N,T,ACC> org.apache.flink.runtime.state.internal.InternalFoldingState<K,N,T,ACC> |
createFoldingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.FoldingStateDescriptor<T,ACC> stateDesc) |
protected <N,T> org.apache.flink.runtime.state.internal.InternalListState<K,N,T> |
createListState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ListStateDescriptor<T> stateDesc) |
protected <N,UK,UV> org.apache.flink.runtime.state.internal.InternalMapState<K,N,UK,UV> |
createMapState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.MapStateDescriptor<UK,UV> stateDesc) |
protected <N,T> org.apache.flink.runtime.state.internal.InternalReducingState<K,N,T> |
createReducingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ReducingStateDescriptor<T> stateDesc) |
protected <N,T> org.apache.flink.runtime.state.internal.InternalValueState<K,N,T> |
createValueState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer,
org.apache.flink.api.common.state.ValueStateDescriptor<T> stateDesc) |
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) |
static RocksIteratorWrapper |
getRocksIterator(org.rocksdb.RocksDB db,
org.rocksdb.ColumnFamilyHandle columnFamilyHandle,
org.rocksdb.ReadOptions readOptions) |
org.rocksdb.WriteOptions |
getWriteOptions() |
void |
notifyCheckpointComplete(long completedCheckpointId) |
int |
numStateEntries() |
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() |
public 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) throws IOException
IOExceptionpublic <N> java.util.stream.Stream<K> getKeys(String state, N namespace)
public void dispose()
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)
protected <N,T> org.apache.flink.runtime.state.internal.InternalValueState<K,N,T> createValueState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ValueStateDescriptor<T> stateDesc) throws Exception
protected <N,T> org.apache.flink.runtime.state.internal.InternalListState<K,N,T> createListState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ListStateDescriptor<T> stateDesc) throws Exception
protected <N,T> org.apache.flink.runtime.state.internal.InternalReducingState<K,N,T> createReducingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.ReducingStateDescriptor<T> stateDesc) throws Exception
protected <N,T,ACC,R> org.apache.flink.runtime.state.internal.InternalAggregatingState<K,N,T,ACC,R> createAggregatingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.AggregatingStateDescriptor<T,ACC,R> stateDesc) throws Exception
protected <N,T,ACC> org.apache.flink.runtime.state.internal.InternalFoldingState<K,N,T,ACC> createFoldingState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.FoldingStateDescriptor<T,ACC> stateDesc) throws Exception
protected <N,UK,UV> org.apache.flink.runtime.state.internal.InternalMapState<K,N,UK,UV> createMapState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.MapStateDescriptor<UK,UV> stateDesc) throws Exception
public File getInstanceBasePath()
public boolean supportsAsynchronousSnapshots()
supportsAsynchronousSnapshots in class org.apache.flink.runtime.state.AbstractKeyedStateBackend<K>@VisibleForTesting public int numStateEntries()
numStateEntries 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 static RocksIteratorWrapper getRocksIterator(org.rocksdb.RocksDB db, org.rocksdb.ColumnFamilyHandle columnFamilyHandle, org.rocksdb.ReadOptions readOptions)
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.