Zakelly commented on code in PR #24895:
URL: https://github.com/apache/flink/pull/24895#discussion_r1632623556


##########
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:
   If so I would suggest another `boolean first` to suppress the check in first 
round. It would achieve both aspects. WDYT?



-- 
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]

Reply via email to