Debian Codegraph @

docs/programmer_reference/rq_conf.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Queue and Recno access method specific configuration</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="am_conf.html" title="Chapter 2.  Access Method Configuration" />
11 <link rel="prev" href="heap_conf.html" title="Heap access method specific configuration" />
12 <link rel="next" href="am.html" title="Chapter 3.  Access Method Operations" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Queue and Recno access method specific configuration</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="heap_conf.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2. 
26 Access Method Configuration
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="am.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="rq_conf"></a>Queue and Recno access method specific configuration</h2>
38 </div>
39 </div>
40 </div>
41 <div class="toc">
42 <dl>
43 <dt>
44 <span class="sect2">
45 <a href="rq_conf.html#am_conf_recno">Managing record-based databases</a>
46 </span>
47 </dt>
48 <dt>
49 <span class="sect2">
50 <a href="rq_conf.html#am_conf_extentsize">Selecting a Queue extent size</a>
51 </span>
52 </dt>
53 <dt>
54 <span class="sect2">
55 <a href="rq_conf.html#am_conf_re_source">Flat-text backing files</a>
56 </span>
57 </dt>
58 <dt>
59 <span class="sect2">
60 <a href="rq_conf.html#am_conf_renumber">Logically renumbering records</a>
61 </span>
62 </dt>
63 </dl>
64 </div>
65 <p>
66 There are a series of configuration tasks which you can perform when
67 using the Queue and Recno access methods. They are described in the following sections.
68 </p>
69 <div class="sect2" lang="en" xml:lang="en">
70 <div class="titlepage">
71 <div>
72 <div>
73 <h3 class="title"><a id="am_conf_recno"></a>Managing record-based databases</h3>
74 </div>
75 </div>
76 </div>
77 <p>When using fixed- or variable-length record-based databases, particularly
78 with flat-text backing files, there are several items that the user can
79 control. The Recno access method can be used to store either variable-
80 or fixed-length data items. By default, the Recno access method stores
81 variable-length data items. The Queue access method can only store
82 fixed-length data items.</p>
83 <div class="sect3" lang="en" xml:lang="en">
84 <div class="titlepage">
85 <div>
86 <div>
87 <h4 class="title"><a id="idp50888032"></a>Record Delimiters</h4>
88 </div>
89 </div>
90 </div>
91 <p>When using the Recno access method to store variable-length records,
92 records read from any backing source file are separated by a specific
93 byte value which marks the end of one record and the beginning of the
94 next. This delimiting value is ignored except when reading records from
95 a backing source file, that is, records may be stored into the database
96 that include the delimiter byte. However, if such records are written
97 out to the backing source file and the backing source file is
98 subsequently read into a database, the records will be split where
99 delimiting bytes were found.</p>
100 <p>For example, UNIX text files can usually be interpreted as a sequence of
101 variable-length records separated by ASCII newline characters. This byte
102 value (ASCII 0x0a) is the default delimiter. Applications may specify a
103 different delimiting byte using the <a href="../api_reference/C/dbset_re_delim.html" class="olink">DB-&gt;set_re_delim()</a> method. If no
104 backing source file is being used, there is no reason to set the
105 delimiting byte value.</p>
106 </div>
107 <div class="sect3" lang="en" xml:lang="en">
108 <div class="titlepage">
109 <div>
110 <div>
111 <h4 class="title"><a id="idp50880416"></a>Record Length</h4>
112 </div>
113 </div>
114 </div>
115 <p>When using the Recno or Queue access methods to store fixed-length
116 records, the record length must be specified. Since the Queue access
117 method always uses fixed-length records, the user must always set the
118 record length prior to creating the database. Setting the record length
119 is what causes the Recno access method to store fixed-length, not
120 variable-length, records.</p>
121 <p>The length of the records is specified by calling the
122 <a href="../api_reference/C/dbset_re_len.html" class="olink">DB-&gt;set_re_len()</a> method. The default length of the records is 0 bytes.
123 Any record read from a backing source file or otherwise stored in the
124 database that is shorter than the declared length will automatically be
125 padded as described for the <a href="../api_reference/C/dbset_re_pad.html" class="olink">DB-&gt;set_re_pad()</a> method. Any record stored
126 that is longer than the declared length results in an error. For
127 further information on backing source files, see
128 <a class="xref" href="rq_conf.html#am_conf_re_source" title="Flat-text backing files">Flat-text backing files</a>.</p>
129 </div>
130 <div class="sect3" lang="en" xml:lang="en">
131 <div class="titlepage">
132 <div>
133 <div>
134 <h4 class="title"><a id="idp50867536"></a>Record Padding Byte Value</h4>
135 </div>
136 </div>
137 </div>
138 <p>When storing fixed-length records in a Queue or Recno database, a pad
139 character may be specified by calling the <a href="../api_reference/C/dbset_re_pad.html" class="olink">DB-&gt;set_re_pad()</a> method. Any
140 record read from the backing source file or otherwise stored in the
141 database that is shorter than the expected length will automatically be
142 padded with this byte value. If fixed-length records are specified but
143 no pad value is specified, a space character (0x20 in the ASCII
144 character set) will be used. For further information on backing source
145 files, see <a class="xref" href="rq_conf.html#am_conf_re_source" title="Flat-text backing files">Flat-text backing files</a>.</p>
146 </div>
147 </div>
148 <div class="sect2" lang="en" xml:lang="en">
149 <div class="titlepage">
150 <div>
151 <div>
152 <h3 class="title"><a id="am_conf_extentsize"></a>Selecting a Queue extent size</h3>
153 </div>
154 </div>
155 </div>
156 <p>
157 In Queue databases, records are allocated sequentially and directly
158 mapped to an offset within the file storage for the database. As
159 records are deleted from the Queue, pages will become empty and will
160 not be reused in normal queue operations. To facilitate the
161 reclamation of disk space a Queue may be partitioned into extents.
162 Each extent is kept in a separate physical file.
163 </p>
164 <p>
165 Extent files are automatically created as needed and marked for
166 deletion when the head of the queue moves off the extent. The extent
167 will not be deleted until all processes close the extent. In addition,
168 Berkeley DB caches a small number of extents that have been recently
169 used; this may delay when an extent will be deleted. The number of
170 extents left open depends on queue activity.
171 </p>
172 <p>
173 The extent size specifies the number of pages that make up each extent.
174 By default, if no extent size is specified, the Queue resides in a
175 single file and disk space is not reclaimed. In choosing an extent
176 size there is a tradeoff between the amount of disk space used and the
177 overhead of creating and deleting files. If the extent size is too
178 small, the system will pay a performance penalty, creating and deleting
179 files frequently. In addition, if the active part of the queue spans
180 many files, all those files will need to be open at the same time,
181 consuming system and process file resources.
182 </p>
183 <p>
184 You can set the Queue extent size using the <a href="../api_reference/C/dbset_q_extentsize.html" class="olink">DB-&gt;set_q_extentsize()</a>
185 method. You can see the current extent size using the
186 <a href="../api_reference/C/dbget_q_extentsize.html" class="olink">DB-&gt;get_q_extentsize()</a> method.
187 </p>
188 </div>
189 <div class="sect2" lang="en" xml:lang="en">
190 <div class="titlepage">
191 <div>
192 <div>
193 <h3 class="title"><a id="am_conf_re_source"></a>Flat-text backing files</h3>
194 </div>
195 </div>
196 </div>
197 <p>It is possible to back any Recno database (either fixed or variable
198 length) with a flat-text source file. This provides fast read (and
199 potentially write) access to databases that are normally created and
200 stored as flat-text files. The backing source file may be specified by
201 calling the <a href="../api_reference/C/dbset_re_source.html" class="olink">DB-&gt;set_re_source()</a> method.</p>
202 <p>The backing source file will be read to initialize the database. In the
203 case of variable length records, the records are assumed to be separated
204 as described for the <a href="../api_reference/C/dbset_re_delim.html" class="olink">DB-&gt;set_re_delim()</a> method. For example, standard
205 UNIX byte stream files can be interpreted as a sequence of variable
206 length records separated by ASCII newline characters. This is the
207 default.</p>
208 <p>When cached data would normally be written back to the underlying
209 database file (for example, when the <a href="../api_reference/C/dbclose.html" class="olink">DB-&gt;close()</a> or
210 <a href="../api_reference/C/dbsync.html" class="olink">DB-&gt;sync()</a> methods are called), the in-memory copy of the database will
211 be written back to the backing source file.</p>
212 <p>The backing source file must already exist (but may be zero-length) when
213 <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a> is called. By default, the backing source file is read
214 lazily, that is, records are not read from the backing source file until
215 they are requested by the application. If multiple processes (not
216 threads) are accessing a Recno database concurrently and either
217 inserting or deleting records, the backing source file must be read in
218 its entirety before more than a single process accesses the database,
219 and only that process should specify the backing source file as part of
220 the <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a> call. This can be accomplished by calling the
221 <a href="../api_reference/C/dbset_flags.html" class="olink">DB-&gt;set_flags()</a> method with the <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_SNAPSHOT" class="olink">DB_SNAPSHOT</a> flag.</p>
222 <p>Reading and writing the backing source file cannot be transactionally
223 protected because it involves filesystem operations that are not part of
224 the Berkeley DB transaction methodology. For this reason, if a temporary
225 database is used to hold the records (a NULL was specified as the file
226 argument to <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a>), <span class="bold"><strong>it is possible to lose the
227 contents of the backing source file if the system crashes at the right
228 instant</strong></span>. If a permanent file is used to hold the database (a filename
229 was specified as the file argument to <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a>), normal database
230 recovery on that file can be used to prevent information loss. It is
231 still possible that the contents of the backing source file itself will
232 be corrupted or lost if the system crashes.</p>
233 <p>For all of the above reasons, the backing source file is generally used
234 to specify databases that are read-only for Berkeley DB applications, and that
235 are either generated on the fly by software tools, or modified using a
236 different mechanism such as a text editor.</p>
237 </div>
238 <div class="sect2" lang="en" xml:lang="en">
239 <div class="titlepage">
240 <div>
241 <div>
242 <h3 class="title"><a id="am_conf_renumber"></a>Logically renumbering records</h3>
243 </div>
244 </div>
245 </div>
246 <p>Records stored in the Queue and Recno access methods are accessed by
247 logical record number. In all cases in Btree databases, and optionally
248 in Recno databases (see the <a href="../api_reference/C/dbset_flags.html" class="olink">DB-&gt;set_flags()</a> method and the
249 <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> flag for more information), record numbers are
250 mutable. This means that the record numbers may change as records are
251 added to and deleted from the database. The deletion of record number
252 4 causes any records numbered 5 and higher to be renumbered downward by
253 1; the addition of a new record after record number 4 causes any
254 records numbered 5 and higher to be renumbered upward by 1. In all
255 cases in Queue databases, and by default in Recno databases, record
256 numbers are not mutable, and the addition or deletion of records to the
257 database will not cause already-existing record numbers to change. For
258 this reason, new records cannot be inserted between already-existing
259 records in databases with immutable record numbers.</p>
260 <p>Cursors pointing into a Btree database or a Recno database with mutable
261 record numbers maintain a reference to a specific record, rather than
262 a record number, that is, the record they reference does not change as
263 other records are added or deleted. For example, if a database contains
264 three records with the record numbers 1, 2, and 3, and the data items
265 "A", "B", and "C", respectively, the deletion of record number 2 ("B")
266 will cause the record "C" to be renumbered downward to record number 2.
267 A cursor positioned at record number 3 ("C") will be adjusted and
268 continue to point to "C" after the deletion. Similarly, a cursor
269 previously referring to the now deleted record number 2 will be
270 positioned between the new record numbers 1 and 2, and an insertion
271 using that cursor will appear between those records. In this manner
272 records can be added and deleted to a database without disrupting the
273 sequential traversal of the database by a cursor.</p>
274 <p>Only cursors created using a single <a href="../api_reference/C/db.html" class="olink">DB</a> handle can adjust each
275 other's position in this way, however. If multiple <a href="../api_reference/C/db.html" class="olink">DB</a> handles
276 have a renumbering Recno database open simultaneously (as when multiple
277 processes share a single database environment), a record referred to by
278 one cursor could change underfoot if a cursor created using another
279 <a href="../api_reference/C/db.html" class="olink">DB</a> handle inserts or deletes records into the database. For
280 this reason, applications using Recno databases with mutable record
281 numbers will usually make all accesses to the database using a single
282 <a href="../api_reference/C/db.html" class="olink">DB</a> handle and cursors created from that handle, or will
283 otherwise single-thread access to the database, for example, by using
284 the Berkeley DB Concurrent Data Store product.</p>
285 <p>In any Queue or Recno databases, creating new records will cause the
286 creation of multiple records if the record number being created is more
287 than one greater than the largest record currently in the database. For
288 example, creating record number 28, when record 25 was previously the
289 last record in the database, will implicitly create records 26 and 27
290 as well as 28. All first, last, next and previous cursor operations
291 will automatically skip over these implicitly created records. So, if
292 record number 5 is the only record the application has created,
293 implicitly creating records 1 through 4, the <a href="../api_reference/C/dbcget.html" class="olink">DBC-&gt;get()</a> method with the
294 <a href="../api_reference/C/dbcget.html#dbcget_DB_FIRST" class="olink">DB_FIRST</a> flag will return record number 5, not record number 1.
295 Attempts to explicitly retrieve implicitly created records by their
296 record number will result in a special error return,
297 <a class="link" href="program_errorret.html#program_errorret.DB_KEYEMPTY">DB_KEYEMPTY</a>.</p>
298 <p>In any Berkeley DB database, attempting to retrieve a deleted record, using
299 a cursor positioned on the record, results in a special error return,
300 <a class="link" href="program_errorret.html#program_errorret.DB_KEYEMPTY">DB_KEYEMPTY</a>. In addition, when using Queue databases or Recno
301 databases with immutable record numbers, attempting to retrieve a deleted
302 record by its record number will also result in the <a class="link" href="program_errorret.html#program_errorret.DB_KEYEMPTY">DB_KEYEMPTY</a>
303 return.</p>
304 </div>
305 </div>
306 <div class="navfooter">
307 <hr />
308 <table width="100%" summary="Navigation footer">
309 <tr>
310 <td width="40%" align="left"><a accesskey="p" href="heap_conf.html">Prev</a> </td>
311 <td width="20%" align="center">
312 <a accesskey="u" href="am_conf.html">Up</a>
313 </td>
314 <td width="40%" align="right"> <a accesskey="n" href="am.html">Next</a></td>
315 </tr>
316 <tr>
317 <td width="40%" align="left" valign="top">Heap access method specific configuration </td>
318 <td width="20%" align="center">
319 <a accesskey="h" href="index.html">Home</a>
320 </td>
321 <td width="40%" align="right" valign="top"> Chapter 3. 
322 Access Method Operations
323 </td>
324 </tr>
325 </table>
326 </div>
327 </body>
328 </html>