forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-30233] Introduce AllFinishedInputConsumableDecider.
- Loading branch information
Showing
3 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...n/java/org/apache/flink/runtime/scheduler/strategy/AllFinishedInputConsumableDecider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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:https://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.scheduler.strategy; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* {@link AllFinishedInputConsumableDecider} is a special {@link InputConsumableDecider}. The input | ||
* is considered to be consumable only when all producer partitions are finished. | ||
*/ | ||
public class AllFinishedInputConsumableDecider implements InputConsumableDecider { | ||
|
||
@Override | ||
public boolean isInputConsumable( | ||
SchedulingExecutionVertex executionVertex, | ||
Set<ExecutionVertexID> verticesToDeploy, | ||
Map<ConsumedPartitionGroup, Boolean> consumableStatusCache) { | ||
for (ConsumedPartitionGroup consumedPartitionGroup : | ||
executionVertex.getConsumedPartitionGroups()) { | ||
|
||
if (!consumableStatusCache.computeIfAbsent( | ||
consumedPartitionGroup, this::isConsumedPartitionGroupConsumable)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private boolean isConsumedPartitionGroupConsumable( | ||
final ConsumedPartitionGroup consumedPartitionGroup) { | ||
return consumedPartitionGroup.getNumberOfUnfinishedPartitions() == 0; | ||
} | ||
|
||
/** Factory for {@link AllFinishedInputConsumableDecider}. */ | ||
public static class Factory implements InputConsumableDecider.Factory { | ||
|
||
public static final Factory INSTANCE = new Factory(); | ||
|
||
private Factory() {} | ||
|
||
@Override | ||
public InputConsumableDecider createInstance( | ||
SchedulingTopology schedulingTopology, | ||
Function<ExecutionVertexID, Boolean> scheduledVertexRetriever) { | ||
return new AllFinishedInputConsumableDecider(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...va/org/apache/flink/runtime/scheduler/strategy/AllFinishedInputConsumableDeciderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* 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:https://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.scheduler.strategy; | ||
|
||
import org.apache.flink.runtime.io.network.partition.ResultPartitionType; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** Tests for {@link AllFinishedInputConsumableDecider}. */ | ||
class AllFinishedInputConsumableDeciderTest { | ||
@Test | ||
void testNotFinishedBlockingInput() { | ||
final TestingSchedulingTopology topology = new TestingSchedulingTopology(); | ||
|
||
final List<TestingSchedulingExecutionVertex> producers = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
final List<TestingSchedulingExecutionVertex> consumer = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
topology.connectAllToAll(producers, consumer) | ||
.withResultPartitionState(ResultPartitionState.CREATED) | ||
.withResultPartitionType(ResultPartitionType.BLOCKING) | ||
.finish(); | ||
|
||
AllFinishedInputConsumableDecider inputConsumableDecider = | ||
createAllFinishedInputConsumableDecider(); | ||
|
||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(0), Collections.emptySet(), new HashMap<>())) | ||
.isFalse(); | ||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(1), Collections.emptySet(), new HashMap<>())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void testAllFinishedBlockingInput() { | ||
final TestingSchedulingTopology topology = new TestingSchedulingTopology(); | ||
|
||
final List<TestingSchedulingExecutionVertex> producers = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
final List<TestingSchedulingExecutionVertex> consumer = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
topology.connectAllToAll(producers, consumer) | ||
.withResultPartitionState(ResultPartitionState.ALL_DATA_PRODUCED) | ||
.withResultPartitionType(ResultPartitionType.BLOCKING) | ||
.finish(); | ||
|
||
AllFinishedInputConsumableDecider inputConsumableDecider = | ||
createAllFinishedInputConsumableDecider(); | ||
|
||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(0), Collections.emptySet(), new HashMap<>())) | ||
.isTrue(); | ||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(1), Collections.emptySet(), new HashMap<>())) | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
void testNotFinishedHybridInput() { | ||
final TestingSchedulingTopology topology = new TestingSchedulingTopology(); | ||
|
||
final List<TestingSchedulingExecutionVertex> producers = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
final List<TestingSchedulingExecutionVertex> consumer = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
topology.connectAllToAll(producers, consumer) | ||
.withResultPartitionState(ResultPartitionState.CREATED) | ||
.withResultPartitionType(ResultPartitionType.HYBRID_FULL) | ||
.finish(); | ||
|
||
AllFinishedInputConsumableDecider inputConsumableDecider = | ||
createAllFinishedInputConsumableDecider(); | ||
|
||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(0), Collections.emptySet(), new HashMap<>())) | ||
.isFalse(); | ||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(1), Collections.emptySet(), new HashMap<>())) | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
void testAllFinishedHybridInput() { | ||
final TestingSchedulingTopology topology = new TestingSchedulingTopology(); | ||
|
||
final List<TestingSchedulingExecutionVertex> producers = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
final List<TestingSchedulingExecutionVertex> consumer = | ||
topology.addExecutionVertices().withParallelism(2).finish(); | ||
|
||
topology.connectAllToAll(producers, consumer) | ||
.withResultPartitionState(ResultPartitionState.ALL_DATA_PRODUCED) | ||
.withResultPartitionType(ResultPartitionType.HYBRID_FULL) | ||
.finish(); | ||
|
||
AllFinishedInputConsumableDecider inputConsumableDecider = | ||
createAllFinishedInputConsumableDecider(); | ||
|
||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(0), Collections.emptySet(), new HashMap<>())) | ||
.isTrue(); | ||
assertThat( | ||
inputConsumableDecider.isInputConsumable( | ||
consumer.get(1), Collections.emptySet(), new HashMap<>())) | ||
.isTrue(); | ||
} | ||
|
||
private static AllFinishedInputConsumableDecider createAllFinishedInputConsumableDecider() { | ||
return new AllFinishedInputConsumableDecider(); | ||
} | ||
} |