Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > a4c98df40e78f6c892308fd6841f950a > files > 919

lib64db4.2-devel-4.2.52-11mdv2007.0.x86_64.rpm

<!--$Id: faq.so,v 10.5 2002/02/04 17:52:37 bostic Exp $-->
<!--Copyright 1997-2003 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Environment FAQ</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,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>Environment</dl></h3></td>
<td align=right><a href="../env/remote.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../cam/intro.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Environment FAQ</h3>
<ol>
<p><li><b>I'm using multiple processes to access an Berkeley DB database
environment; is there any way to ensure that two processes don't run
recovery at the same time, or that all processes have exited the
database environment so that recovery can be run?</b>
<p>It's the responsibility of the processes (and/or threads of control)
using a Berkeley DB environment to ensure recovery is never performed if there
are other processes running recovery or using an existing database
environment.  It would be great if Berkeley DB could solve this, but it
requires a way to single-thread execution on a system, and there's
rarely anything Berkeley DB can use for that purpose -- let alone a portable
method.</p>
<p>Most application suites solve this problem by writing a tiny watch
program that recovers the database environment and then runs the
processes that actually use the database environment to perform work.
The watcher program then monitors the working processes, and if any of
them exit badly for any reason, the watcher kills any remaining
processes and restarts the cycle.</p>
<p><li><b>How can I associate application information with a <a href="../../api_c/db_class.html">DB</a>
or <a href="../../api_c/env_class.html">DB_ENV</a> handle?</b>
<p>In the C API, the <a href="../../api_c/db_class.html">DB</a> and <a href="../../api_c/env_class.html">DB_ENV</a> structures each contain
an "app_private" field intended to be used to reference
application-specific information.  See the <a href="../../api_c/db_class.html">db_create</a> and
<a href="../../api_c/env_class.html">db_env_create</a> documentation for more information.</p>
<p>In the C++ or Java APIs, the easiest way to associate
application-specific data with a handle is to subclass the <a href="../../api_cxx/db_class.html">Db</a>
or <a href="../../api_cxx/env_class.html">DbEnv</a>, for example subclassing <a href="../../api_cxx/db_class.html">Db</a> to get MyDb.
Objects of type MyDb will still have the Berkeley DB API methods available on
them, and you can put any extra data or methods you want into the MyDb
class.  If you are using "callback" APIs that take <a href="../../api_cxx/db_class.html">Db</a> or
<a href="../../api_cxx/env_class.html">DbEnv</a> arguments (for example, <a href="../../api_cxx/db_set_bt_compare.html">Db::set_bt_compare</a>)
these will always be called with the <a href="../../api_cxx/db_class.html">Db</a> or <a href="../../api_cxx/env_class.html">DbEnv</a>
objects you create.  So if you always use MyDb objects, you will be able
to take the first argument to the callback function and cast it to a
MyDb (in C++, cast it to (MyDb*)).  That will allow you to access your
data members or methods.</p>
</ol>
<table width="100%"><tr><td><br></td><td align=right><a href="../env/remote.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../cam/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-2003</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>