Non-reentrant plperlu function & concurrent access

Started by Philippe Langover 15 years ago3 messagesgeneral
Jump to latest
#1Philippe Lang
philippe.lang@attiksystem.ch

Hi,

I have a non-reentrant plperlu function, which does no database modification. It basically stores input data into a file, calls a unix shell command, and reads the result back from another file.

I don't really care about database isolation here, phantom reads and such. It is not likely to be a problem. What could be a problem, is if another call to this function is fired while another one is running.

In this specific case, I could solve the problem by generating random input and ouput filenames, but I would prefer a more general solution, like using some sort of mutex for the function. What is the best way to do that under Postgresql? Although not designed for this (if I understand correctly), would a "serializable" isolation level help here?

Best regards!

-------------------------------------------------------------
Attik System web : http://www.attiksystem.ch
Philippe Lang phone: +41 26 422 13 75
rte de la Fonderie 2 gsm : +41 79 351 49 94
1700 Fribourg pgp : http://keyserver.pgp.com

#2Philippe Lang
philippe.lang@attiksystem.ch
In reply to: Philippe Lang (#1)
Re: Non-reentrant plperlu function & concurrent access

Hi,

I have a non-reentrant plperlu function, which does no database
modification. It basically stores input data into a file, calls a unix
shell command, and reads the result back from another file.

I don't really care about database isolation here, phantom reads and
such. It is not likely to be a problem. What could be a problem, is if
another call to this function is fired while another one is running.

In this specific case, I could solve the problem by generating random
input and ouput filenames, but I would prefer a more general solution,
like using some sort of mutex for the function. What is the best way to
do that under Postgresql? Although not designed for this (if I
understand correctly), would a "serializable" isolation level help
here?

I answer to my own post, sorry...

Maybe Postgresql functions "pg_try_advisory_lock_shared" and "pg_advisory_unlock_shared" are the solution?

-------------------------------------------------------------
Attik System web : http://www.attiksystem.ch
Philippe Lang phone: +41 26 422 13 75
rte de la Fonderie 2 gsm : +41 79 351 49 94
1700 Fribourg pgp : http://keyserver.pgp.com

#3zhong ming wu
mr.z.m.wu@gmail.com
In reply to: Philippe Lang (#2)
Re: Non-reentrant plperlu function & concurrent access

On Tue, Aug 17, 2010 at 4:15 AM, Philippe Lang
<philippe.lang@attiksystem.ch> wrote:

Hi,

I have a non-reentrant plperlu function, which does no database
modification. It basically stores input data into a file, calls a unix
shell command, and reads the result back from another file.

I don't really care about database isolation here, phantom reads and
such. It is not likely to be a problem. What could be a problem, is if
another call to this function is fired while another one is running.

In this specific case, I could solve the problem by generating random
input and ouput filenames, but I would prefer a more general solution,
like using some sort of mutex for the function. What is the best way to
do that under Postgresql? Although not designed for this (if I
understand correctly), would a "serializable" isolation level help
here?

I answer to my own post, sorry...

Maybe Postgresql functions "pg_try_advisory_lock_shared" and "pg_advisory_unlock_shared" are the solution?

There is perl self locking mechanism using flock on __DATA__ . Have
you tried that? google is your friend.