aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2023-12-19 17:35:54 -0800
committerJeff Davis <jdavis@postgresql.org>2023-12-19 17:35:54 -0800
commit766571be16598b401b5527208847145edc6be1f4 (patch)
tree8b996fa24f62b557b285ff07123a1d7e79a56092 /src/backend/access/transam/xlog.c
parentc3a8e2a7cb16d55e3b757934b538cb8b8a0eab02 (diff)
downloadpostgresql-766571be16598b401b5527208847145edc6be1f4.tar.gz
postgresql-766571be16598b401b5527208847145edc6be1f4.zip
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
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 1c77daa611a..56e4d6fb022 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1933,6 +1933,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...
*/