开发者社区 > 大数据与机器学习 > 实时计算 Flink > 正文

Flink CDC改成这样还是不行呢?

Flink CDC改成这样还是不行呢?ca1d34834e98db9df1d0279ad8742f1c.png

展开
收起
真的很搞笑 2023-11-06 20:03:02 42 0
2 条回答
写回答
取消 提交回答
  • 你可以先看看flink,如何配置checkpoint配合自动重启,此回答整理自钉群“Flink CDC 社区”

    2023-11-08 07:41:00
    赞同 展开评论 打赏
  • 看起来你的Flink CDC代码中存在一些错误和问题。以下是我发现的一些问题和建议:

    1. 在设置并行度时,你使用了SetParaLLeLism(TASK_PARALLELISM),但这并不是正确的设置并行度的方法。应该使用setParallelism(TASK_PARALLELISM)来设置并行度。
    2. 在设置checkpoint模式时,你使用了env.getCheckpointConfigO).setCheckpointingMode(CheckpointingMode.EXACTLY_oNCE),但这里缺少了对getCheckpointConfig()的调用。应该使用getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE)
    3. 在设置checkpoint间隔时,你使用了env.getcheckpointConfig().setcheckpointIntervaL(6ooo0),但这里使用了错误的函数名和参数。应该使用setCheckpointInterval(60000)来设置checkpoint间隔为60秒。
    4. 在设置checkpoint存储时,你使用了env.getCheckpointConfigO).setCheckpointStorage(new FileSystemCheckpointStorage( checkpointDirectory: "file://,但这里缺少了对getCheckpointConfig()的调用,并且参数的格式不正确。应该使用FileSystemCheckpointStorage来指定checkpoint存储路径,例如:new FileSystemCheckpointStorage(new Path("file:///path/to/checkpoint/directory"))
    5. 在启用checkpoint并设置checkpoint间隔和模式时,你使用了env.enabLeCheckpointing( interval: 6oooo, CheckpointingMode.EXACTLY_ONCE),但这里使用了错误的函数名和参数。应该使用enableCheckpointing(60000)来启用checkpoint并设置checkpoint间隔为60秒。

    综上所述,你的代码可以修改为以下形式:

    // 创建执行环境
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(TASK_PARALLELISM); // 设置并行度
    
    // 设置checkpoint相关配置
    CheckpointConfig checkpointConfig = env.getCheckpointConfig();
    checkpointConfig.setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE); // 设置checkpoint模式为Exactly Once
    checkpointConfig.setCheckpointInterval(60000); // 设置checkpoint间隔为60秒
    checkpointConfig.enableUnalignedcheckpoints(); // 启用非对齐checkpoint
    checkpointConfig.setExternalizedcheckpointcleanup(CheckpointConfig.ExternalizedcheckpointCleanupMode.RETAIN_ON_FAILURE); // 设置在失败时保留外部checkpoint
    
    // 启用checkpoint并指定存储路径
    FileSystemCheckpointStorage checkpointStorage = new FileSystemCheckpointStorage(new Path("file:///path/to/checkpoint/directory"));
    checkpointConfig.setCheckpointStorage(checkpointStorage); // 设置checkpoint存储路径
    
    // 启用checkpointing并设置相关参数
    env.enableCheckpointing(60000); // 启用checkpointing并设置间隔为60秒
    
    2023-11-07 11:16:52
    赞同 展开评论 打赏

实时计算Flink版是阿里云提供的全托管Serverless Flink云服务,基于 Apache Flink 构建的企业级、高性能实时大数据处理系统。提供全托管版 Flink 集群和引擎,提高作业开发运维效率。

相关产品

  • 实时计算 Flink版
  • 相关电子书

    更多
    Flink CDC Meetup PPT - 龚中强 立即下载
    Flink CDC Meetup PPT - 王赫 立即下载
    Flink CDC Meetup PPT - 覃立辉 立即下载