re_source.html   [plain text]


<!--$Id: re_source.so,v 10.16 2003/10/18 19:15:55 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Flat-text backing files</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>Access Methods</dl></b></td>
<td align=right><a href="../am_conf/extentsize.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../am_conf/renumber.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Flat-text backing files</b></p>
<p>It is possible to back any Recno database (either fixed or variable
length) with a flat-text source file.  This provides fast read (and
potentially write) access to databases that are normally created and
stored as flat-text files.  The backing source file may be specified by
calling the <a href="../../api_c/db_set_re_source.html">DB-&gt;set_re_source</a> method.</p>
<p>The backing source file will be read to initialize the database.  In the
case of variable length records, the records are assumed to be separated
as described for the <a href="../../api_c/db_set_re_delim.html">DB-&gt;set_re_delim</a> method.  For example, standard
UNIX byte stream files can be interpreted as a sequence of variable
length records separated by ASCII newline characters.  This is the
default.</p>
<p>When cached data would normally be written back to the underlying
database file (for example, when the <a href="../../api_c/db_close.html">DB-&gt;close</a> or
<a href="../../api_c/db_sync.html">DB-&gt;sync</a> methods are called), the in-memory copy of the database will
be written back to the backing source file.</p>
<p>The backing source file must already exist (but may be zero-length) when
<a href="../../api_c/db_open.html">DB-&gt;open</a> is called.  By default, the backing source file is read
lazily, that is, records are not read from the backing source file until
they are requested by the application. If multiple processes (not
threads) are accessing a Recno database concurrently and either
inserting or deleting records, the backing source file must be read in
its entirety before more than a single process accesses the database,
and only that process should specify the backing source file as part of
the <a href="../../api_c/db_open.html">DB-&gt;open</a> call.  This can be accomplished by calling the
<a href="../../api_c/db_set_flags.html">DB-&gt;set_flags</a> method with the <a href="../../api_c/db_set_flags.html#DB_SNAPSHOT">DB_SNAPSHOT</a> flag.</p>
<p>Reading and writing the backing source file cannot be transactionally
protected because it involves filesystem operations that are not part of
the Berkeley DB transaction methodology. For this reason, if a temporary
database is used to hold the records (a NULL was specified as the file
argument to <a href="../../api_c/db_open.html">DB-&gt;open</a>), <b>it is possible to lose the
contents of the backing source file if the system crashes at the right
instant</b>. If a permanent file is used to hold the database (a filename
was specified as the file argument to <a href="../../api_c/db_open.html">DB-&gt;open</a>), normal database
recovery on that file can be used to prevent information loss.  It is
still possible that the contents of the backing source file itself will
be corrupted or lost if the system crashes.</p>
<p>For all of the above reasons, the backing source file is generally used
to specify databases that are read-only for Berkeley DB applications, and that
are either generated on the fly by software tools, or modified using a
different mechanism such as a text editor.</p>
<table width="100%"><tr><td><br></td><td align=right><a href="../am_conf/extentsize.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../am_conf/renumber.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>