Package org.apache.flink.state.changelog
Class ChangelogKeyedStateBackend<K>
- java.lang.Object
-
- org.apache.flink.state.changelog.ChangelogKeyedStateBackend<K>
-
- Type Parameters:
K- The key by which state is keyed.
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.common.state.InternalCheckpointListener,org.apache.flink.runtime.state.CheckpointableKeyedStateBackend<K>,org.apache.flink.runtime.state.KeyedStateBackend<K>,org.apache.flink.runtime.state.KeyedStateFactory,org.apache.flink.runtime.state.PriorityQueueSetFactory,org.apache.flink.runtime.state.Snapshotable<org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle>>,org.apache.flink.runtime.state.TestableKeyedStateBackend<K>,org.apache.flink.state.common.PeriodicMaterializationManager.MaterializationTarget,org.apache.flink.util.Disposable
@Internal public class ChangelogKeyedStateBackend<K> extends Object implements org.apache.flink.runtime.state.CheckpointableKeyedStateBackend<K>, org.apache.flink.api.common.state.CheckpointListener, org.apache.flink.runtime.state.TestableKeyedStateBackend<K>, org.apache.flink.api.common.state.InternalCheckpointListener, org.apache.flink.state.common.PeriodicMaterializationManager.MaterializationTarget
AKeyedStateBackendthat keeps state on the underlying delegated keyed state backend as well as on the state change log.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K extends Object>
-
-
Constructor Summary
Constructors Constructor Description ChangelogKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend<K> keyedStateBackend, String subtaskName, org.apache.flink.api.common.ExecutionConfig executionConfig, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider, org.apache.flink.metrics.MetricGroup metricGroup, org.apache.flink.runtime.state.changelog.StateChangelogWriter<? extends org.apache.flink.runtime.state.changelog.ChangelogStateHandle> stateChangelogWriter, Collection<org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle> initialState, org.apache.flink.runtime.state.CheckpointStorageWorkerView checkpointStorageWorkerView)ChangelogKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend<K> keyedStateBackend, String subtaskName, org.apache.flink.api.common.ExecutionConfig executionConfig, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider, org.apache.flink.state.changelog.ChangelogStateBackendMetricGroup metricGroup, org.apache.flink.runtime.state.changelog.StateChangelogWriter<? extends org.apache.flink.runtime.state.changelog.ChangelogStateHandle> stateChangelogWriter, Collection<org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle> initialState, org.apache.flink.runtime.state.CheckpointStorageWorkerView checkpointStorageWorkerView, ChangelogStateFactory changelogStateFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <N,S extends org.apache.flink.api.common.state.State,T>
voidapplyToAllKeys(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,T> stateDescriptor, org.apache.flink.runtime.state.KeyedStateFunction<K,S> function)voidclose()<T extends org.apache.flink.runtime.state.heap.HeapPriorityQueueElement & org.apache.flink.runtime.state.PriorityComparable<? super T> & org.apache.flink.runtime.state.Keyed<?>>
org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue<T>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>
IScreateOrUpdateInternalState(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)booleanderegisterKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K> listener)voiddispose()ChangelogRestoreTarget<K>getChangelogRestoreTarget()KgetCurrentKey()org.apache.flink.runtime.state.KeyedStateBackend<K>getDelegatedKeyedStateBackend(boolean recursive)org.apache.flink.runtime.state.KeyGroupRangegetKeyGroupRange()<N> java.util.stream.Stream<K>getKeys(String state, N namespace)<N> java.util.stream.Stream<org.apache.flink.api.java.tuple.Tuple2<K,N>>getKeysAndNamespaces(String state)org.apache.flink.api.common.typeutils.TypeSerializer<K>getKeySerializer()<N,S extends org.apache.flink.api.common.state.State,T>
SgetOrCreateKeyedState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,T> stateDescriptor)<N,S extends org.apache.flink.api.common.state.State>
SgetPartitionedState(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,?> stateDescriptor)voidhandleMaterializationFailureOrCancellation(long materializationID, org.apache.flink.runtime.state.changelog.SequenceNumber upTo, Throwable cause)voidhandleMaterializationResult(org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle> materializedSnapshot, long materializationID, org.apache.flink.runtime.state.changelog.SequenceNumber upTo)This method is not thread safe.Optional<org.apache.flink.state.common.PeriodicMaterializationManager.MaterializationRunnable>initMaterialization()Initialize state materialization so that materialized data can be persisted durably and included into the checkpoint.booleanisSafeToReuseKVState()voidnotifyCheckpointAborted(long checkpointId)voidnotifyCheckpointComplete(long checkpointId)voidnotifyCheckpointSubsumed(long checkpointId)intnumKeyValueStateEntries()voidregisterCloseable(Closeable closeable)voidregisterKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K> listener)org.apache.flink.runtime.state.SavepointResources<K>savepoint()voidsetCurrentKey(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)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.runtime.state.KeyedStateBackend
isStateImmutableInStateBackend
-
-
-
-
Constructor Detail
-
ChangelogKeyedStateBackend
public ChangelogKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend<K> keyedStateBackend, String subtaskName, org.apache.flink.api.common.ExecutionConfig executionConfig, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider, org.apache.flink.metrics.MetricGroup metricGroup, org.apache.flink.runtime.state.changelog.StateChangelogWriter<? extends org.apache.flink.runtime.state.changelog.ChangelogStateHandle> stateChangelogWriter, Collection<org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle> initialState, org.apache.flink.runtime.state.CheckpointStorageWorkerView checkpointStorageWorkerView)
-
ChangelogKeyedStateBackend
public ChangelogKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend<K> keyedStateBackend, String subtaskName, org.apache.flink.api.common.ExecutionConfig executionConfig, org.apache.flink.runtime.state.ttl.TtlTimeProvider ttlTimeProvider, org.apache.flink.state.changelog.ChangelogStateBackendMetricGroup metricGroup, org.apache.flink.runtime.state.changelog.StateChangelogWriter<? extends org.apache.flink.runtime.state.changelog.ChangelogStateHandle> stateChangelogWriter, Collection<org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle> initialState, org.apache.flink.runtime.state.CheckpointStorageWorkerView checkpointStorageWorkerView, ChangelogStateFactory changelogStateFactory)
-
-
Method Detail
-
getKeyGroupRange
public org.apache.flink.runtime.state.KeyGroupRange getKeyGroupRange()
- Specified by:
getKeyGroupRangein interfaceorg.apache.flink.runtime.state.CheckpointableKeyedStateBackend<K>
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
setCurrentKey
public void setCurrentKey(K newKey)
- Specified by:
setCurrentKeyin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
getCurrentKey
public K getCurrentKey()
- Specified by:
getCurrentKeyin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
getKeySerializer
public org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
- Specified by:
getKeySerializerin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
getKeys
public <N> java.util.stream.Stream<K> getKeys(String state, N namespace)
- Specified by:
getKeysin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
getKeysAndNamespaces
public <N> java.util.stream.Stream<org.apache.flink.api.java.tuple.Tuple2<K,N>> getKeysAndNamespaces(String state)
- Specified by:
getKeysAndNamespacesin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
dispose
public void dispose()
- Specified by:
disposein interfaceorg.apache.flink.util.Disposable- Specified by:
disposein interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
registerKeySelectionListener
public void registerKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K> listener)
- Specified by:
registerKeySelectionListenerin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
deregisterKeySelectionListener
public boolean deregisterKeySelectionListener(org.apache.flink.runtime.state.KeyedStateBackend.KeySelectionListener<K> listener)
- Specified by:
deregisterKeySelectionListenerin interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
applyToAllKeys
public <N,S extends org.apache.flink.api.common.state.State,T> void applyToAllKeys(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,T> stateDescriptor, org.apache.flink.runtime.state.KeyedStateFunction<K,S> function) throws Exception
-
getPartitionedState
public <N,S extends org.apache.flink.api.common.state.State> S getPartitionedState(N namespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,?> stateDescriptor) throws Exception
-
snapshot
@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
-
create
@Nonnull public <T extends org.apache.flink.runtime.state.heap.HeapPriorityQueueElement & org.apache.flink.runtime.state.PriorityComparable<? super T> & 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)
- Specified by:
createin interfaceorg.apache.flink.runtime.state.PriorityQueueSetFactory
-
numKeyValueStateEntries
@VisibleForTesting public int numKeyValueStateEntries()
- Specified by:
numKeyValueStateEntriesin interfaceorg.apache.flink.runtime.state.TestableKeyedStateBackend<K>
-
isSafeToReuseKVState
public boolean isSafeToReuseKVState()
- Specified by:
isSafeToReuseKVStatein interfaceorg.apache.flink.runtime.state.KeyedStateBackend<K>
-
savepoint
@Nonnull public org.apache.flink.runtime.state.SavepointResources<K> savepoint() throws Exception
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId) throws Exception- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Throws:
Exception
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) throws Exception- Specified by:
notifyCheckpointAbortedin interfaceorg.apache.flink.api.common.state.CheckpointListener- Throws:
Exception
-
getOrCreateKeyedState
public <N,S extends org.apache.flink.api.common.state.State,T> S getOrCreateKeyedState(org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.StateDescriptor<S,T> stateDescriptor) throws Exception
-
createOrUpdateInternalState
@Nonnull public <N,SV,SEV,S extends org.apache.flink.api.common.state.State,IS extends S> IS createOrUpdateInternalState(@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
- Specified by:
createOrUpdateInternalStatein interfaceorg.apache.flink.runtime.state.KeyedStateFactory- Throws:
Exception
-
initMaterialization
public Optional<org.apache.flink.state.common.PeriodicMaterializationManager.MaterializationRunnable> initMaterialization() throws Exception
Initialize state materialization so that materialized data can be persisted durably and included into the checkpoint.This method is not thread safe. It should be called either under a lock or through task mailbox executor.
- Specified by:
initMaterializationin interfaceorg.apache.flink.state.common.PeriodicMaterializationManager.MaterializationTarget- Returns:
- a tuple of - future snapshot result from the underlying state backend - a
SequenceNumberidentifying the latest change in the changelog - Throws:
Exception
-
handleMaterializationResult
public void handleMaterializationResult(org.apache.flink.runtime.state.SnapshotResult<org.apache.flink.runtime.state.KeyedStateHandle> materializedSnapshot, long materializationID, org.apache.flink.runtime.state.changelog.SequenceNumber upTo)This method is not thread safe. It should be called either under a lock or through task mailbox executor.- Specified by:
handleMaterializationResultin interfaceorg.apache.flink.state.common.PeriodicMaterializationManager.MaterializationTarget
-
handleMaterializationFailureOrCancellation
public void handleMaterializationFailureOrCancellation(long materializationID, org.apache.flink.runtime.state.changelog.SequenceNumber upTo, Throwable cause)- Specified by:
handleMaterializationFailureOrCancellationin interfaceorg.apache.flink.state.common.PeriodicMaterializationManager.MaterializationTarget
-
getDelegatedKeyedStateBackend
public org.apache.flink.runtime.state.KeyedStateBackend<K> getDelegatedKeyedStateBackend(boolean recursive)
- Specified by:
getDelegatedKeyedStateBackendin interfaceorg.apache.flink.runtime.state.TestableKeyedStateBackend<K>
-
notifyCheckpointSubsumed
public void notifyCheckpointSubsumed(long checkpointId) throws Exception- Specified by:
notifyCheckpointSubsumedin interfaceorg.apache.flink.api.common.state.InternalCheckpointListener- Throws:
Exception
-
getChangelogRestoreTarget
public ChangelogRestoreTarget<K> getChangelogRestoreTarget()
-
-