Re: [HACKERS] Lock freeze ? in MVCC

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Inoue(at)tpf(dot)co(dot)jp (Hiroshi Inoue)
Cc: vadim(at)krs(dot)ru, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Lock freeze ? in MVCC
Date: 1999-04-29 06:01:00
Message-ID: 199904290601.CAA18074@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Do you say about the following stuff in ProcSleep() ?
>
> proc = (PROC *) MAKE_PTR(waitQueue->links.prev);
>
> /* If we are a reader, and they are writers, skip past them */
> for (i = 0; i < waitQueue->size && proc->prio > prio; i++)
> proc = (PROC *) MAKE_PTR(proc->links.prev);
>
> /* The rest of the queue is FIFO, with readers first, writers last */
> for (; i < waitQueue->size && proc->prio <= prio; i++)
> proc = (PROC *) MAKE_PTR(proc->links.prev);
>
> Seems above logic is only for 2 levels of priority(READ/WRITE).
> But it's difficult for me to propose a different design for this.

I think this is a classic priority inversion problem. If the process
holds a lock and is going for another, but their is a higher priority
process waiting for the lock, we have to consider that if we go to
sleep, all people waiting on the lock will have to wait for me to
complete in that queue, so we can either never have a process that
already holds any lock from being superceeded by a higher-priority
sleeping process, or we need to check the priority of all processes
waiting on _our_ locks and check when pulling stuff out of the lock
queue because someone of high priority could come while I am in the
queue waiting.

My recommendation is to not have this go-to-end of queue if there is
someone higher if I already hold _any_ kind of lock. I can easily make
that change if others agree.

It makes the code your are questioning active ONLY if I already don't
have some kind of lock. This may be the most efficient way to do
things, and may not lock things up like you have seen.

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael J Davis 1999-04-29 06:03:53 RE: [HACKERS] FYI: snapshot 4/28/1999 (fwd)
Previous Message Peter T Mount 1999-04-29 05:50:23 FYI: snapshot 4/28/1999 (fwd)