Interface KeyedStateBackend<K>

    • Method Detail

      • setCurrentKey

        void setCurrentKey​(K newKey)
        Sets the current key that is used for partitioned state.
        Parameters:
        newKey - The new current key.
      • getCurrentKey

        K getCurrentKey()
        Returns:
        Current key.
      • setCurrentKeyAndKeyGroup

        void setCurrentKeyAndKeyGroup​(K newKey,
                                      int newKeyGroupIndex)
        Act as a fast path for setCurrentKey(K) when the key group is known.
      • getKeySerializer

        TypeSerializer<K> getKeySerializer()
        Returns:
        Serializer of the key.
      • applyToAllKeys

        <N,​S extends State,​T> void applyToAllKeys​(N namespace,
                                                              TypeSerializer<N> namespaceSerializer,
                                                              StateDescriptor<S,​T> stateDescriptor,
                                                              KeyedStateFunction<K,​S> function)
                                                       throws Exception
        Applies the provided KeyedStateFunction to the state with the provided StateDescriptor of all the currently active keys.
        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.
        Throws:
        Exception
      • getKeys

        <N> Stream<K> getKeys​(String state,
                              N namespace)
        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 it keys are not supported.
      • getKeysAndNamespaces

        <N> Stream<Tuple2<K,​N>> getKeysAndNamespaces​(String state)
        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

        <N,​S extends State,​T> S getOrCreateKeyedState​(TypeSerializer<N> namespaceSerializer,
                                                                  StateDescriptor<S,​T> stateDescriptor)
                                                           throws Exception
        Creates or retrieves a keyed state backed by this state backend.
        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

        <N,​S extends State> S getPartitionedState​(N namespace,
                                                        TypeSerializer<N> namespaceSerializer,
                                                        StateDescriptor<S,​?> stateDescriptor)
                                                 throws Exception
        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.

        Type Parameters:
        N - The type of the namespace.
        S - The type of the state.
        Parameters:
        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

        void dispose()
        Description copied from interface: Disposable
        Disposes the object and releases all resources. After calling this method, calling any methods on the object may result in undefined behavior.
        Specified by:
        dispose in interface Disposable
      • 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 RocksDB 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.