本文主要研究一下flink的ListCheckpointed
实例
public static class CounterSource
extends RichParallelSourceFunction<Long>
implements ListCheckpointed<Long> {
/** current offset for exactly once semantics */
private Long offset;
/** flag for job cancellation */
private volatile boolean isRunning = true;
@Override
public void run(SourceContext<Long> ctx) {
final Object lock = ctx.getCheckpointLock();
while (isRunning) {
// output and state update are atomic
synchronized (lock) {
ctx.collect(offset);
offset += 1;
}
}
}
@Override
public void cancel() {
isRunning = false;
}
@Override
public List<Long> snapshotState(long checkpointId, long checkpointTimestamp) {
return Collections.singletonList(offset);
}
@Override
public

本文深入探讨Flink中ListCheckpointed接口的实现原理,通过具体示例CounterSource,展示了如何通过该接口实现状态保存与恢复,确保Exactly-once语义。并详细解释了snapshotState和restoreState方法的作用。
最低0.47元/天 解锁文章
1468

被折叠的 条评论
为什么被折叠?



