• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/docs/ref/transapp/
1<!--$Id: nested.so,v 10.23 2003/01/24 18:01:58 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB Reference Guide: Nested transactions</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<a name="2"><!--meow--></a>
12<table width="100%"><tr valign=top>
13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Transactional Data Store Applications</dl></b></td>
14<td align=right><a href="../transapp/cursor.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../transapp/admin.html"><img src="../../images/next.gif" alt="Next"></a>
15</td></tr></table>
16<p align=center><b>Nested transactions</b></p>
17<p>Berkeley DB provides support for nested transactions.  Nested transactions
18allow an application to decompose a large or long-running transaction
19into smaller units that may be independently aborted.</p>
20<p>Normally, when beginning a transaction, the application will pass a NULL
21value for the parent argument to <a href="../../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a>.  If, however, the
22parent argument is a <a href="../../api_c/txn_class.html">DB_TXN</a> handle, the newly created transaction
23will be treated as a nested transaction within the parent.  Transactions
24may nest arbitrarily deeply.  For the purposes of this discussion,
25transactions created with a parent identifier will be called
26<i>child transactions</i>.</p>
27<p>Once a transaction becomes a parent, as long as any of its child
28transactions are unresolved (that is, they have neither committed nor
29aborted), the parent may not issue any Berkeley DB calls except to begin more
30child transactions, or to commit or abort.  For example, it may not
31issue any access method or cursor calls.  After all of a parent's
32children have committed or aborted, the parent may again request
33operations on its own behalf.</p>
34<p>The semantics of nested transactions are as follows.  When a child
35transaction is begun, it inherits all the locks of its parent.  This
36means that the child will never block waiting on a lock held by its
37parent.  Further, locks held by two children of the same parent will
38also conflict.  To make this concrete, consider the following set of
39transactions and lock acquisitions.</p>
40<p>Transaction T1 is the parent transaction.  It acquires a write lock on
41item A and then begins two child transactions: C1 and C2.  C1 also wants
42to acquire a write lock on A; this succeeds.  If C2 attempts to acquire
43a write lock on A, it will block until C1 releases the lock, at which
44point it will succeed.  Now, let's say that C1 acquires a write lock on
45B.  If C2 now attempts to obtain a lock on B, it will block.  However,
46let's now assume that C1 commits.  Its locks are anti-inherited, which
47means they are given to T1, so T1 will now hold a lock on B.  At this
48point, C2 would be unblocked and would then acquire a lock on B.</p>
49<p>Child transactions are entirely subservient to their parent transaction.
50They may abort, undoing their operations regardless of the eventual fate
51of the parent.  However, even if a child transaction commits, if its
52parent transaction is eventually aborted, the child's changes are undone
53and the child's transaction is effectively aborted.  Any child
54transactions that are not yet resolved when the parent commits or aborts
55are resolved based on the parent's resolution -- committing if the
56parent commits and aborting if the parent aborts.  Any child
57transactions that are not yet resolved when the parent prepares are also
58prepared.</p>
59<table width="100%"><tr><td><br></td><td align=right><a href="../transapp/cursor.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../transapp/admin.html"><img src="../../images/next.gif" alt="Next"></a>
60</td></tr></table>
61<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
62</body>
63</html>
64