rkhachatryan commented on a change in pull request #10151: [FLINK-14231] Handle 
the processing-time timers before closing operator to properly support endInput
URL: https://github.com/apache/flink/pull/10151#discussion_r346731375
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/ProcessingTimeServiceImpl.java
 ##########
 @@ -39,11 +63,110 @@ public long getCurrentProcessingTime() {
 
        @Override
        public ScheduledFuture<?> registerTimer(long timestamp, 
ProcessingTimeCallback target) {
-               return timerService.registerTimer(timestamp, 
processingTimeCallbackWrapper.apply(target));
+               if (isQuiesced) {
+                       return new NeverCompleteFuture(
+                               
ProcessingTimeServiceUtil.getProcessingTimeDelay(timestamp, 
getCurrentProcessingTime()));
+               }
+
+               final TimerScheduledFuture<?> timer = new 
TimerScheduledFuture<>();
+               timer.setTimer(timerService.registerTimer(timestamp, 
invokeCallbackAndRemovePending(timer, target)));
+
+               pendingTimers.put(timer, true);
+               if (timer.isDone()) {
+                       removePendingTimers(timer);
+               }
+               return timer;
        }
 
        @Override
        public ScheduledFuture<?> scheduleAtFixedRate(ProcessingTimeCallback 
callback, long initialDelay, long period) {
                return 
timerService.scheduleAtFixedRate(processingTimeCallbackWrapper.apply(callback), 
initialDelay, period);
        }
+
+       void quiesce() {
+               isQuiesced = true;
+               completeTimersDoneFutureIfQuiesced();
+       }
+
+       CompletableFuture<?> getTimersDoneFutureAfterQuiescing() {
+               return timersDoneFutureAfterQuiescing;
+       }
+
+       @VisibleForTesting
+       int getNumPendingTimers() {
+               return pendingTimers.size();
+       }
+
+       private ProcessingTimeCallback 
invokeCallbackAndRemovePending(TimerScheduledFuture<?> timer, 
ProcessingTimeCallback target) {
+               ProcessingTimeCallback originalCallback = 
processingTimeCallbackWrapper.apply(target);
 
 Review comment:
   Variable name is confusing: it's actually a wrapped callback, not the 
"originalCallback".

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to