Re: [HACKERS] Lock freeze ? in MVCC - Mailing list pgsql-hackers

From Vadim Mikheev
Subject Re: [HACKERS] Lock freeze ? in MVCC
Date
Msg-id 3726E93A.520E2971@krs.ru
Whole thread Raw
In response to RE: [HACKERS] Lock freeze ? in MVCC  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
Responses RE: [HACKERS] Lock freeze ? in MVCC  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
List pgsql-hackers
Hiroshi Inoue wrote:
> 
> > However, I'm not sure that proposed changes will help in the next case:
> >
> > session-1 => begin;
> > session-1 => insert into tt values (1);       --RowExclusiveLock
> >
> > session-2 => begin;
> > session-2 => insert into tt values (2);       --RowExclusiveLock
> >
> > session-3 => begin;
> > session-3 => lock table tt;                   --AccessExclusiveLock
> >                 (conflicts with 1 & 2)
> >                                 ^
> > session-1 => lock table tt in share mode;     --ShareLock
> >                 (conflicts with 2 & 3)
> >                                     ^
> > This is deadlock situation and must be handled by
> > DeadLockCheck().
> >
> 
> It's really a deadlock ?
> Certainly end/abort of session-2 doesn't wakeup session-1/session3.

You're right again. 
First, I propose the next changes in LockResolveConflicts():

if someone is waiting for lock then we must not take them 
into account (and skip to check for conflicts with lock
holders) if

1. we already has lock with >= priority (currently, more  restrictive locks have greater priority);
or
2. lock requested doesn't conflict with lock of any waiters;
or
3. conflicting waiter is waiting for us: its lock conflicts  with locks we already hold, if any.

I foresee that we also will have to change lock queue ordering
code but I have to think about it more.

Vadim


pgsql-hackers by date:

Previous
From: Vadim Mikheev
Date:
Subject: Re: [HACKERS] Lock freeze ? in MVCC
Next
From: The Hermit Hacker
Date:
Subject: v6.5 Release Date ...