Hi all.
I've been back to this patch for a while recently. I witness that if a WAL writer works fast, the already flushed WAL buffers will be zeroed out and re-initialized for future use by AdvanceXLInsertBuffer in XLogBackgroundFlush, so that WALReadFromBuffers will miss even though the space of WAL buffer is enough. It is much more unfriendly for logical walsenders than physical walsenders, because logical ones consume WAL slower than physical ones due to the extra decoding phase. Seems that the aim of AdvanceXLInsertBuffer in WAL writer contradicts with our reading from WAL buffer. Any thoughts?