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