Skip to content

Commit 632f0fa

Browse files
committed
Repair some flakiness in CheckTargetForConflictsIn.
When we release and reacquire SerializableXactHashLock, we must recheck whether an R/W conflict still needs to be flagged, because it could have changed under us in the meantime. And when we release the partition lock, we must re-walk the list of predicate locks from the beginning, because our pointer could get invalidated under us. Bug report #5952 by Yamamoto Takashi. Patch by Kevin Grittner.
1 parent 38d15f1 commit 632f0fa

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/backend/storage/lmgr/predicate.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,17 @@ CheckTargetForConflictsIn(PREDICATELOCKTARGETTAG *targettag)
37573757
LWLockRelease(partitionLock);
37583758
LWLockRelease(SerializablePredicateLockListLock);
37593759
LWLockAcquire(partitionLock, LW_SHARED);
3760+
3761+
/*
3762+
* The list may have been altered by another process
3763+
* while we weren't holding the partition lock. Start
3764+
* over at the front.
3765+
*/
3766+
nextpredlock = (PREDICATELOCK *)
3767+
SHMQueueNext(&(target->predicateLocks),
3768+
&(target->predicateLocks),
3769+
offsetof(PREDICATELOCK, targetLink));
3770+
37603771
LWLockAcquire(SerializableXactHashLock, LW_SHARED);
37613772
}
37623773
}
@@ -3770,7 +3781,19 @@ CheckTargetForConflictsIn(PREDICATELOCKTARGETTAG *targettag)
37703781
LWLockRelease(SerializableXactHashLock);
37713782
LWLockAcquire(SerializableXactHashLock, LW_EXCLUSIVE);
37723783

3773-
FlagRWConflict(sxact, (SERIALIZABLEXACT *) MySerializableXact);
3784+
/*
3785+
* Re-check after getting exclusive lock because the other
3786+
* transaction may have flagged a conflict.
3787+
*/
3788+
if (!SxactIsRolledBack(sxact)
3789+
&& (!SxactIsCommitted(sxact)
3790+
|| TransactionIdPrecedes(GetTransactionSnapshot()->xmin,
3791+
sxact->finishedBefore))
3792+
&& !RWConflictExists(sxact,
3793+
(SERIALIZABLEXACT *) MySerializableXact))
3794+
{
3795+
FlagRWConflict(sxact, (SERIALIZABLEXACT *) MySerializableXact);
3796+
}
37743797

37753798
LWLockRelease(SerializableXactHashLock);
37763799
LWLockAcquire(SerializableXactHashLock, LW_SHARED);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy