about summary refs log tree commit diff
path: root/db2/btree/bt_page.c
diff options
context:
space:
mode:
Diffstat (limited to 'db2/btree/bt_page.c')
-rw-r--r--db2/btree/bt_page.c141
1 files changed, 71 insertions, 70 deletions
diff --git a/db2/btree/bt_page.c b/db2/btree/bt_page.c
index 87f2811398..6ccd68a5ab 100644
--- a/db2/btree/bt_page.c
+++ b/db2/btree/bt_page.c
@@ -47,7 +47,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)bt_page.c	10.12 (Sleepycat) 5/6/98";
+static const char sccsid[] = "@(#)bt_page.c	10.17 (Sleepycat) 1/3/99";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -65,45 +65,47 @@ static const char sccsid[] = "@(#)bt_page.c	10.12 (Sleepycat) 5/6/98";
  * __bam_new --
  *	Get a new page, preferably from the freelist.
  *
- * PUBLIC: int __bam_new __P((DB *, u_int32_t, PAGE **));
+ * PUBLIC: int __bam_new __P((DBC *, u_int32_t, PAGE **));
  */
 int
-__bam_new(dbp, type, pagepp)
-	DB *dbp;
+__bam_new(dbc, type, pagepp)
+	DBC *dbc;
 	u_int32_t type;
 	PAGE **pagepp;
 {
 	BTMETA *meta;
+	DB *dbp;
 	DB_LOCK metalock;
 	PAGE *h;
 	db_pgno_t pgno;
 	int ret;
 
+	dbp = dbc->dbp;
 	meta = NULL;
 	h = NULL;
 	metalock = LOCK_INVALID;
 
 	pgno = PGNO_METADATA;
-	if ((ret = __bam_lget(dbp, 0, pgno, DB_LOCK_WRITE, &metalock)) != 0)
+	if ((ret = __bam_lget(dbc, 0, pgno, DB_LOCK_WRITE, &metalock)) != 0)
 		goto err;
-	if ((ret = __bam_pget(dbp, (PAGE **)&meta, &pgno, 0)) != 0)
+	if ((ret = memp_fget(dbp->mpf, &pgno, 0, (PAGE **)&meta)) != 0)
 		goto err;
 
 	if (meta->free == PGNO_INVALID) {
-		if ((ret = __bam_pget(dbp, &h, &pgno, DB_MPOOL_NEW)) != 0)
+		if ((ret = memp_fget(dbp->mpf, &pgno, DB_MPOOL_NEW, &h)) != 0)
 			goto err;
 		ZERO_LSN(h->lsn);
 		h->pgno = pgno;
 	} else {
 		pgno = meta->free;
-		if ((ret = __bam_pget(dbp, &h, &pgno, 0)) != 0)
+		if ((ret = memp_fget(dbp->mpf, &pgno, 0, &h)) != 0)
 			goto err;
 		meta->free = h->next_pgno;
 	}
 
 	/* Log the change. */
-	if (DB_LOGGING(dbp)) {
-		if ((ret = __bam_pg_alloc_log(dbp->dbenv->lg_info, dbp->txn,
+	if (DB_LOGGING(dbc)) {
+		if ((ret = __bam_pg_alloc_log(dbp->dbenv->lg_info, dbc->txn,
 		    &meta->lsn, 0, dbp->log_fileid, &meta->lsn, &h->lsn,
 		    h->pgno, (u_int32_t)type, meta->free)) != 0)
 			goto err;
@@ -111,7 +113,7 @@ __bam_new(dbp, type, pagepp)
 	}
 
 	(void)memp_fput(dbp->mpf, (PAGE *)meta, DB_MPOOL_DIRTY);
-	(void)__BT_TLPUT(dbp, metalock);
+	(void)__BT_TLPUT(dbc, metalock);
 
 	P_INIT(h, dbp->pgsize, h->pgno, PGNO_INVALID, PGNO_INVALID, 0, type);
 	*pagepp = h;
@@ -122,28 +124,45 @@ err:	if (h != NULL)
 	if (meta != NULL)
 		(void)memp_fput(dbp->mpf, meta, 0);
 	if (metalock != LOCK_INVALID)
-		(void)__BT_TLPUT(dbp, metalock);
+		(void)__BT_TLPUT(dbc, metalock);
 	return (ret);
 }
 
 /*
+ * __bam_lput --
+ *	The standard lock put call.
+ *
+ * PUBLIC: int __bam_lput __P((DBC *, DB_LOCK));
+ */
+int
+__bam_lput(dbc, lock)
+	DBC *dbc;
+	DB_LOCK lock;
+{
+	return (__BT_LPUT(dbc, lock));
+}
+
+/*
  * __bam_free --
  *	Add a page to the head of the freelist.
  *
- * PUBLIC: int __bam_free __P((DB *, PAGE *));
+ * PUBLIC: int __bam_free __P((DBC *, PAGE *));
  */
 int
-__bam_free(dbp, h)
-	DB *dbp;
+__bam_free(dbc, h)
+	DBC *dbc;
 	PAGE *h;
 {
 	BTMETA *meta;
+	DB *dbp;
 	DBT ldbt;
 	DB_LOCK metalock;
 	db_pgno_t pgno;
 	u_int32_t dirty_flag;
 	int ret, t_ret;
 
+	dbp = dbc->dbp;
+
 	/*
 	 * Retrieve the metadata page and insert the page at the head of
 	 * the free list.  If either the lock get or page get routines
@@ -152,23 +171,23 @@ __bam_free(dbp, h)
 	 */
 	dirty_flag = 0;
 	pgno = PGNO_METADATA;
-	if ((ret = __bam_lget(dbp, 0, pgno, DB_LOCK_WRITE, &metalock)) != 0)
+	if ((ret = __bam_lget(dbc, 0, pgno, DB_LOCK_WRITE, &metalock)) != 0)
 		goto err;
-	if ((ret = __bam_pget(dbp, (PAGE **)&meta, &pgno, 0)) != 0) {
-		(void)__BT_TLPUT(dbp, metalock);
+	if ((ret = memp_fget(dbp->mpf, &pgno, 0, (PAGE **)&meta)) != 0) {
+		(void)__BT_TLPUT(dbc, metalock);
 		goto err;
 	}
 
 	/* Log the change. */
-	if (DB_LOGGING(dbp)) {
+	if (DB_LOGGING(dbc)) {
 		memset(&ldbt, 0, sizeof(ldbt));
 		ldbt.data = h;
 		ldbt.size = P_OVERHEAD;
 		if ((ret = __bam_pg_free_log(dbp->dbenv->lg_info,
-		    dbp->txn, &meta->lsn, 0, dbp->log_fileid, h->pgno,
+		    dbc->txn, &meta->lsn, 0, dbp->log_fileid, h->pgno,
 		    &meta->lsn, &ldbt, meta->free)) != 0) {
 			(void)memp_fput(dbp->mpf, (PAGE *)meta, 0);
-			(void)__BT_TLPUT(dbp, metalock);
+			(void)__BT_TLPUT(dbc, metalock);
 			return (ret);
 		}
 		LSN(h) = LSN(meta);
@@ -182,7 +201,7 @@ __bam_free(dbp, h)
 	{ db_pgno_t __pgno; DB_LSN __lsn;
 		__pgno = h->pgno;
 		__lsn = h->lsn;
-		memset(h, 0xff, dbp->pgsize);
+		memset(h, 0xdb, dbp->pgsize);
 		h->pgno = __pgno;
 		h->lsn = __lsn;
 	}
@@ -194,7 +213,7 @@ __bam_free(dbp, h)
 
 	/* Discard the metadata page. */
 	ret = memp_fput(dbp->mpf, (PAGE *)meta, DB_MPOOL_DIRTY);
-	if ((t_ret = __BT_TLPUT(dbp, metalock)) != 0)
+	if ((t_ret = __BT_TLPUT(dbc, metalock)) != 0)
 		ret = t_ret;
 
 	/* Discard the caller's page reference. */
@@ -212,19 +231,21 @@ err:	if ((t_ret = memp_fput(dbp->mpf, h, dirty_flag)) != 0 && ret == 0)
 #ifdef DEBUG
 /*
  * __bam_lt --
- *	Print out the list of currently held locks.
+ *	Print out the list of locks currently held by a cursor.
  *
- * PUBLIC: int __bam_lt __P((DB *));
+ * PUBLIC: int __bam_lt __P((DBC *));
  */
 int
-__bam_lt(dbp)
-	DB *dbp;
+__bam_lt(dbc)
+	DBC *dbc;
 {
+	DB *dbp;
 	DB_LOCKREQ req;
 
+	dbp = dbc->dbp;
 	if (F_ISSET(dbp, DB_AM_LOCKING)) {
 		req.op = DB_LOCK_DUMP;
-		lock_vec(dbp->dbenv->lk_info, dbp->locker, 0, &req, 1, NULL);
+		lock_vec(dbp->dbenv->lk_info, dbc->locker, 0, &req, 1, NULL);
 	}
 	return (0);
 }
@@ -234,27 +255,29 @@ __bam_lt(dbp)
  * __bam_lget --
  *	The standard lock get call.
  *
- * PUBLIC: int __bam_lget __P((DB *, int, db_pgno_t, db_lockmode_t, DB_LOCK *));
+ * PUBLIC: int __bam_lget
+ * PUBLIC:    __P((DBC *, int, db_pgno_t, db_lockmode_t, DB_LOCK *));
  */
 int
-__bam_lget(dbp, do_couple, pgno, mode, lockp)
-	DB *dbp;
+__bam_lget(dbc, do_couple, pgno, mode, lockp)
+	DBC *dbc;
 	int do_couple;
 	db_pgno_t pgno;
 	db_lockmode_t mode;
 	DB_LOCK *lockp;
 {
+	DB *dbp;
 	DB_LOCKREQ couple[2];
-	u_int32_t locker;
 	int ret;
 
+	dbp = dbc->dbp;
+
 	if (!F_ISSET(dbp, DB_AM_LOCKING)) {
 		*lockp = LOCK_INVALID;
 		return (0);
 	}
 
-	locker = dbp->txn == NULL ? dbp->locker : dbp->txn->txnid;
-	dbp->lock.pgno = pgno;
+	dbc->lock.pgno = pgno;
 
 	/*
 	 * If the object not currently locked, acquire the lock and return,
@@ -263,54 +286,32 @@ __bam_lget(dbp, do_couple, pgno, mode, lockp)
 	 */
 	if (do_couple) {
 		couple[0].op = DB_LOCK_GET;
-		couple[0].obj = &dbp->lock_dbt;
+		couple[0].obj = &dbc->lock_dbt;
 		couple[0].mode = mode;
 		couple[1].op = DB_LOCK_PUT;
 		couple[1].lock = *lockp;
 
-		ret = lock_vec(dbp->dbenv->lk_info, locker, 0, couple, 2, NULL);
+		if (dbc->txn == NULL)
+			ret = lock_vec(dbp->dbenv->lk_info,
+			    dbc->locker, 0, couple, 2, NULL);
+		else
+			ret = lock_tvec(dbp->dbenv->lk_info,
+			    dbc->txn, 0, couple, 2, NULL);
 		if (ret != 0) {
 			/* If we fail, discard the lock we held. */
-			__bam_lput(dbp, *lockp);
+			__BT_LPUT(dbc, *lockp);
 
 			return (ret < 0 ? EAGAIN : ret);
 		}
 		*lockp = couple[0].lock;
 	} else {
-		 ret = lock_get(dbp->dbenv->lk_info,
-		     locker, 0, &dbp->lock_dbt, mode, lockp);
+		if (dbc->txn == NULL)
+			ret = lock_get(dbp->dbenv->lk_info,
+			    dbc->locker, 0, &dbc->lock_dbt, mode, lockp);
+		else
+			ret = lock_tget(dbp->dbenv->lk_info,
+			    dbc->txn, 0, &dbc->lock_dbt, mode, lockp);
 		 return (ret < 0 ? EAGAIN : ret);
 	}
 	return (0);
 }
-
-/*
- * __bam_lput --
- *	The standard lock put call.
- *
- * PUBLIC: int __bam_lput __P((DB *, DB_LOCK));
- */
-int
-__bam_lput(dbp, lock)
-	DB *dbp;
-	DB_LOCK lock;
-{
-	return (__BT_LPUT(dbp, lock));
-}
-
-/*
- * __bam_pget --
- *	The standard page get call.
- *
- * PUBLIC: int __bam_pget __P((DB *, PAGE **, db_pgno_t *, u_int32_t));
- */
-int
-__bam_pget(dbp, hp, pgnop, mpool_flags)
-	DB *dbp;
-	PAGE **hp;
-	db_pgno_t *pgnop;
-	u_int32_t mpool_flags;
-{
-	return (memp_fget((dbp)->mpf,
-	    pgnop, mpool_flags, hp) == 0 ? 0 : __db_pgerr(dbp, *pgnop));
-}