141 lines
6.9 KiB
HTML
141 lines
6.9 KiB
HTML
<!--$Id: db_compact.html 63573 2008-05-23 21:43:21Z trent.nelson $-->
|
|
<!--Copyright (c) 1997,2008 Oracle. All rights reserved.-->
|
|
<!--See the file LICENSE for redistribution information.-->
|
|
<html>
|
|
<head>
|
|
<title>Berkeley DB: DB->compact</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>
|
|
<table width="100%"><tr valign=top>
|
|
<td>
|
|
<b>DB->compact</b>
|
|
</td>
|
|
<td align=right>
|
|
<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a>
|
|
<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
|
|
</tr></table>
|
|
<hr size=1 noshade>
|
|
<tt>
|
|
<b><pre>
|
|
#include <db.h>
|
|
<p>
|
|
int
|
|
DB->compact(DB *db, DB_TXN *txnid,
|
|
DBT *start, DBT *stop, DB_COMPACT *c_data, u_int32_t flags, DBT *end);
|
|
</pre></b>
|
|
<hr size=1 noshade>
|
|
<b>Description: DB->compact</b>
|
|
<p>The DB->compact method compacts Btree and Recno access method
|
|
databases, and optionally returns unused Btree, Hash or Recno database
|
|
pages to the underlying filesystem.</p>
|
|
<p>The DB->compact method
|
|
returns a non-zero error value on failure
|
|
and 0 on success.
|
|
</p>
|
|
<b>Parameters</b> <br>
|
|
<b>txnid</b><ul compact><li>If the operation is part of an application-specified transaction, the
|
|
<b>txnid</b> parameter is a transaction handle returned from
|
|
<a href="../api_c/txn_begin.html">DB_ENV->txn_begin</a>; otherwise NULL. If no transaction handle is
|
|
specified, but the operation occurs in a transactional database, the
|
|
operation will be implicitly transaction protected using multiple
|
|
transactions. These transactions will be periodically committed to
|
|
avoid locking large sections of the tree. Any deadlocks encountered
|
|
cause the compaction operation to retried from the point of the last
|
|
transaction commit.</ul>
|
|
<b>start</b><ul compact><li>If non-NULL, the <b>start</b> parameter is the starting point for
|
|
compaction in a Btree or Recno database. Compaction will start at the
|
|
smallest key greater than or equal to the specified key. If NULL,
|
|
compaction will start at the beginning of the database.</ul>
|
|
<b>stop</b><ul compact><li>If non-NULL, the <b>stop</b> parameter is the stopping point for
|
|
compaction in a Btree or Recno database. Compaction will stop at the
|
|
page with the smallest key greater than the specified key. If NULL,
|
|
compaction will stop at the end of the database.</ul>
|
|
<b>c_data</b><ul compact><li><p>If non-NULL, the <b>c_data</b> parameter contains additional compaction
|
|
configuration parameters, and returns compaction operation statistics,
|
|
in a structure of type DB_COMPACT.</p>
|
|
<p>The following input configuration fields are available from the
|
|
DB_COMPACT structure:</p>
|
|
<br>
|
|
<b>int compact_fillpercent;</b><ul compact><li>If non-zero, the goal for filling pages, specified as a percentage
|
|
between 1 and 100. Any page in a Btree or Recno databases not at or
|
|
above this percentage full will be considered for compaction. The
|
|
default behavior is to consider every page for compaction, regardless
|
|
of its page fill percentage.</ul>
|
|
<b>int compact_pages;</b><ul compact><li>If non-zero, the call will return after that number of pages have been
|
|
freed.</ul>
|
|
<b>db_timeout_t compact_timeout;</b><ul compact><li>If non-zero, and no <b>txnid</b> parameter was specified, the lock
|
|
timeout set for implicit transactions, in microseconds.</ul>
|
|
<br>
|
|
<p>The following output statistics fields are available from the
|
|
DB_COMPACT structure:</p>
|
|
<br>
|
|
<b>u_int32_t compact_deadlock;</b><ul compact><li>An output statistics parameter: if no <b>txnid</b> parameter was
|
|
specified, the number of deadlocks which occurred.</ul>
|
|
<b>u_int32_t compact_pages_examine;</b><ul compact><li>An output statistics parameter: the number of database pages reviewed
|
|
during the compaction phase.</ul>
|
|
<b>u_int32_t compact_pages_free;</b><ul compact><li>An output statistics parameter: the number of database pages freed during
|
|
the compaction phase.</ul>
|
|
<b>u_int32_t compact_levels;</b><ul compact><li>An output statistics parameter: the number of levels removed from the
|
|
Btree or Recno database during the compaction phase.</ul>
|
|
<b>u_int32_t compact_pages_truncated;</b><ul compact><li>An output statistics parameter: the number of database pages returned
|
|
to the filesystem.</ul>
|
|
<br></ul>
|
|
<b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or
|
|
one of the following values:
|
|
<br>
|
|
<b><a name="DB_FREELIST_ONLY">DB_FREELIST_ONLY</a></b><ul compact><li>Do no page compaction, only returning pages to the filesystem that are
|
|
already free and at the end of the file. This flag must be set if the
|
|
database is a Hash access method database.</ul>
|
|
<b><a name="DB_FREE_SPACE">DB_FREE_SPACE</a></b><ul compact><li>Return pages to the filesystem when possible.
|
|
If this flag is not specified, pages emptied as a result of compaction
|
|
will be placed on the free list for re-use, but never returned to the
|
|
filesystem.
|
|
<p>Note that only pages at the end of a file can be returned to the
|
|
filesystem. Because of the one-pass nature of the compaction algorithm,
|
|
any not emptied page near the end of the file inhibits returning pages to
|
|
the file system. A repeated call to the DB->compact method with a low
|
|
<b>compact_fillpercent</b> may be used to return pages in this case.</p></ul>
|
|
<br></ul>
|
|
<b>end</b><ul compact><li>If non-NULL, the <b>end</b> parameter will be filled in with the
|
|
database key marking the end of the compaction operation in a Btree or
|
|
Recno database. This is generally the first key of the page where the
|
|
operation stopped.</ul>
|
|
<br>
|
|
<br><b>Errors</b>
|
|
<p>The DB->compact method
|
|
may fail and return one of the following non-zero errors:</p>
|
|
<br>
|
|
<b>DB_LOCK_DEADLOCK</b><ul compact><li>A transactional database environment operation was selected to resolve
|
|
a deadlock.</ul>
|
|
<b>DB_LOCK_NOTGRANTED</b><ul compact><li>A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
|
|
to grant a lock in the allowed time.</ul>
|
|
<br>
|
|
<br>
|
|
<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election
|
|
unrolled a committed transaction.</ul>
|
|
<br>
|
|
<br>
|
|
<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul>
|
|
<br>
|
|
<br>
|
|
<b>EACCES</b><ul compact><li>An attempt was made to modify a read-only database.</ul>
|
|
<br>
|
|
<br>
|
|
<b>EINVAL</b><ul compact><li>An
|
|
invalid flag value or parameter was specified.</ul>
|
|
<br>
|
|
<hr size=1 noshade>
|
|
<br><b>Class</b>
|
|
<a href="../api_c/db_class.html">DB</a>
|
|
<br><b>See Also</b>
|
|
<a href="../api_c/db_list.html">Databases and Related Methods</a>
|
|
</tt>
|
|
<table width="100%"><tr><td><br></td><td align=right>
|
|
<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
|
|
</td></tr></table>
|
|
<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font>
|
|
</body>
|
|
</html>
|