Lock on arbitrary string feature

From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Lock on arbitrary string feature
Date: 2001-01-11 07:43:39
Message-ID: 3.0.5.32.20010111154339.009fc100@192.228.128.13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

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 instead
else 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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB 2001-01-11 09:04:54 AW: AW: AW: Re: tinterval - operator problems on AIX
Previous Message Mike Cannon-Brookes 2001-01-11 07:28:34 RE: PostgreSQL v7.1BETA3 Bundled and Available ...

Browse pgsql-patches by date

  From Date Subject
Next Message Adam Haberlach 2001-01-11 17:38:41 Re: Lock on arbitrary string feature
Previous Message Tom Lane 2001-01-11 03:45:03 Re: patch for BETWEEN [ASYMMETRIC|SYMMETRIC]