pgsql: Export subxip[] for snapshots taken during recovery. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Export subxip[] for snapshots taken during recovery.
Date
Msg-id E1wzJSC-00000002EZ5-2U8k@gemulon.postgresql.org
Whole thread
List pgsql-committers
Export subxip[] for snapshots taken during recovery.

A snapshot taken during recovery stores all of its in-progress XIDs in
subxip, every running top-level XID included, leaving xip empty.  Unlike
with other snapshots, its suboverflowed flag does not mean that subxip
is redundant.  We nevertheless treated it that way during snapshot
export, so an importing session could see in-progress transactions as
aborted.  This misbehavior could also lead to hint bits being
incorrectly set on the standby; affected tuples then wrongly appeared
visible or invisible to sessions that never imported the snapshot.

To fix, teach snapshot export to include the subxip[] array regardless
of the overflow flag when the snapshot is taken during recovery.  This
is in line with how CopySnapshot() and SerializeSnapshot() already
handle the same issue.

Claude Code diagnosed this problem.  The committed TAP test is a
simplified version of the one that it wrote to demonstrate this bug.

Oversight in commit 6c2003f8a, which enabled snapshot export and import
during recovery.

Author: Peter Geoghegan <pg@bowt.ie>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Bug: #17846
Discussion: https://postgr.es/m/CAH2-WzmHVeYY%3Dpjz9x8DhhxVjXHX0pvoQ-MdiB1Tt6%3Do2GTiKg%40mail.gmail.com
Discussion: https://postgr.es/m/17846-1a0e5ce976f4c01a@postgresql.org
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2ae67ada74d9e8407e4286414dfddf5d157f4dc3

Modified Files
--------------
src/backend/utils/time/snapmgr.c                   |  58 ++++++++----
src/test/recovery/meson.build                      |   1 +
src/test/recovery/t/056_standby_snapshot_export.pl | 104 +++++++++++++++++++++
3 files changed, 147 insertions(+), 16 deletions(-)


pgsql-committers by date:

Previous
From: Masahiko Sawada
Date:
Subject: pgsql: Fix crash in subscription refresh on concurrent relation drop.
Next
From: Andrew Dunstan
Date:
Subject: pgsql: Pin two ctype-dependent test_regex_utf8 cases to pg_c_utf8