Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / docs / programmer_reference / lock_cam_conv.html
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>Berkeley DB Concurrent Data Store locking conventions</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_twopl.html" title="Locking with transactions: two-phase locking" />
12     <link rel="next" href="lock_am_conv.html" title="Berkeley DB Transactional Data Store locking conventions" />
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">Berkeley DB Concurrent Data Store locking conventions</th>
22         </tr>
23         <tr>
24           <td width="20%" align="left"><a accesskey="p" href="lock_twopl.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_am_conv.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_cam_conv"></a>Berkeley DB Concurrent Data Store locking conventions</h2>
38           </div>
39         </div>
40       </div>
41       <p>The Berkeley DB Concurrent Data Store product has a simple set of conventions for locking.  It
42 provides multiple-reader/single-writer semantics, but not per-page
43 locking or transaction recoverability.  As such, it does its locking
44 entirely in the Berkeley DB interface layer.</p>
45       <p>The object it locks is the file, identified by its unique file number.
46 The locking matrix is not one of the two standard lock modes, instead,
47 we use a four-lock set, consisting of the following:</p>
48       <div class="variablelist">
49         <dl>
50           <dt>
51             <span class="term">DB_LOCK_NG</span>
52           </dt>
53           <dd>not granted (always 0)</dd>
54           <dt>
55             <span class="term">DB_LOCK_READ</span>
56           </dt>
57           <dd>read (shared)</dd>
58           <dt>
59             <span class="term">DB_LOCK_WRITE</span>
60           </dt>
61           <dd>write (exclusive)</dd>
62           <dt>
63             <span class="term">DB_LOCK_IWRITE</span>
64           </dt>
65           <dd>intention-to-write (shared with NG and READ, but conflicts with WRITE and IWRITE)</dd>
66         </dl>
67       </div>
68       <p>The IWRITE lock is used for cursors that will be used for updating
69 (IWRITE locks are implicitly obtained for write operations through the
70 Berkeley DB handles, for example, <a href="../api_reference/C/dbput.html" class="olink">DB-&gt;put()</a> or <a href="../api_reference/C/dbdel.html" class="olink">DB-&gt;del()</a>).  While
71 the cursor is reading, the IWRITE lock is held; but as soon as the
72 cursor is about to modify the database, the IWRITE is upgraded to a
73 WRITE lock.  This upgrade blocks until all readers have exited the
74 database.  Because only one IWRITE lock is allowed at any one time, no
75 two cursors can ever try to upgrade to a WRITE lock at the same time,
76 and therefore deadlocks are prevented, which is essential because Berkeley DB Concurrent Data Store
77 does not include deadlock detection and recovery.</p>
78       <p>Applications that need to lock compatibly with Berkeley DB Concurrent Data Store must obey the
79 following rules:</p>
80       <div class="orderedlist">
81         <ol type="1">
82           <li>Use only lock modes DB_LOCK_NG, DB_LOCK_READ, DB_LOCK_WRITE,
83 DB_LOCK_IWRITE.</li>
84           <li>Never attempt to acquire a WRITE lock on an object that is
85 already locked with a READ lock.</li>
86         </ol>
87       </div>
88     </div>
89     <div class="navfooter">
90       <hr />
91       <table width="100%" summary="Navigation footer">
92         <tr>
93           <td width="40%" align="left"><a accesskey="p" href="lock_twopl.html">Prev</a> </td>
94           <td width="20%" align="center">
95             <a accesskey="u" href="lock.html">Up</a>
96           </td>
97           <td width="40%" align="right"> <a accesskey="n" href="lock_am_conv.html">Next</a></td>
98         </tr>
99         <tr>
100           <td width="40%" align="left" valign="top">Locking with transactions: two-phase locking </td>
101           <td width="20%" align="center">
102             <a accesskey="h" href="index.html">Home</a>
103           </td>
104           <td width="40%" align="right" valign="top"> Berkeley DB Transactional Data Store locking conventions</td>
105         </tr>
106       </table>
107     </div>
108   </body>
109 </html>