On Thu, Mar 29, 2001 at 11:32:57AM +0100, Piers Cawley wrote:
> Robin Houston <[EMAIL PROTECTED]> writes:
> > No partial failure allowed, it has to either succeed completely
> > or fail completely.
> Hmm... not quite sure what happens if either of the COMMITs fail. And
> I'd bemused as to how Java would handle it too...
> eval {
>     $fulfillment_dbh->do("BEGIN TRANSACTION");
>     $payment_dbh->do("BEGIN TRANSACTION");
>     do_the_payment_thing($payment_dbh);
>     do_the_fulfillment_thing($fulfillment_dbh);
>     $payment_dbh->do("COMMIT");
>     $fulfillment_dbh->do("COMMIT");

That is not atomic.  You need to do both COMMITs as one operation.

> }

At this point, your process dies horribly.

> if $@ {
>     $fulfillment_dbh->do("ROLLBACK");

Or for more fun, die horribly here instead.

>     $payment_dbh->do("ROLLBACK");
> }

You need the rdbms to do the rollback itself if the commit fails, or if
a connection times out after a BEGIN TRANSACTION and without a COMMIT
occurring.  You need some way of getting the two systems talking to
each other so that they can synchronise the BEGIN TRANSACTIONs and the
COMMITs.  Ouch.

Can someone remind me why I don't do financial work any more?  Oh yeah :-)

David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

    This is a signature.  There are many like it but this one is mine.

** I read encrypted mail first, so encrypt if your message is important **

PGP signature

Reply via email to