Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
DBI and PostgreSQL advisory locksby techcode (Hermit) |
on Nov 20, 2009 at 22:22 UTC ( [id://808537]=perlquestion: print w/replies, xml ) | Need Help?? |
techcode has asked for the wisdom of the Perl Monks concerning the following question: Is there some little known trick when you wan't to use PostgreSQL's advisory locks from Perl?
I first created a function that does: And when I realized that more than one process is ending up with same table row as taken by them (writing to their output table was failing with duplicate key error) - I though, doup, the lock is released (and next process in queue gets the lock) before the transaction is commit-ed and there you go a racing condition. So I changed it to something like (in reality function call is wrapped in eval, and there is a if($@) ...rollback/commit after that): Well if that was working - I wouldn't be writing here :) Is there something I missed in some document or somewhere? I checked my sanity by trying out the things manually with several psql's open, and from there it's working - second lock is blocked until first is released. I'm in process of trying to $db->do("SELECT pg_ad...."); instead of prepare/execute. And if that doesn't change the way it's working - I'm planning on writing a dead simple test code that will try to get two locks on two separate DB connections. Any suggestions? Have you tried freelancing/outsourcing? Check out Scriptlance - I work there since 2003. For more info about Scriptlance and freelancing in general check out my home node.
Back to
Seekers of Perl Wisdom
|
|