forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0cefbe
commit 9dca0d0
Showing
36 changed files
with
3,792 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
70 changes: 70 additions & 0 deletions
70
seatunnel-connectors-v2/connector-cdc/connector-cdc-tidb/pom.xml
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,70 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>connector-cdc</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>connector-cdc-tidb</artifactId> | ||
<name>SeaTunnel : Connectors V2 : CDC : TIDB</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>connector-cdc-base</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>connector-jdbc</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>connector-cdc-base</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>connector-jdbc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.tikv</groupId> | ||
<artifactId>tikv-client-java</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
131 changes: 131 additions & 0 deletions
131
...b/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/tidb/source/TiDBSource.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,131 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.cdc.tidb.source; | ||
|
||
import org.apache.seatunnel.api.configuration.ReadonlyConfig; | ||
import org.apache.seatunnel.api.source.Boundedness; | ||
import org.apache.seatunnel.api.source.SeaTunnelSource; | ||
import org.apache.seatunnel.api.source.SourceReader; | ||
import org.apache.seatunnel.api.source.SourceSplitEnumerator; | ||
import org.apache.seatunnel.api.source.SupportColumnProjection; | ||
import org.apache.seatunnel.api.source.SupportParallelism; | ||
import org.apache.seatunnel.api.table.catalog.CatalogTable; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelRow; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.config.TiDBSourceConfig; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.config.TiDBSourceOptions; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.enumerator.TiDBSourceCheckpointState; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.enumerator.TiDBSourceSplitEnumerator; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.reader.TiDBSourceReader; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.split.TiDBSourceSplit; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TiDBSource | ||
implements SeaTunnelSource<SeaTunnelRow, TiDBSourceSplit, TiDBSourceCheckpointState>, | ||
SupportParallelism, | ||
SupportColumnProjection { | ||
|
||
static final String IDENTIFIER = "TiDB-CDC"; | ||
|
||
private TiDBSourceConfig config; | ||
private final CatalogTable catalogTable; | ||
|
||
public TiDBSource(ReadonlyConfig config, CatalogTable catalogTable) { | ||
|
||
this.config = | ||
TiDBSourceConfig.builder() | ||
.startupMode(config.get(TiDBSourceOptions.STARTUP_MODE)) | ||
.databaseName(config.get(TiDBSourceOptions.DATABASE_NAME)) | ||
.tableName(config.get(TiDBSourceOptions.TABLE_NAME)) | ||
.tiConfiguration(TiDBSourceOptions.getTiConfiguration(config)) | ||
.build(); | ||
this.catalogTable = catalogTable; | ||
} | ||
|
||
/** | ||
* Returns a unique identifier among same factory interfaces. | ||
* | ||
* <p>For consistency, an identifier should be declared as one lower case word (e.g. {@code | ||
* kafka}). If multiple factories exist for different versions, a version should be appended | ||
* using "-" (e.g. {@code elasticsearch-7}). | ||
*/ | ||
@Override | ||
public String getPluginName() { | ||
return IDENTIFIER; | ||
} | ||
|
||
/** | ||
* Get the boundedness of this source. | ||
* | ||
* @return the boundedness of this source. | ||
*/ | ||
@Override | ||
public Boundedness getBoundedness() { | ||
return Boundedness.UNBOUNDED; | ||
} | ||
|
||
/** | ||
* Create source reader, used to produce data. | ||
* | ||
* @param context reader context. | ||
* @return source reader. | ||
* @throws Exception when create reader failed. | ||
*/ | ||
@Override | ||
public SourceReader<SeaTunnelRow, TiDBSourceSplit> createReader(SourceReader.Context context) | ||
throws Exception { | ||
return new TiDBSourceReader(context, config, catalogTable); | ||
} | ||
|
||
/** | ||
* Create source split enumerator, used to generate splits. This method will be called only once | ||
* when start a source. | ||
* | ||
* @param context enumerator context. | ||
* @return source split enumerator. | ||
* @throws Exception when create enumerator failed. | ||
*/ | ||
@Override | ||
public SourceSplitEnumerator<TiDBSourceSplit, TiDBSourceCheckpointState> createEnumerator( | ||
SourceSplitEnumerator.Context<TiDBSourceSplit> context) throws Exception { | ||
return new TiDBSourceSplitEnumerator(context, config); | ||
} | ||
|
||
/** | ||
* Create source split enumerator, used to generate splits. This method will be called when | ||
* restore from checkpoint. | ||
* | ||
* @param context enumerator context. | ||
* @param checkpointState checkpoint state. | ||
* @return source split enumerator. | ||
* @throws Exception when create enumerator failed. | ||
*/ | ||
@Override | ||
public SourceSplitEnumerator<TiDBSourceSplit, TiDBSourceCheckpointState> restoreEnumerator( | ||
SourceSplitEnumerator.Context<TiDBSourceSplit> context, | ||
TiDBSourceCheckpointState checkpointState) | ||
throws Exception { | ||
return new TiDBSourceSplitEnumerator(context, config, checkpointState); | ||
} | ||
|
||
@Override | ||
public List<CatalogTable> getProducedCatalogTables() { | ||
return Collections.singletonList(catalogTable); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...ain/java/org/apache/seatunnel/connectors/seatunnel/cdc/tidb/source/TiDBSourceFactory.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,105 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.cdc.tidb.source; | ||
|
||
import org.apache.seatunnel.api.configuration.ReadonlyConfig; | ||
import org.apache.seatunnel.api.configuration.util.OptionRule; | ||
import org.apache.seatunnel.api.source.SeaTunnelSource; | ||
import org.apache.seatunnel.api.source.SourceSplit; | ||
import org.apache.seatunnel.api.table.catalog.CatalogTable; | ||
import org.apache.seatunnel.api.table.catalog.TablePath; | ||
import org.apache.seatunnel.api.table.connector.TableSource; | ||
import org.apache.seatunnel.api.table.factory.Factory; | ||
import org.apache.seatunnel.api.table.factory.TableSourceFactory; | ||
import org.apache.seatunnel.api.table.factory.TableSourceFactoryContext; | ||
import org.apache.seatunnel.connectors.seatunnel.cdc.tidb.source.config.TiDBSourceOptions; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.tidb.TiDBCatalog; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.tidb.TiDBCatalogFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
import java.io.Serializable; | ||
|
||
@AutoService(Factory.class) | ||
public class TiDBSourceFactory implements TableSourceFactory { | ||
/** | ||
* Returns a unique identifier among same factory interfaces. | ||
* | ||
* <p>For consistency, an identifier should be declared as one lower case word (e.g. {@code | ||
* kafka}). If multiple factories exist for different versions, a version should be appended | ||
* using "-" (e.g. {@code elasticsearch-7}). | ||
*/ | ||
@Override | ||
public String factoryIdentifier() { | ||
return TiDBSource.IDENTIFIER; | ||
} | ||
|
||
/** | ||
* Returns the rule for options. | ||
* | ||
* <p>1. Used to verify whether the parameters configured by the user conform to the rules of | ||
* the options; | ||
* | ||
* <p>2. Used for Web-UI to prompt user to configure option value; | ||
*/ | ||
@Override | ||
public OptionRule optionRule() { | ||
return OptionRule.builder() | ||
.required( | ||
TiDBSourceOptions.DATABASE_NAME, | ||
TiDBSourceOptions.TABLE_NAME, | ||
TiDBSourceOptions.PD_ADDRESSES) | ||
.optional( | ||
TiDBSourceOptions.TIKV_BATCH_GET_CONCURRENCY, | ||
TiDBSourceOptions.TIKV_BATCH_SCAN_CONCURRENCY, | ||
TiDBSourceOptions.TIKV_GRPC_SCAN_TIMEOUT, | ||
TiDBSourceOptions.TIKV_GRPC_TIMEOUT, | ||
TiDBSourceOptions.STARTUP_MODE) | ||
.build(); | ||
} | ||
|
||
/** | ||
* TODO: Implement SupportParallelism in the TableSourceFactory instead of the SeaTunnelSource, | ||
* Then deprecated the method | ||
*/ | ||
@Override | ||
public Class<? extends SeaTunnelSource> getSourceClass() { | ||
return TiDBSource.class; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <T, SplitT extends SourceSplit, StateT extends Serializable> | ||
TableSource<T, SplitT, StateT> createSource(TableSourceFactoryContext context) { | ||
return () -> { | ||
ReadonlyConfig config = context.getOptions(); | ||
TiDBCatalogFactory catalogFactory = new TiDBCatalogFactory(); | ||
// Build tidb catalog. | ||
TiDBCatalog catalog = | ||
(TiDBCatalog) catalogFactory.createCatalog(factoryIdentifier(), config); | ||
|
||
TablePath tablePath = | ||
TablePath.of( | ||
config.get(TiDBSourceOptions.DATABASE_NAME), | ||
config.get(TiDBSourceOptions.TABLE_NAME)); | ||
CatalogTable catalogTable = catalog.getTable(tablePath); | ||
return (SeaTunnelSource<T, SplitT, StateT>) | ||
new TiDBSource(context.getOptions(), catalogTable); | ||
}; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...va/org/apache/seatunnel/connectors/seatunnel/cdc/tidb/source/config/TiDBSourceConfig.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,40 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.cdc.tidb.source.config; | ||
|
||
import org.apache.seatunnel.connectors.cdc.base.option.StartupMode; | ||
|
||
import org.tikv.common.TiConfiguration; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode | ||
public class TiDBSourceConfig { | ||
private String databaseName; | ||
private String tableName; | ||
private StartupMode startupMode; | ||
private TiConfiguration tiConfiguration; | ||
} |
Oops, something went wrong.