[erlang-questions] How to break out from mnesia transaction?

Jani Launonen <>
Mon Feb 5 15:27:56 CET 2007


> Hello!
> 
> I have to implement function a() which have to call function b().
> Function a() is always called from a mnesia transaction, while 
> functionb() can't be called from a mnesia transaction. How can I 
> solve this
> problem elegantly? My idea is start a process from a(), send a message
> to the process, which in turn will call b() (it's now outside of the
> transaction, right?) and when b() returns, the process sends 
> back a
> message to a(). Is there a simpler way to solve the problem?

Sending message from a transaction is a bad idea --- in fact any side-effect inside transaction is a bad idea --- if the transaction have to be restarted (which Mnesia does automatically if need arises). Then there would be several messages sent to the process calling the function b(). 

I wonder if there's elegant solution to this, but perhaps restricting Mnesia transactions to only one (somewhere was such parameter) or giving some unique identifier outside of transaction containing the function a() which is sent with the message to process calling the b(). Then, if b receives the same identifier twice (or more times if Mnesia restarts the transaction several times) it discards such calls, but returns the previous answer. A bit hacky, I have to admit, but it's been some years that I had to study the subject during my thesis. I'm interested in hearing the "correct" solution from pros :)

>                           Bye,NAR
> -- 
> "Beware of bugs in the above code; I have only proved it 
> correct, not
>   tried it."
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions


Jani Launonen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070205/de72227f/attachment.html>


More information about the erlang-questions mailing list