Thesharing commented on a change in pull request #15314: URL: https://github.com/apache/flink/pull/15314#discussion_r603259955
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionView.java ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * This view maintains the finished progress of consumer {@link SchedulingPipelinedRegion}s for each + * {@link ConsumedPartitionGroup}. + */ +public class ConsumerRegionGroupExecutionView implements Iterable<SchedulingPipelinedRegion> { Review comment: I believe that `ConsumerRegionExecutionView` is covered by `ConsumerRegionExecutionViewMaintainerTest`. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/RegionPartitionReleaseStrategy.java ########## @@ -47,10 +49,26 @@ private final Map<ExecutionVertexID, PipelinedRegionExecutionView> regionExecutionViewByVertex = new HashMap<>(); + private final Map<ConsumedPartitionGroup, ConsumerRegionGroupExecutionView> + partitionGroupConsumerRegions = new HashMap<>(); + + private final Map<SchedulingPipelinedRegion, Set<ConsumedPartitionGroup>> + regionConsumedPartitionGroups = new HashMap<>(); + + private final ConsumerRegionGroupExecutionViewTracker consumerRegionGroupExecutionViewTracker = + new ConsumerRegionGroupExecutionViewTracker(); + public RegionPartitionReleaseStrategy(final SchedulingTopology schedulingTopology) { this.schedulingTopology = checkNotNull(schedulingTopology); + init(); + } + private void init() { Review comment: Resolved. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionViewTracker.java ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Track the finished progress of {@link ConsumerRegionGroupExecutionView}s. + * + * <p>NOTE: It only contains {@link SchedulingPipelinedRegion}s that have {@link + * ConsumedPartitionGroup}s. + */ +class ConsumerRegionGroupExecutionViewTracker { + + /** + * The list of {@link ConsumerRegionGroupExecutionView}s that a SchedulingPipelinedRegion + * belongs to. + */ + private final Map<SchedulingPipelinedRegion, List<ConsumerRegionGroupExecutionView>> + executionViewByRegion = new HashMap<>(); + + void init(Iterable<ConsumerRegionGroupExecutionView> executionViews) { Review comment: Resolved. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionViewTracker.java ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Track the finished progress of {@link ConsumerRegionGroupExecutionView}s. + * + * <p>NOTE: It only contains {@link SchedulingPipelinedRegion}s that have {@link + * ConsumedPartitionGroup}s. + */ +class ConsumerRegionGroupExecutionViewTracker { Review comment: Resolved. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionViewTracker.java ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Track the finished progress of {@link ConsumerRegionGroupExecutionView}s. + * + * <p>NOTE: It only contains {@link SchedulingPipelinedRegion}s that have {@link + * ConsumedPartitionGroup}s. + */ +class ConsumerRegionGroupExecutionViewTracker { + + /** + * The list of {@link ConsumerRegionGroupExecutionView}s that a SchedulingPipelinedRegion + * belongs to. + */ + private final Map<SchedulingPipelinedRegion, List<ConsumerRegionGroupExecutionView>> + executionViewByRegion = new HashMap<>(); + + void init(Iterable<ConsumerRegionGroupExecutionView> executionViews) { + for (ConsumerRegionGroupExecutionView executionView : executionViews) { + for (SchedulingPipelinedRegion region : executionView) { + executionViewByRegion + .computeIfAbsent(region, r -> new ArrayList<>()) + .add(executionView); + } + } + } + + void regionFinished(SchedulingPipelinedRegion region) { + for (ConsumerRegionGroupExecutionView executionView : Review comment: Since ConsumerRegionGroupExecutionViewMaintainer only maintains the status of regions with ConsumedPartitionGroup, we need to use `getOrDefault` to avoid Exceptions for source regions. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionViewTrackerTest.java ########## @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.adapter.DefaultSchedulingPipelinedRegion; +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingExecutionVertex; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; +import org.apache.flink.runtime.scheduler.strategy.TestingSchedulingExecutionVertex; +import org.apache.flink.runtime.scheduler.strategy.TestingSchedulingTopology; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link ConsumerRegionGroupExecutionView} and {@link + * ConsumerRegionGroupExecutionViewTracker}. + */ +public class ConsumerRegionGroupExecutionViewTrackerTest extends TestLogger { + + List<TestingSchedulingExecutionVertex> producers; + List<TestingSchedulingExecutionVertex> consumers; + + TestingSchedulingTopology schedulingTopology; Review comment: Agreed. I've simplified this test. Please re-review it. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/RegionPartitionReleaseStrategy.java ########## @@ -98,26 +158,24 @@ private PipelinedRegionExecutionView getPipelinedRegionExecutionViewForVertex( } private List<IntermediateResultPartitionID> filterReleasablePartitions( - final Iterable<? extends SchedulingResultPartition> schedulingResultPartitions) { - return IterableUtils.toStream(schedulingResultPartitions) - .map(SchedulingResultPartition::getId) - .filter(this::areConsumerRegionsFinished) - .collect(Collectors.toList()); - } - - private boolean areConsumerRegionsFinished( - final IntermediateResultPartitionID resultPartitionId) { - final SchedulingResultPartition resultPartition = - schedulingTopology.getResultPartition(resultPartitionId); - return IterableUtils.toStream(resultPartition.getConsumers()) - .map(SchedulingExecutionVertex::getId) - .allMatch(this::isRegionOfVertexFinished); - } + final Iterable<ConsumedPartitionGroup> consumedPartitionGroups) { + + final List<IntermediateResultPartitionID> filteredPartitions = new ArrayList<>(); + + for (ConsumedPartitionGroup consumedPartitionGroup : consumedPartitionGroups) { + final ConsumerRegionGroupExecutionView consumerRegionSet = Review comment: Resolved. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/ConsumerRegionGroupExecutionViewTracker.java ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.flink.runtime.executiongraph.failover.flip1.partitionrelease; + +import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; +import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Track the finished progress of {@link ConsumerRegionGroupExecutionView}s. + * + * <p>NOTE: It only contains {@link SchedulingPipelinedRegion}s that have {@link + * ConsumedPartitionGroup}s. + */ +class ConsumerRegionGroupExecutionViewTracker { + + /** + * The list of {@link ConsumerRegionGroupExecutionView}s that a SchedulingPipelinedRegion + * belongs to. + */ + private final Map<SchedulingPipelinedRegion, List<ConsumerRegionGroupExecutionView>> + executionViewByRegion = new HashMap<>(); + + void init(Iterable<ConsumerRegionGroupExecutionView> executionViews) { + for (ConsumerRegionGroupExecutionView executionView : executionViews) { + for (SchedulingPipelinedRegion region : executionView) { + executionViewByRegion + .computeIfAbsent(region, r -> new ArrayList<>()) + .add(executionView); + } + } + } + + void regionFinished(SchedulingPipelinedRegion region) { + for (ConsumerRegionGroupExecutionView executionView : + executionViewByRegion.getOrDefault(region, Collections.emptyList())) { + executionView.regionFinished(region); + } + } + + void regionUnfinished(SchedulingPipelinedRegion region) { + for (ConsumerRegionGroupExecutionView executionView : + executionViewByRegion.getOrDefault(region, Collections.emptyList())) { Review comment: The same above. -- 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]
