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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 19:27:46
Script start
Timing: Jan 18 2025 19:27:46
Module start 'layout'
Timing: Jan 18 2025 19:27:46
Module start 'content'
Timing: Jan 18 2025 19:27:46
Module end 'content'
Timing: Jan 18 2025 19:27:46
Script end

Main resources:

Total runtime0.8649 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 589.2578152.6406
Module start 'layout' 0.00500.0043 741.898439.4766
Module start 'content' 0.00930.8542 781.3750554.9844
Module end 'content' 0.86350.0013 1,336.359412.1250
Script end 0.8648  1,348.4844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3951160.0002
Check MTime0.00140.1595160.0001
Mysql Total
Database connection0.00080.089510.0008
Mysqli_queries0.812193.8987570.0142
Looping result0.00050.0619550.0000
Template Total0.828695.820.4143
Template load0.00240.283120.0012
Template processing0.826195.517020.4131
Template load and register function0.00010.011310.0001
states
state_id_array0.00130.145710.0013
state_identifier_array0.00090.108020.0005
Override
Cache load0.00210.2454270.0001
Sytem overhead
Fetch class attribute can translate value0.00060.064720.0003
Fetch class attribute name0.00150.178950.0003
XML
Image XML parsing0.00110.123120.0005
class_abstraction
Instantiating content class attribute0.00000.001160.0000
General
dbfile0.00090.1032230.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs