pgsql: Use barrier semantics when reading/writing writtenUpto

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use barrier semantics when reading/writing writtenUpto
Date: 2026-05-03 13:22:22
Message-ID: E1wJWm6-000Cwu-0a@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)anarazel(dot)de>
Discussion: https://postgr.es/m/zqbppucpmkeqecfy4s5kscnru4tbk6khp3ozqz6ad2zijz354k%40w4bdf4z3wqoz
Author: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dfb690dd52375517138ce1ee0f20a831d9585778

Modified Files
--------------
src/backend/replication/walreceiver.c | 2 +-
src/backend/replication/walreceiverfuncs.c | 14 +++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-05-03 18:21:13 pgsql: Mark modified the FSM buffer as dirty during recovery
Previous Message Andrew Dunstan 2026-05-01 19:18:14 pgsql: Add missing connection validation in ECPG