Interface BroadcastState<K,​V>

  • Type Parameters:
    K - The key type of the elements in the BroadcastState.
    V - The value type of the elements in the BroadcastState.
    All Superinterfaces:
    ReadOnlyBroadcastState<K,​V>, State

    @PublicEvolving
    public interface BroadcastState<K,​V>
    extends ReadOnlyBroadcastState<K,​V>
    A type of state that can be created to store the state of a BroadcastStream. This state assumes that the same elements are sent to all instances of an operator.

    CAUTION: the user has to guarantee that all task instances store the same elements in this type of state.

    Each operator instance individually maintains and stores elements in the broadcast state. The fact that the incoming stream is a broadcast one guarantees that all instances see all the elements. Upon recovery or re-scaling, the same state is given to each of the instances. To avoid hotspots, each task reads its previous partition, and if there are more tasks (scale up), then the new instances read from the old instances in a round robin fashion. This is why each instance has to guarantee that it stores the same elements as the rest. If not, upon recovery or rescaling you may have unpredictable redistribution of the partitions, thus unpredictable results.

    • Method Detail

      • put

        void put​(K key,
                 V value)
          throws Exception
        Associates a new value with the given key.
        Parameters:
        key - The key of the mapping
        value - The new value of the mapping
        Throws:
        Exception - Thrown if the system cannot access the state.
      • putAll

        void putAll​(Map<K,​V> map)
             throws Exception
        Copies all of the mappings from the given map into the state.
        Parameters:
        map - The mappings to be stored in this state
        Throws:
        Exception - Thrown if the system cannot access the state.
      • remove

        void remove​(K key)
             throws Exception
        Deletes the mapping of the given key.
        Parameters:
        key - The key of the mapping
        Throws:
        Exception - Thrown if the system cannot access the state.
      • iterator

        Iterator<Map.Entry<K,​V>> iterator()
                                         throws Exception
        Iterates over all the mappings in the state.
        Returns:
        An iterator over all the mappings in the state
        Throws:
        Exception - Thrown if the system cannot access the state.
      • entries

        Iterable<Map.Entry<K,​V>> entries()
                                        throws Exception
        Returns all the mappings in the state.
        Returns:
        An iterable view of all the key-value pairs in the state.
        Throws:
        Exception - Thrown if the system cannot access the state.