RE: User locks code - Mailing list pgsql-hackers

From Mikheev, Vadim
Subject RE: User locks code
Date
Msg-id 3705826352029646A3E91C53F7189E32016743@sectorbase2.sectorbase.com
Whole thread Raw
In response to User locks code  ("Mikheev, Vadim" <vmikheev@SECTORBASE.COM>)
List pgsql-hackers
> Would your suggested implementation allow locking on an
> arbitrary string?

Well, placing string in LOCKTAG is not good so we could
create auxilary hash table in shmem to keep such strings
and use string' address as part of LOCKTAG. New function
(LockRelationKey?) in lmgr.c would first find/place
key in that table, than construct LOCKTAG and call
LockAcquire.
Possible syntax:

LOCK TABLE relation IN {SHARE | EXCLUSIVE} MODEON KEY user-string [FOR TRANSACTION | FOR SESSION];

UNLOCK (RELEASE?) TABLE relation {SHARE | EXCLUSIVE} LOCKON KEY user-string;

(or just some built-in functions).

> If it does then one of the things I'd use it for is to insert
> unique data without having to lock the table or rollback on
> failed insert (unique index still kept as a guarantee).

(Classic example how could be used SAVEPOINTs -:))

So, in your application you would first lock a key in excl mode
(for duration of transaction), than try to select and insert unless
found? (Note that this will not work with serializable isolevel.)

Comments?

Vadim


pgsql-hackers by date:

Previous
From: Justin Clift
Date:
Subject: Idea: Worthwhile creating a wrapper script to automate pg_hba.conf entries?
Next
From: Bruce Momjian
Date:
Subject: Re: Using textin/textout vs. scribbling around