Flink idea测试checkPoint

在Flink StreamExecutionEnvironment对应的configuration中新增配置execution.savepoint.path就可以在启动Flink任务的时候默认从上一次的状态中恢复过来

        Configuration configuration1 = new Configuration();
        //flink parallelism=16 savepoint state
//        configuration1.setString("execution.savepoint.path",
//                "file:///Users/wenbao/checkPoint/d8ca368f349922c36c20498e1bedb9e7/chk-1");
        //flink parallelism=3  savepoint state
        configuration1.setString("execution.savepoint.path",
                "file:///Users/wenbao/checkPoint/efc27bd1f33fcbd5eae9ab8431d64251/chk-1");
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(
                configuration1);

下面是测试hybird source从flink checkPoint中恢复的代码:
 

    public static void main(String[] args) throws Exception {
        
        Configuration configuration1 = new Configuration();
        //flink parallelism=16 savepoint state
//        configuration1.setString("execution.savepoint.path",
//                "file:///Users/wenbao/checkPoint/d8ca368f349922c36c20498e1bedb9e7/chk-1");
        //flink parallelism=3  savepoint state
        configuration1.setString("execution.savepoint.path",
                "file:///Users/wenbao/checkPoint/efc27bd1f33fcbd5eae9ab8431d64251/chk-1");
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(
                configuration1);
        env.setParallelism(4);
        env.enableCheckpointing(30000, CheckpointingMode.EXACTLY_ONCE);
        env.getCheckpointConfig().setCheckpointTimeout(2 * 60 * 1000);
        env.getCheckpointConfig().setTolerableCheckpointFailureNumber(Integer.MAX_VALUE);
        env.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
        env.getCheckpointConfig().enableExternalizedCheckpoints(
                ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
        env.setStateBackend(new FsStateBackend("file:///Users/wenbao/checkPoint"));
        
        Path path = Path.fromLocalFile(new File("a"));
        
        FileSource<String> source = FileSource.forRecordStreamFormat(new TextLineFormat(), path)
                .build();
        HybridSource<String> hybridSource =
                HybridSource.builder(source)
                        .addSource(
                                KafkaSource.<String>builder()
                                        .setStartingOffsets(
                                                OffsetsInitializer.timestamp(1648542406228L))
                                        .setBootstrapServers(
                                                "localhost:9092")
                                        .setTopics("wb_test")
                                        .setGroupId("wb-test")
                                        .setDeserializer(
                                                new KafkaRecordDeserializationSchema<String>() {
                                                    @Override
                                                    public void deserialize(
                                                            ConsumerRecord<byte[], byte[]> record,
                                                            Collector<String> out)
                                                            throws IOException {
                                                        out.collect(new String(record.value()));
                                                    }
                                                    
                                                    @Override
                                                    public TypeInformation<String> getProducedType() {
                                                        return TypeInformation.of(String.class);
                                                    }
                                                })
                                        .build())
                        .build();
        
        DataStreamSource<String> stringDataStreamSource = env.fromSource(hybridSource,
                WatermarkStrategy.noWatermarks(), "file-source", TypeInformation.of(String.class));
        
        stringDataStreamSource.print();
        
        env.execute("aaa");
        
    }

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值