Class AsyncKeyedStateBackendAdaptor<K>

java.lang.Object
org.apache.flink.runtime.state.v2.adaptor.AsyncKeyedStateBackendAdaptor<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, AsyncExecutionController.SwitchContextListener<K>, AsyncKeyedStateBackend<K>, PriorityQueueSetFactory, Snapshotable<SnapshotResult<KeyedStateHandle>>, org.apache.flink.util.Disposable

public class AsyncKeyedStateBackendAdaptor<K> extends Object implements AsyncKeyedStateBackend<K>
A adaptor that transforms KeyedStateBackend into AsyncKeyedStateBackend.
  • Constructor Details

  • Method Details

    • setup

      public void setup(@Nonnull StateRequestHandler stateRequestHandler)
      Description copied from interface: AsyncKeyedStateBackend
      Initializes with some contexts.
      Specified by:
      setup in interface AsyncKeyedStateBackend<K>
      Parameters:
      stateRequestHandler - which handles state request.
    • getOrCreateKeyedState

      public <N, S extends org.apache.flink.api.common.state.v2.State, SV> S getOrCreateKeyedState(N defaultNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) throws Exception
      Description copied from interface: AsyncKeyedStateBackend
      Creates or retrieves a keyed state backed by this state backend.
      Specified by:
      getOrCreateKeyedState in interface AsyncKeyedStateBackend<K>
      Type Parameters:
      N - the type of namespace for partitioning.
      S - The type of the public API state.
      SV - The type of the stored state value.
      Parameters:
      defaultNamespace - the default namespace for this state.
      namespaceSerializer - the serializer for namespace.
      stateDesc - The StateDescriptor that contains the name of the state.
      Returns:
      A new key/value state backed by this backend.
      Throws:
      Exception - Exceptions may occur during initialization of the state and should be forwarded.
    • createStateInternal

      @Nonnull public <N, S extends InternalKeyedState, SV> S createStateInternal(@Nonnull N defaultNamespace, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, @Nonnull org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc) throws Exception
      Description copied from interface: AsyncKeyedStateBackend
      Creates and returns a new state for internal usage.
      Specified by:
      createStateInternal in interface AsyncKeyedStateBackend<K>
      Type Parameters:
      N - the type of namespace for partitioning.
      S - The type of the public API state.
      SV - The type of the stored state value.
      Parameters:
      defaultNamespace - the default namespace for this state.
      namespaceSerializer - the serializer for namespace.
      stateDesc - The StateDescriptor that contains the name of the state.
      Throws:
      Exception - Exceptions may occur during initialization of the state.
    • createStateExecutor

      @Nonnull public StateExecutor createStateExecutor()
      Description copied from interface: AsyncKeyedStateBackend
      Creates a StateExecutor which supports to execute a batch of state requests asynchronously.

      Notice that the AsyncKeyedStateBackend is responsible for shutting down the StateExecutors created by itself when they are no longer in use.

      Specified by:
      createStateExecutor in interface AsyncKeyedStateBackend<K>
      Returns:
      a StateExecutor which supports to execute a batch of state requests asynchronously.
    • getKeyGroupRange

      public KeyGroupRange getKeyGroupRange()
      Description copied from interface: AsyncKeyedStateBackend
      Returns the key groups which this state backend is responsible for.
      Specified by:
      getKeyGroupRange in interface AsyncKeyedStateBackend<K>
    • switchContext

      public void switchContext(@Nullable RecordContext<K> context)
      Description copied from interface: AsyncKeyedStateBackend
      By default, a state backend does nothing when a key is switched in async processing.
      Specified by:
      switchContext in interface AsyncExecutionController.SwitchContextListener<K>
      Specified by:
      switchContext in interface AsyncKeyedStateBackend<K>
    • dispose

      public void dispose()
      Specified by:
      dispose in interface AsyncKeyedStateBackend<K>
      Specified by:
      dispose in interface org.apache.flink.util.Disposable
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • notifyCheckpointComplete

      public void notifyCheckpointComplete(long checkpointId) throws Exception
      Specified by:
      notifyCheckpointComplete in interface org.apache.flink.api.common.state.CheckpointListener
      Throws:
      Exception
    • notifyCheckpointAborted

      public void notifyCheckpointAborted(long checkpointId) throws Exception
      Specified by:
      notifyCheckpointAborted in interface org.apache.flink.api.common.state.CheckpointListener
      Throws:
      Exception
    • notifyCheckpointSubsumed

      public void notifyCheckpointSubsumed(long checkpointId) throws Exception
      Specified by:
      notifyCheckpointSubsumed in interface org.apache.flink.api.common.state.InternalCheckpointListener
      Throws:
      Exception
    • snapshot

      @Nonnull public RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot(long checkpointId, long timestamp, @Nonnull CheckpointStreamFactory streamFactory, @Nonnull CheckpointOptions checkpointOptions) throws Exception
      Description copied from interface: Snapshotable
      Operation that writes a snapshot into a stream that is provided by the given CheckpointStreamFactory and returns a @RunnableFuture that gives a state handle to the snapshot. It is up to the implementation if the operation is performed synchronous or asynchronous. In the later case, the returned Runnable must be executed first before obtaining the handle.
      Specified by:
      snapshot in interface Snapshotable<K>
      Parameters:
      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.
      Returns:
      A runnable future that will yield a StateObject.
      Throws:
      Exception
    • create

      @Nonnull public <T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>> KeyGroupedInternalPriorityQueue<T> create(@Nonnull String stateName, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer)
      Description copied from interface: PriorityQueueSetFactory
      Specified by:
      create in interface PriorityQueueSetFactory
      Type Parameters:
      T - type of the stored elements.
      Parameters:
      stateName - unique name for associated with this queue.
      byteOrderedElementSerializer - a serializer that with a format that is lexicographically ordered in alignment with elementPriorityComparator.
      Returns:
      the queue with the specified unique name.
    • create

      public <T extends HeapPriorityQueueElement & PriorityComparable<? super T> & Keyed<?>> KeyGroupedInternalPriorityQueue<T> create(@Nonnull String stateName, @Nonnull org.apache.flink.api.common.typeutils.TypeSerializer<T> byteOrderedElementSerializer, boolean allowFutureMetadataUpdates)
      Description copied from interface: PriorityQueueSetFactory
      Specified by:
      create in interface PriorityQueueSetFactory
      Type Parameters:
      T - type of the stored elements.
      Parameters:
      stateName - unique name for associated with this queue.
      byteOrderedElementSerializer - a serializer that with a format that is lexicographically ordered in alignment with elementPriorityComparator.
      allowFutureMetadataUpdates - whether allow metadata to update in the future or not.
      Returns:
      the queue with the specified unique name.
    • requiresLegacySynchronousTimerSnapshots

      public boolean requiresLegacySynchronousTimerSnapshots(SnapshotType checkpointType)
      Description copied from interface: AsyncKeyedStateBackend
      Whether the keyed state backend requires legacy synchronous timer snapshots.
      Specified by:
      requiresLegacySynchronousTimerSnapshots in interface AsyncKeyedStateBackend<K>
      Returns:
      true as default in case of AsyncKeyedStateBackend
    • isSafeToReuseKVState

      public boolean isSafeToReuseKVState()
      Description copied from interface: AsyncKeyedStateBackend
      Whether it's safe to reuse key-values from the state-backend, e.g for the purpose of optimization.

      NOTE: this method should not be used to check for InternalPriorityQueue, as the priority queue could be stored on different locations, e.g ForSt state-backend could store that on JVM heap if configuring HEAP as the time-service factory.

      Specified by:
      isSafeToReuseKVState in interface AsyncKeyedStateBackend<K>
      Returns:
      returns ture if safe to reuse the key-values from the state-backend.
    • getKeyedStateBackend

      public CheckpointableKeyedStateBackend<K> getKeyedStateBackend()