自动重试配置
本文提供Flink自动重试场景的实施思路、配置示例和验证方式,可作为实际项目配置参考。
案例
实时同步配置自动重试
解决方案
修改作业启动配置


{
"execution.checkpointing.interval": "10000",
"restart-strategy.fixed-delay.delay": "60s",
"restart-strategy.type": "fixed-delay",
"restart-strategy.fixed-delay.attempts": 10,
"state.backend.type": "filesystem",
"state.checkpoints.dir": "file:///Users/ispong/flink",
"execution.checkpointing.externalized-checkpoint-retention": "RETAIN_ON_CANCELLATION"
}
| 配置项 | 说明 |
|---|---|
| restart-strategy | 重试规则,none:不重试,fixed-delay:固定间隔时间重试(推荐),failure-rate:在给定时间窗口内重试一定次数 |
| restart-strategy.fixed-delay.attempts | 重试次数 |
| restart-strategy.fixed-delay.delay | 重试间隔时间 |
| state.backend.type | checkpoint方式,filesystem文件 |
| state.checkpoints.dir | checkpoint存储地址 |
| execution.checkpointing.interval | 间隔多久记录一次checkpoint,单位毫秒 |
CREATE TABLE from_table
(
username STRING,
age INT
) WITH ( 'connector' = 'mysql-cdc',
'hostname' = 'localhost',
'port' = '30306',
'username' = 'ispong',
'password' = 'ispong123',
'database-name' = 'isxcode_db',
'table-name' = 'cdc_source',
'scan.incremental.snapshot.enabled' = 'false',
'server-time-zone' = 'UTC',
'scan.startup.mode' = 'latest-offset'
);
CREATE TABLE target_table
(
username STRING,
age INT,
PRIMARY KEY (username) NOT ENFORCED
) WITH ( 'connector' = 'jdbc',
'url' = 'jdbc:mysql://localhost:30306/isxcode_db?useSSL=false&allowPublicKeyRetrieval=true',
'driver' = 'com.mysql.cj.jdbc.Driver',
'table-name' = 'cdc_target',
'username' = 'ispong',
'password' = 'ispong123');
INSERT INTO target_table
select *
from from_table;
指定checkpoint路径恢复
指定具体某个point文件进行恢复
{
"execution.checkpointing.interval": "10000",
"restart-strategy.fixed-delay.delay": "60s",
"restart-strategy.type": "fixed-delay",
"restart-strategy.fixed-delay.attempts": 10,
"state.backend.type": "filesystem",
"state.checkpoints.dir": "file:///Users/ispong/flink",
"execution.savepoint.path": "file:///Users/ispong/flink/948eeadc5c91d9d3da00046304874ce8/chk-4",
"execution.checkpointing.externalized-checkpoint-retention": "RETAIN_ON_CANCELLATION"
}

