xintongsong commented on code in PR #20739: URL: https://github.com/apache/flink/pull/20739#discussion_r962634480
########## flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/strategy/PipelinedRegionSchedulingStrategy.java: ########## @@ -219,44 +228,76 @@ private void maybeScheduleRegions(final Set<SchedulingPipelinedRegion> regions) SchedulingStrategyUtils.sortPipelinedRegionsInTopologicalOrder( schedulingTopology, regions); - final Map<ConsumedPartitionGroup, Boolean> consumableStatusCache = new HashMap<>(); - final Set<SchedulingPipelinedRegion> downstreamSchedulableRegions = new HashSet<>(); - for (SchedulingPipelinedRegion region : regionsSorted) { - if (maybeScheduleRegion(region, consumableStatusCache)) { - downstreamSchedulableRegions.addAll( - consumedPartitionGroupsOfRegion.getOrDefault(region, Collections.emptySet()) - .stream() - .flatMap( - consumedPartitionGroups -> - partitionGroupConsumerRegions - .getOrDefault( - consumedPartitionGroups, - Collections.emptySet()) - .stream()) - .collect(Collectors.toSet())); - } + List<SchedulingPipelinedRegion> regionsToSchedule = getAllSchedulableRegions(regionsSorted); + + if (!regionsToSchedule.isEmpty()) { + // schedule regions + regionsToSchedule.forEach(this::scheduleRegion); } + } - if (!downstreamSchedulableRegions.isEmpty()) { - maybeScheduleRegions(downstreamSchedulableRegions); + private List<SchedulingPipelinedRegion> getAllSchedulableRegions( + List<SchedulingPipelinedRegion> regionsSorted) { + final List<SchedulingPipelinedRegion> regionsToSchedule = new LinkedList<>(); + final Queue<SchedulingPipelinedRegion> regionQueue = new LinkedList<>(regionsSorted); + while (!regionQueue.isEmpty()) { + final Map<ConsumedPartitionGroup, Boolean> consumableStatusCache = new HashMap<>(); + final Set<ConsumedPartitionGroup> consumedPartitionGroupCache = new HashSet<>(); + final Set<SchedulingPipelinedRegion> addedToQueue = new HashSet<>(); Review Comment: We can combine `regionsToSchedule` and `addedToQueue` with a `LinkedHashSet`. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org