summaryrefslogtreecommitdiff
path: root/db/btree/bt_reclaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'db/btree/bt_reclaim.c')
-rw-r--r--db/btree/bt_reclaim.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/db/btree/bt_reclaim.c b/db/btree/bt_reclaim.c
index ee722a30f..d48c9dfcf 100644
--- a/db/btree/bt_reclaim.c
+++ b/db/btree/bt_reclaim.c
@@ -1,23 +1,18 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998-2004
- * Sleepycat Software. All rights reserved.
+ * Copyright (c) 1998-2006
+ * Oracle Corporation. All rights reserved.
*
- * $Id: bt_reclaim.c,v 11.15 2004/01/28 03:35:49 bostic Exp $
+ * $Id: bt_reclaim.c,v 12.6 2006/08/24 14:44:44 bostic Exp $
*/
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/btree.h"
+#include "dbinc/lock.h"
/*
* __bam_reclaim --
@@ -31,18 +26,28 @@ __bam_reclaim(dbp, txn)
DB_TXN *txn;
{
DBC *dbc;
+ DB_LOCK meta_lock;
int ret, t_ret;
/* Acquire a cursor. */
if ((ret = __db_cursor(dbp, txn, &dbc, 0)) != 0)
return (ret);
+ /* Write lock the metapage for deallocations. */
+ if ((ret = __db_lget(dbc,
+ 0, PGNO_BASE_MD, DB_LOCK_WRITE, 0, &meta_lock)) != 0)
+ goto err;
+
+ /* Avoid locking every page, we have the handle locked exclusive. */
+ F_SET(dbc, DBC_DONTLOCK);
+
/* Walk the tree, freeing pages. */
ret = __bam_traverse(dbc,
DB_LOCK_WRITE, dbc->internal->root, __db_reclaim_callback, dbc);
+ __TLPUT(dbc, meta_lock);
/* Discard the cursor. */
- if ((t_ret = __db_c_close(dbc)) != 0 && ret == 0)
+err: if ((t_ret = __db_c_close(dbc)) != 0 && ret == 0)
ret = t_ret;
return (ret);
@@ -69,7 +74,8 @@ __bam_truncate(dbc, countp)
ret = __bam_traverse(dbc,
DB_LOCK_WRITE, dbc->internal->root, __db_truncate_callback, &trunc);
- *countp = trunc.count;
+ if (countp != NULL)
+ *countp = trunc.count;
return (ret);
}