Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 234f6d0

Browse files
committed
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
1 parent e9959ff commit 234f6d0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/backend/storage/lmgr/predicate.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,17 @@ SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
877877
LWLockAcquire(SerialControlLock, LW_EXCLUSIVE);
878878

879879
/*
880-
* If no serializable transactions are active, there shouldn't be anything
881-
* to push out to the SLRU. Hitting this assert would mean there's
882-
* something wrong with the earlier cleanup logic.
880+
* If 'xid' is older than the global xmin (== tailXid), there's no need to
881+
* store it, after all. This can happen if the oldest transaction holding
882+
* back the global xmin just finished, making 'xid' uninteresting, but
883+
* ClearOldPredicateLocks() has not yet run.
883884
*/
884885
tailXid = serialControl->tailXid;
885-
Assert(TransactionIdIsValid(tailXid));
886+
if (!TransactionIdIsValid(tailXid) || TransactionIdPrecedes(xid, tailXid))
887+
{
888+
LWLockRelease(SerialControlLock);
889+
return;
890+
}
886891

887892
/*
888893
* If the SLRU is currently unused, zero out the whole active region from

0 commit comments

Comments
 (0)