Skip to content

Commit 691c0df

Browse files
committed
Reset lastOverflowedXid on standby when needed
Currently, lastOverflowedXid is never reset. It's just adjusted on new transactions known to be overflowed. But if there are no overflowed transactions for a long time, snapshots could be mistakenly marked as suboverflowed due to wraparound. This commit fixes this issue by resetting lastOverflowedXid when needed altogether with KnownAssignedXids. Backpatch to all supported versions. Reported-by: Stan Hu Discussion: https://postgr.es/m/CAMBWrQ%3DFp5UAsU_nATY7EMY7NHczG4-DTDU%3DmCvBQZAQ6wa2xQ%40mail.gmail.com Author: Kyotaro Horiguchi, Alexander Korotkov Reviewed-by: Stan Hu, Simon Riggs, Nikolay Samokhvalov, Andrey Borodin, Dmitry Dolgov
1 parent 92224e4 commit 691c0df

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/backend/storage/ipc/procarray.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,24 +3298,41 @@ ExpireTreeKnownAssignedTransactionIds(TransactionId xid, int nsubxids,
32983298

32993299
/*
33003300
* ExpireAllKnownAssignedTransactionIds
3301-
* Remove all entries in KnownAssignedXids
3301+
* Remove all entries in KnownAssignedXids and reset lastOverflowedXid.
33023302
*/
33033303
void
33043304
ExpireAllKnownAssignedTransactionIds(void)
33053305
{
33063306
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
33073307
KnownAssignedXidsRemovePreceding(InvalidTransactionId);
3308+
3309+
/*
3310+
* Reset lastOverflowedXid. Currently, lastOverflowedXid has no use after
3311+
* the call of this function. But do this for unification with what
3312+
* ExpireOldKnownAssignedTransactionIds() do.
3313+
*/
3314+
procArray->lastOverflowedXid = InvalidTransactionId;
33083315
LWLockRelease(ProcArrayLock);
33093316
}
33103317

33113318
/*
33123319
* ExpireOldKnownAssignedTransactionIds
3313-
* Remove KnownAssignedXids entries preceding the given XID
3320+
* Remove KnownAssignedXids entries preceding the given XID and
3321+
* potentially reset lastOverflowedXid.
33143322
*/
33153323
void
33163324
ExpireOldKnownAssignedTransactionIds(TransactionId xid)
33173325
{
33183326
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
3327+
3328+
/*
3329+
* Reset lastOverflowedXid if we know all transactions that have been
3330+
* possibly running are being gone. Not doing so could cause an incorrect
3331+
* lastOverflowedXid value, which makes extra snapshots be marked as
3332+
* suboverflowed.
3333+
*/
3334+
if (TransactionIdPrecedes(procArray->lastOverflowedXid, xid))
3335+
procArray->lastOverflowedXid = InvalidTransactionId;
33193336
KnownAssignedXidsRemovePreceding(xid);
33203337
LWLockRelease(ProcArrayLock);
33213338
}

0 commit comments

Comments
 (0)