summaryrefslogtreecommitdiff
path: root/db/docs/ref/lock/nondb.html
blob: 1146ae76c16f6cd9b779ab66f3300cad46814f92 (plain)
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
<!--$Id: nondb.so,v 10.15 2001/05/22 19:39:31 bostic Exp $-->
<!--Copyright 1997-2004 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Locking and non-Berkeley DB applications</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></h3></td>
<td align=right><a href="../lock/am_conv.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../log/intro.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Locking and non-Berkeley DB applications</h3>
<p>The Lock subsystem is useful outside the context of Berkeley DB.  It can be
used to manage concurrent access to any collection of either ephemeral
or persistent objects.  That is, the lock region can persist across
invocations of an application, so it can be used to provide long-term
locking (for example, conference room scheduling).</p>
<p>In order to use the locking subsystem in such a general way, the
applications must adhere to a convention for identifying objects and
lockers.  Consider a conference room scheduling problem, in which there
are three conference rooms scheduled in half-hour intervals. The
scheduling application must then select a way to identify each
conference room/time slot combination.  In this case, we could describe
the objects being locked as bytestrings consisting of the conference
room name, the date when it is needed, and the beginning of the
appropriate half-hour slot.</p>
<p>Lockers are 32-bit numbers, so we might choose to use the User ID of
the individual running the scheduling program.  To schedule half-hour
slots, all the application needs to do is issue a <a href="../../api_c/lock_get.html">DB_ENV-&gt;lock_get</a> call
for the appropriate locker/object pair.  To schedule a longer slot, the
application needs to issue a <a href="../../api_c/lock_vec.html">DB_ENV-&gt;lock_vec</a> call, with one
<a href="../../api_c/lock_get.html">DB_ENV-&gt;lock_get</a> operation per half-hour -- up to the total length.  If
the <a href="../../api_c/lock_vec.html">DB_ENV-&gt;lock_vec</a> call fails, the application would have to release
the parts of the time slot that were obtained.</p>
<p>To cancel a reservation, the application would make the appropriate
<a href="../../api_c/lock_put.html">DB_ENV-&gt;lock_put</a> calls.  To reschedule a reservation, the
<a href="../../api_c/lock_get.html">DB_ENV-&gt;lock_get</a> and <a href="../../api_c/lock_put.html">DB_ENV-&gt;lock_put</a> calls could all be made inside of
a single <a href="../../api_c/lock_vec.html">DB_ENV-&gt;lock_vec</a> call.  The output of <a href="../../api_c/lock_stat.html">DB_ENV-&gt;lock_stat</a> could
be post-processed into a human-readable schedule of conference room
use.</p>
<table width="100%"><tr><td><br></td><td align=right><a href="../lock/am_conv.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../log/intro.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2004</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>