Remove definition of builtin function
[platform/upstream/db4.git] / btree / bt_reclaim.c
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1998-2009 Oracle.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 #include "db_config.h"
10
11 #include "db_int.h"
12 #include "dbinc/db_page.h"
13 #include "dbinc/btree.h"
14 #include "dbinc/lock.h"
15
16 /*
17  * __bam_reclaim --
18  *      Free a database.
19  *
20  * PUBLIC: int __bam_reclaim __P((DB *, DB_THREAD_INFO *, DB_TXN *));
21  */
22 int
23 __bam_reclaim(dbp, ip, txn)
24         DB *dbp;
25         DB_THREAD_INFO *ip;
26         DB_TXN *txn;
27 {
28         DBC *dbc;
29         DB_LOCK meta_lock;
30         int ret, t_ret;
31
32         /* Acquire a cursor. */
33         if ((ret = __db_cursor(dbp, ip, txn, &dbc, 0)) != 0)
34                 return (ret);
35
36         /* Write lock the metapage for deallocations. */
37         if ((ret = __db_lget(dbc,
38             0, PGNO_BASE_MD, DB_LOCK_WRITE, 0, &meta_lock)) != 0)
39                 goto err;
40
41         /* Avoid locking every page, we have the handle locked exclusive. */
42         F_SET(dbc, DBC_DONTLOCK);
43
44         /* Walk the tree, freeing pages. */
45         ret = __bam_traverse(dbc,
46             DB_LOCK_WRITE, dbc->internal->root, __db_reclaim_callback, NULL);
47
48         if ((t_ret = __TLPUT(dbc, meta_lock)) != 0 && ret == 0)
49                 ret = t_ret;
50
51         /* Discard the cursor. */
52 err:    if ((t_ret = __dbc_close(dbc)) != 0 && ret == 0)
53                 ret = t_ret;
54
55         return (ret);
56 }
57
58 /*
59  * __bam_truncate --
60  *      Truncate a database.
61  *
62  * PUBLIC: int __bam_truncate __P((DBC *, u_int32_t *));
63  */
64 int
65 __bam_truncate(dbc, countp)
66         DBC *dbc;
67         u_int32_t *countp;
68 {
69         u_int32_t count;
70         int ret;
71
72 #ifdef HAVE_COMPRESSION
73         u_int32_t comp_count;
74
75         comp_count = 0;
76         if (DB_IS_COMPRESSED(dbc->dbp) &&
77             (ret = __bam_compress_count(dbc, NULL, &comp_count)) != 0)
78                 return (ret);
79 #endif
80
81         count = 0;
82
83         /* Walk the tree, freeing pages. */
84         ret = __bam_traverse(dbc,
85             DB_LOCK_WRITE, dbc->internal->root, __db_truncate_callback, &count);
86
87 #ifdef HAVE_COMPRESSION
88         if (DB_IS_COMPRESSED(dbc->dbp)) {
89                 if (countp != NULL)
90                         *countp = comp_count;
91         } else
92 #endif
93         if (countp != NULL)
94                 *countp = count;
95
96         return (ret);
97 }