Anton Kalashnikov created FLINK-41715:
-----------------------------------------

             Summary: AdaptiveScheduler counts slots of a cancelled execution 
as available when checking desired resources outside rescale restarts 
                 Key: FLINK-41715
                 URL: https://issues.apache.org/jira/browse/FLINK-41715
             Project: Flink
          Issue Type: Bug
          Components: Runtime / Coordination
    Affects Versions: 2.5.0
            Reporter: Anton Kalashnikov


h3. Problem                                           
  The desired-resources check of the adaptive scheduler is evaluated against 
all slots allocated to the job, including slots that are still held by an 
execution that is being canceled.          
  \{{AdaptiveScheduler#hasDesiredResources()}} compares \{{desiredResources}} 
with \{{declarativeSlotPool.getAllSlotsInformation()}}.          

                                  
  ExecutionGraph creation does not use that view. 
\{{AdaptiveScheduler#determineParallelism}} uses 
\{{declarativeSlotPool.getFreeSlotTracker().getFreeSlotsInformation()}}. So the 
check that decides to proceed and the code that acts on the decision disagree 
about how many slots are available.                                             
                                                       
                                                                                
                                                                                
                                    
  FLINK-40379 fixes this only for rescale-triggered restarts, where the restart 
target parallelism is known: \{{WaitingForResources}} gates "desired resources" 
on the free-slot-based parallelism.  
  Every path without a restart target still uses the all-slots view:            
                                                                                
                                                                                
                                                         
  * \{{Restarting#goToSubsequentState()}}: a restart without a target goes 
straight to \{{CreatingExecutionGraph}} as soon as \{{hasDesiredResources()}} 
is true.                                      
  * \{{WaitingForResources#hasDesiredResources()}}: without a restart target it 
delegates to \{{AdaptiveScheduler#hasDesiredResources()}}. This is what the 
stabilization phases of the               
  \{{StateTransitionManager}} wait for, e.g. when \{{WaitingForResources}} is 
entered from \{{Restarting}} or from \{{CreatingExecutionGraph}} with no 
target.                                                                         
                                                                                
                                                       
  h3. Consequence                                                               
                                                                                
                                         
  Slots of the canceled execution are returned to the pool asynchronously, so 
for a short time they count as "desired resources reached" but are not free. 
ExecutionGraph creation then sees fewer 
  free slots than the check counted. It either creates the graph with a lower 
parallelism than desired, which a later rescale has to correct and so costs an 
avoidable extra restart, or, if fewer  
  than the minimum required slots are free, it fails with 
\{{NoResourceAvailableException}}.                                              
                                                                                
                                                              
  This is the same over-counting that FLINK-40379 removes for rescale restarts, 
with a narrower blast radius.                                                   
                                    
                                                                                
                                                                                
                                    
  h3. Proposal                                                                  
                                                                                
                                          
  * Add \{{AdaptiveScheduler#hasDesiredResourcesAmongFreeSlots()}}, which 
evaluates \{{desiredResources}} against 
\{{getFreeSlotTracker().getFreeSlotsInformation()}}.                            
     
  * Use it in \{{WaitingForResources#hasDesiredResources()}} when there is no 
restart target, and in \{{Restarting#goToSubsequentState()}} instead of 
\{{hasDesiredResources()}}.                      
  * Keep \{{AdaptiveScheduler#hasDesiredResources()}} unchanged. \{{Executing}} 
uses it for rescale-up detection, where the running job's own slots are 
legitimately not free.                        
                                                                                
                                                                                
                                    
  h3. Tests                                                                     
                                                                                
                                    
                                                                                
                                                                                
                                    
  * \{{WaitingForResourcesTest}} and \{{RestartingTest}}: a context where the 
all-slots view reports "desired" but the free-slot view does not must keep the 
state waiting.                           
  * \{{AdaptiveSchedulerTest}}: \{{hasDesiredResourcesAmongFreeSlots()}} must 
not count slots reserved by an execution being cancelled.                       
                                        
                                                                                
                                                                                
                                    
  See the review discussion on the pull request for FLINK-40379. 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to