Additional write barrier in AdvanceXLInsertBuffer().

First, mark the xlblocks member with InvalidXLogRecPtr, then issue a
write barrier, then initialize it. That ensures that the xlblocks
member doesn't appear valid while the contents are being initialized.

In preparation for reading WAL buffer contents without a lock.

Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACVfFMfqD5oLzZSQQZWfXiJqd-NdX0_317veP6FuB31QWA@mail.gmail.com
Reviewed-by: Andres Freund
This commit is contained in:
Jeff Davis 2023-12-19 17:35:54 -08:00
parent c3a8e2a7cb
commit 766571be16

View File

@ -1932,6 +1932,14 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) XLOG_BLCKSZ);
/*
* Mark the xlblock with InvalidXLogRecPtr and issue a write barrier
* before initializing. Otherwise, the old page may be partially
* zeroed but look valid.
*/
pg_atomic_write_u64(&XLogCtl->xlblocks[nextidx], InvalidXLogRecPtr);
pg_write_barrier();
/*
* Be sure to re-zero the buffer so that bytes beyond what we've
* written will look like zeroes and not valid XLOG records...