Class InternalTimerServiceImpl<K,N>
- java.lang.Object
-
- org.apache.flink.streaming.api.operators.InternalTimerServiceImpl<K,N>
-
- All Implemented Interfaces:
InternalTimerService<N>
- Direct Known Subclasses:
InternalTimerServiceAsyncImpl
public class InternalTimerServiceImpl<K,N> extends Object implements InternalTimerService<N>
InternalTimerService
that stores timers on the Java heap.
-
-
Field Summary
Fields Modifier and Type Field Description protected StreamTaskCancellationContext
cancellationContext
Context that allows us to stop firing timers if the containing task has been cancelled.protected long
currentWatermark
The local event time, as denoted by the last receivedWatermark
.protected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>>
eventTimeTimersQueue
Event time timers that are currently in-flight.protected KeyContext
keyContext
protected ScheduledFuture<?>
nextTimer
The one and only Future (if any) registered to execute the nextTriggerable
action, when its (processing) time arrives.protected ProcessingTimeService
processingTimeService
protected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>>
processingTimeTimersQueue
Processing time timers that are currently in-flight.protected TaskIOMetricGroup
taskIOMetricGroup
protected Triggerable<K,N>
triggerTarget
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceWatermark(long time)
long
currentProcessingTime()
Returns the current processing time.long
currentWatermark()
Returns the current event-time watermark.void
deleteEventTimeTimer(N namespace, long time)
Deletes the timer for the given key and namespace.void
deleteProcessingTimeTimer(N namespace, long time)
Deletes the timer for the given key and namespace.void
forEachEventTimeTimer(BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.void
forEachProcessingTimeTimer(BiConsumerWithException<N,Long,Exception> consumer)
Performs an action for each registered timer.protected void
foreachTimer(BiConsumerWithException<N,Long,Exception> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue)
TypeSerializer<K>
getKeySerializer()
TypeSerializer<N>
getNamespaceSerializer()
int
numEventTimeTimers()
int
numEventTimeTimers(N namespace)
int
numProcessingTimeTimers()
int
numProcessingTimeTimers(N namespace)
void
registerEventTimeTimer(N namespace, long time)
Registers a timer to be fired when event time watermark passes the given time.void
registerProcessingTimeTimer(N namespace, long time)
Registers a timer to be fired when processing time passes the given time.void
restoreTimersForKeyGroup(InternalTimersSnapshot<?,?> restoredSnapshot, int keyGroupIdx)
Restore the timers (both processing and event time ones) for a givenkeyGroupIdx
.InternalTimersSnapshot<K,N>
snapshotTimersForKeyGroup(int keyGroupIdx)
Snapshots the timers (both processing and event time ones) for a givenkeyGroupIdx
.void
startTimerService(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, Triggerable<K,N> triggerTarget)
Starts the localInternalTimerServiceImpl
by: Setting thekeySerialized
andnamespaceSerializer
for the timers it will contain.boolean
tryAdvanceWatermark(long time, InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn)
-
-
-
Field Detail
-
processingTimeService
protected final ProcessingTimeService processingTimeService
-
taskIOMetricGroup
protected final TaskIOMetricGroup taskIOMetricGroup
-
keyContext
protected final KeyContext keyContext
-
processingTimeTimersQueue
protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> processingTimeTimersQueue
Processing time timers that are currently in-flight.
-
eventTimeTimersQueue
protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> eventTimeTimersQueue
Event time timers that are currently in-flight.
-
cancellationContext
protected final StreamTaskCancellationContext cancellationContext
Context that allows us to stop firing timers if the containing task has been cancelled.
-
currentWatermark
protected long currentWatermark
The local event time, as denoted by the last receivedWatermark
.
-
nextTimer
protected ScheduledFuture<?> nextTimer
The one and only Future (if any) registered to execute the nextTriggerable
action, when its (processing) time arrives.
-
triggerTarget
protected Triggerable<K,N> triggerTarget
-
-
Method Detail
-
startTimerService
public void startTimerService(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, Triggerable<K,N> triggerTarget)
Starts the localInternalTimerServiceImpl
by:- Setting the
keySerialized
andnamespaceSerializer
for the timers it will contain. - Setting the
triggerTarget
which contains the action to be performed when a timer fires. - Re-registering timers that were retrieved after recovering from a node failure, if any.
This method can be called multiple times, as long as it is called with the same serializers.
- Setting the
-
currentProcessingTime
public long currentProcessingTime()
Description copied from interface:InternalTimerService
Returns the current processing time.- Specified by:
currentProcessingTime
in interfaceInternalTimerService<K>
-
currentWatermark
public long currentWatermark()
Description copied from interface:InternalTimerService
Returns the current event-time watermark.- Specified by:
currentWatermark
in interfaceInternalTimerService<K>
-
registerProcessingTimeTimer
public void registerProcessingTimeTimer(N namespace, long time)
Description copied from interface:InternalTimerService
Registers a timer to be fired when processing time passes the given time. The namespace you pass here will be provided when the timer fires.- Specified by:
registerProcessingTimeTimer
in interfaceInternalTimerService<K>
-
registerEventTimeTimer
public void registerEventTimeTimer(N namespace, long time)
Description copied from interface:InternalTimerService
Registers a timer to be fired when event time watermark passes the given time. The namespace you pass here will be provided when the timer fires.- Specified by:
registerEventTimeTimer
in interfaceInternalTimerService<K>
-
deleteProcessingTimeTimer
public void deleteProcessingTimeTimer(N namespace, long time)
Description copied from interface:InternalTimerService
Deletes the timer for the given key and namespace.- Specified by:
deleteProcessingTimeTimer
in interfaceInternalTimerService<K>
-
deleteEventTimeTimer
public void deleteEventTimeTimer(N namespace, long time)
Description copied from interface:InternalTimerService
Deletes the timer for the given key and namespace.- Specified by:
deleteEventTimeTimer
in interfaceInternalTimerService<K>
-
forEachEventTimeTimer
public void forEachEventTimeTimer(BiConsumerWithException<N,Long,Exception> consumer) throws Exception
Description copied from interface:InternalTimerService
Performs an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.- Specified by:
forEachEventTimeTimer
in interfaceInternalTimerService<K>
- Throws:
Exception
-
forEachProcessingTimeTimer
public void forEachProcessingTimeTimer(BiConsumerWithException<N,Long,Exception> consumer) throws Exception
Description copied from interface:InternalTimerService
Performs an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.- Specified by:
forEachProcessingTimeTimer
in interfaceInternalTimerService<K>
- Throws:
Exception
-
foreachTimer
protected void foreachTimer(BiConsumerWithException<N,Long,Exception> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> queue) throws Exception
- Throws:
Exception
-
tryAdvanceWatermark
public boolean tryAdvanceWatermark(long time, InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn) throws Exception
- Returns:
- true if following watermarks can be processed immediately. False if the firing timers should be interrupted as soon as possible.
- Throws:
Exception
-
snapshotTimersForKeyGroup
public InternalTimersSnapshot<K,N> snapshotTimersForKeyGroup(int keyGroupIdx)
Snapshots the timers (both processing and event time ones) for a givenkeyGroupIdx
.- Parameters:
keyGroupIdx
- the id of the key-group to be put in the snapshot.- Returns:
- a snapshot containing the timers for the given key-group, and the serializers for them
-
getKeySerializer
public TypeSerializer<K> getKeySerializer()
-
getNamespaceSerializer
public TypeSerializer<N> getNamespaceSerializer()
-
restoreTimersForKeyGroup
public void restoreTimersForKeyGroup(InternalTimersSnapshot<?,?> restoredSnapshot, int keyGroupIdx)
Restore the timers (both processing and event time ones) for a givenkeyGroupIdx
.- Parameters:
restoredSnapshot
- the restored snapshot containing the key-group's timers, and the serializers that were used to write themkeyGroupIdx
- the id of the key-group to be put in the snapshot.
-
numProcessingTimeTimers
@VisibleForTesting public int numProcessingTimeTimers()
-
numEventTimeTimers
@VisibleForTesting public int numEventTimeTimers()
-
numProcessingTimeTimers
@VisibleForTesting public int numProcessingTimeTimers(N namespace)
-
numEventTimeTimers
@VisibleForTesting public int numEventTimeTimers(N namespace)
-
-