Forums / Developer / eZ API: nested transactions, transaction unsafe methods

eZ API: nested transactions, transaction unsafe methods

Author Message

Piotrek Karaś

Monday 05 May 2008 12:00:37 pm

For a number of eZ methods and functions, you have this warning:

NOTE: Transaction unsafe. If you call several transaction unsafe methods you must enclose the calls within a db transaction; thus within db->begin and db->commit.

How does this apply to methods that have a transaction defined in them <b>and</b> have this transaction note? Example:
<i>kernel/classes/ezcontentobjecttreenode.php</i>

static function removeSubtrees( $deleteIDArray, $moveToTrash = true, $infoOnly = false )
    {
        ....
        $db = eZDB::instance();
        $db->begin();
        foreach ( $deleteIDArray as $deleteID )
        {
        ....
        }
        $db->commit();
        ...
    }

Then imagine this:

$db = eZDB::instance();
$db->begin();
eZContentObjectTreeNode::removeSubtrees( ... );
...
$db->commit();

Would that somehow nest transactions (which would be the first I've heard of)? Or does it trick the inner transaction to be continued (and the inner commit to be skipped)? Or does the inner transaction simply end the first transaction (just as if a commit was queried) as soon as the inner begin is triggered?

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Gaetano Giunta

Monday 05 May 2008 2:07:15 pm

Transactions are not really nested, as the underlying support in the db drivers varies so much from one db to the other that it would be impossible to get it acceptably reliable across implementations.

What happens is that the outer transaction gets committed at the end, the inner ones do not.

Also if any of the inner transactions gets rolled back (ie. $db->rollback(); ), the complete transaction stack gets rolled back.

Principal Consultant International Business
Member of the Community Project Board

Piotrek Karaś

Monday 05 May 2008 2:36:30 pm

Gaetano,

Thanks for the explanation!

<i>Transactions are not really nested...</i>
Yes, I did expect that, but it seemed to describe best what appears to happen (or rather what the code looks like) ;)

<i>What happens is that the outer transaction gets committed at the end, the inner ones do not. Also if any of the inner transactions gets rolled back (ie. $db->rollback(); ), the complete transaction stack gets rolled back.</i>
Is that a standard MySQL behavior, or some eZ mechanism supporting it? Couldn't find MySQL manual analyzing such scenario...

Cheers,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu