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