zhuzhurk commented on a change in pull request #10067: [FLINK-14375][runtime] 
Avoid to notify scheduler about fake or outdated state update
URL: https://github.com/apache/flink/pull/10067#discussion_r342475462
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/SchedulerBase.java
 ##########
 @@ -417,12 +417,50 @@ public void cancel() {
        @Override
        public final boolean updateTaskExecutionState(final TaskExecutionState 
taskExecutionState) {
                final Optional<ExecutionVertexID> executionVertexId = 
getExecutionVertexId(taskExecutionState.getID());
-               if (executionVertexId.isPresent()) {
-                       executionGraph.updateState(taskExecutionState);
-                       
updateTaskExecutionStateInternal(executionVertexId.get(), taskExecutionState);
+
+               boolean updateSuccess = 
executionGraph.updateState(taskExecutionState);
+
+               if (updateSuccess && executionVertexId.isPresent()) {
+                       final Optional<TaskExecutionState> 
validTaskExecutionState = getValidTaskExecutionState(
+                               executionVertexId.get(),
+                               taskExecutionState);
+
+                       if (validTaskExecutionState.isPresent()) {
+                               
updateTaskExecutionStateInternal(executionVertexId.get(), 
validTaskExecutionState.get());
+                       }
                        return true;
+               } else {
+                       return false;
                }
-               return false;
+       }
+
+       private Optional<TaskExecutionState> getValidTaskExecutionState(
+                       final ExecutionVertexID executionVertexId,
+                       final TaskExecutionState taskExecutionState) {
+
+               final ExecutionVertex executionVertex = 
getExecutionVertex(executionVertexId);
+               final ExecutionAttemptID currentExecutionAttemptID = 
executionVertex.getCurrentExecutionAttempt().getAttemptId();
+
+               // only notifies FINISHED and FAILED states which are needed at 
the moment.
+               // can be refined in FLINK-14233 after the legacy scheduler is 
removed and
+               // the actions are factored out from ExecutionGraph.
+               switch (taskExecutionState.getExecutionState()) {
+                       case FINISHED:
+                       case FAILED:
+                               if (executionVertex.getExecutionState() == 
taskExecutionState.getExecutionState()) {
+                                       return Optional.of(
+                                               new TaskExecutionState(
 
 Review comment:
   Good idea. Will take this change.
   Need to mention that we need to `getExecutionVertexIdOrThrow` before 
invoking `executionGraph.updateState` in case its a terminal state that 
deregisters the execution from execution graph.

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