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>
InternalTimerServicethat stores timers on the Java heap.
-
-
Field Summary
Fields Modifier and Type Field Description protected StreamTaskCancellationContextcancellationContextContext that allows us to stop firing timers if the containing task has been cancelled.protected longcurrentWatermarkThe local event time, as denoted by the last receivedWatermark.protected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>>eventTimeTimersQueueEvent time timers that are currently in-flight.protected KeyContextkeyContextprotected ScheduledFuture<?>nextTimerThe one and only Future (if any) registered to execute the nextTriggerableaction, when its (processing) time arrives.protected ProcessingTimeServiceprocessingTimeServiceprotected KeyGroupedInternalPriorityQueue<TimerHeapInternalTimer<K,N>>processingTimeTimersQueueProcessing time timers that are currently in-flight.protected TaskIOMetricGrouptaskIOMetricGroupprotected Triggerable<K,N>triggerTarget
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvanceWatermark(long time)longcurrentProcessingTime()Returns the current processing time.longcurrentWatermark()Returns 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>getKeySerializer()org.apache.flink.api.common.typeutils.TypeSerializer<N>getNamespaceSerializer()voidinitializeWatermark(long watermark)Initialize watermark after restore.intnumEventTimeTimers()intnumEventTimeTimers(N namespace)intnumProcessingTimeTimers()intnumProcessingTimeTimers(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.InternalTimersSnapshot<K,N>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 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 nextTriggerableaction, when its (processing) time arrives.
-
triggerTarget
protected Triggerable<K,N> triggerTarget
-
-
Method Detail
-
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>
-
initializeWatermark
public void initializeWatermark(long watermark)
Description copied from interface:InternalTimerServiceInitialize watermark after restore.- Specified by:
initializeWatermarkin interfaceInternalTimerService<K>
-
registerProcessingTimeTimer
public void registerProcessingTimeTimer(N namespace, long time)
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
public void registerEventTimeTimer(N namespace, long time)
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
public void deleteProcessingTimeTimer(N namespace, long time)
Description copied from interface:InternalTimerServiceDeletes the timer for the given key and namespace.- Specified by:
deleteProcessingTimeTimerin interfaceInternalTimerService<K>
-
deleteEventTimeTimer
public void deleteEventTimeTimer(N namespace, long time)
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,Exception> consumer) throws Exception
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,Exception> consumer) throws Exception
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,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 org.apache.flink.api.common.typeutils.TypeSerializer<K> getKeySerializer()
-
getNamespaceSerializer
public org.apache.flink.api.common.typeutils.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)
-
-