Flink CDC 整库实时同步示例仓库,基于 Flink 1.20 + flink-cdc 3.x,支持 MySQL → MySQL 和 MySQL → Paimon 两种同步模式。
| 模块 | 说明 |
|---|---|
| flink-demo | DataStream / SQL / CDC DDL / UDF / TableFunction 示例与 Mock 数据源 |
| cdc-mysql-sync | 整库同步核心:flink-cdc 3.x → JDBC sink,含 SchemaEvolver |
| cdc-paimon-sync | CDC → Apache Paimon 数据湖同步(MySQL + MongoDB) |
| e2e-tests | 端到端集成测试(Testcontainers) |
最简单的方式是使用 Docker Compose 一键启动所有服务:
# 1. 启动所有服务(MySQL + Flink)
chmod +x test-cdc.sh
./test-cdc.sh start
# 2. 访问 Web UI
# Flink UI: http://localhost:18081
# MySQL Source: localhost:33061
# MySQL Sink: localhost:33062
# 3. 运行测试
./test-ddl-changes.sh # DDL 变更测试
./test-load.sh # 性能测试
# 4. 停止服务
./test-cdc.sh stop
# 切换到 JDK 11
export JAVA_HOME=/Users/gaotingkai/Library/Java/JavaVirtualMachines/corretto-11.0.21/Contents/Home
export PATH="$JAVA_HOME/bin:$PATH"
# 编译(跳过测试)
./mvnw -DskipTests package
# 运行单元测试(排除集成测试)
./mvnw test -Dtest='!*IT,!*IntegrationTest,!*FlinkSqlWDSTest'
# 运行覆盖率报告
./mvnw verify -Djacoco.skip=false -pl cdc-mysql-sync
open cdc-mysql-sync/target/site/jacoco/index.html
修改 config.properties 中的 MySQL 连接信息后:
# 在 cdc-mysql-sync 目录下运行
java -cp target/cdc-mysql-sync-1.1.0-jar-with-dependencies.jar \
io.sophiadata.flink.sync.FlinkSqlWDS \
--config config.properties
详细说明见 FlinkSqlWDS.java。
提供完整的 Docker 测试环境,包括: - MySQL 源数据库和目标数据库 - Flink 集群 - 自动化测试脚本 - 性能测试工具
详细使用说明见 DOCKER_TEST_GUIDE.md。
| 测试类型 | 脚本 | 说明 |
|---|---|---|
| 基础功能 | ./test-cdc.sh start |
一键启动所有服务 |
| DDL 变更 | ./test-ddl-changes.sh |
测试 Schema 变更同步 |
| 性能测试 | ./test-load.sh |
大批量数据同步性能 |
| 集成测试 | ./mvnw test |
单元测试和集成测试 |
| 工具 | 状态 | 说明 |
|---|---|---|
| CI/CD | ✅ GitHub Actions | lint + unit + IT + package + CodeQL |
| 依赖更新 | ✅ Dependabot | 每周自动创建依赖 PR |
| 代码格式化 | ✅ spotless | google-java-format AOSP 风格 |
| 代码规范 | ✅ checkstyle | 阿里巴巴 Java 规范 |
| 测试覆盖率 | ✅ JaCoCo | 覆盖率报告已配置 |
| 安全扫描 | ✅ CodeQL | Java 安全静态分析 |
| 依赖审计 | ✅ dependency-review | GitHub 原生依赖安全审计 |
详细工程化文档见 docs/reliability/。
MySQL (Source) ──CDC──> Flink (cdc-mysql-sync) ──JDBC──> MySQL (Sink)
│
├── SchemaEvolver: 自动处理 schema 变更
└── CDBBatchSink: 批量写入 + 按表分组
sink_ 前缀扫码订阅 ima 知识库,获取大数据学习资料:

$ claude mcp add Bigdata_Code_Tutorial \
-- python -m otcore.mcp_server <graph>