2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id$";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
21
#include "dbinc/db_page.h"
22
#include "dbinc/hash.h"
26
* Reclaim the pages from a subdatabase and return them to the
27
* parent free list. For now, we link each freed page on the list
28
* separately. If people really store hash databases in subdatabases
29
* and do a lot of creates and deletes, this is going to be a problem,
30
* because hash needs chunks of contiguous storage. We may eventually
31
* need to go to a model where we maintain the free list with chunks of
32
* contiguous pages as well.
34
* PUBLIC: int __ham_reclaim __P((DB *, DB_TXN *txn));
37
__ham_reclaim(dbp, txn)
45
/* Open up a cursor that we'll use for traversing. */
46
if ((ret = dbp->cursor(dbp, txn, &dbc, 0)) != 0)
48
hcp = (HASH_CURSOR *)dbc->internal;
50
if ((ret = __ham_get_meta(dbc)) != 0)
53
if ((ret = __ham_traverse(dbc,
54
DB_LOCK_WRITE, __db_reclaim_callback, dbc, 1)) != 0)
56
if ((ret = dbc->c_close(dbc)) != 0)
58
if ((ret = __ham_release_meta(dbc)) != 0)
62
err: if (hcp->hdr != NULL)
63
(void)__ham_release_meta(dbc);
64
(void)dbc->c_close(dbc);
70
* Reclaim the pages from a subdatabase and return them to the
73
* PUBLIC: int __ham_truncate __P((DB *, DB_TXN *txn, u_int32_t *));
76
__ham_truncate(dbp, txn, countp)
86
/* Open up a cursor that we'll use for traversing. */
87
if ((ret = dbp->cursor(dbp, txn, &dbc, 0)) != 0)
89
hcp = (HASH_CURSOR *)dbc->internal;
91
if ((ret = __ham_get_meta(dbc)) != 0)
97
if ((ret = __ham_traverse(dbc,
98
DB_LOCK_WRITE, __db_truncate_callback, &trunc, 1)) != 0)
100
if ((ret = __ham_release_meta(dbc)) != 0)
102
if ((ret = dbc->c_close(dbc)) != 0)
104
*countp = trunc.count;
107
err: if (hcp->hdr != NULL)
108
(void)__ham_release_meta(dbc);
109
(void)dbc->c_close(dbc);