Interface AsyncKeyedStateBackend<K>

All Superinterfaces:
AsyncExecutionController.SwitchContextListener<K>, AutoCloseable, org.apache.flink.api.common.state.CheckpointListener, Closeable, org.apache.flink.util.Disposable, org.apache.flink.api.common.state.InternalCheckpointListener, PriorityQueueSetFactory, Snapshotable<SnapshotResult<KeyedStateHandle>>
All Known Implementing Classes:
AsyncKeyedStateBackendAdaptor

@Internal public interface AsyncKeyedStateBackend<K> extends Snapshotable<SnapshotResult<KeyedStateHandle>>, org.apache.flink.api.common.state.InternalCheckpointListener, PriorityQueueSetFactory, org.apache.flink.util.Disposable, Closeable, AsyncExecutionController.SwitchContextListener<K>
An async keyed state backend provides methods supporting to access keyed state asynchronously and in batch.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a StateExecutor which supports to execute a batch of state requests asynchronously.
    <N, S extends InternalKeyedState, SV>
    S
    createStateInternal(N defaultNamespace, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, org.apache.flink.api.common.state.v2.StateDescriptor<SV> stateDesc)
    Creates and returns a new state for internal usage.
    void
     
    Returns the key groups which this state backend is responsible for.
    <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)
    Creates or retrieves a keyed state backed by this state backend.
    default boolean
    Whether it's safe to reuse key-values from the state-backend, e.g for the purpose of optimization.
    default boolean
    Whether the keyed state backend requires legacy synchronous timer snapshots.
    void
    setup(StateRequestHandler stateRequestHandler)
    Initializes with some contexts.
    default void
    By default, a state backend does nothing when a key is switched in async processing.

    Methods inherited from interface org.apache.flink.api.common.state.CheckpointListener

    notifyCheckpointAborted, notifyCheckpointComplete

    Methods inherited from interface java.io.Closeable

    close

    Methods inherited from interface org.apache.flink.api.common.state.InternalCheckpointListener

    notifyCheckpointSubsumed

    Methods inherited from interface org.apache.flink.runtime.state.PriorityQueueSetFactory

    create, create

    Methods inherited from interface org.apache.flink.runtime.state.Snapshotable

    snapshot
  • Method Details

    • setup

      void setup(@Nonnull StateRequestHandler stateRequestHandler)
      Initializes with some contexts.
      Parameters:
      stateRequestHandler - which handles state request.
    • getOrCreateKeyedState

      <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
      Creates or retrieves a keyed state backed by this state backend.
      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 <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
      Creates and returns a new state for internal usage.
      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 StateExecutor createStateExecutor()
      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.

      Returns:
      a StateExecutor which supports to execute a batch of state requests asynchronously.
    • getKeyGroupRange

      KeyGroupRange getKeyGroupRange()
      Returns the key groups which this state backend is responsible for.
    • switchContext

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

      default boolean requiresLegacySynchronousTimerSnapshots(SnapshotType checkpointType)
      Whether the keyed state backend requires legacy synchronous timer snapshots.
      Parameters:
      checkpointType -
      Returns:
      true as default in case of AsyncKeyedStateBackend
    • isSafeToReuseKVState

      default boolean isSafeToReuseKVState()
      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.

      Returns:
      returns ture if safe to reuse the key-values from the state-backend.
    • dispose

      void dispose()
      Specified by:
      dispose in interface org.apache.flink.util.Disposable