-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[FLINK-36690][runtime] Fix schema operator hanging under extreme parallelized pressure #3680
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
Closed
yuxiqian
wants to merge
2
commits into
apache:master
from
yuxiqian:fix/schema-evolve-e2e-passing-rate
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
207 changes: 207 additions & 0 deletions
207
...st/java/org/apache/flink/cdc/connectors/mysql/source/MySqlParallelizedPipelineITCase.java
This file contains hidden or 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,207 @@ | ||
| /* | ||
| * 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.cdc.connectors.mysql.source; | ||
|
|
||
| import org.apache.flink.cdc.common.configuration.Configuration; | ||
| import org.apache.flink.cdc.common.pipeline.PipelineOptions; | ||
| import org.apache.flink.cdc.common.pipeline.SchemaChangeBehavior; | ||
| import org.apache.flink.cdc.composer.PipelineExecution; | ||
| import org.apache.flink.cdc.composer.definition.PipelineDef; | ||
| import org.apache.flink.cdc.composer.definition.SinkDef; | ||
| import org.apache.flink.cdc.composer.definition.SourceDef; | ||
| import org.apache.flink.cdc.composer.flink.FlinkPipelineComposer; | ||
| import org.apache.flink.cdc.connectors.mysql.factory.MySqlDataSourceFactory; | ||
| import org.apache.flink.cdc.connectors.mysql.testutils.UniqueDatabase; | ||
| import org.apache.flink.cdc.connectors.values.ValuesDatabase; | ||
| import org.apache.flink.cdc.connectors.values.factory.ValuesDataFactory; | ||
| import org.apache.flink.cdc.connectors.values.sink.ValuesDataSinkOptions; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.PrintStream; | ||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
| import java.time.Duration; | ||
| import java.util.Collections; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.apache.flink.cdc.connectors.mysql.testutils.MySqSourceTestUtils.TEST_PASSWORD; | ||
| import static org.apache.flink.cdc.connectors.mysql.testutils.MySqSourceTestUtils.TEST_USER; | ||
| import static org.apache.flink.cdc.connectors.mysql.testutils.MySqSourceTestUtils.getServerId; | ||
| import static org.apache.flink.cdc.connectors.mysql.testutils.MySqSourceTestUtils.loopCheck; | ||
| import static org.apache.flink.configuration.CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** Parallelized Integration test for MySQL connector. */ | ||
| public class MySqlParallelizedPipelineITCase extends MySqlSourceTestBase { | ||
|
|
||
| private static final int PARALLELISM = 4; | ||
| private static final int TEST_TABLE_NUMBER = 100; | ||
|
|
||
| // Always use parent-first classloader for CDC classes. | ||
| // The reason is that ValuesDatabase uses static field for holding data, we need to make sure | ||
| // the class is loaded by AppClassloader so that we can verify data in the test case. | ||
| private static final org.apache.flink.configuration.Configuration MINI_CLUSTER_CONFIG = | ||
| new org.apache.flink.configuration.Configuration(); | ||
|
|
||
| static { | ||
| MINI_CLUSTER_CONFIG.set( | ||
| ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL, | ||
| Collections.singletonList("org.apache.flink.cdc")); | ||
| } | ||
|
|
||
| private final PrintStream standardOut = System.out; | ||
| private final ByteArrayOutputStream outCaptor = new ByteArrayOutputStream(); | ||
|
|
||
| private final UniqueDatabase parallelismDatabase = | ||
| new UniqueDatabase( | ||
| MYSQL_CONTAINER, "extreme_parallelism_test_database", TEST_USER, TEST_PASSWORD); | ||
|
|
||
| @Before | ||
| public void init() { | ||
| // Take over STDOUT as we need to check the output of values sink | ||
| System.setOut(new PrintStream(outCaptor)); | ||
| // Initialize in-memory database | ||
| ValuesDatabase.clear(); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanup() { | ||
| System.setOut(standardOut); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExtremeParallelizedSchemaChange() throws Exception { | ||
| final String databaseName = parallelismDatabase.getDatabaseName(); | ||
| try (Connection conn = | ||
| DriverManager.getConnection( | ||
| MYSQL_CONTAINER.getJdbcUrl(), TEST_USER, TEST_PASSWORD); | ||
| Statement stat = conn.createStatement()) { | ||
| stat.execute(String.format("CREATE DATABASE %s;", databaseName)); | ||
| stat.execute(String.format("USE %s;", databaseName)); | ||
| for (int i = 1; i <= TEST_TABLE_NUMBER; i++) { | ||
| stat.execute(String.format("DROP TABLE IF EXISTS TABLE%d;", i)); | ||
| stat.execute( | ||
| String.format( | ||
| "CREATE TABLE TABLE%d (ID INT NOT NULL PRIMARY KEY,VERSION VARCHAR(17));", | ||
| i)); | ||
| stat.execute(String.format("INSERT INTO TABLE%d VALUES (%d, 'No.%d');", i, i, i)); | ||
| } | ||
| } catch (SQLException e) { | ||
| LOG.error("Initialize table failed.", e); | ||
| throw e; | ||
| } | ||
| LOG.info("Table initialized successfully."); | ||
|
|
||
| FlinkPipelineComposer composer = FlinkPipelineComposer.ofMiniCluster(); | ||
|
|
||
| // Setup MySQL source | ||
| Configuration sourceConfig = new Configuration(); | ||
| sourceConfig.set(MySqlDataSourceOptions.HOSTNAME, MYSQL_CONTAINER.getHost()); | ||
| sourceConfig.set(MySqlDataSourceOptions.PORT, MYSQL_CONTAINER.getDatabasePort()); | ||
| sourceConfig.set(MySqlDataSourceOptions.USERNAME, TEST_USER); | ||
| sourceConfig.set(MySqlDataSourceOptions.PASSWORD, TEST_PASSWORD); | ||
| sourceConfig.set(MySqlDataSourceOptions.SERVER_TIME_ZONE, "UTC"); | ||
| sourceConfig.set(MySqlDataSourceOptions.TABLES, "\\.*.\\.*"); | ||
| sourceConfig.set(MySqlDataSourceOptions.SERVER_ID, getServerId(PARALLELISM)); | ||
|
|
||
| SourceDef sourceDef = | ||
| new SourceDef(MySqlDataSourceFactory.IDENTIFIER, "MySQL Source", sourceConfig); | ||
|
|
||
| // Setup value sink | ||
| Configuration sinkConfig = new Configuration(); | ||
| sinkConfig.set(ValuesDataSinkOptions.MATERIALIZED_IN_MEMORY, true); | ||
| SinkDef sinkDef = new SinkDef(ValuesDataFactory.IDENTIFIER, "Value Sink", sinkConfig); | ||
|
|
||
| // Setup pipeline | ||
| Configuration pipelineConfig = new Configuration(); | ||
| pipelineConfig.set(PipelineOptions.PIPELINE_PARALLELISM, PARALLELISM); | ||
| pipelineConfig.set( | ||
| PipelineOptions.PIPELINE_SCHEMA_CHANGE_BEHAVIOR, SchemaChangeBehavior.EVOLVE); | ||
| PipelineDef pipelineDef = | ||
| new PipelineDef( | ||
| sourceDef, | ||
| sinkDef, | ||
| Collections.emptyList(), | ||
| Collections.emptyList(), | ||
| Collections.emptyList(), | ||
| pipelineConfig); | ||
|
|
||
| // Execute the pipeline | ||
| PipelineExecution execution = composer.compose(pipelineDef); | ||
| Thread executeThread = | ||
| new Thread( | ||
| () -> { | ||
| try { | ||
| execution.execute(); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
|
|
||
| executeThread.start(); | ||
|
|
||
| try { | ||
| loopCheck( | ||
| () -> | ||
| outCaptor.toString().trim().split("\n").length | ||
| >= TEST_TABLE_NUMBER * (PARALLELISM + 1), | ||
| "collect enough rows", | ||
| Duration.ofSeconds(120), | ||
| Duration.ofSeconds(1)); | ||
| } finally { | ||
| executeThread.interrupt(); | ||
| } | ||
|
|
||
| // Check the order and content of all received events | ||
| String outputEvents = outCaptor.toString(); | ||
| assertThat(outputEvents) | ||
| .contains( | ||
| IntStream.rangeClosed(1, TEST_TABLE_NUMBER) | ||
| .boxed() | ||
| .flatMap( | ||
| i -> | ||
| Stream.concat( | ||
| IntStream.range(0, PARALLELISM) | ||
| .boxed() | ||
| .map( | ||
| subTaskId -> | ||
| String.format( | ||
| "%d> CreateTableEvent{tableId=%s.TABLE%d, schema=columns={`ID` INT NOT NULL,`VERSION` VARCHAR(17)}, primaryKeys=ID, options=()}", | ||
| subTaskId, | ||
| parallelismDatabase | ||
| .getDatabaseName(), | ||
| i)), | ||
| Stream.of( | ||
| String.format( | ||
| "> DataChangeEvent{tableId=%s.TABLE%d, before=[], after=[%d, No.%d], op=INSERT, meta=()}", | ||
| parallelismDatabase | ||
| .getDatabaseName(), | ||
| i, | ||
| i, | ||
| i)))) | ||
| .collect(Collectors.toList())); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.