<p>The hardest part of upgrading your application from a 2.X code base to
the 3.0 release is translating the Berkeley DB environment open, close and
remove calls.</p>
<p>There were two logical changes in this part of the Berkeley DB interface.
First, in Berkeley DB 3.0, there are no longer separate structures that
represent each subsystem (for example, DB_LOCKTAB or DB_TXNMGR) and an
overall <ahref="../api_reference/C/env.html"class="olink">DB_ENV</a> environment structure. Instead there is only the
<ahref="../api_reference/C/env.html"class="olink">DB_ENV</a> references should be passed around by your application instead of passing around
DB_LOCKTAB or DB_TXNMGR references. This is likely to be a simple
change for most applications as few applications use the lock_XXX,
log_XXX, memp_XXX or txn_XXX interfaces to create Berkeley DB environments.</p>
<p>The second change is that there are no longer separate open, close, and
unlink interfaces to the Berkeley DB subsystems. For example, in previous
releases, it was possible to open a lock subsystem either using
db_appinit or using the lock_open call. In the 3.0 release the XXX_open
interfaces to the subsystems have been removed, and subsystems must now
be opened using the 3.0 replacement for the db_appinit call.</p>
<p>To upgrade your application, first find each place your application opens,
closes and/or removes a Berkeley DB environment. This will be code of the form:</p>
<preclass="programlisting">db_appinit, db_appexit
lock_open, lock_close, lock_unlink
log_open, log_close, log_unlink
memp_open, memp_close, memp_unlink
txn_open, txn_close, txn_unlink</pre>
<p>Each of these groups of calls should be replaced with calls to
<ahref="../api_reference/C/envcreate.html"class="olink">db_env_create()</a>, <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a>, <ahref="../api_reference/C/envclose.html"class="olink">DB_ENV->close()</a>, and <ahref="../api_reference/C/envremove.html"class="olink">DB_ENV->remove()</a>.
</p>
<p>The <ahref="../api_reference/C/envcreate.html"class="olink">db_env_create()</a> call and the call to the <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a>
method replace the db_appinit, lock_open, log_open, memp_open and txn_open
calls. The <ahref="../api_reference/C/envclose.html"class="olink">DB_ENV->close()</a> method replaces the db_appexit,
lock_close, log_close, memp_close and txn_close calls. The
<ahref="../api_reference/C/envremove.html"class="olink">DB_ENV->remove()</a> call replaces the lock_unlink, log_unlink,
memp_unlink and txn_unlink calls.</p>
<p>Here's an example creating a Berkeley DB environment using the 2.X interface:</p>
<preclass="programlisting">/*
* db_init --
* Initialize the environment.
*/
DB_ENV *
db_init(home)
char *home;
{
DB_ENV *dbenv;
if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL)
<p>Note that in this example, you no longer need the DB_LOCKTAB structure
reference that was required in Berkeley DB 2.X releases.</p>
<p>The final issue with upgrading the db_appinit call is the DB_MPOOL_PRIVATE
option previously provided for the db_appinit call. If your application
is using this flag, it should almost certainly use the new
<ahref="../api_reference/C/envopen.html#envopen_DB_PRIVATE"class="olink">DB_PRIVATE</a> flag to the <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a> method. Regardless, you
should carefully consider this change before converting to use the
<p>Translating db_appexit or XXX_close calls to <ahref="../api_reference/C/envclose.html"class="olink">DB_ENV->close()</a> is equally
simple. Instead of taking a reference to a per-subsystem structure such
as DB_LOCKTAB or DB_TXNMGR, all calls take a reference to a <ahref="../api_reference/C/env.html"class="olink">DB_ENV</a>
structure. The calling sequence is otherwise unchanged. Note that as
the application no longer allocates the memory for the DB_ENV structure,
application code to discard it after the call to db_appexit() is no longer
needed.</p>
<p>Translating XXX_unlink calls to <ahref="../api_reference/C/envremove.html"class="olink">DB_ENV->remove()</a> is slightly more complex.
As with <ahref="../api_reference/C/envclose.html"class="olink">DB_ENV->close()</a>, the call takes a reference to a <ahref="../api_reference/C/env.html"class="olink">DB_ENV</a>
structure instead of a per-subsystem structure. The calling sequence is
slightly different, however. Here is an example of removing a lock region
using the 2.X interface:</p>
<preclass="programlisting">DB_ENV *dbenv;
ret = lock_unlink(dir, 1, dbenv);</pre>
<p>In the Berkeley DB 3.0 release, this code fragment would be written as:</p>
<preclass="programlisting">DB_ENV *dbenv;
ret = dbenv->remove(dbenv, dir, NULL, DB_FORCE);</pre>
<p>The additional argument to the <ahref="../api_reference/C/envremove.html"class="olink">DB_ENV->remove()</a> function is a
configuration argument similar to that previously taken by db_appinit and
now taken by the <ahref="../api_reference/C/envopen.html"class="olink">DB_ENV->open()</a> method. For backward compatibility
this new argument should simply be set to NULL. The force argument to
XXX_unlink is now a flag value that is set by bitwise inclusively <spanclass="bold"><strong>OR</strong></span>'ing it the
<ahref="../api_reference/C/envremove.html"class="olink">DB_ENV->remove()</a> flag argument.</p>