-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[FLINK-39722][pipeline-connector][fluss] Support Fluss CDC Yaml Source. #4494
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b955c6f
[FLINK-39722][pipeline-connector][fluss] Support Fluss CDC Yaml Source.
4b5d360
support complex type
dd50c35
Refactor FlussPipelineITCase from fluss to fluss.
05499e4
Expose metric for fluss source
3b21c89
modified based on leonard's advice.
b22d3ea
fix fluss fink for different version.
24610b5
modified based on leonard's advice 2.
b963116
modified based on leonard'advice 3
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
171 changes: 171 additions & 0 deletions
171
...s/src/main/java/org/apache/flink/cdc/connectors/fluss/factory/FlussDataSourceFactory.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,171 @@ | ||
| /* | ||
| * 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.fluss.factory; | ||
|
|
||
| import org.apache.flink.cdc.common.configuration.ConfigOption; | ||
| import org.apache.flink.cdc.common.factories.DataSourceFactory; | ||
| import org.apache.flink.cdc.common.factories.FactoryHelper; | ||
| import org.apache.flink.cdc.common.source.DataSource; | ||
| import org.apache.flink.cdc.common.source.discover.TableDiscoverer; | ||
| import org.apache.flink.cdc.common.source.discover.TableDiscovererFactory; | ||
| import org.apache.flink.cdc.connectors.fluss.source.FlussDataSource; | ||
|
|
||
| import org.apache.fluss.client.initializer.OffsetsInitializer; | ||
| import org.apache.fluss.config.ConfigOptions; | ||
| import org.apache.fluss.config.Configuration; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.BOOTSTRAP_SERVERS; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.CLIENT_PROPERTIES_PREFIX; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.SCAN_DISCOVERY_INTERVAL; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.SCAN_KV_SNAPSHOT_LEASE_DURATION; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.SCAN_KV_SNAPSHOT_LEASE_ID; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.SCAN_STARTUP_MODE; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.SCAN_STARTUP_TIMESTAMP; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.TABLE_DISCOVERER_OPTIONS_PREFIX; | ||
| import static org.apache.flink.cdc.connectors.fluss.source.FlussDataSourceOptions.TABLE_DISCOVERER_TYPE; | ||
|
|
||
| /** Factory for creating configured instances of {@link FlussDataSource}. */ | ||
| public class FlussDataSourceFactory implements DataSourceFactory { | ||
|
|
||
| public static final String IDENTIFIER = "fluss"; | ||
|
|
||
| @Override | ||
| public DataSource createDataSource(Context context) { | ||
| FactoryHelper.createFactoryHelper(this, context) | ||
| .validateExcept(CLIENT_PROPERTIES_PREFIX, TABLE_DISCOVERER_OPTIONS_PREFIX); | ||
|
|
||
| org.apache.flink.cdc.common.configuration.Configuration factoryConfiguration = | ||
| context.getFactoryConfiguration(); | ||
|
|
||
| String startupMode = factoryConfiguration.get(SCAN_STARTUP_MODE); | ||
|
|
||
| Configuration flussConfig = toFlussClientConfig(factoryConfiguration); | ||
|
|
||
| TableDiscoverer discoverer = | ||
| createDiscoverer(factoryConfiguration, context.getClassLoader()); | ||
|
|
||
| OffsetsInitializer offsetsInitializer = | ||
| getOffsetsInitializer(startupMode, factoryConfiguration); | ||
|
|
||
| long scanDiscoveryIntervalMs = factoryConfiguration.get(SCAN_DISCOVERY_INTERVAL).toMillis(); | ||
|
|
||
| return new FlussDataSource( | ||
| flussConfig, | ||
| factoryConfiguration, | ||
| discoverer, | ||
| offsetsInitializer, | ||
| scanDiscoveryIntervalMs); | ||
| } | ||
|
|
||
| private static TableDiscoverer createDiscoverer( | ||
| org.apache.flink.cdc.common.configuration.Configuration config, | ||
| ClassLoader classLoader) { | ||
| String type = config.get(TABLE_DISCOVERER_TYPE); | ||
| return TableDiscovererFactory.createDiscoverer(type, classLoader); | ||
| } | ||
|
|
||
| @Override | ||
| public String identifier() { | ||
| return IDENTIFIER; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<ConfigOption<?>> requiredOptions() { | ||
| Set<ConfigOption<?>> options = new HashSet<>(); | ||
| options.add(BOOTSTRAP_SERVERS); | ||
| return options; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<ConfigOption<?>> optionalOptions() { | ||
| Set<ConfigOption<?>> options = new HashSet<>(); | ||
| options.add(TABLE_DISCOVERER_TYPE); | ||
| options.add(SCAN_STARTUP_MODE); | ||
| options.add(SCAN_STARTUP_TIMESTAMP); | ||
| options.add(SCAN_DISCOVERY_INTERVAL); | ||
| options.add(SCAN_KV_SNAPSHOT_LEASE_ID); | ||
| options.add(SCAN_KV_SNAPSHOT_LEASE_DURATION); | ||
| return options; | ||
| } | ||
|
|
||
| private static OffsetsInitializer getOffsetsInitializer( | ||
| String startupMode, org.apache.flink.cdc.common.configuration.Configuration config) { | ||
| if ("earliest".equalsIgnoreCase(startupMode)) { | ||
| return OffsetsInitializer.earliest(); | ||
| } else if ("latest".equalsIgnoreCase(startupMode)) { | ||
| return OffsetsInitializer.latest(); | ||
| } else if ("full".equalsIgnoreCase(startupMode)) { | ||
| return OffsetsInitializer.full(); | ||
| } else if ("timestamp".equalsIgnoreCase(startupMode)) { | ||
| String timestampStr = config.get(SCAN_STARTUP_TIMESTAMP); | ||
| if (timestampStr == null || timestampStr.isEmpty()) { | ||
| throw new IllegalArgumentException( | ||
| "'scan.startup.timestamp' is required when scan.startup.mode is 'timestamp'."); | ||
| } | ||
| long timestampMs = parseTimestamp(timestampStr); | ||
| return OffsetsInitializer.timestamp(timestampMs); | ||
| } else { | ||
| throw new IllegalArgumentException("Unsupported startup mode: " + startupMode); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Parses a timestamp string to a long value. Supports both epoch milliseconds and 'yyyy-MM-dd | ||
| * HH:mm:ss' format. | ||
| */ | ||
| private static long parseTimestamp(String timestampStr) { | ||
| if (timestampStr.matches("\\d+")) { | ||
| return Long.parseLong(timestampStr); | ||
| } | ||
| try { | ||
| return java.time.LocalDateTime.parse( | ||
| timestampStr, | ||
| java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | ||
| .atZone(java.time.ZoneId.systemDefault()) | ||
| .toInstant() | ||
| .toEpochMilli(); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException( | ||
| String.format( | ||
| "Invalid 'scan.startup.timestamp' value '%s'. " | ||
| + "Expected format: 'yyyy-MM-dd HH:mm:ss' or epoch milliseconds.", | ||
| timestampStr), | ||
| e); | ||
| } | ||
| } | ||
|
|
||
| private static Configuration toFlussClientConfig( | ||
| org.apache.flink.cdc.common.configuration.Configuration factoryConfig) { | ||
| Configuration flussConfig = new Configuration(); | ||
| flussConfig.setString( | ||
| ConfigOptions.BOOTSTRAP_SERVERS.key(), factoryConfig.get(BOOTSTRAP_SERVERS)); | ||
|
|
||
| factoryConfig | ||
| .toMap() | ||
| .forEach( | ||
| (key, value) -> { | ||
| if (key.startsWith(CLIENT_PROPERTIES_PREFIX)) { | ||
| flussConfig.setString(key.substring("properties.".length()), value); | ||
| } | ||
| }); | ||
| return flussConfig; | ||
| } | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we keep the
identifier()compatibility alias here?TableDiscovererFactoryis@PublicEvolving, and the current master API intentionally retains this default method as the legacy name fortype(). Removing it in an unrelated Fluss source PR can break third-party discoverer code compiled against the current SPI and also leaves the compatibility-alias Javadoc attached toobjectIdClass(). Unless this removal is part of a separately reviewed SPI migration, restoring the alias would avoid an unnecessary compatibility regression.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since https://issues.apache.org/jira/browse/FLINK-39732 is for the same version of the Fluss YAML source, semantic simplicity takes priority.