/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
/*
* Copyright (c) 1990, 1993, 1994, 1995, 1996
* Keith Bostic. All rights reserved.
*/
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#ifndef lint
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#endif
#include "db_int.h"
#include "db_page.h"
#include "btree.h"
/*
* __bam_rsearch --
* Search a btree for a record number.
*
* PUBLIC: int __bam_rsearch __P((DBC *, db_recno_t *, u_int32_t, int, int *));
*/
int
{
PAGE *h;
BT_STK_CLR(cp);
/*
* There are several ways we search a btree tree. The flags argument
* specifies if we're acquiring read or write locks and if we are
* locking pairs of pages. In addition, if we're adding or deleting
* an item, we have to lock the entire tree, regardless. See btree.h
* for more details.
*
* If write-locking pages, we need to know whether or not to acquire a
* write lock on a page before getting it. This depends on how deep it
* is in tree, which we don't know until we acquire the root page. So,
* if we need to lock the root page we may have to upgrade it later,
* because we won't get the correct lock initially.
*
* Retrieve the root page.
*/
return (ret);
return (ret);
}
/*
* Decide if we need to save this page; if we do, write lock it.
* We deliberately don't lock-couple on this call. If the tree
* is tiny, i.e., one page, and two threads are busily updating
* the root page, we're almost guaranteed deadlocks galore, as
* each one gets a read lock and then blocks the other's attempt
* for a write lock.
*/
if (!stack &&
return (ret);
return (ret);
}
stack = 1;
}
/*
* If appending to the tree, set the record number now -- we have the
* root page locked.
*
* Delete only deletes exact matches, read only returns exact matches.
* Note, this is different from __bam_search(), which returns non-exact
* matches for read.
*
* The record may not exist. We can only return the correct location
* for the record immediately after the last record in the tree, so do
* a fast check now.
*/
*exactp = 0;
} else {
*exactp = 1;
else {
*exactp = 0;
return (DB_NOTFOUND);
}
}
}
/*
* !!!
* Record numbers in the tree are 0-based, but the recno is
* 1-based. All of the calculations below have to take this
* into account.
*/
for (total = 0;;) {
switch (TYPE(h)) {
case P_LBTREE:
/*
* There may be logically deleted records on the page,
* walk the page correcting for them. The record may
* not exist if there are enough deleted records in the
* page.
*/
for (i = recno - 1;; --i) {
if (B_DISSET(GET_BKEYDATA(h,
++recno;
if (i == 0)
break;
}
*exactp = 0;
ret = DB_NOTFOUND;
goto err;
}
}
/* Correct from 1-based to 0-based for a page offset. */
--recno;
return (ret);
case P_IBTREE:
break;
}
break;
case P_LRECNO:
/* Correct from 1-based to 0-based for a page offset. */
--recno;
return (ret);
case P_IRECNO:
break;
}
break;
default:
}
--indx;
if (stack) {
/* Return if this is the lowest page wanted. */
return (ret);
}
if (ret != 0)
goto err;
if ((ret =
goto err;
} else {
/*
* Decide if we want to return a pointer to the next
* page in the stack. If we do, write lock it and
* never unlock it.
*/
stack = 1;
if ((ret =
goto err;
}
goto err;
}
/* NOTREACHED */
__bam_stkrel(dbc, 0);
return (ret);
}
/*
* __bam_adjust --
* Adjust the tree after adding or deleting a record.
*
* PUBLIC: int __bam_adjust __P((DBC *, int32_t));
*/
int
{
PAGE *h;
int ret;
/* Update the record counts for the tree. */
if (DB_LOGGING(dbc) &&
adjust, 1)) != 0)
return (ret);
else
RE_NREC_ADJ(h, adjust);
return (ret);
}
}
return (0);
}
/*
* __bam_nrecs --
* Return the number of records in the tree.
*
* PUBLIC: int __bam_nrecs __P((DBC *, db_recno_t *));
*/
int
{
PAGE *h;
int ret;
return (ret);
return (ret);
return (0);
}
/*
* __bam_total --
* Return the number of records below a page.
*
* PUBLIC: db_recno_t __bam_total __P((PAGE *));
*/
__bam_total(h)
PAGE *h;
{
nrecs = 0;
switch (TYPE(h)) {
case P_LBTREE:
/* Check for logically deleted records. */
++nrecs;
break;
case P_IBTREE:
break;
case P_LRECNO:
break;
case P_IRECNO:
break;
}
return (nrecs);
}