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.