Flink的checkpoint原理就不说了,官网以及博客都有说明,有兴趣的同学可以自行查阅。
本文主要从源码层面分析一下checkpoint是如何周期性触发的。
分析
首先通过如下配置启用CheckPoint
env.enableCheckpointing(1000);
不设置,则默认CheckPoint间隔为-1,即不启用CheckPoint
/** Periodic checkpoint triggering interval. */
private long checkpointInterval = -1; // disabled
如不设置则在构建jobGraph时checkpointInterval 会被赋值为Long.MAX_VALUE
StreamingJobGraphGenerator#configureCheckpointing
long interval = cfg.getCheckpointInterval();
if (interval < MINIMAL_CHECKPOINT_TIME) {
// interval of max value means disable periodic checkpoint
interval = Long.MAX_VALUE;
}
同时会初始化三个列表:
// collect the vertices that receive "trigger checkpoint" messages.
// currently, these are all the sources
List<JobVertexID> triggerVertices = new ArrayList<>();
// collect the vertices that need to acknowledge the checkpoint
// currently, these are all vertices
List<JobVertexID> ackVertices = new ArrayList<>(jobVertices.size());
// collect the vertices that receive "comm