Re: Lock on arbitrary string feature

From: Jan Wieck <janwieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Lock on arbitrary string feature
Date: 2001-01-11 19:57:04
Message-ID: 200101111957.OAA04649@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my> writes:
> > Has anyone any input to offer on adding an arbitrary locking feature?
>
> > Where
> > GETLOCK "string" will lock on "string", the lock being only released at the
> > end of a transaction.
>
> > Any comments, suggestions or tips would be welcome. It looks like quite a
> > complex thing to do - I've only just started looking at the postgresql
> > internals and the lock manager.
>
> A lock is basically an entry in a shared hash table, so you could
> implement this just by having a different kind of key (ie, the given
> string) for these sorts of locks.
>
> However, the whole thing strikes me as more of an ugly kluge than a
> clean solution to the real problem. If you're not using a UNIQUE
> constraint then you're relying on application logic to guarantee
> consistency, which is bad. If you do have a UNIQUE constraint and
> want to layer this sort of application lock on top of it, then you
> still have the problem of unexpected failures if some instance/portion
> of your application does inserts without remembering to get the
> application-level lock. So, as Vadim remarked, doing the insert and
> rolling back to a savepoint on failure would be a much better answer.

You're right that it's ugly, but at least it'd be a temporary
"solution" for the fact that we cannot catch exceptions in
triggers yet. So the if/else logic will currently not work
reliable in a trigger without beeing able to lock before the
SELECT.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-01-11 20:30:22 Overprotectiveness in DefineQueryRewrite?
Previous Message Oleg Bartunov 2001-01-11 19:22:09 Re: AW: Re: GiST for 7.1 !!

Browse pgsql-patches by date

  From Date Subject
Next Message Lincoln Yeoh 2001-01-12 02:37:39 Re: Lock on arbitrary string feature
Previous Message Tom Lane 2001-01-11 18:26:19 Re: Lock on arbitrary string feature