pnowojski commented on code in PR #24895:
URL: https://github.com/apache/flink/pull/24895#discussion_r1631419185
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/InternalTimerServiceImpl.java:
##########
@@ -307,18 +307,36 @@ void onProcessingTime(long time) throws Exception {
}
public void advanceWatermark(long time) throws Exception {
- currentWatermark = time;
+ Preconditions.checkState(
+ tryAdvanceWatermark(
+ time,
+ () -> {
+ // Never stop advancing.
+ return false;
+ }));
+ }
+ /**
+ * @return true if following watermarks can be processed immediately.
False if the firing timers
+ * should be interrupted as soon as possible.
+ */
+ public boolean tryAdvanceWatermark(
+ long time, InternalTimeServiceManager.ShouldStopAdvancingFn
shouldStopAdvancingFn)
+ throws Exception {
+ currentWatermark = time;
InternalTimer<K, N> timer;
-
while ((timer = eventTimeTimersQueue.peek()) != null
&& timer.getTimestamp() <= time
&& !cancellationContext.isCancelled()) {
keyContext.setCurrentKey(timer.getKey());
eventTimeTimersQueue.poll();
triggerTarget.onEventTime(timer);
taskIOMetricGroup.getNumFiredTimers().inc();
+ if (shouldStopAdvancingFn.shouldStopAdvancing()) {
+ return false;
+ }
Review Comment:
I've added a comment explaining why this is at the end:
```
// Check if we should stop advancing after at least one
iteration to guarantee progress
// and prevent a potential starvation.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]