Debian Codegraph @

docs/programmer_reference/transapp_nested.html

raw symbols SCIP
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="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="transapp.html" title="Chapter 11.  Berkeley DB Transactional Data Store Applications" />
11 <link rel="prev" href="transapp_cursor.html" title="Transactional cursors" />
12 <link rel="next" href="transapp_admin.html" title="Environment infrastructure" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Nested transactions</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="transapp_cursor.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 11. 
26 Berkeley DB Transactional Data Store Applications
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="transapp_admin.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="transapp_nested"></a>Nested transactions</h2>
38 </div>
39 </div>
40 </div>
41 <p>Berkeley DB provides support for nested transactions. Nested transactions
42 allow an application to decompose a large or long-running transaction
43 into smaller units that may be independently aborted.</p>
44 <p>Normally, when beginning a transaction, the application will pass a NULL
45 value for the parent argument to <a href="../api_reference/C/txnbegin.html" class="olink">DB_ENV-&gt;txn_begin()</a>. If, however, the
46 parent argument is a <a href="../api_reference/C/txn.html" class="olink">TXN</a> handle, the newly created transaction
47 will be treated as a nested transaction within the parent. Transactions
48 may nest arbitrarily deeply. For the purposes of this discussion,
49 transactions created with a parent identifier will be called
50 <span class="emphasis"><em>child transactions</em></span>.</p>
51 <p>Once a transaction becomes a parent, as long as any of its child
52 transactions are unresolved (that is, they have neither committed nor
53 aborted), the parent may not issue any Berkeley DB calls except to begin more
54 child transactions, or to commit or abort. For example, it may not
55 issue any access method or cursor calls. After all of a parent's
56 children have committed or aborted, the parent may again request
57 operations on its own behalf.</p>
58 <p>The semantics of nested transactions are as follows. When a child
59 transaction is begun, it inherits all the locks of its parent. This
60 means that the child will never block waiting on a lock held by its
61 parent. Further, locks held by two children of the same parent will
62 also conflict. To make this concrete, consider the following set of
63 transactions and lock acquisitions.</p>
64 <p>Transaction T1 is the parent transaction. It acquires a write lock on
65 item A and then begins two child transactions: C1 and C2. C1 also wants
66 to acquire a write lock on A; this succeeds. If C2 attempts to acquire
67 a write lock on A, it will block until C1 releases the lock, at which
68 point it will succeed. Now, let's say that C1 acquires a write lock on
69 B. If C2 now attempts to obtain a lock on B, it will block. However,
70 let's now assume that C1 commits. Its locks are anti-inherited, which
71 means they are given to T1, so T1 will now hold a lock on B. At this
72 point, C2 would be unblocked and would then acquire a lock on B.</p>
73 <p>Child transactions are entirely subservient to their parent transaction.
74 They may abort, undoing their operations regardless of the eventual fate
75 of the parent. However, even if a child transaction commits, if its
76 parent transaction is eventually aborted, the child's changes are undone
77 and the child's transaction is effectively aborted. Any child
78 transactions that are not yet resolved when the parent commits or aborts
79 are resolved based on the parent's resolution -- committing if the
80 parent commits and aborting if the parent aborts. Any child
81 transactions that are not yet resolved when the parent prepares are also
82 prepared.</p>
83 </div>
84 <div class="navfooter">
85 <hr />
86 <table width="100%" summary="Navigation footer">
87 <tr>
88 <td width="40%" align="left"><a accesskey="p" href="transapp_cursor.html">Prev</a> </td>
89 <td width="20%" align="center">
90 <a accesskey="u" href="transapp.html">Up</a>
91 </td>
92 <td width="40%" align="right"> <a accesskey="n" href="transapp_admin.html">Next</a></td>
93 </tr>
94 <tr>
95 <td width="40%" align="left" valign="top">Transactional cursors </td>
96 <td width="20%" align="center">
97 <a accesskey="h" href="index.html">Home</a>
98 </td>
99 <td width="40%" align="right" valign="top"> Environment infrastructure</td>
100 </tr>
101 </table>
102 </div>
103 </body>
104 </html>