Debian Codegraph @

docs/api_reference/CXX/txnbegin.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>DbEnv::txn_begin()</title>
7 <link rel="stylesheet" href="apiReference.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 C++ API Reference" />
10 <link rel="up" href="txn.html" title="Chapter 13.  The DbTxn Handle" />
11 <link rel="prev" href="txnrecover.html" title="DbEnv::txn_recover()" />
12 <link rel="next" href="txncheckpoint.html" title="DbEnv::txn_checkpoint()" />
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">DbEnv::txn_begin()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="txnrecover.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 13. 
26 The DbTxn Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="txncheckpoint.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="txnbegin"></a>DbEnv::txn_begin()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 DbEnv::txn_begin(DbTxn *parent, DbTxn **tid, u_int32_t flags);</pre>
45 <p>
46 The <code class="methodname">DbEnv::txn_begin()</code> method creates a new transaction in the
47 environment and copies a pointer to a <a class="link" href="txn.html" title="Chapter 13.  The DbTxn Handle">DbTxn</a> that
48 uniquely identifies it into the memory to which <span class="bold"><strong>tid</strong></span>
49 refers. Calling the <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a>,
50 <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> or
51 <a class="xref" href="txndiscard.html" title="DbTxn::discard()">DbTxn::discard()</a> methods will
52 discard the returned handle.
53 </p>
54 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
55 <h3 class="title">Note</h3>
56 <p>
57 Transactions may only span threads if they do so serially; that is, each transaction
58 must be active in only a single thread of control at a time. This restriction holds
59 for parents of nested transactions as well; no two children may be concurrently active
60 in more than one thread of control at any one time.
61 </p>
62 </div>
63 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
64 <h3 class="title">Note</h3>
65 <p>
66 Cursors may not span transactions; that is, each cursor must be opened and closed within
67 a single transaction.
68 </p>
69 </div>
70 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
71 <h3 class="title">Note</h3>
72 <p>
73 A parent transaction may not issue any Berkeley DB operations — except for
74 <code class="methodname">DbEnv::txn_begin()</code>,
75 <a class="xref" href="txnabort.html" title="DbTxn::abort()">DbTxn::abort()</a>
76 and <a class="xref" href="txncommit.html" title="DbTxn::commit()">DbTxn::commit()</a> — while it
77 has active child transactions (child transactions that have not yet
78 been committed or aborted).
79 </p>
80 </div>
81 <p>
82 The <code class="methodname">DbEnv::txn_begin()</code> <span>
83
84 <span>
85 method either returns a non-zero error value or throws an
86 exception that encapsulates a non-zero error value on
87 failure, and returns 0 on success.
88 </span>
89 </span>
90 </p>
91 <div class="sect2" lang="en" xml:lang="en">
92 <div class="titlepage">
93 <div>
94 <div>
95 <h3 class="title"><a id="idp10323016"></a>Parameters</h3>
96 </div>
97 </div>
98 </div>
99 <div class="sect3" lang="en" xml:lang="en">
100 <div class="titlepage">
101 <div>
102 <div>
103 <h4 class="title"><a id="idp10322368"></a>parent</h4>
104 </div>
105 </div>
106 </div>
107 <p>
108 If the <span class="bold"><strong>parent</strong></span> parameter is non-NULL,
109 the new transaction will be a nested transaction, with the transaction
110 indicated by <span class="bold"><strong>parent</strong></span> as its parent.
111 Transactions may be nested to any level. In the presence of
112 distributed transactions and two-phase commit, only the parental
113 transaction, that is a transaction without a <span class="bold"><strong>parent</strong></span> specified, should be passed as an
114 parameter to <a class="xref" href="txnprepare.html" title="DbTxn::prepare()">DbTxn::prepare()</a>.
115 </p>
116 </div>
117 <div class="sect3" lang="en" xml:lang="en">
118 <div class="titlepage">
119 <div>
120 <div>
121 <h4 class="title"><a id="idp10281968"></a>flags</h4>
122 </div>
123 </div>
124 </div>
125 <p>
126 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
127 or by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing
128 together one or more of the following values:
129 </p>
130 <div class="itemizedlist">
131 <ul type="disc">
132 <li>
133 <p>
134 <code class="literal">DB_READ_COMMITTED</code>
135 </p>
136 <p>
137 This transaction will have degree 2 isolation. This provides for
138 cursor stability but not repeatable reads. Data items which have been
139 previously read by this transaction may be deleted or modified by
140 other transactions before this transaction completes.
141 </p>
142 </li>
143 <li>
144 <p>
145 <code class="literal">DB_READ_UNCOMMITTED</code>
146 </p>
147 <p>
148 This transaction will have degree 1 isolation. Read operations
149 performed by the transaction may read modified but not yet committed
150 data. Silently ignored if the <code class="literal">DB_READ_UNCOMMITTED</code>
151 flag was not specified when the underlying database was opened.
152 </p>
153 </li>
154 <li>
155 <p><a id="txnbegin_DB_TXN_BULK"></a>
156
157 <code class="literal">DB_TXN_BULK</code>
158 </p>
159 <p>
160 Enable transactional bulk insert optimization. When
161 this flag is set, the transaction avoids
162 logging the contents of insertions on newly allocated
163 database pages. In a transaction that inserts a
164 large number of new records, the I/O savings of
165 choosing this option can be significant.
166 </p>
167 <p>Users of
168 this option should be aware of several issues. When
169 the optimization is in effect, page allocations that
170 extend the database file are logged as usual; this
171 allows transaction aborts to work correctly, both
172 online and during recovery. At commit time, the
173 database's pages are flushed to disk, eliminating the
174 need to roll-forward the transaction during normal
175 recovery. However, there are other recovery
176 operations that depend on roll-forward, and care must
177 be taken when <code class="literal">DB_TXN_BULK</code> transactions interact with
178 them.
179 </p>
180 <p>In particular, <code class="literal">DB_TXN_BULK</code> is incompatible
181 with replication, and is simply ignored when
182 replication is enabled. Also, hot backup procedures
183 must follow a particular protocol, introduced in
184 Berkeley DB 11gR2.5.1, which is to set the
185 <a class="xref" href="envset_flags.html#set_flags_DB_HOTBACKUP_IN_PROGRESS">
186 <code class="literal">DB_HOTBACKUP_IN_PROGRESS</code>
187 </a>
188 flag in the environment before
189 starting to copy files. It is important
190 to note that incremental hot backups can be
191 invalidated by use of the bulk insert optimization.
192 For more information, see the
193 section on Hot Backup in the <span class="emphasis"><em>Getting Started
194 With Transaction Processing Guide</em></span> and the description of the flag
195 <a class="xref" href="envset_flags.html#set_flags_DB_HOTBACKUP_IN_PROGRESS">
196 <code class="literal">DB_HOTBACKUP_IN_PROGRESS</code>
197 </a> in
198 <code class="literal">DB_ENV-&gt;set_flags</code>.
199 </p>
200 <p>
201 The bulk insert optimization is effective only for
202 top-level transactions. The <code class="literal">DB_TXN_BULK</code> flag is ignored
203 when <span class="bold"><strong>parent</strong></span> is non-null.
204 </p>
205 </li>
206 <li>
207 <p>
208 <code class="literal">DB_TXN_NOSYNC</code>
209 </p>
210 <p>
211 Do not synchronously flush the log when this transaction commits or
212 prepares. This means the transaction will exhibit the ACI (atomicity,
213 consistency, and isolation) properties, but not D (durability); that
214 is, database integrity will be maintained but it is possible that this
215 transaction may be undone during recovery.
216 </p>
217 <p>
218 This behavior may be set for a Berkeley DB environment using the
219 <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
220 method. Any value specified to this method overrides that setting.
221 </p>
222 </li>
223 <li>
224 <p><a id="txnbegin_DB_TXN_NOWAIT"></a>
225 <code class="literal">DB_TXN_NOWAIT</code>
226 </p>
227 <p>
228 If a lock is unavailable for any Berkeley DB operation performed in
229 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>
230 (or <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED" class="olink">DB_LOCK_NOTGRANTED</a>
231 if the database environment has been configured using the
232 <a class="link" href="envset_flags.html#envset_flags_DB_TIME_NOTGRANTED">DB_TIME_NOTGRANTED</a>
233 flag).
234 </p>
235 <p>
236 This behavior may be set for a Berkeley DB environment using the
237 <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
238 method. Any value specified to this method overrides that setting.
239 </p>
240 </li>
241 <li>
242 <p><a id="txnbegin_DB_TXN_SNAPSHOT"></a>
243 <code class="literal">DB_TXN_SNAPSHOT</code>
244 </p>
245 <p>
246 This transaction will execute with
247 <a href="../../programmer_reference/transapp_read.html" class="olink">snapshot isolation</a>. For
248 databases with the
249 <a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a>
250 flag set, data values will be read as they are when the transaction
251 begins, without taking read locks. Silently ignored for operations on
252 databases with
253 <a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a>
254 not set on the underlying database (read locks are acquired).
255 </p>
256 <p>
257 The error <code class="literal">DB_LOCK_DEADLOCK</code> will be
258 returned from update operations if a snapshot transaction attempts to
259 update data which was modified after the snapshot transaction read it.
260 </p>
261 </li>
262 <li>
263 <p>
264 <code class="literal">DB_TXN_SYNC</code>
265 </p>
266 <p>
267 Synchronously flush the log when this transaction commits or prepares.
268 This means the transaction will exhibit all of the ACID (atomicity,
269 consistency, isolation, and durability) properties.
270 </p>
271 <p>
272 This behavior is the default for Berkeley DB environments unless the
273 <code class="literal">DB_TXN_NOSYNC</code> flag was specified to the
274 <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a> method.
275 Any value specified to this method overrides that setting.
276 </p>
277 </li>
278 <li>
279 <p>
280 <code class="literal">DB_TXN_WAIT</code>
281 </p>
282 <p>
283 If a lock is unavailable for any Berkeley DB operation performed in
284 the context of this transaction, wait for the lock.
285 </p>
286 <p>
287 This behavior is the default for Berkeley DB environments unless the
288 <code class="literal">DB_TXN_NOWAIT</code> flag was specified to the
289 <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a> method.
290 Any value specified to this method overrides that setting.
291 </p>
292 </li>
293 <li>
294 <p>
295 <code class="literal">DB_TXN_WRITE_NOSYNC</code>
296 </p>
297 <p>
298 Write, but do not synchronously flush, the log when this transaction
299 commits. This means the transaction will exhibit the ACI (atomicity,
300 consistency, and isolation) properties, but not D (durability); that
301 is, database integrity will be maintained, but if the system fails, it
302 is possible some number of the most recently committed transactions
303 may be undone during recovery. The number of transactions at risk is
304 governed by how often the system flushes dirty buffers to disk and how
305 often the log is flushed or checkpointed.
306 </p>
307 <p>
308 This behavior may be set for a Berkeley DB environment using the
309 <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a>
310 method. Any value specified to this method overrides that setting.
311 </p>
312 </li>
313 </ul>
314 </div>
315 </div>
316 </div>
317 <div class="sect2" lang="en" xml:lang="en">
318 <div class="titlepage">
319 <div>
320 <div>
321 <h3 class="title"><a id="idp10339720"></a>Errors</h3>
322 </div>
323 </div>
324 </div>
325 <p>
326 The <code class="methodname">DbEnv::txn_begin()</code> <span>
327
328 <span>
329 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
330 exception, encapsulating one of the following non-zero errors, or return one
331 of the following non-zero errors:
332 </span>
333 </span>
334 </p>
335 <div class="sect3" lang="en" xml:lang="en">
336 <div class="titlepage">
337 <div>
338 <div>
339 <h4 class="title"><a id="idp10336912"></a><span>DbMemoryException or </span> ENOMEM</h4>
340 </div>
341 </div>
342 </div>
343 <p>
344 The maximum number of concurrent transactions has been
345 reached.
346 </p>
347 <p>
348 <a class="xref" href="dbmemory.html" title="DbMemoryException">DbMemoryException</a> is thrown if
349 your Berkeley DB API is configured to throw exceptions.
350 Otherwise, <code class="literal">ENOMEM</code> is returned.
351 </p>
352 </div>
353 </div>
354 <div class="sect2" lang="en" xml:lang="en">
355 <div class="titlepage">
356 <div>
357 <div>
358 <h3 class="title"><a id="idp10337776"></a>Class</h3>
359 </div>
360 </div>
361 </div>
362 <p>
363 <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>
364 </p>
365 </div>
366 <div class="sect2" lang="en" xml:lang="en">
367 <div class="titlepage">
368 <div>
369 <div>
370 <h3 class="title"><a id="idp10326904"></a>See Also</h3>
371 </div>
372 </div>
373 </div>
374 <p>
375 <a class="xref" href="txn.html#txnlist" title="Transaction Subsystem and Related Methods">Transaction Subsystem and Related Methods</a>
376 </p>
377 </div>
378 </div>
379 <div class="navfooter">
380 <hr />
381 <table width="100%" summary="Navigation footer">
382 <tr>
383 <td width="40%" align="left"><a accesskey="p" href="txnrecover.html">Prev</a> </td>
384 <td width="20%" align="center">
385 <a accesskey="u" href="txn.html">Up</a>
386 </td>
387 <td width="40%" align="right"> <a accesskey="n" href="txncheckpoint.html">Next</a></td>
388 </tr>
389 <tr>
390 <td width="40%" align="left" valign="top">DbEnv::txn_recover() </td>
391 <td width="20%" align="center">
392 <a accesskey="h" href="index.html">Home</a>
393 </td>
394 <td width="40%" align="right" valign="top"> DbEnv::txn_checkpoint()</td>
395 </tr>
396 </table>
397 </div>
398 </body>
399 </html>