Lock on arbitrary string feature - Mailing list pgsql-hackers

From Lincoln Yeoh
Subject Lock on arbitrary string feature
Date
Msg-id 3.0.5.32.20010111154339.009fc100@192.228.128.13
Whole thread Raw
In response to Re: [PATCHES] Re: Recursion and SPI  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: Lock on arbitrary string feature
Re: Lock on arbitrary string feature
List pgsql-hackers
Hi,

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.

While the lock is held, other processes trying to do GETLOCK "string" will
block until the lock is released.

This feature can allow applications to better serialize things. For
example: inserting unique records. Cooperating applications could just do
something like:

GETLOCK "mytable.key2=1234";
SELECT count(*) from mytable where key2=1234 for update;
if count==0, insert the stuff.elsif count==1 update the stuff insteadelse something is wrong!

The lock will thus only affect applications interested in mytable where
key2=1234

In contrast the current alternatives appear to be either LOCK the entire
table (preventing ALL inserts and selects), or to create a UNIQUE
constraint (forcing complete rollbacks and restarts in event of a collision
:( ).

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.

Cheerio,
Link.







pgsql-hackers by date:

Previous
From: Tom Samplonius
Date:
Subject: Re: A post-7.1 wish-list.
Next
From: Zeugswetter Andreas SB
Date:
Subject: AW: AW: AW: Re: tinterval - operator problems on AIX