Class BatchExecutionKeyedStateBackend<K>

    • Constructor Detail

      • BatchExecutionKeyedStateBackend

        public BatchExecutionKeyedStateBackend​(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
                                               KeyGroupRange keyGroupRange,
                                               org.apache.flink.api.common.ExecutionConfig executionConfig)
    • Method Detail

      • setCurrentKey

        public void setCurrentKey​(K newKey)
        Description copied from interface: KeyedStateBackend
        Sets the current key that is used for partitioned state.
        Specified by:
        setCurrentKey in interface KeyedStateBackend<K>
        Parameters:
        newKey - The new current key.
      • getKeySerializer

        public org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
        Specified by:
        getKeySerializer in interface KeyedStateBackend<K>
        Returns:
        Serializer of the key.
      • 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,
                                                                                                       KeyedStateFunction<K,​S> function)
        Description copied from interface: KeyedStateBackend
        Applies the provided KeyedStateFunction to the state with the provided StateDescriptor of all the currently active keys.
        Specified by:
        applyToAllKeys in interface KeyedStateBackend<K>
        Type Parameters:
        N - The type of the namespace.
        S - The type of the state.
        Parameters:
        namespace - the namespace of the state.
        namespaceSerializer - the serializer for the namespace.
        stateDescriptor - the descriptor of the state to which the function is going to be applied.
        function - the function to be applied to the keyed state.
      • getKeys

        public <N> Stream<K> getKeys​(String state,
                                     N namespace)
        Specified by:
        getKeys in interface KeyedStateBackend<K>
        Parameters:
        state - State variable for which existing keys will be returned.
        namespace - Namespace for which existing keys will be returned.
        Returns:
        A stream of all keys for the given state and namespace. Modifications to the state during iterating over its keys are not supported.
      • getKeys

        public <N> Stream<K> getKeys​(List<String> states,
                                     N namespace)
        Specified by:
        getKeys in interface KeyedStateBackend<K>
        Parameters:
        states - State variables for which existing keys will be returned.
        namespace - Namespace for which existing keys will be returned.
        Returns:
        A stream of all keys for the multiple states and a given namespace. Modifications to the states during iterating over its keys are not supported.
      • getKeysAndNamespaces

        public <N> Stream<org.apache.flink.api.java.tuple.Tuple2<K,​N>> getKeysAndNamespaces​(String state)
        Specified by:
        getKeysAndNamespaces in interface KeyedStateBackend<K>
        Parameters:
        state - State variable for which existing keys will be returned.
        Returns:
        A stream of all keys for the given state and namespace. Modifications to the state during iterating over it keys are not supported. Implementations go not make any ordering guarantees about the returned tupes. Two records with the same key or namespace may not be returned near each other in the stream.
      • 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
        Description copied from interface: KeyedStateBackend
        Creates or retrieves a keyed state backed by this state backend.
        Specified by:
        getOrCreateKeyedState in interface KeyedStateBackend<K>
        Type Parameters:
        N - The type of the namespace.
        S - The type of the state.
        Parameters:
        namespaceSerializer - The serializer used for the namespace type of the state
        stateDescriptor - The identifier for the state. This contains name and can create a default state value.
        Returns:
        A new key/value state backed by this backend.
        Throws:
        Exception - Exceptions may occur during initialization of the state and should be forwarded.
      • 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
        Description copied from interface: KeyedStateBackend
        Creates or retrieves a partitioned state backed by this state backend.

        TODO: NOTE: This method does a lot of work caching / retrieving states just to update the namespace. This method should be removed for the sake of namespaces being lazily fetched from the keyed state backend, or being set on the state directly.

        Specified by:
        getPartitionedState in interface KeyedStateBackend<K>
        Type Parameters:
        N - The type of the namespace.
        S - The type of the state.
        stateDescriptor - The identifier for the state. This contains name and can create a default state value.
        Returns:
        A new key/value state backed by this backend.
        Throws:
        Exception - Exceptions may occur during initialization of the state and should be forwarded.
      • dispose

        public void dispose()
        Specified by:
        dispose in interface org.apache.flink.util.Disposable
        Specified by:
        dispose in interface KeyedStateBackend<K>
      • 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
                                                                                                                                                StateSnapshotTransformer.StateSnapshotTransformFactory<SEV> snapshotTransformFactory)
                                                                                                                                         throws Exception
        Description copied from interface: KeyedStateFactory
        Creates or updates internal state and returns a new InternalKvState.
        Specified by:
        createOrUpdateInternalState in interface KeyedStateFactory
        Type Parameters:
        N - The type of the namespace.
        SV - The type of the stored state value.
        SEV - The type of the stored state value or entry for collection types (list or map).
        S - The type of the public API state.
        IS - The type of internal state.
        Parameters:
        namespaceSerializer - TypeSerializer for the state namespace.
        stateDesc - The StateDescriptor that contains the name of the state.
        snapshotTransformFactory - factory of state snapshot transformer.
        Throws:
        Exception
      • snapshot

        @Nonnull
        public RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshot​(long checkpointId,
                                                                         long timestamp,
                                                                         @Nonnull
                                                                         CheckpointStreamFactory streamFactory,
                                                                         @Nonnull
                                                                         CheckpointOptions checkpointOptions)
        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.