From 8926b83835fb9f0d90318e83150ca6645735140d Mon Sep 17 00:00:00 2001 From: Maxim Orlov Date: Wed, 23 Oct 2024 15:44:28 +0300 Subject: [PATCH v1] Hold XidGenLock to read TransamVariables->nextXid --- src/backend/storage/lmgr/predicate.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index 2030322f95..6dce4d8443 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -3419,9 +3419,6 @@ ReleasePredicateLocks(bool isCommit, bool isReadOnlySafe) topLevelIsDeclaredReadOnly = SxactIsReadOnly(MySerializableXact); /* - * We don't hold XidGenLock lock here, assuming that TransactionId is - * atomic! - * * If this value is changing, we don't care that much whether we get the * old or new value -- it is just used to determine how far * SxactGlobalXmin must advance before this transaction can be fully @@ -3429,7 +3426,9 @@ ReleasePredicateLocks(bool isCommit, bool isReadOnlySafe) * transaction to complete before freeing some RAM; correctness of visible * behavior is not affected. */ + LWLockAcquire(XidGenLock, LW_SHARED); MySerializableXact->finishedBefore = XidFromFullTransactionId(TransamVariables->nextXid); + LWLockRelease(XidGenLock); /* * If it's not a commit it's either a rollback or a read-only transaction -- 2.47.0