[erlang-questions] How to break out from mnesia transaction?
Jani Launonen
launoja@REDACTED
Mon Feb 5 15:52:49 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)
I meant "... only one transaction and checking if it succeeded. If not, some recovery action should take place."
But I think that the actual details of the two functions dictates the suitable solution and my ideas here are just hacks that might work or not depending on the details.
>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
> > erlang-questions@REDACTED
> > 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/bcbc9f18/attachment.htm>
More information about the erlang-questions
mailing list