Reputation: 41
I am reading the flink examples here https://ci.apache.org/projects/flink/flink-docs-release-1.8/dev/stream/state/state.html, and can not figure out the point of the existence of the synchronized block.
I have googled a lot and can not find useful answers, from flink's documentation, for each parallelism there will be a state instance, and also the run method in one instance of CounterSource will not be called from different threads, so what is the point for the below code
val lock = ctx.getCheckpointLock
while (isRunning) {
// output and state update are atomic
lock.synchronized({
ctx.collect(offset)
offset += 1
})
}
Upvotes: 4
Views: 999
Reputation: 43499
Checkpointing occurs in another thread. The purpose of this lock is to prevent the source from modifying its state while a checkpoint is taking a snapshot of the state.
Upvotes: 3