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
InternalTimerService that stores timers on the Java heap.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StreamTaskCancellationContextContext that allows us to stop firing timers if the containing task has been cancelled.protected longThe local event time, as denoted by the last receivedWatermark.protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> Event time timers that are currently in-flight.protected final KeyContextprotected ScheduledFuture<?>The one and only Future (if any) registered to execute the nextTriggerableaction, when its (processing) time arrives.protected final ProcessingTimeServiceprotected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> Processing time timers that are currently in-flight.protected final TaskIOMetricGroupprotected Triggerable<K,N> -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceWatermark(long time) longReturns the current processing time.longReturns the current event-time watermark.voiddeleteEventTimeTimer(N namespace, long time) Deletes the timer for the given key and namespace.voiddeleteProcessingTimeTimer(N namespace, long time) Deletes the timer for the given key and namespace.voidforEachEventTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, Exception> consumer) Performs an action for each registered timer.voidforEachProcessingTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, Exception> consumer) Performs an action for each registered timer.protected voidforeachTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, Exception> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> queue) org.apache.flink.api.common.typeutils.TypeSerializer<K>org.apache.flink.api.common.typeutils.TypeSerializer<N>intintnumEventTimeTimers(N namespace) intintnumProcessingTimeTimers(N namespace) voidregisterEventTimeTimer(N namespace, long time) Registers a timer to be fired when event time watermark passes the given time.voidregisterProcessingTimeTimer(N namespace, long time) Registers a timer to be fired when processing time passes the given time.voidrestoreTimersForKeyGroup(InternalTimersSnapshot<?, ?> restoredSnapshot, int keyGroupIdx) Restore the timers (both processing and event time ones) for a givenkeyGroupIdx.snapshotTimersForKeyGroup(int keyGroupIdx) Snapshots the timers (both processing and event time ones) for a givenkeyGroupIdx.voidstartTimerService(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, Triggerable<K, N> triggerTarget) Starts the localInternalTimerServiceImplby: Setting thekeySerializedandnamespaceSerializerfor the timers it will contain.booleantryAdvanceWatermark(long time, InternalTimeServiceManager.ShouldStopAdvancingFn shouldStopAdvancingFn)
-
Field Details
-
processingTimeService
-
taskIOMetricGroup
-
keyContext
-
processingTimeTimersQueue
protected final KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>> processingTimeTimersQueueProcessing time timers that are currently in-flight. -
eventTimeTimersQueue
Event time timers that are currently in-flight. -
cancellationContext
Context that allows us to stop firing timers if the containing task has been cancelled. -
currentWatermark
protected long currentWatermarkThe local event time, as denoted by the last receivedWatermark. -
nextTimer
The one and only Future (if any) registered to execute the nextTriggerableaction, when its (processing) time arrives. -
triggerTarget
-
-
Method Details
-
startTimerService
public void startTimerService(org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.typeutils.TypeSerializer<N> namespaceSerializer, Triggerable<K, N> triggerTarget) Starts the localInternalTimerServiceImplby:- Setting the
keySerializedandnamespaceSerializerfor the timers it will contain. - Setting the
triggerTargetwhich 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:InternalTimerServiceReturns the current processing time.- Specified by:
currentProcessingTimein interfaceInternalTimerService<K>
-
currentWatermark
public long currentWatermark()Description copied from interface:InternalTimerServiceReturns the current event-time watermark.- Specified by:
currentWatermarkin interfaceInternalTimerService<K>
-
registerProcessingTimeTimer
Description copied from interface:InternalTimerServiceRegisters 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:
registerProcessingTimeTimerin interfaceInternalTimerService<K>
-
registerEventTimeTimer
Description copied from interface:InternalTimerServiceRegisters 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:
registerEventTimeTimerin interfaceInternalTimerService<K>
-
deleteProcessingTimeTimer
Description copied from interface:InternalTimerServiceDeletes the timer for the given key and namespace.- Specified by:
deleteProcessingTimeTimerin interfaceInternalTimerService<K>
-
deleteEventTimeTimer
Description copied from interface:InternalTimerServiceDeletes the timer for the given key and namespace.- Specified by:
deleteEventTimeTimerin interfaceInternalTimerService<K>
-
forEachEventTimeTimer
public void forEachEventTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, throws ExceptionException> consumer) Description copied from interface:InternalTimerServicePerforms an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.- Specified by:
forEachEventTimeTimerin interfaceInternalTimerService<K>- Throws:
Exception
-
forEachProcessingTimeTimer
public void forEachProcessingTimeTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, throws ExceptionException> consumer) Description copied from interface:InternalTimerServicePerforms an action for each registered timer. The timer service will set the key context for the timers key before invoking the action.- Specified by:
forEachProcessingTimeTimerin interfaceInternalTimerService<K>- Throws:
Exception
-
foreachTimer
protected void foreachTimer(org.apache.flink.util.function.BiConsumerWithException<N, Long, throws ExceptionException> consumer, KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K, N>> queue) - Throws:
Exception
-
advanceWatermark
- 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
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
-
getNamespaceSerializer
-
restoreTimersForKeyGroup
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
-
numEventTimeTimers
-