Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 632f0fa

Browse filesBrowse 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
Copy full SHA for 632f0fa

File tree

Expand file treeCollapse file tree

1 file changed

+24
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-1
lines changed

‎src/backend/storage/lmgr/predicate.c

Copy file name to clipboardExpand all lines: src/backend/storage/lmgr/predicate.c
+24-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.