Re: Snapshot related assert failure on skink
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andres Freund <andres@anarazel.de>
Cc: Tomas Vondra <tomas@vondra.me>, Thomas Munro <thomas.munro@gmail.com>,
pgsql-hackers@postgresql.org, Robert Haas <robertmhaas@gmail.com>
Date: 2025-03-23T16:43:05Z
Lists: pgsql-hackers
On 21/03/2025 17:16, Andres Freund wrote: > Am I right in understanding that the only scenario (when in > STANDBY_SNAPSHOT_READY), where ExpireOldKnownAssignedTransactionIds() would > "legally" remove a transaction, rather than the commit / abort records doing > so, is if the primary crash-restarted while transactions were ongoing? > > Those transactions won't have a commit/abort records and thus won't trigger > ExpireTreeKnownAssignedTransactionIds(), which otherwise would have updated > ->xactCompletionCount? Correct. > When writing the snapshot caching patch, I tried to make sure that all the > places that maintain ->latestCompletedXid also update > ->xactCompletionCount. Afaict that's still the case. Which, I think, means > that we're also missing calls to MaintainLatestCompletedXidRecovery()? Yep, I was just looking at that too. > If latestCompletedXid is incorrect visibility determinations end up wrong... I think it happens to work, because the transactions are effectively aborted. latestCompletedXid is used to initialize xmax in GetSnapshotData. If, for example, latestCompletedXid is incorrectly set to 1000 even though XID 1001 already aborted, a snapshot with xmax=1000 still correctly considers XID 1001 as "not visible". As soon as a transaction commits, latestCompletedXid is fixed. AFAICS we could skip updating latestCompletedXid on aborts altogether and rename it to latestCommittedXid. But it's hardly worth optimizing for aborts. For the same reason, I believe the assertion failure we're discussing here is also harmless. Even though the reused snapshot has a smaller xmin than expected, all those transactions aborted and are thus not visible anyway. In any case, let's be tidy and fix both latestCompletedXid and xactCompletionCount. -- Heikki Linnakangas Neon (https://neon.tech)
Commits
-
Fix rare assertion failure in standby, if primary is restarted
- 66235baab72b 14.18 landed
- b30c77a0e480 15.13 landed
- 2f33de3cdbc8 16.9 landed
- 302ce5bd93b4 17.5 landed
- 2817525f0d56 18.0 landed
-
Remove unnecessary GetTransactionSnapshot() calls
- 952365cded63 18.0 cited
-
Update TransactionXmin when MyProc->xmin is updated
- 578a7fe7b6f8 18.0 cited
-
Replace known_assigned_xids_lck with memory barriers.
- 119c23eb9819 17.0 cited
-
snapshot scalability: cache snapshots using a xact completion counter.
- 623a9ba79bbd 14.0 cited