A writer that writes data in blocks to a file channel. The writer receives the data blocks in the form of {@link org.apache.flink.core.memory.MemorySegment}, which it writes entirely to the channel, regardless of how space in the segment is used. The writing happens in an asynchronous fashion. That is, a write request is not processed by the thread that issues it, but by an asynchronous writer thread. Once the request is done, the asynchronous writer adds the MemorySegment to a
return queue where it can be popped by the worker thread, to be reused. The return queue is in this case a {@link java.util.concurrent.LinkedBlockingQueue}, such that the working thread blocks until the request has been served, if the request is still pending when the it requires the segment back.
Typical write behind is realized, by having a small set of segments in the return queue at all times. When a memory segment must be written, the request is issued to the writer and a new segment is immediately popped from the return queue. Once too many requests have been issued and the I/O thread cannot keep up, the working thread naturally blocks until another segment is available again.