Allow a no-wait lock acquisition to succeed in more cases.
Robert Haas <rhaas@postgresql.org>
Allow a no-wait lock acquisition to succeed in more cases. We don't determine the position at which a process waiting for a lock should insert itself into the wait queue until we reach ProcSleep(), and we may at that point discover that we must insert ourselves ahead of everyone who wants a conflicting lock, in which case we obtain the lock immediately. Up until now, a no-wait lock acquisition would fail in such cases, erroneously claiming that the lock couldn't be obtained immediately. Fix that by trying ProcSleep even in the no-wait case. No back-patch for now, because I'm treating this as an improvement to the existing no-wait feature. It could instead be argued that it's a bug fix, on the theory that there should never be any case whatsoever where no-wait fails to obtain a lock that would have been obtained immediately without no-wait, but I'm reluctant to interpret the semantics of no-wait that strictly. Robert Haas and Jingxian Li Discussion: http://postgr.es/m/CA+TgmobCH-kMXGVpb0BB-iNMdtcNkTvcZ4JBxDJows3kYM+GDg@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/storage/lmgr/lock.c | modified | +69 −50 |
| src/backend/storage/lmgr/proc.c | modified | +18 −2 |
| src/include/storage/proc.h | modified | +3 −1 |
| src/test/isolation/expected/lock-nowait.out | added | +9 −0 |
| src/test/isolation/isolation_schedule | modified | +1 −0 |
| src/test/isolation/specs/lock-nowait.spec | added | +28 −0 |
Discussion
- [PATCH] LockAcquireExtended improvement 19 messages · 2023-11-28 → 2024-05-23