Skip to content

Commit f13c1d8

Browse files
committed
[FLINK-37284][runtime] Fix ForwardForConsecutiveHashPartitioner cannot be chained in Adaptive batch.
1 parent ea28cad commit f13c1d8

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/AdaptiveGraphManager.java

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup;
3333
import org.apache.flink.streaming.api.graph.util.JobVertexBuildContext;
3434
import org.apache.flink.streaming.api.graph.util.OperatorChainInfo;
35+
import org.apache.flink.streaming.api.transformations.StreamExchangeMode;
3536
import org.apache.flink.streaming.runtime.partitioner.ForwardForConsecutiveHashPartitioner;
3637
import org.apache.flink.streaming.runtime.partitioner.ForwardForUnspecifiedPartitioner;
3738
import org.apache.flink.streaming.runtime.partitioner.ForwardPartitioner;
@@ -618,6 +619,15 @@ && isChainableSource(
618619
streamGraph.getStreamNode(edge.getSourceId()), streamGraph))
619620
|| isChainable(edge, streamGraph)) {
620621
edge.setPartitioner(new ForwardPartitioner<>());
622+
623+
// ForwardForConsecutiveHashPartitioner may use BATCH exchange mode, which prevents
624+
// operator chaining. To enable chaining for edges using this partitioner, we need
625+
// to set their exchange mode to UNDEFINED.
626+
if (partitioner instanceof ForwardForConsecutiveHashPartitioner
627+
&& edge.getExchangeMode() == StreamExchangeMode.BATCH) {
628+
edge.setExchangeMode(StreamExchangeMode.UNDEFINED);
629+
}
630+
621631
// Currently, there is no intra input key correlation for edge with
622632
// ForwardForUnspecifiedPartitioner, and we need to modify it to false.
623633
if (partitioner instanceof ForwardForUnspecifiedPartitioner) {

flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/StreamEdge.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class StreamEdge implements Serializable {
7171
/** The name of the operator in the target vertex. */
7272
private final String targetOperatorName;
7373

74-
private final StreamExchangeMode exchangeMode;
74+
private StreamExchangeMode exchangeMode;
7575

7676
private long bufferTimeout;
7777

@@ -195,6 +195,10 @@ public StreamExchangeMode getExchangeMode() {
195195
return exchangeMode;
196196
}
197197

198+
void setExchangeMode(StreamExchangeMode exchangeMode) {
199+
this.exchangeMode = exchangeMode;
200+
}
201+
198202
public void setPartitioner(StreamPartitioner<?> partitioner) {
199203
configureKeyCorrelation(partitioner);
200204
this.outputPartitioner = partitioner;

flink-streaming-java/src/test/java/org/apache/flink/streaming/api/graph/AdaptiveGraphManagerTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.flink.streaming.api.graph;
2020

21+
import org.apache.flink.api.common.RuntimeExecutionMode;
2122
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
2223
import org.apache.flink.api.common.functions.MapFunction;
2324
import org.apache.flink.api.common.typeinfo.Types;
@@ -32,6 +33,10 @@
3233
import org.apache.flink.streaming.api.functions.sink.v2.DiscardingSink;
3334
import org.apache.flink.streaming.api.operators.ChainingStrategy;
3435
import org.apache.flink.streaming.api.transformations.MultipleInputTransformation;
36+
import org.apache.flink.streaming.api.transformations.PartitionTransformation;
37+
import org.apache.flink.streaming.api.transformations.StreamExchangeMode;
38+
import org.apache.flink.streaming.runtime.partitioner.ForwardForConsecutiveHashPartitioner;
39+
import org.apache.flink.streaming.runtime.partitioner.RebalancePartitioner;
3540

3641
import org.apache.flink.shaded.guava32.com.google.common.collect.Iterables;
3742

@@ -235,6 +240,33 @@ void testSourceChain() {
235240
assertThat(jobGraph.getVerticesSortedTopologicallyFromSources().size()).isEqualTo(4);
236241
}
237242

243+
@Test
244+
void testForwardForConsecutiveHashPartitionerChain() {
245+
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
246+
env.setRuntimeMode(RuntimeExecutionMode.BATCH);
247+
env.setParallelism(1);
248+
249+
final DataStream<Integer> source = env.fromData(1, 2, 3);
250+
final DataStream<Integer> forward =
251+
new DataStream<>(
252+
env,
253+
new PartitionTransformation<>(
254+
source.getTransformation(),
255+
new ForwardForConsecutiveHashPartitioner<>(
256+
new RebalancePartitioner<>()),
257+
StreamExchangeMode.BATCH));
258+
forward.print();
259+
260+
StreamGraph streamGraph1 = env.getStreamGraph(false);
261+
streamGraph1.setDynamic(true);
262+
JobGraph jobGraph1 = generateJobGraphInLazilyMode(streamGraph1);
263+
264+
StreamGraph streamGraph2 = env.getStreamGraph(false);
265+
streamGraph2.setDynamic(true);
266+
JobGraph jobGraph2 = StreamingJobGraphGenerator.createJobGraph(streamGraph2);
267+
assertThat(isJobGraphEquivalent(jobGraph1, jobGraph2)).isTrue();
268+
}
269+
238270
private static JobGraph generateJobGraphInLazilyMode(StreamGraph streamGraph) {
239271
AdaptiveGraphManager adaptiveGraphManager =
240272
new AdaptiveGraphManager(

0 commit comments

Comments
 (0)