Thesharing commented on a change in pull request #16687:
URL: https://github.com/apache/flink/pull/16687#discussion_r688481343



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/LocalInputPreferredSlotSharingStrategy.java
##########
@@ -214,87 +253,112 @@ private ExecutionSlotSharingGroup 
tryFindAvailableProducerExecutionSlotSharingGr
 
             final ExecutionVertexID executionVertexId = 
executionVertex.getId();
 
-            for (SchedulingResultPartition partition : 
executionVertex.getConsumedResults()) {
-                final ExecutionVertexID producerVertexId = 
partition.getProducer().getId();
-                if (!inSameLogicalSlotSharingGroup(producerVertexId, 
executionVertexId)) {
-                    continue;
-                }
-
-                final ExecutionSlotSharingGroup producerGroup =
-                        executionSlotSharingGroupMap.get(producerVertexId);
-
-                checkState(producerGroup != null);
-                if (isGroupAvailableForVertex(producerGroup, 
executionVertexId)) {
-                    return producerGroup;
+            Set<ExecutionSlotSharingGroup> availableGroupsForCurrentVertex =
+                    
availableGroupsForJobVertex.get(executionVertexId.getJobVertexId());
+
+            for (ConsumedPartitionGroup consumedPartitionGroup :
+                    executionVertex.getConsumedPartitionGroups()) {
+
+                Set<ExecutionSlotSharingGroup> candidateGroups =
+                        
candidateGroupsForConsumedPartitionGroup.computeIfAbsent(
+                                consumedPartitionGroup,
+                                group ->
+                                        
computeAllCandidateGroupsForConsumedPartitionGroup(
+                                                
executionVertexId.getJobVertexId(), group));
+
+                while (!candidateGroups.isEmpty()) {
+                    // There are two cases for this candidate group:
+                    // 1. The group is available for this vertex, and it will 
be assigned to this
+                    // vertex
+                    // 2. The group is not available for this vertex, because 
it's assigned to
+                    // another vertex
+                    // No matter what case it is, the candidate group is no 
longer a candidate and
+                    // should be removed
+                    ExecutionSlotSharingGroup candidateGroup = 
IterableUtils.pop(candidateGroups);
+                    if 
(availableGroupsForCurrentVertex.contains(candidateGroup)) {
+                        return candidateGroup;
+                    }
                 }
             }
 
             return null;
         }
 
         private boolean inSameLogicalSlotSharingGroup(
-                final ExecutionVertexID executionVertexId1,
-                final ExecutionVertexID executionVertexId2) {
+                final JobVertexID jobVertexId1, final JobVertexID 
jobVertexId2) {
 
             return Objects.equals(
-                    
getSlotSharingGroup(executionVertexId1).getSlotSharingGroupId(),
-                    
getSlotSharingGroup(executionVertexId2).getSlotSharingGroupId());
+                    
checkNotNull(getSlotSharingGroup(jobVertexId1)).getSlotSharingGroupId(),
+                    
checkNotNull(getSlotSharingGroup(jobVertexId2)).getSlotSharingGroupId());

Review comment:
       Thank you for pointing this out. Resolved.




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