-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flink] Introduce bypass append compact coordinator and worker (#3936)
- Loading branch information
1 parent
aa3bfb1
commit fa7623e
Showing
13 changed files
with
546 additions
and
100 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...-flink-1.18/src/test/java/org/apache/paimon/flink/UnawareBucketAppendOnlyTableITCase.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,88 @@ | ||
/* | ||
* 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.paimon.flink; | ||
|
||
import org.apache.paimon.Snapshot; | ||
|
||
import org.apache.flink.types.Row; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions.CHECKPOINTING_INTERVAL; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** Test case for append-only managed unaware-bucket table. */ | ||
public class UnawareBucketAppendOnlyTableITCase extends CatalogITCaseBase { | ||
|
||
@Override | ||
protected List<String> ddl() { | ||
return Collections.singletonList( | ||
"CREATE TABLE IF NOT EXISTS append_table (id INT, data STRING) WITH ('bucket' = '-1')"); | ||
} | ||
|
||
@Test | ||
public void testCompactionInStreamingMode() throws Exception { | ||
batchSql("ALTER TABLE append_table SET ('compaction.min.file-num' = '2')"); | ||
batchSql("ALTER TABLE append_table SET ('compaction.early-max.file-num' = '4')"); | ||
batchSql("ALTER TABLE append_table SET ('continuous.discovery-interval' = '1 s')"); | ||
|
||
sEnv.getConfig().getConfiguration().set(CHECKPOINTING_INTERVAL, Duration.ofMillis(500)); | ||
sEnv.executeSql( | ||
"CREATE TEMPORARY TABLE Orders_in (\n" | ||
+ " f0 INT,\n" | ||
+ " f1 STRING\n" | ||
+ ") WITH (\n" | ||
+ " 'connector' = 'datagen',\n" | ||
+ " 'rows-per-second' = '1',\n" | ||
+ " 'number-of-rows' = '10'\n" | ||
+ ")"); | ||
|
||
assertStreamingHasCompact("INSERT INTO append_table SELECT * FROM Orders_in", 60000); | ||
// ensure data gen finished | ||
Thread.sleep(5000); | ||
|
||
List<Row> rows = batchSql("SELECT * FROM append_table"); | ||
assertThat(rows.size()).isEqualTo(10); | ||
} | ||
|
||
private void assertStreamingHasCompact(String sql, long timeout) throws Exception { | ||
long start = System.currentTimeMillis(); | ||
long currentId = 1; | ||
sEnv.executeSql(sql); | ||
Snapshot snapshot; | ||
while (true) { | ||
snapshot = findSnapshot("append_table", currentId); | ||
if (snapshot != null) { | ||
if (snapshot.commitKind() == Snapshot.CommitKind.COMPACT) { | ||
break; | ||
} | ||
currentId++; | ||
} | ||
long now = System.currentTimeMillis(); | ||
if (now - start > timeout) { | ||
throw new RuntimeException( | ||
"Time up for streaming execute, don't get expected result."); | ||
} | ||
Thread.sleep(1000); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
paimon-flink/paimon-flink-1.18/src/test/resources/log4j2-test.properties
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,28 @@ | ||
################################################################################ | ||
# 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. | ||
################################################################################ | ||
|
||
# Set root logger level to OFF to not flood build logs | ||
# set manually to INFO for debugging purposes | ||
rootLogger.level = OFF | ||
rootLogger.appenderRef.test.ref = TestLogger | ||
|
||
appender.testlogger.name = TestLogger | ||
appender.testlogger.type = CONSOLE | ||
appender.testlogger.target = SYSTEM_ERR | ||
appender.testlogger.layout.type = PatternLayout | ||
appender.testlogger.layout.pattern = %-4r [%tid %t] %-5p %c %x - %m%n |
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
88 changes: 88 additions & 0 deletions
88
...-flink-1.19/src/test/java/org/apache/paimon/flink/UnawareBucketAppendOnlyTableITCase.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,88 @@ | ||
/* | ||
* 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.paimon.flink; | ||
|
||
import org.apache.paimon.Snapshot; | ||
|
||
import org.apache.flink.types.Row; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions.CHECKPOINTING_INTERVAL; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** Test case for append-only managed unaware-bucket table. */ | ||
public class UnawareBucketAppendOnlyTableITCase extends CatalogITCaseBase { | ||
|
||
@Override | ||
protected List<String> ddl() { | ||
return Collections.singletonList( | ||
"CREATE TABLE IF NOT EXISTS append_table (id INT, data STRING) WITH ('bucket' = '-1')"); | ||
} | ||
|
||
@Test | ||
public void testCompactionInStreamingMode() throws Exception { | ||
batchSql("ALTER TABLE append_table SET ('compaction.min.file-num' = '2')"); | ||
batchSql("ALTER TABLE append_table SET ('compaction.early-max.file-num' = '4')"); | ||
batchSql("ALTER TABLE append_table SET ('continuous.discovery-interval' = '1 s')"); | ||
|
||
sEnv.getConfig().getConfiguration().set(CHECKPOINTING_INTERVAL, Duration.ofMillis(500)); | ||
sEnv.executeSql( | ||
"CREATE TEMPORARY TABLE Orders_in (\n" | ||
+ " f0 INT,\n" | ||
+ " f1 STRING\n" | ||
+ ") WITH (\n" | ||
+ " 'connector' = 'datagen',\n" | ||
+ " 'rows-per-second' = '1',\n" | ||
+ " 'number-of-rows' = '10'\n" | ||
+ ")"); | ||
|
||
assertStreamingHasCompact("INSERT INTO append_table SELECT * FROM Orders_in", 60000); | ||
// ensure data gen finished | ||
Thread.sleep(5000); | ||
|
||
List<Row> rows = batchSql("SELECT * FROM append_table"); | ||
assertThat(rows.size()).isEqualTo(10); | ||
} | ||
|
||
private void assertStreamingHasCompact(String sql, long timeout) throws Exception { | ||
long start = System.currentTimeMillis(); | ||
long currentId = 1; | ||
sEnv.executeSql(sql); | ||
Snapshot snapshot; | ||
while (true) { | ||
snapshot = findSnapshot("append_table", currentId); | ||
if (snapshot != null) { | ||
if (snapshot.commitKind() == Snapshot.CommitKind.COMPACT) { | ||
break; | ||
} | ||
currentId++; | ||
} | ||
long now = System.currentTimeMillis(); | ||
if (now - start > timeout) { | ||
throw new RuntimeException( | ||
"Time up for streaming execute, don't get expected result."); | ||
} | ||
Thread.sleep(1000); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
paimon-flink/paimon-flink-1.19/src/test/resources/log4j2-test.properties
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,28 @@ | ||
################################################################################ | ||
# 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. | ||
################################################################################ | ||
|
||
# Set root logger level to OFF to not flood build logs | ||
# set manually to INFO for debugging purposes | ||
rootLogger.level = OFF | ||
rootLogger.appenderRef.test.ref = TestLogger | ||
|
||
appender.testlogger.name = TestLogger | ||
appender.testlogger.type = CONSOLE | ||
appender.testlogger.target = SYSTEM_ERR | ||
appender.testlogger.layout.type = PatternLayout | ||
appender.testlogger.layout.pattern = %-4r [%tid %t] %-5p %c %x - %m%n |
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
49 changes: 49 additions & 0 deletions
49
...-common/src/main/java/org/apache/paimon/flink/sink/AppendBypassCompactWorkerOperator.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,49 @@ | ||
/* | ||
* 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.paimon.flink.sink; | ||
|
||
import org.apache.paimon.append.AppendOnlyCompactionTask; | ||
import org.apache.paimon.table.FileStoreTable; | ||
|
||
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; | ||
import org.apache.flink.types.Either; | ||
|
||
/** A {@link AppendCompactWorkerOperator} to bypass Committable inputs. */ | ||
public class AppendBypassCompactWorkerOperator | ||
extends AppendCompactWorkerOperator<Either<Committable, AppendOnlyCompactionTask>> { | ||
|
||
public AppendBypassCompactWorkerOperator(FileStoreTable table, String commitUser) { | ||
super(table, commitUser); | ||
} | ||
|
||
@Override | ||
public void open() throws Exception { | ||
super.open(); | ||
} | ||
|
||
@Override | ||
public void processElement(StreamRecord<Either<Committable, AppendOnlyCompactionTask>> element) | ||
throws Exception { | ||
if (element.getValue().isLeft()) { | ||
output.collect(new StreamRecord<>(element.getValue().left())); | ||
} else { | ||
unawareBucketCompactor.processElement(element.getValue().right()); | ||
} | ||
} | ||
} |
Oops, something went wrong.