Flink CDC调查

Flink CDC

一些参考文档

源码层面深入

  1. flink调用代码示例如下:
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;
import com.alibaba.ververica.cdc.debezium.StringDebeziumDeserializationSchema;
import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;

public class MySqlBinlogSourceExample {
  public static void main(String[] args) throws Exception {
    SourceFunction<String> sourceFunction = MySQLSource.<String>builder()
      .hostname("localhost")
      .port(3306)
      .databaseList("inventory") // monitor all tables under inventory database
      .username("flinkuser")
      .password("flinkpw")
      .deserializer(new StringDebeziumDeserializationSchema()) // converts SourceRecord to String
      .build();

    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    env
      .addSource(sourceFunction)
      .print().setParallelism(1); // use parallelism 1 for sink to keep message ordering

    env.execute();
  }
}
  1. flink-cdc-connectors这个项目的Mysql读取相关的UML类图,整理如下:


    flink_cdc_MySQLSource.png
  • 上步骤的重点为一个Mysql的source类,即com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
    此为一个builder,进行相关参数和启动模式的梳理,最后创建一个debezium读取的类:
    com.alibaba.ververica.cdc.debezium.DebeziumSourceFunction,此为flink的一个SourceFunction,
    由它进行snapshot和增量binlog的读取。
    该类的代码描述:
/**
 * The {@link DebeziumSourceFunction} is a streaming data source that pulls captured change data
 * from databases into Flink.
 *
 * <p>There are two workers during the runtime. One worker periodically pulls records from the
 * database and pushes the records into the {@link Handover}. The other worker consumes the records
 * from the {@link Handover} and convert the records to the data in Flink style. The reason why
 * don't use one workers is because debezium has different behaviours in snapshot phase and
 * streaming phase.
 *
 * <p>Here we use the {@link Handover} as the buffer to submit data from the producer to the
 * consumer. Because the two threads don't communicate to each other directly, the error reporting
 * also relies on {@link Handover}. When the engine gets errors, the engine uses the {@link
 * DebeziumEngine.CompletionCallback} to report errors to the {@link Handover} and wakes up the
 * consumer to check the error. However, the source function just closes the engine and wakes up the
 * producer if the error is from the Flink side.
 *
 * <p>If the execution is canceled or finish(only snapshot phase), the exit logic is as same as the
 * logic in the error reporting.
 *
 * <p>The source function participates in checkpointing and guarantees that no data is lost during a
 * failure, and that the computation processes elements "exactly once".
 *
 * <p>Note: currently, the source function can't run in multiple parallel instances.
 *
 * <p>Please refer to Debezium's documentation for the available configuration properties:
 * https://debezium.io/documentation/reference/1.2/development/engine.html#engine-properties
 */
  1. CDC具体调用流程图汇总


    flink_mysql_cdc.png

初步结论

  • 目前由于使用debezium server进行数据同步,目前只支持单并发;多并发的实现issue中反馈正在开发中,待新版本确认;
  • 省去了kafka和debezium的部署,整体架构较简单;
  • 如果现架构既有kafka部署,而且希望中间缓存解耦,或者需要做多topic多分区以提高并发度的话;目前还是得保留kafka。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 一. 背景 数据准实时复制(CDC)是目前行内实时数据需求大量使用的技术,目前行内已经大量使用IBM CDC 软件...
    jianwbj阅读 3,991评论 0 2
  • ## Flink CDC ### 一些参考文档 - 简介 https://developer.aliyun.com...
    andy_1bde阅读 3,418评论 1 0
  • 一. Flink 1.9 新特性 总的变更:https://issues.apache.org/jira/secu...
    sj_91d7阅读 3,373评论 0 2
  • 表情是什么,我认为表情就是表现出来的情绪。表情可以传达很多信息。高兴了当然就笑了,难过就哭了。两者是相互影响密不可...
    Persistenc_6aea阅读 131,008评论 2 7
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 9,235评论 0 4

友情链接更多精彩内容