1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

Fix race condition in committing a serializable transaction

The finished transaction list can contain XIDs that are older than the
serializable global xmin. It's a short-lived state;
ClearOldPredicateLocks() removes any such transactions from the list,
and it's called whenever the global xmin advances. But if another
backend calls SummarizeOldestCommittedSxact() in that window, it will
call SerialAdd() on an XID that's older than the global xmin, or if
there are no more transactions running, when global xmin is
invalid. That trips the assertion in SerialAdd().

Fixes bug #18658 reported by Andrew Bille. Thanks to Alexander Lakhin
for analysis. Backpatch to all versions.

Discussion: https://www.postgresql.org/message-id/18658-7dab125ec688c70b%40postgresql.org
This commit is contained in:
Heikki Linnakangas 2024-10-21 09:49:21 +03:00
parent 57a36e890d
commit 1a43de5e0a

View File

@ -877,12 +877,17 @@ SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
LWLockAcquire(SerialControlLock, LW_EXCLUSIVE); LWLockAcquire(SerialControlLock, LW_EXCLUSIVE);
/* /*
* If no serializable transactions are active, there shouldn't be anything * If 'xid' is older than the global xmin (== tailXid), there's no need to
* to push out to the SLRU. Hitting this assert would mean there's * store it, after all. This can happen if the oldest transaction holding
* something wrong with the earlier cleanup logic. * back the global xmin just finished, making 'xid' uninteresting, but
* ClearOldPredicateLocks() has not yet run.
*/ */
tailXid = serialControl->tailXid; tailXid = serialControl->tailXid;
Assert(TransactionIdIsValid(tailXid)); if (!TransactionIdIsValid(tailXid) || TransactionIdPrecedes(xid, tailXid))
{
LWLockRelease(SerialControlLock);
return;
}
/* /*
* If the SLRU is currently unused, zero out the whole active region from * If the SLRU is currently unused, zero out the whole active region from