1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>DbEnv::txn_begin()</title>
<link rel="stylesheet" href="apiReference.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB C++ API Reference" />
<link rel="up" href="txn.html" title="Chapter 13. The DbTxn Handle" />
<link rel="prev" href="txnabort.html" title="DbTxn::abort()" />
<link rel="next" href="txncheckpoint.html" title="DbEnv::txn_checkpoint()" />
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">DbEnv::txn_begin()</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="txnabort.html">Prev</a> </td>
<th width="60%" align="center">Chapter 13.
The DbTxn Handle
</th>
<td width="20%" align="right"> <a accesskey="n" href="txncheckpoint.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="txnbegin"></a>DbEnv::txn_begin()</h2>
</div>
</div>
</div>
<pre class="programlisting">#include <db_cxx.h>
int
DbEnv::txn_begin(DbTxn *parent, DbTxn **tid, u_int32_t flags);</pre>
<p>
The <code class="methodname">DbEnv::txn_begin()</code> method creates a new transaction in the
environment and copies a pointer to a <a class="link" href="txn.html" title="Chapter 13. The DbTxn Handle">DbTxn</a> that
uniquely identifies it into the memory to which <span class="bold"><strong>tid</strong></span>
refers. Calling the <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a>,
<a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> or
<a class="xref" href="txndiscard.html" title="DbTxn::discard()">DbTxn::discard()</a> methods will
discard the returned handle.
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
Transactions may only span threads if they do so serially; that is, each transaction
must be active in only a single thread of control at a time. This restriction holds
for parents of nested transactions as well; no two children may be concurrently active
in more than one thread of control at any one time.
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
Cursors may not span transactions; that is, each cursor must be opened and closed within
a single transaction.
</p>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
A parent transaction may not issue any Berkeley DB operations — except for
<code class="methodname">DbEnv::txn_begin()</code>,
<a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a>
and <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> — while it
has active child transactions (child transactions that have not yet
been committed or aborted).
</p>
</div>
<p>
The <code class="methodname">DbEnv::txn_begin()</code> <span>
<span>
method either returns a non-zero error value or throws an
exception that encapsulates a non-zero error value on
failure, and returns 0 on success.
</span>
</span>
</p>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id1713416"></a>Parameters</h3>
</div>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="id1713420"></a>flags</h4>
</div>
</div>
</div>
<p>
The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
or by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing
together one or more of the following values:
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>
<code class="literal">DB_READ_COMMITTED</code>
</p>
<p>
This transaction will have degree 2 isolation. This provides for
cursor stability but not repeatable reads. Data items which have been
previously read by this transaction may be deleted or modified by
other transactions before this transaction completes.
</p>
</li>
<li>
<p>
<code class="literal">DB_READ_UNCOMMITTED</code>
</p>
<p>
This transaction will have degree 1 isolation. Read operations
performed by the transaction may read modified but not yet committed
data. Silently ignored if the <code class="literal">DB_READ_UNCOMMITTED</code>
flag was not specified when the underlying database was opened.
</p>
</li>
<li>
<p>
<code class="literal">DB_TXN_NOSYNC</code>
</p>
<p>
Do not synchronously flush the log when this transaction commits or
prepares. This means the transaction will exhibit the ACI (atomicity,
consistency, and isolation) properties, but not D (durability); that
is, database integrity will be maintained but it is possible that this
transaction may be undone during recovery.
</p>
<p>
This behavior may be set for a Berkeley DB environment using the
<a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
method. Any value specified to this method overrides that setting.
</p>
</li>
<li>
<p><a id="txnbegin_DB_TXN_NOWAIT"></a>
<code class="literal">DB_TXN_NOWAIT</code>
</p>
<p>
If a lock is unavailable for any Berkeley DB operation performed in
the context of this transaction, cause the operation to return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_LOCK_DEADLOCK" class="olink">DB_LOCK_DEADLOCK</a>
(or <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED" class="olink">DB_LOCK_NOTGRANTED</a>
if the database environment has been configured using the
<a class="link" href="envset_flags.html#envset_flags_DB_TIME_NOTGRANTED">DB_TIME_NOTGRANTED</a>
flag).
</p>
<p>
This behavior may be set for a Berkeley DB environment using the
<a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
method. Any value specified to this method overrides that setting.
</p>
</li>
<li>
<p><a id="txnbegin_DB_TXN_SNAPSHOT"></a>
<code class="literal">DB_TXN_SNAPSHOT</code>
</p>
<p>
This transaction will execute with
<a href="../../programmer_reference/transapp_read.html" class="olink">snapshot isolation</a>. For
databases with the
<a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a>
flag set, data values will be read as they are when the transaction
begins, without taking read locks. Silently ignored for operations on
databases with
<a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a>
not set on the underlying database (read locks are acquired).
</p>
<p>
The error <code class="literal">DB_LOCK_DEADLOCK</code> will be
returned from update operations if a snapshot transaction attempts to
update data which was modified after the snapshot transaction read it.
</p>
</li>
<li>
<p>
<code class="literal">DB_TXN_SYNC</code>
</p>
<p>
Synchronously flush the log when this transaction commits or prepares.
This means the transaction will exhibit all of the ACID (atomicity,
consistency, isolation, and durability) properties.
</p>
<p>
This behavior is the default for Berkeley DB environments unless the
<code class="literal">DB_TXN_NOSYNC</code> flag was specified to the
<a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a> method.
Any value specified to this method overrides that setting.
</p>
</li>
<li>
<p>
<code class="literal">DB_TXN_WAIT</code>
</p>
<p>
If a lock is unavailable for any Berkeley DB operation performed in
the context of this transaction, wait for the lock.
</p>
<p>
This behavior is the default for Berkeley DB environments unless the
<code class="literal">DB_TXN_NOWAIT</code> flag was specified to the
<a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a> method.
Any value specified to this method overrides that setting.
</p>
</li>
<li>
<p>
<code class="literal">DB_TXN_WRITE_NOSYNC</code>
</p>
<p>
Write, but do not synchronously flush, the log when this transaction
commits. This means the transaction will exhibit the ACI (atomicity,
consistency, and isolation) properties, but not D (durability); that
is, database integrity will be maintained, but if the system fails, it
is possible some number of the most recently committed transactions
may be undone during recovery. The number of transactions at risk is
governed by how often the system flushes dirty buffers to disk and how
often the log is flushed or checkpointed.
</p>
<p>
This behavior may be set for a Berkeley DB environment using the
<a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
method. Any value specified to this method overrides that setting.
</p>
</li>
</ul>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="id1713997"></a>parent</h4>
</div>
</div>
</div>
<p>
If the <span class="bold"><strong>parent</strong></span> parameter is non-NULL,
the new transaction will be a nested transaction, with the transaction
indicated by <span class="bold"><strong>parent</strong></span> as its parent.
Transactions may be nested to any level. In the presence of
distributed transactions and two-phase commit, only the parental
transaction, that is a transaction without a <span class="bold"><strong>parent</strong></span> specified, should be passed as an
parameter to <a class="xref" href="txnprepare.html" title="DbTxn::prepare()">DbTxn::prepare()</a>.
</p>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id1714105"></a>Errors</h3>
</div>
</div>
</div>
<p>
The <code class="methodname">DbEnv::txn_begin()</code> <span>
<span>
method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
exception, encapsulating one of the following non-zero errors, or return one
of the following non-zero errors:
</span>
</span>
</p>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="id1713659"></a><span>DbMemoryException</span> or ENOMEM</h4>
</div>
</div>
</div>
<p>
The maximum number of concurrent transactions has been
reached.
</p>
<p>
<a class="xref" href="dbmemory.html" title="DbMemoryException">DbMemoryException</a> is thrown if
your Berkeley DB API is configured to throw exceptions.
Otherwise, <code class="literal">ENOMEM</code> is returned.
</p>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id1713954"></a>Class</h3>
</div>
</div>
</div>
<p>
<a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a>, <a class="link" href="txn.html" title="Chapter 13. The DbTxn Handle">DbTxn</a>
</p>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="id1714069"></a>See Also</h3>
</div>
</div>
</div>
<p>
<a class="xref" href="txn.html#txnlist" title="Transaction Subsystem and Related Methods">Transaction Subsystem and Related Methods</a>
</p>
</div>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="txnabort.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="txn.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="txncheckpoint.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">DbTxn::abort() </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> DbEnv::txn_checkpoint()</td>
</tr>
</table>
</div>
</body>
</html>
|