| 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>Locking without transactions</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.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 Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="lock.html" title="Chapter 16. The Locking Subsystem" /> |
| 11 | <link rel="prev" href="lock_page.html" title="Locking granularity" /> |
| 12 | <link rel="next" href="lock_twopl.html" title="Locking with transactions: two-phase locking" /> |
| 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">Locking without transactions</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="lock_page.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 16. |
| 26 | The Locking Subsystem |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="lock_twopl.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="lock_notxn"></a>Locking without transactions</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>If an application runs with locking specified, but not transactions (for |
| 42 | example, <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> is callsed with <a href="../api_reference/C/envopen.html#envopen_DB_INIT_LOCK" class="olink">DB_INIT_LOCK</a> or |
| 43 | <a href="../api_reference/C/envopen.html#envopen_DB_INIT_CDB" class="olink">DB_INIT_CDB</a> specified, but not <a href="../api_reference/C/envopen.html#envopen_DB_INIT_TXN" class="olink">DB_INIT_TXN</a>), locks are |
| 44 | normally acquired during each Berkeley DB operation and released before the |
| 45 | operation returns to the caller. The only exception is in the case of |
| 46 | cursor operations. Cursors identify a particular position in a file. |
| 47 | For this reason, cursors must retain read locks across cursor calls to |
| 48 | make sure that the position is uniquely identifiable during a subsequent |
| 49 | cursor call, and so that an operation using <a href="../api_reference/C/dbcget.html#dbcget_DB_CURRENT" class="olink">DB_CURRENT</a> will |
| 50 | always refer to the same record as a previous cursor call. These cursor |
| 51 | locks cannot be released until the cursor is either repositioned and a |
| 52 | new cursor lock established (for example, using the <a href="../api_reference/C/dbcget.html#dbcget_DB_NEXT" class="olink">DB_NEXT</a> |
| 53 | or <a href="../api_reference/C/dbcget.html#dbcget_DB_SET" class="olink">DB_SET</a> flags), or the cursor is closed. As a result, |
| 54 | application writers are encouraged to close cursors as soon as |
| 55 | possible.</p> |
| 56 | <p>It is important to realize that concurrent applications that use locking |
| 57 | must ensure that two concurrent threads do not block each other. |
| 58 | However, because Btree and Hash access method page splits can occur at |
| 59 | any time, there is virtually no way to guarantee that an application |
| 60 | that writes the database cannot deadlock. Applications running without |
| 61 | the protection of transactions may deadlock, and can leave the database |
| 62 | in an inconsistent state when they do so. Applications that need |
| 63 | concurrent access, but not transactions, are more safely implemented |
| 64 | using the Berkeley DB Concurrent Data Store Product.</p> |
| 65 | </div> |
| 66 | <div class="navfooter"> |
| 67 | <hr /> |
| 68 | <table width="100%" summary="Navigation footer"> |
| 69 | <tr> |
| 70 | <td width="40%" align="left"><a accesskey="p" href="lock_page.html">Prev</a> </td> |
| 71 | <td width="20%" align="center"> |
| 72 | <a accesskey="u" href="lock.html">Up</a> |
| 73 | </td> |
| 74 | <td width="40%" align="right"> <a accesskey="n" href="lock_twopl.html">Next</a></td> |
| 75 | </tr> |
| 76 | <tr> |
| 77 | <td width="40%" align="left" valign="top">Locking granularity </td> |
| 78 | <td width="20%" align="center"> |
| 79 | <a accesskey="h" href="index.html">Home</a> |
| 80 | </td> |
| 81 | <td width="40%" align="right" valign="top"> Locking with transactions: two-phase locking</td> |
| 82 | </tr> |
| 83 | </table> |
| 84 | </div> |
| 85 | </body> |
| 86 | </html> |