Repository navigation
Fix shared snapshot slot ID locking - #2256
protectione055 wants to merge 1 commit into
Conversation
yjhjstz
left a comment
There was a problem hiding this comment.
Looks good to me. GpDropTempTables() was updating slotid under only the per-slot slotLock, while SharedSnapshotAdd() and SharedSnapshotLookup() scan slotid under SharedSnapshotLock. Since the two sides used different locks, a scan could race with the update. Taking SharedSnapshotLock first, then slotLock, fixes that.
I checked sharedsnapshot.c and found no path that holds slotLock and then waits on SharedSnapshotLock (the error path in getSharedSnapshot releases slotLock first), so the lock order is consistent and shouldn't deadlock. The extra exclusive lock only applies on session reset, which is rare.
Two optional suggestions:
- Add a comment near the
slotLockfield noting that the directory lock must be taken first. - Mention how the race was found (reproduction or code reading).
There was a problem hiding this comment.
Hi, @protectione055 welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!
GpDropTempTables() updates slotid under the per-slot lock, while SharedSnapshotAdd() and SharedSnapshotLookup() scan slot IDs under SharedSnapshotLock. These locks do not serialize the update with concurrent directory scans. Acquire SharedSnapshotLock exclusively before the existing per-slot lock when updating slotid during a session reset. Retain the per-slot lock for slot-local readers and release the locks in reverse order. Assisted-by: ChatGPT
Head branch was pushed to by a user without write access
6ae3a23 to
79aca01
Compare
|
Thanks for the review and suggestions.
I’ve added a comment next to
I found the locking mismatch while reading the code and haven’t constructed a test case that reproduces a failure. In theory, if a concurrent scan observed a partial |
What does this PR do?
GpDropTempTables()updatesslotidunder the per-slot lock, whileSharedSnapshotAdd()andSharedSnapshotLookup()scan slot IDs underSharedSnapshotLock. These accesses use different locks and can runconcurrently.
Acquire
SharedSnapshotLockin exclusive mode before the existingper-slot lock when updating
slotidduring a session reset. Thisserializes the update with directory scans while preserving protection
for per-slot readers. Release the locks in reverse order.
Type of Change
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
Adds an exclusive directory-lock acquisition when a session reset
updates its shared snapshot slot ID.
Checklist