hash_reclaim.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: hash__reclaim_8c-source.html,v 1.1 2008/06/08 10:19:38 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <errno.h>
00018 #include <string.h>
00019 #endif
00020 
00021 #include "db_int.h"
00022 #include "db_page.h"
00023 #include "db_shash.h"
00024 #include "hash.h"
00025 #include "lock.h"
00026 
00027 /*
00028  * CDB___ham_reclaim --
00029  *      Reclaim the pages from a subdatabase and return them to the
00030  * parent free list.  For now, we link each freed page on the list
00031  * separately.  If people really store hash databases in subdatabases
00032  * and do a lot of creates and deletes, this is going to be a problem,
00033  * because hash needs chunks of contiguous storage.  We may eventually
00034  * need to go to a model where we maintain the free list with chunks of
00035  * contiguous pages as well.
00036  *
00037  * PUBLIC: int CDB___ham_reclaim __P((DB *, DB_TXN *txn));
00038  */
00039 int
00040 CDB___ham_reclaim(dbp, txn)
00041         DB *dbp;
00042         DB_TXN *txn;
00043 {
00044         DBC *dbc;
00045         HASH_CURSOR *hcp;
00046         int ret;
00047 
00048         /* Open up a cursor that we'll use for traversing. */
00049         if ((ret = dbp->cursor(dbp, txn, &dbc, 0)) != 0)
00050                 return (ret);
00051         hcp = (HASH_CURSOR *)dbc->internal;
00052 
00053         if ((ret = CDB___ham_get_meta(dbc)) != 0)
00054                 goto err;
00055 
00056         if ((ret = CDB___ham_traverse(dbp,
00057             dbc, DB_LOCK_WRITE, CDB___db_reclaim_callback, dbc)) != 0)
00058                 goto err;
00059         if ((ret = dbc->c_close(dbc)) != 0)
00060                 goto err;
00061         if ((ret = CDB___ham_release_meta(dbc)) != 0)
00062                 goto err;
00063         return (0);
00064 
00065 err:    if (hcp->hdr != NULL)
00066                 (void)CDB___ham_release_meta(dbc);
00067         (void)dbc->c_close(dbc);
00068         return (ret);
00069 }

Generated on Sun Jun 8 10:56:37 2008 for GNUmifluz by  doxygen 1.5.5