Re: Order of granting with many waiting on one lock - Mailing list pgsql-general

From Pavan Deolasee
Subject Re: Order of granting with many waiting on one lock
Date
Msg-id CABOikdOMUvOwW-0QqiKodHQOvX-uqcyE+DiN0+PcAPJZGNtSzg@mail.gmail.com
Whole thread Raw
In response to Order of granting with many waiting on one lock  (Chris Angelico <rosuav@gmail.com>)
Responses Re: Order of granting with many waiting on one lock  (Chris Angelico <rosuav@gmail.com>)
List pgsql-general
On Mon, Feb 11, 2013 at 12:26 PM, Chris Angelico <rosuav@gmail.com> wrote:
> Is there any sort of guarantee that all
> the processes will eventually get a turn, or could two processes
> handball the lock to each other and play keepings-off against the
> other eighteen?
>

That should not happen. There are instances when a lock requester will
be promoted ahead of others to avoid deadlock, but in the scenario you
described, no single process will starve forever. See following
comment in ProcSleep() function under src/backend/storage/lmgr/proc.c
which is self-explanatory.

/*
     * Determine where to add myself in the wait queue.
     *
     * Normally I should go at the end of the queue.  However, if I already
     * hold locks that conflict with the request of any previous waiter, put
     * myself in the queue just in front of the first such waiter. This is not
     * a necessary step, since deadlock detection would move me to before that
     * waiter anyway; but it's relatively cheap to detect such a conflict
     * immediately, and avoid delaying till deadlock timeout.
     *
     * Special case: if I find I should go in front of some waiter, check to
     * see if I conflict with already-held locks or the requests before that
     * waiter.  If not, then just grant myself the requested lock immediately.
     * This is the same as the test for immediate grant in LockAcquire, except
     * we are only considering the part of the wait queue before my insertion
     * point.
     */

Thanks,
Pavan

--
Pavan Deolasee
http://www.linkedin.com/in/pavandeolasee

pgsql-general by date:

Previous
From: Chris Angelico
Date:
Subject: Order of granting with many waiting on one lock
Next
From: Chris Angelico
Date:
Subject: Re: Order of granting with many waiting on one lock