rkhachatryan commented on a change in pull request #10151: [FLINK-14231] Handle 
the processing-time timers when closing operators to make endInput semantics on 
the operator chain strict
URL: https://github.com/apache/flink/pull/10151#discussion_r355584129
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
 ##########
 @@ -1011,10 +989,25 @@ TimerService getTimerService() {
                return timerService;
        }
 
-       public ProcessingTimeService getProcessingTimeService(int 
operatorIndex) {
+       @VisibleForTesting
+       StreamOperator<?> getHeadOperator() {
+               return operatorChain.getHeadOperator();
+       }
+
+       public ProcessingTimeService getProcessingTimeService(OperatorID 
operatorID) {
+               Preconditions.checkNotNull(operatorID);
                Preconditions.checkState(timerService != null, "The timer 
service has not been initialized.");
-               MailboxExecutor mailboxExecutor = 
mailboxProcessor.getMailboxExecutor(operatorIndex);
-               return new ProcessingTimeServiceImpl(timerService, callback -> 
deferCallbackToMailbox(mailboxExecutor, callback));
+               Preconditions.checkState(operatorChain != null, "operatorChain 
has not been initialized.");
+
+               ProcessingTimeService processingTimeService = 
operatorChain.getOperatorProcessingTimeService(operatorID);
+               if (processingTimeService == null) {
+                       processingTimeService = new ProcessingTimeServiceImpl(
+                               timerService,
+                               callback -> 
deferCallbackToMailbox(operatorChain.getOperatorMailboxExecutor(operatorID), 
callback));
+                       
operatorChain.setOperatorProcessingTimeService(operatorID, 
(ProcessingTimeServiceImpl) processingTimeService);
+               }
 
 Review comment:
   The call chain seems quite strange:
   ```
   operator -> task.getProcessingTimerService(this.getOperatorId)
   task -> chain.getProcessingTimerService(id)
   chain -> this.getWrapper(id).getTimerService
   wrapper -> return this.timerService
   ```
   
   But it's the `operator` and its `wrapper` that actually need this 
`timerService`, right?
   
   Also, nullable `getOperatorProcessingTimeService` which is set outside is 
quite fragile.
   
   So let's store `timerService` in `AbstractStreamOperator` and expose it to 
its `wrapper`.
   Then we also don't need mapping in `OperatorChain` from `OperatorID` to 
wrapper (`allOperatorWrappers`).
   The only issue is to create `ProcessingTimeService` - we can pass some 
factory for this.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to