1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Standard lock modes</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
<link rel="up" href="lock.html" title="Chapter 16. The Locking Subsystem" />
<link rel="prev" href="lock_max.html" title="Configuring locking: sizing the system" />
<link rel="next" href="lock_dead.html" title="Deadlock detection" />
</head>
<body>
<div xmlns="" class="navheader">
<div class="libver">
<p>Library Version 12.1.6.1</p>
</div>
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Standard lock modes</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="lock_max.html">Prev</a> </td>
<th width="60%" align="center">Chapter 16. The Locking Subsystem </th>
<td width="20%" align="right"> <a accesskey="n" href="lock_dead.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="lock_stdmode"></a>Standard lock modes</h2>
</div>
</div>
</div>
<p>
The Berkeley DB locking protocol is described by a conflict
matrix. A conflict matrix is an NxN array in which N is the
number of different lock modes supported, and the (i, j)th
entry of the array indicates whether a lock of mode i
conflicts with a lock of mode j. In addition, Berkeley DB
defines the type <span class="bold"><strong>db_lockmode_t</strong></span>,
which is the type of a lock mode within a conflict matrix.
</p>
<p>
The following is an example of a conflict matrix. The actual
conflict matrix used by Berkeley DB to support the underlying
access methods is more complicated, but this matrix shows the
lock mode relationships available to applications using the
Berkeley DB Locking subsystem interfaces directly.
</p>
<div class="variablelist">
<dl>
<dt>
<span class="term">DB_LOCK_NG</span>
</dt>
<dd>not granted (always 0)</dd>
<dt>
<span class="term">DB_LOCK_READ</span>
</dt>
<dd>read (shared)</dd>
<dt>
<span class="term">DB_LOCK_WRITE</span>
</dt>
<dd>write (exclusive)</dd>
<dt>
<span class="term">DB_LOCK_IWRITE</span>
</dt>
<dd>intention to write (shared)</dd>
<dt>
<span class="term">DB_LOCK_IREAD</span>
</dt>
<dd>intention to read (shared)</dd>
<dt>
<span class="term">DB_LOCK_IWR</span>
</dt>
<dd>intention to read and write (shared)</dd>
</dl>
</div>
<p>
In a conflict matrix, the rows indicate the lock that is
held, and the columns indicate the lock that is requested. A 1
represents a conflict (that is, do not grant the lock if the
indicated lock is held), and a 0 indicates that it is OK to
grant the lock.
</p>
<pre class="programlisting"> Notheld Read Write IWrite IRead IRW
Notheld 0 0 0 0 0 0
Read* 0 0 1 1 0 1
Write** 0 1 1 1 1 1
Intent Write 0 1 1 0 0 0
Intent Read 0 0 1 0 0 0
Intent RW 0 1 1 0 0 0</pre>
<div class="variablelist">
<dl>
<dt>
<span class="term">*</span>
</dt>
<dd>
In this case, suppose that there is a read lock
held on an object. A new request for a read lock would
be granted, but a request for a write lock would
not.
</dd>
<dt>
<span class="term">**</span>
</dt>
<dd>
In this case, suppose that there is a write lock
held on an object. A new request for either a read or
write lock would be denied.
</dd>
</dl>
</div>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="lock_max.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="lock.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="lock_dead.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Configuring locking: sizing the
system </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Deadlock detection</td>
</tr>
</table>
</div>
</body>
</html>
|