CDC 采集开发
这个提交包含在:
@@ -101,7 +101,9 @@ services:
|
||||
build:
|
||||
context: ./m2/seatunnel
|
||||
dockerfile: Dockerfile
|
||||
image: aixun-datagov/seatunnel:2.3.13-ingestion-kingbase-20261104
|
||||
additional_contexts:
|
||||
native_cdc: ../../aixun-modules/aixun-integration/seatunnel-native-cdc/target
|
||||
image: aixun-datagov/seatunnel:2.3.13-cdc-20261120-r2
|
||||
container_name: aixun-datagov-m2-seatunnel
|
||||
hostname: m2-seatunnel
|
||||
labels: *m2-labels
|
||||
|
||||
@@ -20,6 +20,15 @@ fetch() {
|
||||
fetch "${ARTIFACT_DIR}/connector-jdbc-2.3.13.jar" \
|
||||
d6be827cc6a529791f985a114fa65f032dde229b2c4b4f0b6ad1ae9328770d2e \
|
||||
https://repo1.maven.org/maven2/org/apache/seatunnel/connector-jdbc/2.3.13/connector-jdbc-2.3.13.jar
|
||||
fetch "${ARTIFACT_DIR}/connector-cdc-mysql-2.3.13.jar" \
|
||||
57b13e1a4d9cd3055db39692e42dfd8fa8ee3d4b22197ba7de4296107cc360da \
|
||||
https://repo.maven.apache.org/maven2/org/apache/seatunnel/connector-cdc-mysql/2.3.13/connector-cdc-mysql-2.3.13.jar
|
||||
fetch "${ARTIFACT_DIR}/connector-cdc-base-2.3.13.jar" \
|
||||
e0db5a70576ce6a7b189d43c268c99d4a912bfa26348442d7fd4fda22571a88a \
|
||||
https://repo.maven.apache.org/maven2/org/apache/seatunnel/connector-cdc-base/2.3.13/connector-cdc-base-2.3.13.jar
|
||||
fetch "${ARTIFACT_DIR}/connector-doris-2.3.13.jar" \
|
||||
032f60e81022035bf84e975263cd20e87ede6118f8b3582b284491d80c5a50b7 \
|
||||
https://repo.maven.apache.org/maven2/org/apache/seatunnel/connector-doris/2.3.13/connector-doris-2.3.13.jar
|
||||
fetch "${ARTIFACT_DIR}/connector-http-base-2.3.13.jar" \
|
||||
3ed4a53bfff002a96bbf437bae02b03579b7e2c10c1be953bea7b8968d494a5e \
|
||||
https://repo1.maven.org/maven2/org/apache/seatunnel/connector-http-base/2.3.13/connector-http-base-2.3.13.jar
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import org.apache.seatunnel.api.table.catalog.*;
|
||||
import org.apache.seatunnel.api.table.type.*;
|
||||
import org.apache.seatunnel.api.source.Collector;
|
||||
import org.apache.seatunnel.api.serialization.DeserializationSchema;
|
||||
import org.apache.seatunnel.format.json.ogg.OggJsonDeserializationSchema;
|
||||
import org.apache.seatunnel.format.json.debezium.DebeziumJsonDeserializationSchema;
|
||||
import java.util.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/** Real 2.3.13 decoder contract; no broker, database or secret access. */
|
||||
class CdcFormatProbe {
|
||||
public static void main(String[] args) throws Exception {
|
||||
var columns=List.<Column>of(PhysicalColumn.of("ID",BasicType.INT_TYPE,10L,false,null,null),
|
||||
PhysicalColumn.of("NAME",BasicType.STRING_TYPE,100L,true,null,null));
|
||||
var table=CatalogTable.of(TableIdentifier.of("cdc","APP","ORDERS"),new TableSchema(columns,null,List.of()),Map.of(),List.of(),"");
|
||||
for(String format:List.of("ogg_json","debezium_json")){
|
||||
DeserializationSchema<SeaTunnelRow> decoder=format.equals("ogg_json")?
|
||||
new OggJsonDeserializationSchema(table,null,null,false):new DebeziumJsonDeserializationSchema(table,false,false);
|
||||
List<SeaTunnelRow> rows=new ArrayList<>();
|
||||
Collector<SeaTunnelRow> collector=new Collector<>(){
|
||||
public void collect(SeaTunnelRow row){rows.add(row);}
|
||||
public Object getCheckpointLock(){return this;}
|
||||
};
|
||||
String op=format.equals("ogg_json")?"op_type":"op";
|
||||
String[] operations=format.equals("ogg_json")?new String[]{"I","U","D"}:new String[]{"c","u","d"};
|
||||
String a="{\"ID\":1,\"NAME\":\"before\"}",b="{\"ID\":2,\"NAME\":null}";
|
||||
String[] messages={"{\""+op+"\":\""+operations[0]+"\",\"before\":null,\"after\":"+a+"}",
|
||||
"{\""+op+"\":\""+operations[1]+"\",\"before\":"+a+",\"after\":"+b+"}",
|
||||
"{\""+op+"\":\""+operations[2]+"\",\"before\":"+b+",\"after\":null}"};
|
||||
for(String msg:messages)decoder.deserialize(msg.getBytes(StandardCharsets.UTF_8),collector);
|
||||
if(rows.size()!=4 || rows.get(0).getRowKind()!=RowKind.INSERT || rows.get(1).getRowKind()!=RowKind.UPDATE_BEFORE ||
|
||||
rows.get(2).getRowKind()!=RowKind.UPDATE_AFTER || rows.get(3).getRowKind()!=RowKind.DELETE ||
|
||||
!Integer.valueOf(1).equals(rows.get(1).getField(0)) || !Integer.valueOf(2).equals(rows.get(2).getField(0)) || rows.get(2).getField(1)!=null)
|
||||
throw new AssertionError("Changelog contract failed: "+format);
|
||||
boolean failed=false;try{decoder.deserialize("invalid-json".getBytes(StandardCharsets.UTF_8),collector);}catch(Exception e){failed=true;}
|
||||
if(!failed)throw new AssertionError("Malformed change was silently skipped");
|
||||
System.out.println(format+": INSERT, UPDATE_BEFORE, UPDATE_AFTER, DELETE, key change, null, malformed rejection PASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.apache.seatunnel.api.table.factory.*;
|
||||
/** Class loading only: never connects to a database or submits a job. */
|
||||
class CdcPluginProbe {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ClassLoader loader=Thread.currentThread().getContextClassLoader();
|
||||
String source=args.length==0?"MySQL-CDC":args[0];
|
||||
System.out.println("SOURCE="+FactoryUtil.discoverFactory(loader,TableSourceFactory.class,source).factoryIdentifier());
|
||||
System.out.println("SINK="+FactoryUtil.discoverFactory(loader,TableSinkFactory.class,"Doris").factoryIdentifier());
|
||||
System.out.println("DRIVER="+Class.forName("com.mysql.cj.jdbc.Driver").getName());
|
||||
if("Oracle-CDC".equals(source))System.out.println("DRIVER="+Class.forName("oracle.jdbc.OracleDriver").getName());
|
||||
if("SqlServer-CDC".equals(source))System.out.println("DRIVER="+Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").getName());
|
||||
if("Dameng-Native-CDC".equals(source))System.out.println("DRIVER="+Class.forName("dm.jdbc.driver.DmDriver").getName());
|
||||
if("Kingbase-Native-CDC".equals(source))System.out.println("DRIVER="+Class.forName("com.kingbase8.Driver").getName());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,34 @@
|
||||
FROM aixun-datagov/poc-seatunnel:2.3.13-auth-1
|
||||
|
||||
USER root
|
||||
COPY patches/RestJobExecutionEnvironment.java /tmp/aixun-cdc-patch/RestJobExecutionEnvironment.java
|
||||
RUN javac --release 8 -cp /opt/seatunnel/starter/seatunnel-starter.jar -d /tmp/aixun-cdc-patch/classes /tmp/aixun-cdc-patch/RestJobExecutionEnvironment.java && \
|
||||
jar uf /opt/seatunnel/starter/seatunnel-starter.jar -C /tmp/aixun-cdc-patch/classes . && \
|
||||
rm -rf /tmp/aixun-cdc-patch
|
||||
RUN install -d -o seatunnel -g seatunnel /opt/seatunnel/plugins/connector-jdbc
|
||||
RUN install -d -o seatunnel -g seatunnel /opt/seatunnel/plugins/connector-cdc-mysql
|
||||
RUN install -d -o seatunnel -g seatunnel /opt/seatunnel/plugins/connector-cdc-oracle /opt/seatunnel/plugins/connector-cdc-sqlserver
|
||||
COPY local/artifacts/connector-cdc-base-2.3.13.jar /opt/seatunnel/plugins/connector-cdc-mysql/connector-cdc-base-2.3.13.jar
|
||||
COPY local/artifacts/connector-cdc-base-2.3.13.jar /opt/seatunnel/plugins/connector-cdc-oracle/connector-cdc-base-2.3.13.jar
|
||||
COPY local/artifacts/connector-cdc-base-2.3.13.jar /opt/seatunnel/plugins/connector-cdc-sqlserver/connector-cdc-base-2.3.13.jar
|
||||
COPY local/artifacts/connector-cdc-oracle-2.3.13.jar /opt/seatunnel/connectors/connector-cdc-oracle-2.3.13.jar
|
||||
COPY patches/OracleDialect.java patches/OracleSchema.java patches/OracleSnapshotSplitReadTask.java /tmp/aixun-oracle-patch/
|
||||
RUN javac --release 8 -cp '/opt/seatunnel/starter/seatunnel-starter.jar:/opt/seatunnel/lib/*:/opt/seatunnel/connectors/*:/opt/seatunnel/plugins/connector-cdc-oracle/*' -d /tmp/aixun-oracle-patch/classes /tmp/aixun-oracle-patch/*.java && \
|
||||
jar uf /opt/seatunnel/connectors/connector-cdc-oracle-2.3.13.jar -C /tmp/aixun-oracle-patch/classes . && \
|
||||
rm -rf /tmp/aixun-oracle-patch
|
||||
COPY local/artifacts/connector-cdc-sqlserver-2.3.13.jar /opt/seatunnel/connectors/connector-cdc-sqlserver-2.3.13.jar
|
||||
COPY local/artifacts/connector-kafka-2.3.13.jar /opt/seatunnel/connectors/connector-kafka-2.3.13.jar
|
||||
COPY local/artifacts/ojdbc11-23.26.2.0.0.jar /opt/seatunnel/lib/ojdbc11-23.26.2.0.0.jar
|
||||
COPY local/artifacts/orai18n-23.26.2.0.0.jar /opt/seatunnel/lib/orai18n-23.26.2.0.0.jar
|
||||
COPY local/artifacts/mssql-jdbc-13.4.0.jre11.jar /opt/seatunnel/lib/mssql-jdbc-13.4.0.jre11.jar
|
||||
COPY local/artifacts/connector-jdbc-2.3.13.jar /opt/seatunnel/connectors/connector-jdbc-2.3.13.jar
|
||||
COPY local/artifacts/connector-cdc-mysql-2.3.13.jar /opt/seatunnel/connectors/connector-cdc-mysql-2.3.13.jar
|
||||
COPY local/artifacts/connector-doris-2.3.13.jar /opt/seatunnel/connectors/connector-doris-2.3.13.jar
|
||||
COPY local/artifacts/connector-http-base-2.3.13.jar /opt/seatunnel/connectors/connector-http-base-2.3.13.jar
|
||||
COPY local/artifacts/connector-file-local-2.3.13.jar /opt/seatunnel/connectors/connector-file-local-2.3.13.jar
|
||||
COPY local/artifacts/connector-hive-2.3.13.jar /opt/seatunnel/connectors/connector-hive-2.3.13.jar
|
||||
COPY local/artifacts/mysql-connector-j-9.5.0.jar /opt/seatunnel/plugins/connector-jdbc/mysql-connector-j-9.5.0.jar
|
||||
COPY local/artifacts/mysql-connector-j-9.5.0.jar /opt/seatunnel/lib/mysql-connector-j-9.5.0.jar
|
||||
COPY local/artifacts/postgresql-42.7.13.jar /opt/seatunnel/plugins/connector-jdbc/postgresql-42.7.13.jar
|
||||
COPY local/artifacts/mariadb-java-client-3.5.10.jar /opt/seatunnel/plugins/connector-jdbc/mariadb-java-client-3.5.10.jar
|
||||
COPY local/artifacts/hive-jdbc-4.2.0-standalone.jar /opt/seatunnel/plugins/connector-jdbc/hive-jdbc-4.2.0-standalone.jar
|
||||
@@ -16,6 +38,15 @@ COPY local/artifacts/DmJdbcDriver18-8.1.3.62.jar /opt/seatunnel/plugins/connecto
|
||||
COPY local/artifacts/mssql-jdbc-13.4.0.jre11.jar /opt/seatunnel/plugins/connector-jdbc/mssql-jdbc-13.4.0.jre11.jar
|
||||
COPY local/artifacts/ojdbc11-23.26.2.0.0.jar /opt/seatunnel/plugins/connector-jdbc/ojdbc11-23.26.2.0.0.jar
|
||||
COPY local/artifacts/kingbase8-9.0.1.jre7.jar /opt/seatunnel/plugins/connector-jdbc/kingbase8-9.0.1.jre7.jar
|
||||
COPY --from=native_cdc connector-aixun-native-cdc-2.3.13-1.jar /opt/seatunnel/connectors/connector-aixun-dameng-cdc-2.3.13-1.jar
|
||||
COPY --from=native_cdc connector-aixun-native-cdc-2.3.13-1.jar /opt/seatunnel/connectors/connector-aixun-kingbase-cdc-2.3.13-1.jar
|
||||
COPY local/artifacts/kingbase8-9.0.1.jre7.jar /opt/seatunnel/lib/kingbase8-9.0.1.jre7.jar
|
||||
COPY local/artifacts/DmJdbcDriver18-8.1.3.62.jar /opt/seatunnel/lib/DmJdbcDriver18-8.1.3.62.jar
|
||||
RUN printf '\nseatunnel.source.Dameng-Native-CDC = connector-aixun-dameng-cdc\nseatunnel.source.Kingbase-Native-CDC = connector-aixun-kingbase-cdc\n' >> /opt/seatunnel/connectors/plugin-mapping.properties
|
||||
COPY patches/VerifyNativeDiscovery.java /tmp/VerifyNativeDiscovery.java
|
||||
RUN javac --release 8 -cp /opt/seatunnel/starter/seatunnel-starter.jar -d /tmp /tmp/VerifyNativeDiscovery.java && \
|
||||
java -DSEATUNNEL_HOME=/opt/seatunnel -cp '/tmp:/opt/seatunnel/starter/seatunnel-starter.jar:/opt/seatunnel/lib/*' VerifyNativeDiscovery && \
|
||||
rm /tmp/VerifyNativeDiscovery.java /tmp/VerifyNativeDiscovery.class
|
||||
COPY --chmod=0555 start-seatunnel.sh /opt/aixun-m2/start-seatunnel.sh
|
||||
RUN find /opt/seatunnel/lib /opt/seatunnel/connectors -type f -iname '*opengauss*.jar' -delete && \
|
||||
test "$(find /opt/seatunnel/lib /opt/seatunnel/connectors -type f -iname '*opengauss*.jar' | wc -l)" -eq 0 && \
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
/** Read-only local DM capability check. Does not mine business logs, change parameters, or apply DDL. */
|
||||
class NativeCdcCapabilityProbe {
|
||||
public static void main(String[] args)throws Exception{
|
||||
Properties p=new Properties();p.setProperty("user",System.getenv("DATAGOV_DM_USERNAME"));
|
||||
p.setProperty("password",System.getenv("DATAGOV_DM_PASSWORD"));p.setProperty("connectTimeout","5000");p.setProperty("socketTimeout","15000");
|
||||
Class.forName("dm.jdbc.driver.DmDriver");
|
||||
try(Connection db=DriverManager.getConnection("jdbc:dm://"+System.getenv("DATAGOV_DM_HOST")+":"+System.getenv("DATAGOV_DM_PORT"),p)){
|
||||
try(Statement s=db.createStatement();ResultSet rs=s.executeQuery("SELECT ID_CODE() FROM DUAL")){if(rs.next())System.out.println("DM_BUILD="+rs.getString(1));}
|
||||
try(Statement s=db.createStatement();ResultSet rs=s.executeQuery("SELECT PARA_NAME,PARA_VALUE FROM V$DM_INI WHERE PARA_NAME IN ('RLOG_APPEND_LOGIC','RLOG_LLOG_COMPRESS','LOGMNR_DELAY_ANALYZE')")){
|
||||
while(rs.next())System.out.println(rs.getString(1)+"="+rs.getString(2));
|
||||
}
|
||||
check(db,"ARCHIVE_COLUMNS","SELECT NAME,FIRST_CHANGE#,NEXT_CHANGE# FROM V$ARCHIVED_LOG WHERE 1=0");
|
||||
check(db,"LOGMNR_COLUMNS","SELECT OPERATION,COMMIT_SCN,STATUS,SCN,SSN,REDO_VALUE,UNDO_VALUE FROM V$LOGMNR_CONTENTS WHERE 1=0");
|
||||
}catch(SQLException e){System.out.println("PROBE_FAILED SQLSTATE="+e.getSQLState()+" CODE="+e.getErrorCode());System.exit(2);}
|
||||
}
|
||||
static void check(Connection db,String label,String sql){
|
||||
try(Statement s=db.createStatement();ResultSet r=s.executeQuery(sql)){System.out.println(label+"=PASS");}
|
||||
catch(SQLException e){System.out.println(label+"=UNAVAILABLE SQLSTATE="+e.getSQLState()+" CODE="+e.getErrorCode());}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fetch pinned CDC dependencies from Maven Central; never modifies a running node."""
|
||||
import hashlib
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
ARTIFACTS = (
|
||||
("org/apache/seatunnel/connector-kafka/2.3.13", "connector-kafka-2.3.13.jar", "303f5d9544e8cc192a50374c5cb8c1ad2c3f6123955291e66e8ff9dd14909298"),
|
||||
("org/apache/seatunnel/connector-cdc-oracle/2.3.13", "connector-cdc-oracle-2.3.13.jar", "1ffbf133b9eac604a4efdaa12874607945efa6fda4bc95a58187d4e9a70cd23a"),
|
||||
("org/apache/seatunnel/connector-cdc-sqlserver/2.3.13", "connector-cdc-sqlserver-2.3.13.jar", "8bfe28f5bcffc08ed9f6784e5a717ae8a54d47eb7b5e51d2dfbd9e959e90edc2"),
|
||||
("com/oracle/database/nls/orai18n/23.26.2.0.0", "orai18n-23.26.2.0.0.jar", "d0ed0aadf7e319ee8f313a85436919eb75f1012cc20f97d384e72adfbecfe3bd"),
|
||||
)
|
||||
|
||||
def main():
|
||||
root = Path(__file__).resolve().parent / "local/artifacts"
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
for coordinate, name, expected in ARTIFACTS:
|
||||
target = root / name
|
||||
data = target.read_bytes() if target.exists() else urllib.request.urlopen(
|
||||
"https://repo.maven.apache.org/maven2/" + coordinate + "/" + name, timeout=60).read()
|
||||
if hashlib.sha256(data).hexdigest() != expected:
|
||||
raise SystemExit("Checksum mismatch: " + name)
|
||||
if not target.exists():
|
||||
target.write_bytes(data)
|
||||
print("PASS " + name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.oracle.source;
|
||||
|
||||
import org.apache.seatunnel.api.table.catalog.CatalogTable;
|
||||
import org.apache.seatunnel.api.table.catalog.ConstraintKey;
|
||||
import org.apache.seatunnel.api.table.catalog.PrimaryKey;
|
||||
import org.apache.seatunnel.common.utils.SeaTunnelException;
|
||||
import org.apache.seatunnel.connectors.cdc.base.config.JdbcSourceConfig;
|
||||
import org.apache.seatunnel.connectors.cdc.base.dialect.JdbcDataSourceDialect;
|
||||
import org.apache.seatunnel.connectors.cdc.base.source.enumerator.splitter.ChunkSplitter;
|
||||
import org.apache.seatunnel.connectors.cdc.base.source.reader.external.FetchTask;
|
||||
import org.apache.seatunnel.connectors.cdc.base.source.split.SourceSplitBase;
|
||||
import org.apache.seatunnel.connectors.cdc.base.utils.CatalogTableUtils;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.config.OracleSourceConfig;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.config.OracleSourceConfigFactory;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.source.enumerator.OracleChunkSplitter;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.source.reader.fetch.OracleSourceFetchTaskContext;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.source.reader.fetch.logminer.OracleRedoLogFetchTask;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.source.reader.fetch.scan.OracleSnapshotFetchTask;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.utils.OracleSchema;
|
||||
|
||||
import io.debezium.connector.oracle.OracleConnection;
|
||||
import io.debezium.jdbc.JdbcConnection;
|
||||
import io.debezium.relational.TableId;
|
||||
import io.debezium.relational.history.TableChanges.TableChange;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.seatunnel.connectors.seatunnel.cdc.oracle.utils.OracleConnectionUtils.createOracleConnection;
|
||||
|
||||
public class OracleDialect implements JdbcDataSourceDialect {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final OracleSourceConfigFactory configFactory;
|
||||
private final OracleSourceConfig sourceConfig;
|
||||
private transient OracleSchema oracleSchema;
|
||||
private final Map<TableId, CatalogTable> tableMap;
|
||||
|
||||
public OracleDialect(
|
||||
OracleSourceConfigFactory configFactory, List<CatalogTable> catalogTables) {
|
||||
this.configFactory = configFactory;
|
||||
this.sourceConfig = configFactory.create(0);
|
||||
this.tableMap = CatalogTableUtils.convertTables(catalogTables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Oracle";
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
@Override
|
||||
public boolean isDataCollectionIdCaseSensitive(JdbcSourceConfig sourceConfig) {
|
||||
try (JdbcConnection jdbcConnection = openJdbcConnection(sourceConfig)) {
|
||||
OracleConnection oracleConnection = (OracleConnection) jdbcConnection;
|
||||
return oracleConnection.getOracleVersion().getMajor() == 11;
|
||||
} catch (SQLException e) {
|
||||
throw new SeaTunnelException("Error reading oracle variables: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcConnection openJdbcConnection(JdbcSourceConfig sourceConfig) {
|
||||
OracleConnection connection=createOracleConnection(sourceConfig.getDbzConnectorConfig().getJdbcConfig());
|
||||
String pdb=((OracleSourceConfig)sourceConfig).getDbzConnectorConfig().getPdbName();
|
||||
if(pdb!=null) {
|
||||
try { connection.setSessionToPdb(pdb); }
|
||||
catch(RuntimeException e) {
|
||||
try { connection.close(); } catch(SQLException close) { e.addSuppressed(close); }
|
||||
throw new SeaTunnelException("Cannot switch Oracle metadata connection to target PDB",e);
|
||||
}
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSplitter createChunkSplitter(JdbcSourceConfig sourceConfig) {
|
||||
return new OracleChunkSplitter(sourceConfig, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableId> discoverDataCollections(JdbcSourceConfig sourceConfig) {
|
||||
OracleSourceConfig oracleSourceConfig = (OracleSourceConfig) sourceConfig;
|
||||
String pdb=oracleSourceConfig.getDbzConnectorConfig().getPdbName();
|
||||
String database = pdb==null?oracleSourceConfig.getDbzConnectorConfig().getDatabaseName():pdb;
|
||||
|
||||
return tableMap.keySet().stream()
|
||||
.map(tableId -> new TableId(database, tableId.schema(), tableId.table()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableChange queryTableSchema(JdbcConnection jdbc, TableId tableId) {
|
||||
if (oracleSchema == null) {
|
||||
oracleSchema = new OracleSchema(sourceConfig.getDbzConnectorConfig(), tableMap);
|
||||
}
|
||||
return oracleSchema.getTableSchema(jdbc, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OracleSourceFetchTaskContext createFetchTaskContext(
|
||||
SourceSplitBase sourceSplitBase, JdbcSourceConfig taskSourceConfig) {
|
||||
return new OracleSourceFetchTaskContext(taskSourceConfig, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchTask<SourceSplitBase> createFetchTask(SourceSplitBase sourceSplitBase) {
|
||||
if (sourceSplitBase.isSnapshotSplit()) {
|
||||
return new OracleSnapshotFetchTask(sourceSplitBase.asSnapshotSplit());
|
||||
} else {
|
||||
return new OracleRedoLogFetchTask(sourceSplitBase.asIncrementalSplit());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PrimaryKey> getPrimaryKey(JdbcConnection jdbcConnection, TableId tableId) {
|
||||
return Optional.ofNullable(tableMap.get(tableId).getTableSchema().getPrimaryKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConstraintKey> getConstraintKeys(JdbcConnection jdbcConnection, TableId tableId) {
|
||||
return tableMap.get(tableId).getTableSchema().getConstraintKeys();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.oracle.utils;
|
||||
|
||||
import org.apache.seatunnel.api.table.catalog.CatalogTable;
|
||||
import org.apache.seatunnel.common.utils.SeaTunnelException;
|
||||
import org.apache.seatunnel.connectors.cdc.base.utils.CatalogTableUtils;
|
||||
|
||||
import io.debezium.connector.oracle.OracleConnection;
|
||||
import io.debezium.connector.oracle.OracleConnectorConfig;
|
||||
import io.debezium.jdbc.JdbcConnection;
|
||||
import io.debezium.relational.Table;
|
||||
import io.debezium.relational.TableId;
|
||||
import io.debezium.relational.Tables;
|
||||
import io.debezium.relational.history.TableChanges;
|
||||
import io.debezium.relational.history.TableChanges.TableChange;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** A component used to get schema by table path. */
|
||||
public class OracleSchema {
|
||||
|
||||
private final OracleConnectorConfig connectorConfig;
|
||||
private final Map<TableId, TableChange> schemasByTableId;
|
||||
private final Map<TableId, CatalogTable> tableMap;
|
||||
|
||||
public OracleSchema(
|
||||
OracleConnectorConfig connectorConfig, Map<TableId, CatalogTable> tableMap) {
|
||||
this.connectorConfig = connectorConfig;
|
||||
this.schemasByTableId = new HashMap<>();
|
||||
this.tableMap = tableMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets table schema for the given table path. It will request to MySQL server by running `SHOW
|
||||
* CREATE TABLE` if cache missed.
|
||||
*/
|
||||
public TableChange getTableSchema(JdbcConnection jdbc, TableId tableId) {
|
||||
// Also switch on cache hits: the same connection may have been reset to CDB by log mining.
|
||||
if(connectorConfig.getPdbName()!=null) {
|
||||
try { ((OracleConnection)jdbc).setSessionToPdb(connectorConfig.getPdbName()); }
|
||||
catch(RuntimeException e) {throw new SeaTunnelException("Cannot switch Oracle schema session to target PDB",e);}
|
||||
}
|
||||
// read schema from cache first
|
||||
TableChange schema = schemasByTableId.get(tableId);
|
||||
if (schema == null) {
|
||||
schema = readTableSchema(jdbc, tableId);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
private TableChange readTableSchema(JdbcConnection jdbc, TableId tableId) {
|
||||
OracleConnection oracleConnection = (OracleConnection) jdbc;
|
||||
Tables tables = new Tables();
|
||||
|
||||
try {
|
||||
oracleConnection.readSchema(
|
||||
tables,
|
||||
tableId.catalog(),
|
||||
tableId.schema(),
|
||||
id -> connectorConfig.getTableFilters().dataCollectionFilter().isIncluded(id) ||
|
||||
(connectorConfig.getPdbName()!=null && tableMap.containsKey(tableId) &&
|
||||
java.util.Objects.equals(id.schema(),tableId.schema()) && java.util.Objects.equals(id.table(),tableId.table())),
|
||||
null,
|
||||
false);
|
||||
for (TableId id : tables.tableIds()) {
|
||||
TableId configured=id;
|
||||
if(connectorConfig.getPdbName()!=null && !tableMap.containsKey(id) && tableMap.containsKey(tableId) &&
|
||||
java.util.Objects.equals(id.schema(),tableId.schema()) && java.util.Objects.equals(id.table(),tableId.table()))configured=tableId;
|
||||
if (tableMap.containsKey(configured)) {
|
||||
Table table =
|
||||
CatalogTableUtils.mergeCatalogTableConfig(
|
||||
tables.forTable(id).edit().tableId(configured).create(), tableMap.get(configured));
|
||||
TableChanges.TableChange tableChange =
|
||||
new TableChanges.TableChange(
|
||||
TableChanges.TableChangeType.CREATE, table);
|
||||
schemasByTableId.put(configured, tableChange);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new SeaTunnelException(
|
||||
String.format("Failed to read schema for table %s ", tableId), e);
|
||||
}
|
||||
|
||||
if (!schemasByTableId.containsKey(tableId)) {
|
||||
throw new SeaTunnelException(
|
||||
String.format("Can't obtain schema for table %s ", tableId));
|
||||
}
|
||||
|
||||
return schemasByTableId.get(tableId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* 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.oracle.source.reader.fetch.scan;
|
||||
|
||||
import org.apache.seatunnel.connectors.cdc.base.relational.JdbcSourceEventDispatcher;
|
||||
import org.apache.seatunnel.connectors.cdc.base.source.split.SnapshotSplit;
|
||||
import org.apache.seatunnel.connectors.cdc.base.source.split.wartermark.WatermarkKind;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.source.offset.RedoLogOffset;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.utils.OracleConnectionUtils;
|
||||
import org.apache.seatunnel.connectors.seatunnel.cdc.oracle.utils.OracleUtils;
|
||||
|
||||
import org.apache.kafka.connect.errors.ConnectException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.debezium.DebeziumException;
|
||||
import io.debezium.connector.oracle.OracleConnection;
|
||||
import io.debezium.connector.oracle.OracleConnectorConfig;
|
||||
import io.debezium.connector.oracle.OracleDatabaseSchema;
|
||||
import io.debezium.connector.oracle.OracleOffsetContext;
|
||||
import io.debezium.connector.oracle.OraclePartition;
|
||||
import io.debezium.pipeline.EventDispatcher;
|
||||
import io.debezium.pipeline.source.AbstractSnapshotChangeEventSource;
|
||||
import io.debezium.pipeline.source.spi.SnapshotProgressListener;
|
||||
import io.debezium.pipeline.spi.ChangeRecordEmitter;
|
||||
import io.debezium.pipeline.spi.SnapshotResult;
|
||||
import io.debezium.relational.RelationalSnapshotChangeEventSource;
|
||||
import io.debezium.relational.SnapshotChangeRecordEmitter;
|
||||
import io.debezium.relational.Table;
|
||||
import io.debezium.relational.TableId;
|
||||
import io.debezium.util.Clock;
|
||||
import io.debezium.util.ColumnUtils;
|
||||
import io.debezium.util.Strings;
|
||||
import io.debezium.util.Threads;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
|
||||
/** A wrapped task to fetch snapshot split of table. */
|
||||
public class OracleSnapshotSplitReadTask
|
||||
extends AbstractSnapshotChangeEventSource<OraclePartition, OracleOffsetContext> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OracleSnapshotSplitReadTask.class);
|
||||
|
||||
/** Interval for showing a log statement with the progress while scanning a single table. */
|
||||
private static final Duration LOG_INTERVAL = Duration.ofMillis(10_000);
|
||||
|
||||
private final OracleConnectorConfig connectorConfig;
|
||||
private final OracleDatabaseSchema databaseSchema;
|
||||
private final OracleConnection jdbcConnection;
|
||||
private final JdbcSourceEventDispatcher<OraclePartition> dispatcher;
|
||||
private final Clock clock;
|
||||
private final SnapshotSplit snapshotSplit;
|
||||
private final OracleOffsetContext offsetContext;
|
||||
private final SnapshotProgressListener<OraclePartition> snapshotProgressListener;
|
||||
|
||||
public OracleSnapshotSplitReadTask(
|
||||
OracleConnectorConfig connectorConfig,
|
||||
OracleOffsetContext previousOffset,
|
||||
SnapshotProgressListener<OraclePartition> snapshotProgressListener,
|
||||
OracleDatabaseSchema databaseSchema,
|
||||
OracleConnection jdbcConnection,
|
||||
JdbcSourceEventDispatcher<OraclePartition> dispatcher,
|
||||
SnapshotSplit snapshotSplit) {
|
||||
super(connectorConfig, snapshotProgressListener);
|
||||
this.offsetContext = previousOffset;
|
||||
this.connectorConfig = connectorConfig;
|
||||
this.databaseSchema = databaseSchema;
|
||||
this.jdbcConnection = jdbcConnection;
|
||||
this.dispatcher = dispatcher;
|
||||
this.clock = Clock.SYSTEM;
|
||||
this.snapshotSplit = snapshotSplit;
|
||||
this.snapshotProgressListener = snapshotProgressListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotResult<OracleOffsetContext> execute(
|
||||
ChangeEventSourceContext context,
|
||||
OraclePartition partition,
|
||||
OracleOffsetContext previousOffset)
|
||||
throws InterruptedException {
|
||||
SnapshottingTask snapshottingTask = getSnapshottingTask(partition, previousOffset);
|
||||
final SnapshotContext<OraclePartition, OracleOffsetContext> ctx;
|
||||
try {
|
||||
ctx = prepare(partition);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to initialize snapshot context.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
return doExecute(context, previousOffset, ctx, snapshottingTask);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Snapshot was interrupted before completion");
|
||||
throw e;
|
||||
} catch (Exception t) {
|
||||
throw new DebeziumException(t);
|
||||
} finally {
|
||||
complete(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SnapshotResult<OracleOffsetContext> doExecute(
|
||||
ChangeEventSourceContext context,
|
||||
OracleOffsetContext previousOffset,
|
||||
SnapshotContext snapshotContext,
|
||||
SnapshottingTask snapshottingTask)
|
||||
throws Exception {
|
||||
final OracleSnapshotContext ctx = (OracleSnapshotContext) snapshotContext;
|
||||
ctx.offset = offsetContext;
|
||||
|
||||
final RedoLogOffset lowWatermark =
|
||||
OracleConnectionUtils.currentRedoLogOffset(jdbcConnection);
|
||||
LOG.info(
|
||||
"Snapshot step 1 - Determining low watermark {} for split {}",
|
||||
lowWatermark,
|
||||
snapshotSplit);
|
||||
((SnapshotSplitChangeEventSourceContext) context).setLowWatermark(lowWatermark);
|
||||
dispatcher.dispatchWatermarkEvent(
|
||||
ctx.partition.getSourcePartition(), snapshotSplit, lowWatermark, WatermarkKind.LOW);
|
||||
|
||||
LOG.info("Snapshot step 2 - Snapshotting data");
|
||||
createDataEvents(ctx, snapshotSplit.getTableId());
|
||||
|
||||
final RedoLogOffset highWatermark =
|
||||
OracleConnectionUtils.currentRedoLogOffset(jdbcConnection);
|
||||
LOG.info(
|
||||
"Snapshot step 3 - Determining high watermark {} for split {}",
|
||||
highWatermark,
|
||||
snapshotSplit);
|
||||
((SnapshotSplitChangeEventSourceContext) context).setHighWatermark(highWatermark);
|
||||
dispatcher.dispatchWatermarkEvent(
|
||||
ctx.partition.getSourcePartition(),
|
||||
snapshotSplit,
|
||||
highWatermark,
|
||||
WatermarkKind.HIGH);
|
||||
return SnapshotResult.completed(ctx.offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SnapshottingTask getSnapshottingTask(
|
||||
OraclePartition partition, OracleOffsetContext previousOffset) {
|
||||
return new SnapshottingTask(false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SnapshotContext<OraclePartition, OracleOffsetContext> prepare(
|
||||
OraclePartition partition) throws Exception {
|
||||
// The previous split's complete() resets the shared connection to CDB.
|
||||
if (connectorConfig.getPdbName() != null) {
|
||||
jdbcConnection.setSessionToPdb(connectorConfig.getPdbName());
|
||||
}
|
||||
return new OracleSnapshotContext(partition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void complete(SnapshotContext snapshotContext) {
|
||||
if (connectorConfig.getPdbName() != null) {
|
||||
jdbcConnection.resetSessionToCdb();
|
||||
}
|
||||
}
|
||||
|
||||
private void createDataEvents(
|
||||
RelationalSnapshotChangeEventSource.RelationalSnapshotContext<
|
||||
OraclePartition, OracleOffsetContext>
|
||||
snapshotContext,
|
||||
TableId tableId)
|
||||
throws Exception {
|
||||
EventDispatcher.SnapshotReceiver<OraclePartition> snapshotReceiver =
|
||||
dispatcher.getSnapshotChangeEventReceiver();
|
||||
LOG.debug("Snapshotting table {}", tableId);
|
||||
createDataEventsForTable(
|
||||
snapshotContext, snapshotReceiver, databaseSchema.tableFor(tableId));
|
||||
snapshotReceiver.completeSnapshot();
|
||||
}
|
||||
|
||||
/** Dispatches the data change events for the records of a single table. */
|
||||
private void createDataEventsForTable(
|
||||
RelationalSnapshotChangeEventSource.RelationalSnapshotContext<
|
||||
OraclePartition, OracleOffsetContext>
|
||||
snapshotContext,
|
||||
EventDispatcher.SnapshotReceiver<OraclePartition> snapshotReceiver,
|
||||
Table table)
|
||||
throws InterruptedException {
|
||||
|
||||
long exportStart = clock.currentTimeInMillis();
|
||||
LOG.info("Exporting data from split '{}' of table {}", snapshotSplit.splitId(), table.id());
|
||||
|
||||
final String selectSql =
|
||||
OracleUtils.buildSplitScanQuery(
|
||||
snapshotSplit.getTableId(),
|
||||
snapshotSplit.getSplitKeyType(),
|
||||
snapshotSplit.getSplitStart() == null,
|
||||
snapshotSplit.getSplitEnd() == null);
|
||||
LOG.info(
|
||||
"For split '{}' of table {} using select statement: '{}'",
|
||||
snapshotSplit.splitId(),
|
||||
table.id(),
|
||||
selectSql);
|
||||
|
||||
try (PreparedStatement selectStatement =
|
||||
OracleUtils.readTableSplitDataStatement(
|
||||
jdbcConnection,
|
||||
selectSql,
|
||||
snapshotSplit.getSplitStart() == null,
|
||||
snapshotSplit.getSplitEnd() == null,
|
||||
snapshotSplit.getSplitStart(),
|
||||
snapshotSplit.getSplitEnd(),
|
||||
snapshotSplit.getSplitKeyType(),
|
||||
connectorConfig.getSnapshotFetchSize());
|
||||
ResultSet rs = selectStatement.executeQuery()) {
|
||||
|
||||
ColumnUtils.ColumnArray columnArray = ColumnUtils.toArray(rs, table);
|
||||
long rows = 0;
|
||||
Threads.Timer logTimer = getTableScanLogTimer();
|
||||
|
||||
while (rs.next()) {
|
||||
rows++;
|
||||
final Object[] row =
|
||||
jdbcConnection.rowToArray(table, databaseSchema, rs, columnArray);
|
||||
if (logTimer.expired()) {
|
||||
long stop = clock.currentTimeInMillis();
|
||||
LOG.info(
|
||||
"Exported {} records for split '{}' after {}",
|
||||
rows,
|
||||
snapshotSplit.splitId(),
|
||||
Strings.duration(stop - exportStart));
|
||||
snapshotProgressListener.rowsScanned(
|
||||
snapshotContext.partition, table.id(), rows);
|
||||
logTimer = getTableScanLogTimer();
|
||||
}
|
||||
dispatcher.dispatchSnapshotEvent(
|
||||
snapshotContext.partition,
|
||||
table.id(),
|
||||
getChangeRecordEmitter(snapshotContext, table.id(), row),
|
||||
snapshotReceiver);
|
||||
}
|
||||
LOG.info(
|
||||
"Finished exporting {} records for split '{}', total duration '{}'",
|
||||
rows,
|
||||
snapshotSplit.splitId(),
|
||||
Strings.duration(clock.currentTimeInMillis() - exportStart));
|
||||
} catch (SQLException e) {
|
||||
throw new ConnectException("Snapshotting of table " + table.id() + " failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected ChangeRecordEmitter<OraclePartition> getChangeRecordEmitter(
|
||||
SnapshotContext<OraclePartition, OracleOffsetContext> snapshotContext,
|
||||
TableId tableId,
|
||||
Object[] row) {
|
||||
snapshotContext.offset.event(tableId, clock.currentTime());
|
||||
return new SnapshotChangeRecordEmitter<>(
|
||||
snapshotContext.partition, snapshotContext.offset, row, clock);
|
||||
}
|
||||
|
||||
private Threads.Timer getTableScanLogTimer() {
|
||||
return Threads.timer(clock, LOG_INTERVAL);
|
||||
}
|
||||
|
||||
private static class OracleSnapshotContext
|
||||
extends RelationalSnapshotChangeEventSource.RelationalSnapshotContext<
|
||||
OraclePartition, OracleOffsetContext> {
|
||||
|
||||
public OracleSnapshotContext(OraclePartition partition) throws SQLException {
|
||||
super(partition, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Based on Apache SeaTunnel 2.3.13. AiXun change: fail closed before parsing
|
||||
* a restored CDC job when durable checkpoint data is absent or too old.
|
||||
*/
|
||||
package org.apache.seatunnel.engine.server.rest;
|
||||
|
||||
import org.apache.seatunnel.shade.com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.seatunnel.shade.com.typesafe.config.Config;
|
||||
import org.apache.seatunnel.shade.org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.seatunnel.api.common.JobContext;
|
||||
import org.apache.seatunnel.engine.common.Constant;
|
||||
import org.apache.seatunnel.engine.common.config.JobConfig;
|
||||
import org.apache.seatunnel.engine.core.dag.actions.Action;
|
||||
import org.apache.seatunnel.engine.core.dag.logical.LogicalDag;
|
||||
import org.apache.seatunnel.engine.core.job.AbstractJobEnvironment;
|
||||
import org.apache.seatunnel.engine.core.job.JobImmutableInformation;
|
||||
import org.apache.seatunnel.engine.core.job.JobPipelineCheckpointData;
|
||||
import org.apache.seatunnel.engine.core.parse.MultipleTableJobConfigParser;
|
||||
import org.apache.seatunnel.engine.server.SeaTunnelServer;
|
||||
import com.hazelcast.instance.impl.Node;
|
||||
import com.hazelcast.spi.impl.NodeEngineImpl;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
public class RestJobExecutionEnvironment extends AbstractJobEnvironment {
|
||||
private final Config seaTunnelJobConfig;
|
||||
private final NodeEngineImpl nodeEngine;
|
||||
private final Long jobId;
|
||||
private final SeaTunnelServer seaTunnelServer;
|
||||
public RestJobExecutionEnvironment(SeaTunnelServer server,JobConfig jobConfig,Config config,
|
||||
Node node,boolean restore,Long jobId) {
|
||||
super(jobConfig,restore);
|
||||
this.seaTunnelServer=server;this.seaTunnelJobConfig=config;this.nodeEngine=node.getNodeEngine();
|
||||
this.jobConfig.setJobContext(new JobContext(jobId!=null?jobId:nodeEngine.getHazelcastInstance()
|
||||
.getFlakeIdGenerator(Constant.SEATUNNEL_ID_GENERATOR_NAME).newId()));
|
||||
this.jobId=Long.valueOf(this.jobConfig.getJobContext().getJobId());
|
||||
}
|
||||
public Long getJobId(){return jobId;}
|
||||
@VisibleForTesting @Override public LogicalDag getLogicalDag(){
|
||||
ImmutablePair<List<Action>,Set<URL>> parsed=getJobConfigParser().parse(seaTunnelServer.getClassLoaderService());
|
||||
actions.addAll(parsed.getLeft());jarUrls.addAll(commonPluginJars);jarUrls.addAll(parsed.getRight());
|
||||
actions.forEach(action->addCommonPluginJarsToAction(action,new HashSet<>(commonPluginJars),Collections.emptySet()));
|
||||
return getLogicalDagGenerator().generate();
|
||||
}
|
||||
@Override protected MultipleTableJobConfigParser getJobConfigParser(){
|
||||
List<JobPipelineCheckpointData> checkpoints=Collections.emptyList();
|
||||
Config env=seaTunnelJobConfig.getConfig("env");
|
||||
boolean guarded=env.hasPath("\"aixun.restore.checkpoint\"");
|
||||
if(guarded && !isStartWithSavePoint)throw new IllegalStateException("AIXUN_RESTORE_FLAG_REQUIRED");
|
||||
if(isStartWithSavePoint){
|
||||
checkpoints=seaTunnelServer.getCheckpointService().getLatestCheckpointData(jobConfig.getJobContext().getJobId());
|
||||
if(checkpoints.isEmpty())throw new IllegalStateException("AIXUN_RESTORE_CHECKPOINT_MISSING");
|
||||
if(guarded){
|
||||
long minimum=env.getLong("\"aixun.restore.checkpoint\"");
|
||||
if(checkpoints.size()!=1 || minimum<0 || checkpoints.get(0).getCheckpointId()<minimum)
|
||||
throw new IllegalStateException("AIXUN_RESTORE_CHECKPOINT_STALE");
|
||||
}
|
||||
}
|
||||
return new MultipleTableJobConfigParser(seaTunnelJobConfig,idGenerator,jobConfig,commonPluginJars,isStartWithSavePoint,checkpoints);
|
||||
}
|
||||
public JobImmutableInformation build(){
|
||||
return new JobImmutableInformation(Long.parseLong(jobConfig.getJobContext().getJobId()),jobConfig.getName(),
|
||||
isStartWithSavePoint,nodeEngine.getSerializationService(),getLogicalDag(),new ArrayList<>(jarUrls),new ArrayList<>(connectorJarIdentifiers));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.Collections;
|
||||
import org.apache.seatunnel.api.common.PluginIdentifier;
|
||||
import org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelSourcePluginDiscovery;
|
||||
|
||||
/** Build-time regression check against the actual engine, without database access. */
|
||||
public final class VerifyNativeDiscovery {
|
||||
public static void main(String[] args) {
|
||||
SeaTunnelSourcePluginDiscovery discovery = new SeaTunnelSourcePluginDiscovery();
|
||||
for (String name : new String[] {"Dameng-Native-CDC", "Kingbase-Native-CDC"}) {
|
||||
PluginIdentifier id = PluginIdentifier.of("seatunnel", "source", name);
|
||||
if (discovery.getPluginJarPaths(Collections.singletonList(id)).size() != 2) {
|
||||
throw new IllegalStateException("Expected native connector and CDC base: " + name);
|
||||
}
|
||||
System.out.println("Native discovery PASS: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户