Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flink] Infer parallelism only in situation of parallelism is not set. #4975

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,18 @@ protected Integer inferSourceParallelism(StreamExecutionEnvironment env) {
Boolean.parseBoolean(envConfig.toMap().get(FLINK_INFER_SCAN_PARALLELISM)));
}
Integer parallelism = options.get(FlinkConnectorOptions.SCAN_PARALLELISM);
if (parallelism == null && options.get(FlinkConnectorOptions.INFER_SCAN_PARALLELISM)) {
if (parallelism == null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand the parallelism inferring logic this PR wants to achieve, please see if this is correct.

  1. If Paimon option SCAN_PARALLELISM is configured, then use this value.
  2. Else if Flink configuration parallelism.default is configured, then use this value.
  3. Else if Paimon option INFER_SCAN_PARALLELISM is set to true, and the parallelism of source can be inferred by Paimon (like when fixed bucket + unbounded stream), then Paimon would provide an inference result.
  4. Else Paimon would not set the parallelism of the source operator, instead it would be Flink infra that decide the parallelism of this operator

// Infer parallelism when parallelism is not set and infer scan parallelism is
// enabled.
&& env.getParallelism() == -1
&& options.get(FlinkConnectorOptions.INFER_SCAN_PARALLELISM)) {
if (isUnbounded()) {
parallelism = Math.max(1, options.get(CoreOptions.BUCKET));
// In unaware bucket or dynamic bucket mode, we can't infer parallelism.
if (options.get(CoreOptions.BUCKET) == -1) {
return null;
} else {
parallelism = Math.max(1, options.get(CoreOptions.BUCKET));
}
} else {
scanSplitsForInference();
parallelism = splitStatistics.splitNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void testInferScanParallelism() throws Exception {
null);
PaimonDataStreamScanProvider runtimeProvider = runtimeProvider(tableSource);
StreamExecutionEnvironment sEnv1 = StreamExecutionEnvironment.createLocalEnvironment();
sEnv1.setParallelism(-1);
System.out.println(sEnv1.getParallelism());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This print seems unnecessary.

DataStream<RowData> sourceStream1 =
runtimeProvider.produceDataStream(s -> Optional.empty(), sEnv1);
assertThat(sourceStream1.getParallelism()).isEqualTo(1);
Expand Down Expand Up @@ -117,8 +119,7 @@ public void testInferStreamParallelism() throws Exception {
StreamExecutionEnvironment sEnv1 = StreamExecutionEnvironment.createLocalEnvironment();
DataStream<RowData> sourceStream1 =
runtimeProvider.produceDataStream(s -> Optional.empty(), sEnv1);
// parallelism = 1 for table with -1 bucket.
assertThat(sourceStream1.getParallelism()).isEqualTo(1);
assertThat(sourceStream1.getParallelism()).isEqualTo(sEnv1.getParallelism());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public void testNumRecordsIn() throws Exception {
tEnv.executeSql("INSERT INTO T VALUES (1, 10), (2, 20), (3, 30)").await();
tEnv.executeSql(
"CREATE TEMPORARY TABLE B ( k INT, v INT ) WITH ( 'connector' = 'blackhole' )");
TableResult tableResult = tEnv.executeSql("INSERT INTO B SELECT * FROM T");
TableResult tableResult =
tEnv.executeSql(
"INSERT INTO B SELECT * FROM T/*+ OPTIONS('scan.parallelism'='1')*/");
JobClient client = tableResult.getJobClient().get();
JobID jobId = client.getJobID();
tableResult.await();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static void init(String warehouse, int parallelism) {
sEnv = StreamTableEnvironment.create(sExeEnv);

bExeEnv = buildBatchEnv(parallelism, "none");
// set no default parallelism
bExeEnv.setParallelism(-1);
bEnv = StreamTableEnvironment.create(bExeEnv, EnvironmentSettings.inBatchMode());

ReadWriteTableTestUtil.warehouse = warehouse;
Expand Down
Loading