1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Nested Transactions</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" /> 10 <link rel="up" href="usingtxns.html" title="Chapter 3. Transaction Basics" /> 11 <link rel="prev" href="autocommit.html" title="Auto Commit" /> 12 <link rel="next" href="txncursor.html" title="Transactional Cursors" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Nested Transactions</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="autocommit.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 3. Transaction Basics</th> 23 <td width="20%" align="right"> <a accesskey="n" href="txncursor.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="nestedtxn"></a>Nested Transactions</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 A <span class="emphasis"><em>nested transaction</em></span> is used to provide a 38 transactional guarantee for a subset of operations performed within 39 the scope of a larger transaction. Doing this allows you to commit 40 and abort the subset of operations independently of the larger 41 transaction. 42 </p> 43 <p> 44 The rules to the usage of a nested transaction are as follows: 45 </p> 46 <div class="itemizedlist"> 47 <ul type="disc"> 48 <li> 49 <p> 50 While the nested (child) transaction is active, the parent 51 transaction may not perform any operations other than to commit 52 or abort, or to create more child transactions. 53 </p> 54 </li> 55 <li> 56 <p> 57 Committing a nested transaction has no effect on the state 58 of the parent transaction. The parent transaction is still 59 uncommitted. However, the parent transaction can now 60 see any modifications made by the child transaction. 61 Those modifications, of course, are still hidden to all 62 other transactions until the parent also commits. 63 </p> 64 </li> 65 <li> 66 <p> 67 Likewise, aborting the nested transaction has no effect on 68 the state of the parent transaction. The only result of the 69 abort is that neither the parent nor any 70 other transactions will see any of the 71 database modifications performed under the protection of the 72 nested transaction. 73 </p> 74 </li> 75 <li> 76 <p> 77 If the parent transaction commits or aborts while it has 78 active children, the child transactions are resolved in the 79 same way as the parent. That is, if the parent aborts, then 80 the child transactions abort as well. If the parent commits, 81 then whatever modifications have been performed by the child 82 transactions are also committed. 83 </p> 84 </li> 85 <li> 86 <p> 87 The locks held by a nested transaction are not released when 88 that transaction commits. Rather, they are now held by the 89 parent transaction until such a time as that parent commits. 90 </p> 91 </li> 92 <li> 93 <p> 94 Any database modifications performed by the nested transaction 95 are not visible outside of the larger encompassing 96 transaction until such a time as that parent transaction is 97 committed. 98 </p> 99 </li> 100 <li> 101 <p> 102 The depth of the nesting that you can achieve with nested 103 transaction is limited only by memory. 104 </p> 105 </li> 106 </ul> 107 </div> 108 <p> 109 To create a nested transaction, simply pass the parent transaction's 110 handle when you created the nested transaction's handle. For 111 example: 112 </p> 113 <pre class="programlisting"> // parent transaction 114 DbTxn *parentTxn, *childTxn; 115 ret = myEnv.txn_begin(NULL, &parentTxn, 0); 116 // child transaction 117 ret = myEnv.txn_begin(parent_txn, &childTxn, 0); </pre> 118 </div> 119 <div class="navfooter"> 120 <hr /> 121 <table width="100%" summary="Navigation footer"> 122 <tr> 123 <td width="40%" align="left"><a accesskey="p" href="autocommit.html">Prev</a> </td> 124 <td width="20%" align="center"> 125 <a accesskey="u" href="usingtxns.html">Up</a> 126 </td> 127 <td width="40%" align="right"> <a accesskey="n" href="txncursor.html">Next</a></td> 128 </tr> 129 <tr> 130 <td width="40%" align="left" valign="top">Auto Commit </td> 131 <td width="20%" align="center"> 132 <a accesskey="h" href="index.html">Home</a> 133 </td> 134 <td width="40%" align="right" valign="top"> Transactional Cursors</td> 135 </tr> 136 </table> 137 </div> 138 </body> 139</html> 140