]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Use barrier semantics when reading/writing writtenUpto
authorAlexander Korotkov <akorotkov@postgresql.org>
Sun, 3 May 2026 13:21:25 +0000 (16:21 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Sun, 3 May 2026 13:22:02 +0000 (16:22 +0300)
commitdfb690dd52375517138ce1ee0f20a831d9585778
treec0fb1fa162af269bd5d3e9f2c4b258bb9278e81f
parentc34a280c85b39b6e875afa56542a055d2b90b640
Use barrier semantics when reading/writing writtenUpto

The walreceiver publishes its write position lock-free via writtenUpto.
On weakly-ordered architectures (ARM, PowerPC), both sides of this
handshake need explicit barriers so that the lock-less reader sees a
consistent state.

Use pg_atomic_write_membarrier_u64() at both write sites and
pg_atomic_read_membarrier_u64() in GetWalRcvWriteRecPtr().  This matches
the barrier semantics that GetWalRcvFlushRecPtr() and other LSN-position
functions get implicitly from their spinlock acquire/release, and
protects from bugs caused by expectations of similar barrier guarantees
from different LSN-position functions.

Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/zqbppucpmkeqecfy4s5kscnru4tbk6khp3ozqz6ad2zijz354k%40w4bdf4z3wqoz
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
src/backend/replication/walreceiver.c
src/backend/replication/walreceiverfuncs.c