Skip to content

Commit 766571b

Browse files
committed
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
1 parent c3a8e2a commit 766571b

File tree

1 file changed

+8
-0
lines changed
  • src/backend/access/transam

1 file changed

+8
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,14 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
19321932

19331933
NewPage = (XLogPageHeader) (XLogCtl->pages + nextidx * (Size) XLOG_BLCKSZ);
19341934

1935+
/*
1936+
* Mark the xlblock with InvalidXLogRecPtr and issue a write barrier
1937+
* before initializing. Otherwise, the old page may be partially
1938+
* zeroed but look valid.
1939+
*/
1940+
pg_atomic_write_u64(&XLogCtl->xlblocks[nextidx], InvalidXLogRecPtr);
1941+
pg_write_barrier();
1942+
19351943
/*
19361944
* Be sure to re-zero the buffer so that bytes beyond what we've
19371945
* written will look like zeroes and not valid XLOG records...

0 commit comments

Comments
 (0)