Flink-CDC 关闭初始化读表锁, DDL 锁 Schema 锁, 使用增量或者全量或者指定偏移量

<dependency>
	<groupId>com.ververica</groupId>
	<artifactId>flink-sql-connector-mysql-cdc</artifactId>
	<version>2.2.1</version>
</dependency>

1, 关闭全局锁

情形: 

Snapshot step 3  的时候会进行锁表, 

Snapshot step 6  的时候会锁库

Snapshot step 7  的时候读全量表

According to the connector configuration both schema and data will be snapshotted
Snapshot step 1 - Preparing
Snapshot step 2 - Determining captured tables
Snapshot step 3 - Locking captured tables [hello.order]
Snapshot step 4 - Determining snapshot offset
Read binlog position of MySQL primary server
Snapshot step 5 - Reading structure of captured tablesAll eligible tables schema should be captured, capturing: [tcec.hello....
Snapshot step 6 - Persisting schema history
Releasing global read lock to enable MySQL writes
Writes to MySQL tables prevented for a total of 00:00:13.912
Snapshot step 7 - Snapshotting data
Snapshotting contents of 1 tables while still in transaction
For table 'hello.order' using select statement: 'SELECT * FROM `hello`.`order`'
Finished exporting 195 records for table

MySqlSnapshotChangeEventSource.class:147

Properties properties = new Properties();
properties.setProperty("debezium.snapshot.locking.mode", "none");
// 使用这个配置关闭全部锁表
properties.setProperty("test.disable.global.locking", "true");

DebeziumSourceFunction<String> sourceFunction = MySqlSource.<String>builder()
		.hostname("127.0.0.1")
		.port(3306)
		.username("root")
		.password("123456")
		.databaseList("hello")
		.tableList("order") //多个表逗号分隔
		.debeziumProperties(properties)
		.deserializer(new Config())
        .startupOptions(StartupOptions.specificOffset("mysql-bin.000002",123123));
		.build();

2,  初始化不读取全量数据, 使用增量模式

// 指定偏移量增量模式, 初始化不会读取数据
builder.startupOptions(StartupOptions.specificOffset("mysql-bin.000002",123123));


// 默认全量
public static StartupOptions initial() {
	return new StartupOptions(StartupMode.INITIAL, (String)null, (Integer)null, (Long)null);
}

// 从最开始的binlog 开始
public static StartupOptions earliest() {
	return new StartupOptions(StartupMode.EARLIEST_OFFSET, (String)null, (Integer)null, (Long)null);
}

// 从最后的binlog开始
public static StartupOptions latest() {
	return new StartupOptions(StartupMode.LATEST_OFFSET, (String)null, (Integer)null, (Long)null);
}

// 从指定的binlog开始
public static StartupOptions specificOffset(String specificOffsetFile, int specificOffsetPos) {
	return new StartupOptions(StartupMode.SPECIFIC_OFFSETS, specificOffsetFile, specificOffsetPos, (Long)null);
}

// 从指定binlog时间开始
public static StartupOptions timestamp(long startupTimestampMillis) {
	return new StartupOptions(StartupMode.TIMESTAMP, (String)null, (Integer)null, startupTimestampMillis);
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值