1<!--$Id: txn_begin.so,v 10.80 2006/12/13 18:09:09 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: DB_ENV-&gt;txn_begin</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<table width="100%"><tr valign=top>
12<td>
13<b>DB_ENV-&gt;txn_begin</b>
14</td>
15<td align=right>
16<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a>
17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db.h&gt;
23<p>
24int
25DB_ENV-&gt;txn_begin(DB_ENV *env,
26    DB_TXN *parent, DB_TXN **tid, u_int32_t flags);
27</pre></b>
28<hr size=1 noshade>
29<b>Description: DB_ENV-&gt;txn_begin</b>
30<p>The DB_ENV-&gt;txn_begin method creates a new transaction in the environment
31and copies a pointer to a <a href="../api_c/txn_class.html">DB_TXN</a> that uniquely identifies it into
32the memory to which <b>tid</b> refers.  Calling the <a href="../api_c/txn_abort.html">DB_TXN-&gt;abort</a>,
33<a href="../api_c/txn_commit.html">DB_TXN-&gt;commit</a> or <a href="../api_c/txn_discard.html">DB_TXN-&gt;discard</a> methods will discard the returned
34handle.</p>
35<p><b>Note: Transactions may only span threads if they do so serially;
36that is, each transaction must be active in only a single thread
37of control at a time.  This restriction holds for parents of nested
38transactions as well; no two children may be concurrently active in
39more than one thread of control at any one time.</b></p>
40<p><b>Note: Cursors may not span transactions; that is, each cursor must be
41opened and closed within a single transaction.</b></p>
42<p><b>Note: A parent transaction may not issue any Berkeley DB operations -- except for
43DB_ENV-&gt;txn_begin, <a href="../api_c/txn_abort.html">DB_TXN-&gt;abort</a> and <a href="../api_c/txn_commit.html">DB_TXN-&gt;commit</a> -- while it has
44active child transactions (child transactions that have not yet been
45committed or aborted).</b></p>
46<p>The DB_ENV-&gt;txn_begin method
47returns a non-zero error value on failure
48and 0 on success.
49</p>
50<b>Parameters</b> <br>
51 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one
52or more of the following values:
53<br>
54<b><a name="DB_READ_COMMITTED">DB_READ_COMMITTED</a></b><ul compact><li>This transaction will have degree 2 isolation.  This provides for cursor
55stability but not repeatable reads.  Data items which have been
56previously read by this transaction may be deleted or modified by other
57transactions before this transaction completes.</ul>
58<b><a name="DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a></b><ul compact><li>This transaction will have degree 1 isolation.  Read operations
59performed by the transaction may read modified but not yet committed
60data.  Silently ignored if the DB_READ_UNCOMMITTED flag was not
61specified when the underlying database was opened.</ul>
62<b><a name="DB_TXN_NOSYNC">DB_TXN_NOSYNC</a></b><ul compact><li>Do not synchronously flush the log when this transaction commits or
63prepares. This means the transaction will exhibit the ACI (atomicity,
64consistency, and isolation) properties, but not D (durability); that is,
65database integrity will be maintained but it is possible that this
66transaction may be undone during recovery.
67<p>This behavior may be set for a Berkeley DB environment using the
68<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a> method.  Any value specified to this method overrides
69that setting.</p></ul>
70<b><a name="DB_TXN_NOWAIT">DB_TXN_NOWAIT</a></b><ul compact><li>If a lock is unavailable for any Berkeley DB operation performed in the context
71of this transaction, cause the operation to
72return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> (or <a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> if the
73database environment has been configured using the
74<a href="../api_c/env_set_flags.html#DB_TIME_NOTGRANTED">DB_TIME_NOTGRANTED</a> flag).
75<p>This behavior may be set for a Berkeley DB environment using the
76<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a> method.  Any value specified to this method overrides
77that setting.</p></ul>
78<b><a name="DB_TXN_SNAPSHOT">DB_TXN_SNAPSHOT</a></b><ul compact><li>This transaction will execute with <a href="../ref/transapp/read.html">snapshot isolation</a>.  For databases with the <a href="../api_c/db_open.html#DB_MULTIVERSION">DB_MULTIVERSION</a>
79flag set, data values will be read as they are when the transaction
80begins, without taking read locks.  Silently ignored for operations on
81databases with <a href="../api_c/db_open.html#DB_MULTIVERSION">DB_MULTIVERSION</a> not set on the underlying
82database (read locks are acquired).
83<p>The error <a name="DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> will be returned from update
84operations if a snapshot transaction attempts to update data
85which was modified after the snapshot transaction read it.</p></ul>
86<b><a name="DB_TXN_SYNC">DB_TXN_SYNC</a></b><ul compact><li>Synchronously flush the log when this transaction commits or prepares.
87This means the transaction will exhibit all of the ACID (atomicity,
88consistency, isolation, and durability) properties.
89<p>This behavior is the default for Berkeley DB environments unless the
90DB_TXN_NOSYNC flag was specified to the
91<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a> method.  Any value specified to this method overrides
92that setting.</p></ul>
93<b><a name="DB_TXN_WAIT">DB_TXN_WAIT</a></b><ul compact><li>If a lock is unavailable for any Berkeley DB operation performed in the context
94of this transaction, wait for the lock.
95<p>This behavior is the default for Berkeley DB environments unless the
96DB_TXN_NOWAIT flag was specified to the
97<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a> method.  Any value specified to this method overrides
98that setting.</p></ul>
99<b><a name="DB_TXN_WRITE_NOSYNC">DB_TXN_WRITE_NOSYNC</a></b><ul compact><li>Write, but do not synchronously flush, the log when this transaction
100commits.  This means the transaction will exhibit the ACI (atomicity,
101consistency, and isolation) properties, but not D (durability); that is,
102database integrity will be maintained, but if the system fails, it is
103possible some number of the most recently committed transactions may be
104undone during recovery.  The number of transactions at risk is governed
105by how often the system flushes dirty buffers to disk and how often the
106log is flushed or checkpointed.
107<p>This behavior may be set for a Berkeley DB environment using the
108<a href="../api_c/env_set_flags.html">DB_ENV-&gt;set_flags</a> method.  Any value specified to this method overrides
109that setting.</p></ul>
110<br></ul>
111 <b>parent</b><ul compact><li>If the <b>parent</b> parameter is non-NULL, the new transaction will
112be a nested transaction, with the transaction indicated by
113<b>parent</b> as its parent.  Transactions may be nested to any level.
114In the presence of distributed transactions and two-phase commit, only
115the parental transaction, that is a transaction without a <b>parent</b>
116specified, should be passed as an parameter to <a href="../api_c/txn_prepare.html">DB_TXN-&gt;prepare</a>.</ul>
117<br>
118<br><b>Errors</b>
119<p>The DB_ENV-&gt;txn_begin method
120may fail and return one of the following non-zero errors:</p>
121<br>
122<b>ENOMEM</b><ul compact><li>The maximum number of concurrent transactions has been reached.</ul>
123<br>
124<hr size=1 noshade>
125<br><b>Class</b>
126<a href="../api_c/env_class.html">DB_ENV</a>, <a href="../api_c/txn_class.html">DB_TXN</a>
127<br><b>See Also</b>
128<a href="../api_c/txn_list.html">Transaction Subsystem and Related Methods</a>
129</tt>
130<table width="100%"><tr><td><br></td><td align=right>
131<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
132</td></tr></table>
133<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
134</body>
135</html>
136