nondb.html   [plain text]


<!--$Id: nondb.so,v 10.15 2001/05/22 19:39:31 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  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><b><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></b></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 align=center><b>Locking and non-Berkeley DB applications</b></p>
<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>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>