• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/programmer_reference/
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��15.�� 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 class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Berkeley DB Concurrent Data Store locking conventions</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="lock_twopl.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��15.��
23		The Locking Subsystem
24        </th>
25          <td width="20%" align="right">��<a accesskey="n" href="lock_am_conv.html">Next</a></td>
26        </tr>
27      </table>
28      <hr />
29    </div>
30    <div class="sect1" lang="en" xml:lang="en">
31      <div class="titlepage">
32        <div>
33          <div>
34            <h2 class="title" style="clear: both"><a id="lock_cam_conv"></a>Berkeley DB Concurrent Data Store locking conventions</h2>
35          </div>
36        </div>
37      </div>
38      <p>The Berkeley DB Concurrent Data Store product has a simple set of conventions for locking.  It
39provides multiple-reader/single-writer semantics, but not per-page
40locking or transaction recoverability.  As such, it does its locking
41entirely in the Berkeley DB interface layer.</p>
42      <p>The object it locks is the file, identified by its unique file number.
43The locking matrix is not one of the two standard lock modes, instead,
44we use a four-lock set, consisting of the following:</p>
45      <div class="variablelist">
46        <dl>
47          <dt>
48            <span class="term">DB_LOCK_NG</span>
49          </dt>
50          <dd>not granted (always 0)</dd>
51          <dt>
52            <span class="term">DB_LOCK_READ</span>
53          </dt>
54          <dd>read (shared)</dd>
55          <dt>
56            <span class="term">DB_LOCK_WRITE</span>
57          </dt>
58          <dd>write (exclusive)</dd>
59          <dt>
60            <span class="term">DB_LOCK_IWRITE</span>
61          </dt>
62          <dd>intention-to-write (shared with NG and READ, but conflicts with WRITE and IWRITE)</dd>
63        </dl>
64      </div>
65      <p>The IWRITE lock is used for cursors that will be used for updating
66(IWRITE locks are implicitly obtained for write operations through the
67Berkeley 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
68the cursor is reading, the IWRITE lock is held; but as soon as the
69cursor is about to modify the database, the IWRITE is upgraded to a
70WRITE lock.  This upgrade blocks until all readers have exited the
71database.  Because only one IWRITE lock is allowed at any one time, no
72two cursors can ever try to upgrade to a WRITE lock at the same time,
73and therefore deadlocks are prevented, which is essential because Berkeley DB Concurrent Data Store
74does not include deadlock detection and recovery.</p>
75      <p>Applications that need to lock compatibly with Berkeley DB Concurrent Data Store must obey the
76following rules:</p>
77      <div class="orderedlist">
78        <ol type="1">
79          <li>Use only lock modes DB_LOCK_NG, DB_LOCK_READ, DB_LOCK_WRITE,
80DB_LOCK_IWRITE.</li>
81          <li>Never attempt to acquire a WRITE lock on an object that is
82already locked with a READ lock.</li>
83        </ol>
84      </div>
85    </div>
86    <div class="navfooter">
87      <hr />
88      <table width="100%" summary="Navigation footer">
89        <tr>
90          <td width="40%" align="left"><a accesskey="p" href="lock_twopl.html">Prev</a>��</td>
91          <td width="20%" align="center">
92            <a accesskey="u" href="lock.html">Up</a>
93          </td>
94          <td width="40%" align="right">��<a accesskey="n" href="lock_am_conv.html">Next</a></td>
95        </tr>
96        <tr>
97          <td width="40%" align="left" valign="top">Locking with transactions: two-phase locking��</td>
98          <td width="20%" align="center">
99            <a accesskey="h" href="index.html">Home</a>
100          </td>
101          <td width="40%" align="right" valign="top">��Berkeley DB Transactional Data Store locking conventions</td>
102        </tr>
103      </table>
104    </div>
105  </body>
106</html>
107