:wave: Im trying to understand how flink batches/b...
# troubleshooting
z
👋 Im trying to understand how flink batches/buffers records in a sink. I've looked at a few TableAPI sink implementations and often they append records to a buffer and then flush once specified conditions are met (buffer length / time). • How does this work with checkpointing? • Will flink force a flush prior to checkpointing? • What happens to records buffered in the sink when a job dies? Additionally, does flink treat TableAPI sinks differently than DatastreamAPI sinks? Can I follow the same pattern to buffer records? Any docs/articles/code entrypoints would be greatly appreciated! gratitude thank you
y
Hi Zack, Flink would invoke the sink operator’s processElement (or SinkFunction.invoke(), etc) when it collects a record to be written out to the external system, and invoke the operator’s snapshotState() method when checkpointing. Buffering and flushing are regarded as internal implementations of the sink operator itself, and Flink infra has little knowledge of them. So if you found a buffering mechanism in the TableAPI sink operator, you should also be able to found the flushing mechanism somewhere in the operator’s codes. From my little experience, if an operator has a buffering optimization and it needs to achieve exactly-once semantics, it should flush the buffer out to downstream or external systems before checkpointing, or store the buffered records into states. Besides, Flink does provide some built-in helper classes to help sinks better get prepared before checkpoints, like https://nightlies.apache.org/flink/flink-docs-master/api/java/org/apache/flink/streaming/api/functions/sink/TwoPhaseCommitSinkFunction.html You may also refer to this article https://flink.apache.org/2018/02/28/an-overview-of-end-to-end-exactly-once-processing-in-apache-flink-with-apache-kafka-too/
🙌 1