-
Notifications
You must be signed in to change notification settings - Fork 332
[Bitsail][Connector] support pg cdc #402
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
Open
xubo123
wants to merge
4
commits into
bytedance:master
Choose a base branch
from
xubo123:bitsail-support-pg-cdc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,052
−27
Open
Changes from all commits
Commits
Show all changes
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,10 @@ interface BaseReaderOptions { | |
key(READER_PREFIX + "db_name") | ||
.noDefaultValue(String.class); | ||
|
||
ConfigOption<String> CONNECTION_TIMEZONE = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should move to |
||
key(READER_PREFIX + "connection_timezone") | ||
.defaultValue("UTC"); | ||
|
||
ConfigOption<String> TABLE_NAME = | ||
key(READER_PREFIX + "table_name") | ||
.noDefaultValue(String.class); | ||
|
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 |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
</properties> | ||
|
||
<dependencies> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes? |
||
</dependencies> | ||
|
||
</project> |
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
64 changes: 64 additions & 0 deletions
64
bitsail-connectors/connector-cdc/connector-cdc-jdbc-base/pom.xml
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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2022-2023 Bytedance Ltd. and/or its affiliates. | ||
~ | ||
~ Licensed 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>com.bytedance.bitsail</groupId> | ||
<artifactId>connector-cdc</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>connector-cdc-jdbc-base</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<debezium.version>1.6.4.Final</debezium.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.bytedance.bitsail</groupId> | ||
<artifactId>connector-cdc-base</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.debezium</groupId> | ||
<artifactId>debezium-embedded</artifactId> | ||
<version>${debezium.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>jakarta.activation</groupId> | ||
<artifactId>jakarta.activation-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.apache.kafka</groupId> | ||
<artifactId>kafka-clients</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.debezium</groupId> | ||
<artifactId>debezium-core</artifactId> | ||
<version>${debezium.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
91 changes: 91 additions & 0 deletions
91
...va/com/bytedance/bitsail/connector/cdc/jdbc/source/config/AbstractJdbcDebeziumConfig.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,91 @@ | ||
/* | ||
* Copyright 2022-2023 Bytedance Ltd. and/or its affiliates. | ||
* | ||
* Licensed 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 com.bytedance.bitsail.connector.cdc.jdbc.source.config; | ||
|
||
import com.bytedance.bitsail.common.configuration.BitSailConfiguration; | ||
import com.bytedance.bitsail.connector.cdc.error.BinlogReaderErrorCode; | ||
import com.bytedance.bitsail.connector.cdc.jdbc.source.constant.DebeziumConstant; | ||
import com.bytedance.bitsail.connector.cdc.model.ClusterInfo; | ||
import com.bytedance.bitsail.connector.cdc.model.ConnectionInfo; | ||
import com.bytedance.bitsail.connector.cdc.option.BinlogReaderOptions; | ||
|
||
import io.debezium.config.Configuration; | ||
import io.debezium.relational.RelationalDatabaseConnectorConfig; | ||
import lombok.Getter; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.time.ZoneId; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
@Getter | ||
public abstract class AbstractJdbcDebeziumConfig { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public static final String DEBEZIUM_PREFIX = "job.reader.debezium."; | ||
|
||
private final String hostname; | ||
private final int port; | ||
private final String username; | ||
private final String password; | ||
|
||
// debezium configuration | ||
private final Properties dbzProperties; | ||
private final Configuration dbzConfiguration; | ||
private final RelationalDatabaseConnectorConfig dbzJdbcConnectorConfig; | ||
private String dbName; | ||
|
||
public AbstractJdbcDebeziumConfig(BitSailConfiguration jobConf) { | ||
List<ClusterInfo> clusterInfo = jobConf.getNecessaryOption(BinlogReaderOptions.CONNECTIONS, BinlogReaderErrorCode.REQUIRED_VALUE); | ||
//Only support one DB | ||
assert (clusterInfo.size() == 1); | ||
ConnectionInfo connectionInfo = clusterInfo.get(0).getMaster(); | ||
assert (connectionInfo != null); | ||
this.dbzProperties = extractProps(jobConf); | ||
this.hostname = connectionInfo.getHost(); | ||
this.port = connectionInfo.getPort(); | ||
this.username = jobConf.getNecessaryOption(BinlogReaderOptions.USER_NAME, BinlogReaderErrorCode.REQUIRED_VALUE); | ||
this.password = jobConf.getNecessaryOption(BinlogReaderOptions.PASSWORD, BinlogReaderErrorCode.REQUIRED_VALUE); | ||
this.dbName = jobConf.getNecessaryOption(BinlogReaderOptions.DB_NAME, BinlogReaderErrorCode.REQUIRED_VALUE); | ||
String timezone = jobConf.get(BinlogReaderOptions.CONNECTION_TIMEZONE); | ||
fillConnectionInfo(jobConf, this.dbzProperties, connectionInfo, timezone); | ||
|
||
this.dbzConfiguration = Configuration.from(this.dbzProperties); | ||
this.dbzJdbcConnectorConfig = getJdbcConnectorConfig(this.dbzConfiguration); | ||
} | ||
|
||
public static Properties extractProps(BitSailConfiguration jobConf) { | ||
Properties props = new Properties(); | ||
jobConf.getKeys().stream() | ||
.filter(s -> s.startsWith(DEBEZIUM_PREFIX)) | ||
.map(s -> StringUtils.substringAfter(s, DEBEZIUM_PREFIX)) | ||
.forEach(s -> props.setProperty(s, jobConf.getString(DEBEZIUM_PREFIX + s))); | ||
return props; | ||
} | ||
|
||
public abstract RelationalDatabaseConnectorConfig getJdbcConnectorConfig(Configuration config); | ||
|
||
public void fillConnectionInfo(BitSailConfiguration jobConf, Properties props, ConnectionInfo connectionInfo, String timezone) { | ||
props.put(DebeziumConstant.DATABASE_HOSTNAME, connectionInfo.getHost()); | ||
props.put(DebeziumConstant.DATABASE_PORT, String.valueOf(connectionInfo.getPort())); | ||
props.put(DebeziumConstant.DATABASE_USER, username); | ||
props.put(DebeziumConstant.DATABASE_PASSWORD, password); | ||
props.put(DebeziumConstant.DATABASE_NAME, dbName); | ||
props.put(DebeziumConstant.DATABASE_TIMEZONE, ZoneId.of(timezone).toString()); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
.../main/java/com/bytedance/bitsail/connector/cdc/jdbc/source/constant/DebeziumConstant.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,25 @@ | ||
/* | ||
* Copyright 2022-2023 Bytedance Ltd. and/or its affiliates. | ||
* | ||
* Licensed 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 com.bytedance.bitsail.connector.cdc.jdbc.source.constant; | ||
|
||
public class DebeziumConstant { | ||
public static final String DATABASE_HOSTNAME = "database.hostname"; | ||
public static final String DATABASE_PORT = "database.port"; | ||
public static final String DATABASE_USER = "database.user"; | ||
public static final String DATABASE_PASSWORD = "database.password"; | ||
public static final String DATABASE_NAME = "database.dbname"; | ||
public static final String DATABASE_TIMEZONE = "database.serverTimezone"; | ||
} |
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.
When we need add exception throw in here?