Interface BroadcastState<K,V>
-
- Type Parameters:
K- The key type of the elements in theBroadcastState.V- The value type of the elements in theBroadcastState.
- 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 aBroadcastStream. 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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Iterable<Map.Entry<K,V>>entries()Returns all the mappings in the state.Iterator<Map.Entry<K,V>>iterator()Iterates over all the mappings in the state.voidput(K key, V value)Associates a new value with the given key.voidputAll(Map<K,V> map)Copies all of the mappings from the given map into the state.voidremove(K key)Deletes the mapping of the given key.-
Methods inherited from interface org.apache.flink.api.common.state.ReadOnlyBroadcastState
contains, get, immutableEntries
-
-
-
-
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 mappingvalue- 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.
-
-