Debian Codegraph @

docs/api_reference/C/dbcompact.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>DB-&gt;compact()</title>
7 <link rel="stylesheet" href="apiReference.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 C API Reference" />
10 <link rel="up" href="db.html" title="Chapter 2.  The DB Handle" />
11 <link rel="prev" href="dbclose.html" title="DB-&gt;close()" />
12 <link rel="next" href="db_copy.html" title="db_copy" />
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">DB-&gt;compact()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbclose.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2. 
26 The DB Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="db_copy.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="dbcompact"></a>DB-&gt;compact()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db.h&gt;
42
43 int
44 DB-&gt;compact(DB *db, DB_TXN *txnid,
45 DBT *start, DBT *stop, DB_COMPACT *c_data, u_int32_t flags, DBT *end); </pre>
46 <p>
47 The <code class="methodname">DB-&gt;compact()</code> method compacts Btree,
48 Hash, and Recno access method databases, and optionally returns
49 unused Btree, Hash or Recno database pages to the underlying
50 filesystem.
51 </p>
52 <p>
53 The <code class="methodname">DB-&gt;compact()</code> <span>
54 <span>
55 method returns a non-zero error value on failure and 0 on success.
56 </span>
57
58 </span>
59 </p>
60 <div class="sect2" lang="en" xml:lang="en">
61 <div class="titlepage">
62 <div>
63 <div>
64 <h3 class="title"><a id="idp49300048"></a>Parameters</h3>
65 </div>
66 </div>
67 </div>
68 <div class="sect3" lang="en" xml:lang="en">
69 <div class="titlepage">
70 <div>
71 <div>
72 <h4 class="title"><a id="idp49291016"></a>txnid</h4>
73 </div>
74 </div>
75 </div>
76 <p>
77 If the operation is part of an application-specified transaction, the
78 <span class="bold"><strong>txnid</strong></span> parameter is a transaction
79 handle returned from <a class="xref" href="txnbegin.html" title="DB_ENV-&gt;txn_begin()">DB_ENV-&gt;txn_begin()</a>;
80 if the operation is part of a Berkeley DB Concurrent Data Store group, the
81 <span class="bold"><strong>txnid</strong></span> parameter is a handle returned
82 from <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV-&gt;cdsgroup_begin()">DB_ENV-&gt;cdsgroup_begin()</a>;
83 otherwise NULL.
84 </p>
85 <p>
86 If a transaction handle is supplied to this method, then the operation is
87 performed using that transaction. In this event, large sections of the
88 tree may be locked during the course of the transaction.
89 </p>
90 <p>
91 If no transaction handle is specified, but the operation occurs
92 in a transactional database, the operation will be implicitly
93 transaction protected using multiple transactions. These transactions
94 will be periodically committed to avoid locking large sections of the
95 tree. Any deadlocks encountered cause the compaction operation to
96 be retried from the point of the last transaction commit.
97 </p>
98 </div>
99 <div class="sect3" lang="en" xml:lang="en">
100 <div class="titlepage">
101 <div>
102 <div>
103 <h4 class="title"><a id="idp49364280"></a>start</h4>
104 </div>
105 </div>
106 </div>
107 <p>
108 If non-NULL, the <span class="bold"><strong>start</strong></span>
109 parameter is the starting point for compaction. For a
110 Btree or Recno database, compaction will start at the
111 smallest key greater than or equal to the specified key.
112 For a Hash database, the compaction will start in the
113 bucket specified by the integer stored in the key. If
114 NULL, compaction will start at the beginning of the
115 database.
116 </p>
117 </div>
118 <div class="sect3" lang="en" xml:lang="en">
119 <div class="titlepage">
120 <div>
121 <div>
122 <h4 class="title"><a id="idp49235384"></a>stop</h4>
123 </div>
124 </div>
125 </div>
126 <p>
127 If non-NULL, the <span class="bold"><strong>stop</strong></span>
128 parameter is the stopping point for compaction. For a
129 Btree or Recno database, compaction will stop at the page
130 with the smallest key greater than the specified key.
131 For a Hash database, compaction will stop in the bucket
132 specified by the integer stored in the key. If NULL,
133 compaction will stop at the end of the database.
134 </p>
135 </div>
136 <div class="sect3" lang="en" xml:lang="en">
137 <div class="titlepage">
138 <div>
139 <div>
140 <h4 class="title"><a id="idp49216144"></a>c_data</h4>
141 </div>
142 </div>
143 </div>
144 <p>
145 If non-NULL, the <span class="bold"><strong>c_data</strong></span> parameter
146 contains additional compaction configuration parameters, and returns
147 compaction operation statistics, in a structure of type
148 <code class="literal">DB_COMPACT</code>.
149 </p>
150 <p>
151 The following input configuration fields are available from the
152 <code class="literal">DB_COMPACT</code> structure:
153 </p>
154 <div class="itemizedlist">
155 <ul type="disc">
156 <li>
157 <p>
158 <code class="literal">int compact_fillpercent;</code>
159 </p>
160 <p>
161 If non-zero, this provides the goal for filling
162 pages, specified as a percentage between 1 and 100.
163 Any page in the database not at or above this
164 percentage full will be considered for compaction.
165 The default behavior is to consider every page for
166 compaction, regardless of its page fill percentage.
167 </p>
168 </li>
169 <li>
170 <p>
171 <code class="literal">int compact_pages;</code>
172 </p>
173 <p>
174 If non-zero, the call will return after the
175 specified number of pages have been freed, or no
176 more pages can be freed.
177 </p>
178 </li>
179 <li>
180 <p>
181 <code class="literal">db_timeout_t compact_timeout;</code>
182 </p>
183 <p>
184 If non-zero, and no
185 <span class="bold"><strong>txnid</strong></span> parameter was
186 specified, this parameter identifies the lock
187 timeout used for implicit transactions, in
188 microseconds.
189 </p>
190 </li>
191 </ul>
192 </div>
193 <p>
194 The following output statistics fields are available from the
195 <code class="literal">DB_COMPACT</code> structure:
196 </p>
197 <div class="itemizedlist">
198 <ul type="disc">
199 <li>
200 <p>
201 <code class="literal">u_int32_t compact_deadlock;</code>
202 </p>
203 <p>
204 An output statistics parameter: if no
205 <span class="bold"><strong>txnid</strong></span> parameter was
206 specified, the number of deadlocks which occurred.
207 </p>
208 </li>
209 <li>
210 <p>
211 <code class="literal">u_int32_t compact_pages_examine;</code>
212 </p>
213 <p>
214 An output statistics parameter: the number of
215 database pages reviewed during the compaction
216 phase.
217 </p>
218 </li>
219 <li>
220 <p>
221 <code class="literal">u_int32_t compact_empty_buckets;</code>
222 </p>
223 <p>
224 An output statistics parameter: the number of empty
225 hash buckets that were found the compaction phase.
226 </p>
227 </li>
228 <li>
229 <p>
230 <code class="literal">u_int32_t compact_pages_free;</code>
231 </p>
232 <p>
233 An output statistics parameter: the number of
234 database pages freed during the compaction phase.
235 </p>
236 </li>
237 <li>
238 <p>
239 <code class="literal">u_int32_t compact_levels;</code>
240 </p>
241 <p>
242 An output statistics parameter: the number of levels
243 removed from the Btree or Recno database during the
244 compaction phase.
245 </p>
246 </li>
247 <li>
248 <p>
249 <code class="literal">u_int32_t compact_pages_truncated;</code>
250 </p>
251 <p>
252 An output statistics parameter: the number of
253 database pages returned to the filesystem.
254 </p>
255 </li>
256 </ul>
257 </div>
258 </div>
259 <div class="sect3" lang="en" xml:lang="en">
260 <div class="titlepage">
261 <div>
262 <div>
263 <h4 class="title"><a id="idp49398720"></a>flags</h4>
264 </div>
265 </div>
266 </div>
267 <p>
268 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
269 or one of the following values:
270 </p>
271 <div class="itemizedlist">
272 <ul type="disc">
273 <li>
274 <p><a id="compact_DB_FREELIST_ONLY"></a>
275 <code class="literal">DB_FREELIST_ONLY</code>
276 </p>
277 <p>
278 Do no page compaction, only returning pages to the
279 filesystem that are already free and at the end of
280 the file.
281 </p>
282 </li>
283 <li>
284 <p><a id="compact_DB_FREE_SPACE"></a>
285 <code class="literal">DB_FREE_SPACE</code>
286 </p>
287 <p>
288 Return pages to the filesystem when possible. If
289 this flag is not specified, pages emptied as a
290 result of compaction will be placed on the free
291 list for re-use, but never returned to the
292 filesystem.
293 </p>
294 <p>
295 Note that only pages at the end of a file can be
296 returned to the filesystem. Because of the
297 one-pass nature of the compaction algorithm, any
298 unemptied page near the end of the file inhibits
299 returning pages to the file system. A repeated
300 call to the <code class="methodname">DB-&gt;compact()</code>
301 method with a low
302 <span class="bold"><strong>compact_fillpercent</strong></span>
303 may be used to return pages in this case.
304 </p>
305 </li>
306 </ul>
307 </div>
308 </div>
309 <div class="sect3" lang="en" xml:lang="en">
310 <div class="titlepage">
311 <div>
312 <div>
313 <h4 class="title"><a id="idp49416288"></a>end</h4>
314 </div>
315 </div>
316 </div>
317 <p>
318 If non-NULL, the <span class="bold"><strong>end</strong></span>
319 parameter will be filled with the database key marking
320 the end of the compaction operation in a Btree or Recno
321 database. This is generally the first key of the page
322 where the operation stopped. For a Hash database, this
323 will hold the integer value representing which bucket the
324 compaction stopped in.
325 </p>
326 </div>
327 </div>
328 <div class="sect2" lang="en" xml:lang="en">
329 <div class="titlepage">
330 <div>
331 <div>
332 <h3 class="title"><a id="idp49392784"></a>Errors</h3>
333 </div>
334 </div>
335 </div>
336 <p>
337 The <code class="methodname">DB-&gt;compact()</code> <span>
338 <span>
339 method may fail and return one of the following non-zero errors:
340 </span>
341
342 </span>
343 </p>
344 <div class="sect3" lang="en" xml:lang="en">
345 <div class="titlepage">
346 <div>
347 <div>
348 <h4 class="title"><a id="idp49382944"></a>DB_LOCK_DEADLOCK</h4>
349 </div>
350 </div>
351 </div>
352 <p>
353 A transactional database environment operation was selected to resolve
354 a deadlock.
355 </p>
356 </div>
357 <div class="sect3" lang="en" xml:lang="en">
358 <div class="titlepage">
359 <div>
360 <div>
361 <h4 class="title"><a id="idp49415232"></a>DB_LOCK_NOTGRANTED</h4>
362 </div>
363 </div>
364 </div>
365 <p>
366 A Berkeley DB Concurrent Data Store database environment configured
367 for lock timeouts was unable to grant a lock in the allowed time.
368 </p>
369 <p>
370 You attempted to open a database handle that is configured
371 for no waiting exclusive locking, but the exclusive lock could not be
372 immediately obtained. See
373 <a class="xref" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
374 for more information.
375 </p>
376 </div>
377 <div class="sect3" lang="en" xml:lang="en">
378 <div class="titlepage">
379 <div>
380 <div>
381 <h4 class="title"><a id="idp49414624"></a> DB_REP_HANDLE_DEAD</h4>
382 </div>
383 </div>
384 </div>
385 <p>
386 When a client synchronizes with the master, it is possible for committed
387 transactions to be rolled back. This invalidates all the database and cursor
388 handles opened in the replication environment. Once this occurs, an attempt to use
389 such a handle will
390
391 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
392 The application will need to discard the handle and open a new one in order to
393 continue processing.
394 </p>
395 </div>
396 <div class="sect3" lang="en" xml:lang="en">
397 <div class="titlepage">
398 <div>
399 <div>
400 <h4 class="title"><a id="idp49427920"></a>DB_REP_LOCKOUT</h4>
401 </div>
402 </div>
403 </div>
404 <p>
405 The operation was blocked by client/master synchronization.
406 </p>
407 </div>
408 <div class="sect3" lang="en" xml:lang="en">
409 <div class="titlepage">
410 <div>
411 <div>
412 <h4 class="title"><a id="idp49425952"></a>EACCES</h4>
413 </div>
414 </div>
415 </div>
416 <p>
417 An attempt was made to modify a read-only database.
418 </p>
419 </div>
420 <div class="sect3" lang="en" xml:lang="en">
421 <div class="titlepage">
422 <div>
423 <div>
424 <h4 class="title"><a id="idp49423920"></a>EINVAL</h4>
425 </div>
426 </div>
427 </div>
428 <p>
429 An invalid flag value or parameter was specified.
430 </p>
431 </div>
432 </div>
433 <div class="sect2" lang="en" xml:lang="en">
434 <div class="titlepage">
435 <div>
436 <div>
437 <h3 class="title"><a id="idp49393960"></a>Class</h3>
438 </div>
439 </div>
440 </div>
441 <p>
442 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
443 </p>
444 </div>
445 <div class="sect2" lang="en" xml:lang="en">
446 <div class="titlepage">
447 <div>
448 <div>
449 <h3 class="title"><a id="idp49413392"></a>See Also</h3>
450 </div>
451 </div>
452 </div>
453 <p>
454 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
455 </p>
456 </div>
457 </div>
458 <div class="navfooter">
459 <hr />
460 <table width="100%" summary="Navigation footer">
461 <tr>
462 <td width="40%" align="left"><a accesskey="p" href="dbclose.html">Prev</a> </td>
463 <td width="20%" align="center">
464 <a accesskey="u" href="db.html">Up</a>
465 </td>
466 <td width="40%" align="right"> <a accesskey="n" href="db_copy.html">Next</a></td>
467 </tr>
468 <tr>
469 <td width="40%" align="left" valign="top">DB-&gt;close() </td>
470 <td width="20%" align="center">
471 <a accesskey="h" href="index.html">Home</a>
472 </td>
473 <td width="40%" align="right" valign="top"> db_copy</td>
474 </tr>
475 </table>
476 </div>
477 </body>
478 </html>