When writing custom checkpointed sources for Flink, one must make sure that emitting elements downstream, checkpointing and watermarks are emitted in a synchronized fashion. This is done by acquiring StreamContext.getCheckpointLock
Flink 1.10 introduced a deprecation to StreamTask.getCheckpointLock and is now recommending the use of MailboxExecutor for operation which require such synchronization.
I have a custom source implementation which is split into multiple phases. A SourceFunction[T] for reading file locations and an OneInputStreamOperator for downloading and emitting these elements downstream. Up until now, I used StreamSourceContexts.getSourceContext to receive the SourceContext used to emit elements, which looked as follows:
ctx = StreamSourceContexts.getSourceContext(
getOperatorConfig.getTimeCharacteristic,
getProcessingTimeService,
getContainingTask.getCheckpointLock,
getContainingTask.getStreamStatusMaintainer,
output,
getRuntimeContext.getExecutionConfig.getAutoWatermarkInterval,
-1
)
And this context is being used throughout the code to emit elements and watermarks:
ctx.getCheckpointLock.synchronized(ctx.collect(item))
ctx.getCheckpointLock.synchronized(ctx.emitWatermark(watermark))
Is using the checkpoint lock still the preferred way to emit elements downstream? Or is it now recommended that we use MailboxExecutor instead and make collection and watermark inside the mailbox execution thread?