forked from apache/flink-cdc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 7ced72b6426e9723f91933ef0144fdda4b9c072d Author: Hang Ruan <ruanhang1993@hotmail.com> Date: Thu Jun 8 17:01:39 2023 +0800 [mysql-cdc] Supports MYSQL_TYPE_TYPED_ARRAY column type when parsing the table map event This closes apache#2001 commit a847655ed68c4d5874ced69006686362f23140e7 Author: Leonard Xu <leonard@apache.org> Date: Thu Jun 8 15:33:54 2023 +0800 [mysql-cdc][hotfix] Optimize the error msg when binlog expire in source commit 32f77ef0075dfd2b522df07809ab2aea8ae6de54 Author: Leonard Xu <leonard@apache.org> Date: Wed Jun 7 17:49:41 2023 +0800 [mysql-cdc] Optimize the error msg when binlog expire or server id conflict This closes apache#2010. commit da5cbf54e6b219956088bb99cec44d93f1011ff7 Author: He Wang <wanghechn@qq.com> Date: Thu Jun 8 13:50:24 2023 +0800 [oceanbase] add jdbc options and support oracle mode (apache#1854) commit 0e221382601e352215091d9cd1cb59fa2175063b Author: Leonard Xu <leonard@apache.org> Date: Wed Jun 7 17:34:57 2023 +0800 [mysql-cdc] Add handler for catching async exceptions in snapshot reading executor This closes apache#2016. commit 15e5e4d34dc05edcbdcfe15ff906213352a2cd02 Author: Hang Ruan <ruanhang1993@hotmail.com> Date: Wed Jun 7 17:26:59 2023 +0800 [hotfix][mysql-cdc] Use session timezone instead of local time zone as the default server time zone This closes apache#2015. commit 13235e2f2dca73320988a430b765f1fafa8e8f26 Author: Hang Ruan <ruanhang1993@hotmail.com> Date: Wed Jun 7 17:22:07 2023 +0800 [mysql] Fix NullPointerException when database name or table name contains dot This closes apache#2006. commit 6aa0fc4de353473cb7cda844a432e3dd5ddf4fea Author: Hang Ruan <ruanhang1993@hotmail.com> Date: Thu Jan 12 02:18:52 2023 +0000 [mysql] Fix NullPointerException caused by mysql ignores the capitalization when splitting chunks commit e9fed740f55f7f1e675e5fe83f7e04efb5e3f866 Author: ehui <374488688@qq.com> Date: Tue Jun 6 13:06:03 2023 +0800 [sqlserver] Fix old change data that will be captured when the latest mode starts (apache#2176) commit d2ffa0902038e9aec0e2b92fa4e82a066d1b123f Author: Tyrantlucifer <tyrantlucifer@apache.org> Date: Mon Jun 5 23:15:33 2023 +0800 [core] support print configuration options for connectors (apache#2099) commit a00abf88178feb6a2c699129e1f6aefb005960c7 Author: He Wang <wanghechn@qq.com> Date: Mon Jun 5 16:40:54 2023 +0800 [oceanbase] support libobcdc 4.x and fix restore timestamp config (apache#2161) commit 061602d Author: ehui <374488688@qq.com> Date: Mon Jun 5 23:49:15 2023 +0800 oralce commit 8dc46cc Author: ehui <374488688@qq.com> Date: Mon Jun 5 00:18:50 2023 +0800 [oracle]
- Loading branch information
Showing
5 changed files
with
374 additions
and
5 deletions.
There are no files selected for viewing
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
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
248 changes: 248 additions & 0 deletions
248
...t/java/com/ververica/cdc/connectors/oracle/source/read/fetch/OracleScanFetchTaskTest.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,248 @@ | ||
/* | ||
* Copyright 2022 Ververica Inc. | ||
* | ||
* 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.ververica.cdc.connectors.oracle.source.read.fetch; | ||
|
||
import org.apache.flink.table.api.DataTypes; | ||
import org.apache.flink.table.types.DataType; | ||
|
||
import com.ververica.cdc.connectors.base.config.JdbcSourceConfig; | ||
import com.ververica.cdc.connectors.base.dialect.JdbcDataSourceDialect; | ||
import com.ververica.cdc.connectors.base.source.assigner.splitter.ChunkSplitter; | ||
import com.ververica.cdc.connectors.base.source.meta.split.SnapshotSplit; | ||
import com.ververica.cdc.connectors.base.source.meta.split.SourceRecords; | ||
import com.ververica.cdc.connectors.base.source.reader.external.IncrementalSourceScanFetcher; | ||
import com.ververica.cdc.connectors.oracle.source.OracleDialect; | ||
import com.ververica.cdc.connectors.oracle.source.OracleSourceTestBase; | ||
import com.ververica.cdc.connectors.oracle.source.config.OracleSourceConfig; | ||
import com.ververica.cdc.connectors.oracle.source.config.OracleSourceConfigFactory; | ||
import com.ververica.cdc.connectors.oracle.source.reader.fetch.OracleScanFetchTask; | ||
import com.ververica.cdc.connectors.oracle.source.reader.fetch.OracleSourceFetchTaskContext; | ||
import com.ververica.cdc.connectors.oracle.utils.OracleTestUtils; | ||
import com.ververica.cdc.connectors.oracle.utils.RecordsFormatter; | ||
import io.debezium.connector.oracle.OracleConnection; | ||
import io.debezium.data.Envelope; | ||
import io.debezium.jdbc.JdbcConnection; | ||
import io.debezium.pipeline.EventDispatcher; | ||
import io.debezium.pipeline.spi.OffsetContext; | ||
import io.debezium.relational.TableId; | ||
import io.debezium.schema.DataCollectionSchema; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.apache.kafka.connect.header.ConnectHeaders; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
import org.junit.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.ververica.cdc.connectors.oracle.source.utils.OracleConnectionUtils.createOracleConnection; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** Tests for {@link OracleScanFetchTask}. */ | ||
public class OracleScanFetchTaskTest extends OracleSourceTestBase { | ||
|
||
@Test | ||
public void testChangingDataInSnapshotScan() throws Exception { | ||
OracleTestUtils.createAndInitialize(OracleTestUtils.ORACLE_CONTAINER, "customer.sql"); | ||
|
||
String tableName = ORACLE_SCHEMA + ".CUSTOMERS"; | ||
|
||
OracleSourceConfigFactory sourceConfigFactory = | ||
getConfigFactory(new String[] {tableName}, 10); | ||
OracleSourceConfig sourceConfig = sourceConfigFactory.create(0); | ||
OracleDialect oracleDialect = new OracleDialect(sourceConfigFactory); | ||
|
||
String[] changingDataSql = | ||
new String[] { | ||
"UPDATE " + tableName + " SET address = 'Hangzhou' where id = 103", | ||
"DELETE FROM " + tableName + " where id = 102", | ||
"INSERT INTO " + tableName + " VALUES(102, 'user_2','Shanghai','123567891234')", | ||
"UPDATE " + tableName + " SET address = 'Shanghai' where id = 103", | ||
"UPDATE " + tableName + " SET address = 'Hangzhou' where id = 110", | ||
"UPDATE " + tableName + " SET address = 'Hangzhou' where id = 111", | ||
}; | ||
|
||
MakeChangeEventTaskContext makeChangeEventTaskContext = | ||
new MakeChangeEventTaskContext( | ||
sourceConfig, | ||
oracleDialect, | ||
createOracleConnection( | ||
sourceConfig.getDbzConnectorConfig().getJdbcConfig()), | ||
() -> executeSql(sourceConfig, changingDataSql)); | ||
|
||
final DataType dataType = | ||
DataTypes.ROW( | ||
DataTypes.FIELD("ID", DataTypes.BIGINT()), | ||
DataTypes.FIELD("NAME", DataTypes.STRING()), | ||
DataTypes.FIELD("ADDRESS", DataTypes.STRING()), | ||
DataTypes.FIELD("PHONE_NUMBER", DataTypes.STRING())); | ||
|
||
List<SnapshotSplit> snapshotSplits = getSnapshotSplits(sourceConfig, oracleDialect); | ||
|
||
String[] expected = | ||
new String[] { | ||
"+I[101, user_1, Shanghai, 123567891234]", | ||
"+I[102, user_2, Shanghai, 123567891234]", | ||
"+I[103, user_3, Shanghai, 123567891234]", | ||
"+I[109, user_4, Shanghai, 123567891234]", | ||
"+I[110, user_5, Hangzhou, 123567891234]", | ||
"+I[111, user_6, Hangzhou, 123567891234]", | ||
"+I[118, user_7, Shanghai, 123567891234]", | ||
"+I[121, user_8, Shanghai, 123567891234]", | ||
"+I[123, user_9, Shanghai, 123567891234]", | ||
}; | ||
|
||
List<String> actual = | ||
readTableSnapshotSplits(snapshotSplits, makeChangeEventTaskContext, 1, dataType); | ||
assertEqualsInAnyOrder(Arrays.asList(expected), actual); | ||
} | ||
|
||
private List<String> readTableSnapshotSplits( | ||
List<SnapshotSplit> snapshotSplits, | ||
OracleSourceFetchTaskContext taskContext, | ||
int scanSplitsNum, | ||
DataType dataType) | ||
throws Exception { | ||
IncrementalSourceScanFetcher sourceScanFetcher = | ||
new IncrementalSourceScanFetcher(taskContext, 0); | ||
|
||
List<SourceRecord> result = new ArrayList<>(); | ||
for (int i = 0; i < scanSplitsNum; i++) { | ||
SnapshotSplit sqlSplit = snapshotSplits.get(i); | ||
if (sourceScanFetcher.isFinished()) { | ||
sourceScanFetcher.submitTask( | ||
taskContext.getDataSourceDialect().createFetchTask(sqlSplit)); | ||
} | ||
Iterator<SourceRecords> res; | ||
while ((res = sourceScanFetcher.pollSplitRecords()) != null) { | ||
while (res.hasNext()) { | ||
SourceRecords sourceRecords = res.next(); | ||
result.addAll(sourceRecords.getSourceRecordList()); | ||
} | ||
} | ||
} | ||
|
||
sourceScanFetcher.close(); | ||
|
||
assertNotNull(sourceScanFetcher.getExecutorService()); | ||
assertTrue(sourceScanFetcher.getExecutorService().isTerminated()); | ||
|
||
return formatResult(result, dataType); | ||
} | ||
|
||
private List<String> formatResult(List<SourceRecord> records, DataType dataType) { | ||
final RecordsFormatter formatter = new RecordsFormatter(dataType); | ||
return formatter.format(records); | ||
} | ||
|
||
private List<SnapshotSplit> getSnapshotSplits( | ||
OracleSourceConfig sourceConfig, JdbcDataSourceDialect sourceDialect) { | ||
String databaseName = sourceConfig.getDatabaseList().get(0); | ||
List<TableId> tableIdList = | ||
sourceConfig.getTableList().stream() | ||
.map(tableId -> TableId.parse(databaseName + "." + tableId)) | ||
.collect(Collectors.toList()); | ||
final ChunkSplitter chunkSplitter = sourceDialect.createChunkSplitter(sourceConfig); | ||
|
||
List<SnapshotSplit> snapshotSplitList = new ArrayList<>(); | ||
for (TableId table : tableIdList) { | ||
Collection<SnapshotSplit> snapshotSplits = chunkSplitter.generateSplits(table); | ||
snapshotSplitList.addAll(snapshotSplits); | ||
} | ||
return snapshotSplitList; | ||
} | ||
|
||
public static OracleSourceConfigFactory getConfigFactory( | ||
String[] captureTables, int splitSize) { | ||
Properties debeziumProperties = new Properties(); | ||
debeziumProperties.setProperty("log.mining.strategy", "online_catalog"); | ||
debeziumProperties.setProperty("log.mining.continuous.mine", "true"); | ||
|
||
return (OracleSourceConfigFactory) | ||
new OracleSourceConfigFactory() | ||
.hostname(ORACLE_CONTAINER.getHost()) | ||
.port(ORACLE_CONTAINER.getOraclePort()) | ||
.username(ORACLE_CONTAINER.getUsername()) | ||
.password(ORACLE_CONTAINER.getPassword()) | ||
.databaseList(ORACLE_DATABASE) | ||
.tableList(captureTables) | ||
.debeziumProperties(debeziumProperties) | ||
.splitSize(splitSize); | ||
} | ||
|
||
private boolean executeSql(OracleSourceConfig sourceConfig, String[] sqlStatements) { | ||
JdbcConnection connection = | ||
createOracleConnection(sourceConfig.getDbzConnectorConfig().getJdbcConfig()); | ||
try { | ||
connection.setAutoCommit(false); | ||
connection.execute(sqlStatements); | ||
connection.commit(); | ||
} catch (SQLException e) { | ||
LOG.error("Failed to execute sql statements.", e); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
class MakeChangeEventTaskContext extends OracleSourceFetchTaskContext { | ||
|
||
private Supplier<Boolean> makeChangeEventFunction; | ||
|
||
public MakeChangeEventTaskContext( | ||
JdbcSourceConfig jdbcSourceConfig, | ||
OracleDialect oracleDialect, | ||
OracleConnection connection, | ||
Supplier<Boolean> makeChangeEventFunction) { | ||
super(jdbcSourceConfig, oracleDialect, connection); | ||
this.makeChangeEventFunction = makeChangeEventFunction; | ||
} | ||
|
||
@Override | ||
public EventDispatcher.SnapshotReceiver getSnapshotReceiver() { | ||
EventDispatcher.SnapshotReceiver snapshotReceiver = super.getSnapshotReceiver(); | ||
return new EventDispatcher.SnapshotReceiver() { | ||
|
||
@Override | ||
public void changeRecord( | ||
DataCollectionSchema schema, | ||
Envelope.Operation operation, | ||
Object key, | ||
Struct value, | ||
OffsetContext offset, | ||
ConnectHeaders headers) | ||
throws InterruptedException { | ||
snapshotReceiver.changeRecord(schema, operation, key, value, offset, headers); | ||
} | ||
|
||
@Override | ||
public void completeSnapshot() throws InterruptedException { | ||
snapshotReceiver.completeSnapshot(); | ||
// make change events | ||
makeChangeEventFunction.get(); | ||
Thread.sleep(120 * 1000); | ||
} | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.