Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

hash_reclaim.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: hash_reclaim.c,v 12.2 2005/06/16 20:22:53 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #endif
00015 
00016 #include "db_int.h"
00017 #include "dbinc/db_page.h"
00018 #include "dbinc/hash.h"
00019 
00020 /*
00021  * __ham_reclaim --
00022  *      Reclaim the pages from a subdatabase and return them to the
00023  * parent free list.  For now, we link each freed page on the list
00024  * separately.  If people really store hash databases in subdatabases
00025  * and do a lot of creates and deletes, this is going to be a problem,
00026  * because hash needs chunks of contiguous storage.  We may eventually
00027  * need to go to a model where we maintain the free list with chunks of
00028  * contiguous pages as well.
00029  *
00030  * PUBLIC: int __ham_reclaim __P((DB *, DB_TXN *txn));
00031  */
00032 int
00033 __ham_reclaim(dbp, txn)
00034         DB *dbp;
00035         DB_TXN *txn;
00036 {
00037         DBC *dbc;
00038         HASH_CURSOR *hcp;
00039         int ret;
00040 
00041         /* Open up a cursor that we'll use for traversing. */
00042         if ((ret = __db_cursor(dbp, txn, &dbc, 0)) != 0)
00043                 return (ret);
00044         hcp = (HASH_CURSOR *)dbc->internal;
00045 
00046         if ((ret = __ham_get_meta(dbc)) != 0)
00047                 goto err;
00048 
00049         if ((ret = __ham_traverse(dbc,
00050             DB_LOCK_WRITE, __db_reclaim_callback, dbc, 1)) != 0)
00051                 goto err;
00052         if ((ret = __db_c_close(dbc)) != 0)
00053                 goto err;
00054         if ((ret = __ham_release_meta(dbc)) != 0)
00055                 goto err;
00056         return (0);
00057 
00058 err:    if (hcp->hdr != NULL)
00059                 (void)__ham_release_meta(dbc);
00060         (void)__db_c_close(dbc);
00061         return (ret);
00062 }
00063 
00064 /*
00065  * __ham_truncate --
00066  *      Reclaim the pages from a subdatabase and return them to the
00067  * parent free list.
00068  *
00069  * PUBLIC: int __ham_truncate __P((DBC *, u_int32_t *));
00070  */
00071 int
00072 __ham_truncate(dbc, countp)
00073         DBC *dbc;
00074         u_int32_t *countp;
00075 {
00076         db_trunc_param trunc;
00077         int ret, t_ret;
00078 
00079         if ((ret = __ham_get_meta(dbc)) != 0)
00080                 return (ret);
00081 
00082         trunc.count = 0;
00083         trunc.dbc = dbc;
00084 
00085         ret = __ham_traverse(dbc,
00086             DB_LOCK_WRITE, __db_truncate_callback, &trunc, 1);
00087 
00088         if ((t_ret = __ham_release_meta(dbc)) != 0 && ret == 0)
00089                 ret = t_ret;
00090 
00091         if (countp != NULL)
00092                 *countp = trunc.count;
00093         return (ret);
00094 }

Generated on Sun Dec 25 12:14:30 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2