db_dup.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <errno.h>
#include <string.h>
#endif
#include "db_int.h"
#include "db_page.h"
#include "btree.h"
#include "db_am.h"
/*
* __db_dput --
* Put a duplicate item onto a duplicate page at the given index.
*
* PUBLIC: int __db_dput __P((DBC *, DBT *,
* PUBLIC: PAGE **, db_indx_t *, int (*)(DBC *, u_int32_t, PAGE **)));
*/
int
{
int ret;
/*
* We need some access method independent threshold for when we put
* a duplicate item onto an overflow page.
*/
return (ret);
} else {
}
else
if (ret != 0)
/*
* XXX
* Pages not returned to free list.
*/
return (ret);
}
/*
* Now, pagep references the page on which to insert and indx is the
* the location to insert.
*/
return (ret);
return (0);
}
/*
* __db_drem --
* Remove a duplicate at the given index on the given page.
*
* PUBLIC: int __db_drem __P((DBC *,
* PUBLIC: PAGE **, u_int32_t, int (*)(DBC *, PAGE *)));
*/
int
{
int ret;
/* Check if we are freeing a big item. */
return (ret);
} else
if (ret != 0)
return (ret);
/*
* If the page is emptied, then the page is freed and the pp
* parameter is set to reference the next, locked page in the
* duplicate chain, if one exists. If there was no such page,
* then it is set to NULL.
*
* !!!
* __db_relink will set the dirty bit for us.
*/
return (ret);
return (ret);
} else
return (0);
}
/*
* __db_dend --
* Find the last page in a set of offpage duplicates.
*
* PUBLIC: int __db_dend __P((DBC *, db_pgno_t, PAGE **));
*/
int
{
PAGE *h;
int ret;
/*
* This implements DB_KEYLAST. The last page is returned in pp; pgno
* should be the page number of the first page of the duplicate chain.
*
* *pp may be non-NULL -- if given a valid page use it.
*/
goto started;
for (;;) {
return (ret);
}
break;
return (ret);
}
return (0);
}
/*
* __db_dsplit --
* Split a page of duplicates, calculating the split point based
* on an element of size "size" being added at "*indxp".
* On entry hp contains a pointer to the page-pointer of the original
* page. On exit, it returns a pointer to the page containing "*indxp"
* and "indxp" has been modified to reflect the index on the new page
* where the element should be added. The function returns with
* the page on which the insert should happen, not yet put.
*/
static int
{
h = *hp;
ret = 0;
/* Create a temporary page to do compaction onto. */
return (ret);
/* Create new page for the split. */
return (ret);
}
/* Figure out the split point */
did_indx = 0;
if (i == indx) {
did_indx = 1;
/* We've crossed the halfway point. */
*indxp = 0;
} else
*indxp = i;
break;
}
*indxp = i;
}
else
sum += BOVERFLOW_SIZE;
/* We've crossed the halfway point. */
i++;
break;
}
}
/*
* Check if we have set the return values of the index pointer and
* page pointer.
*/
if (!did_indx) {
}
if (DB_LOGGING(dbc)) {
return (ret);
}
}
/*
* If it's a btree, adjust the cursors.
*
* i is the index of the first element to move onto the new page.
*/
else
s = BOVERFLOW_SIZE;
}
/*
* Now do data compaction by copying the remaining stuff onto the
* temporary page and then copying it back to the real page.
*/
else
s = BOVERFLOW_SIZE;
}
/*
* This page (the temporary) should be only half full, so we do two
* memcpy's, one for the top of the page and one for the bottom of
* the page. This way we avoid copying the middle which should be
* about half a page.
*/
if (DB_LOGGING(dbc)) {
/*
* XXX
* If either of these fails, are we leaving pages pinned?
* Yes, but it seems like this happens in error case.
*/
return (ret);
return (ret);
}
/*
* Finally, if there was a next page after the page being
* split, fix its prev pointer.
*/
/*
* Figure out if the location we're interested in is on the new
* page, and if so, reset the callers' pointer. Push the other
* page back to the store.
*/
if (*hp == h)
else
}
/*
* __db_ditem --
* Remove an item from a page.
*
* PUBLIC: int __db_ditem __P((DBC *, PAGE *, u_int32_t, u_int32_t));
*/
int
{
int ret;
if (DB_LOGGING(dbc)) {
return (ret);
}
/*
* If there's only a single item on the page, we don't have to
* work hard.
*/
return (0);
}
/*
* memmove(3), the regions may overlap.
*/
/* Adjust the indices' offsets. */
/* Shift the indices down. */
/* If it's a btree, adjust the cursors. */
return (0);
}
/*
* __db_pitem --
* Put an item on a page.
*
* PUBLIC: int __db_pitem
* PUBLIC: __P((DBC *, PAGE *, u_int32_t, u_int32_t, DBT *, DBT *));
*/
int
{
int ret;
u_int8_t *p;
/*
* Put a single item onto a page. The logic figuring out where to
* insert and whether it fits is handled in the caller. All we do
* here is manage the page shuffling. We cheat a little bit in that
* we don't want to copy the dbt on a normal put twice. If hdr is
* NULL, we create a BKEYDATA structure on the page, otherwise, just
* copy the caller's information onto the page.
*
* This routine is also used to put entries onto the page where the
* entry is pre-built, e.g., during recovery. In this case, the hdr
* will point to the entry, and the data argument will be NULL.
*
* !!!
* There's a tremendous potential for off-by-one errors here, since
* the passed in header sizes must be adjusted for the structure's
* placeholder for the trailing variable-length data field.
*/
if (DB_LOGGING(dbc))
return (ret);
}
/* Adjust the index table, then put the item on the page. */
/* If it's a btree, adjust the cursors. */
return (0);
}
/*
* __db_relink --
* Relink around a deleted page.
*
* PUBLIC: int __db_relink __P((DBC *, u_int32_t, PAGE *, PAGE **, int));
*/
int
int needlock;
{
int ret;
ret = 0;
/*
* two pages (the before and after). For an add, we only need one
* because, the split took care of the prev.
*/
goto err;
goto err;
}
}
goto err;
goto err;
}
}
/* Log the change. */
if (DB_LOGGING(dbc)) {
goto err;
}
/*
* Modify and release the two pages.
*
* !!!
* The parameter new_next gets set to the page following the page we
* are removing. If there is no following page, then new_next gets
* set to NULL.
*/
if (add_rem == DB_ADD_PAGE)
else
else {
}
if (ret != 0)
goto err;
if (needlock)
goto err;
if (needlock)
}
return (0);
return (ret);
}
/*
* __db_ddup --
* Delete an offpage chain of duplicates.
*
* PUBLIC: int __db_ddup __P((DBC *, db_pgno_t, int (*)(DBC *, PAGE *)));
*/
int
{
int ret;
do {
return (ret);
}
if (DB_LOGGING(dbc)) {
return (ret);
}
return (ret);
} while (pgno != PGNO_INVALID);
return (0);
}
/*
* __db_addpage --
* Create a new page and link it onto the next_pgno field of the
* current page.
*/
static int
{
int ret;
return (ret);
if (DB_LOGGING(dbc)) {
return (ret);
}
}
return (ret);
*indxp = 0;
return (0);
}
/*
* __db_dsearch --
* Search a set of duplicates for the proper position for a new duplicate.
*
* + pgno is the page number of the page on which to begin searching.
* Since we can continue duplicate searches, it might not be the first
* page.
*
* + If we are continuing a search, then *pp may be non-NULL in which
* case we do not have to retrieve the page.
*
* + If we are continuing a search, then *indxp contains the first
* on pgno of where we should begin the search.
*
* NOTE: if there is no comparison function, then continuing is
* meaningless, and *pp should always be NULL and *indxp will be
* ignored.
*
* 3 return values::
*
* + pp is the returned page pointer of where this element should go.
* + indxp is the returned index on that page
* + cmpp is the returned final comparison result.
*
* PUBLIC: int __db_dsearch __P((DBC *,
* PUBLIC: int, DBT *, db_pgno_t, db_indx_t *, PAGE **, int *));
*/
int
{
PAGE *h;
int ret;
/*
* We may have been given a valid page, but we may not be
* able to use it. The problem is that the application is
* doing a join and we're trying to continue the search,
* but since the items aren't sorted, we can't. Discard
* the page if it's not the one we're going to start with
* anyway.
*/
return (ret);
}
/*
* If no duplicate function is specified, just go to the end
* of the duplicate set.
*/
if (is_insert) {
return (ret);
return (0);
}
/*
* We are looking for a specific duplicate, so do a linear
* search.
*/
goto nocmp_started;
for (;;) {
goto pg_err;
nocmp_started: h = *pp;
continue;
/*
* The duplicate may have already been deleted,
* if it's a btree page, in which case we skip
* it.
*/
continue;
return (0);
}
break;
return (ret);
}
return (0);
}
/*
* We have a comparison routine, i.e., the duplicates are sorted.
* Walk through the chain of duplicates, checking the last entry
* on each page to decide if it's the page we want to search.
*
* *pp may be non-NULL -- if we were given a valid page (e.g., are
* in mid-search), then use the provided page.
*/
goto cmp_started;
for (;;) {
goto pg_err;
cmp_started: h = *pp;
break;
/*
* Even when continuing a search, make sure we don't skip
* entries on a new page
*/
*indxp = 0;
return (ret);
}
/* Next, do a binary search on the page. */
return (0);
goto check_delete;
}
if (*cmpp > 0) {
lim--;
}
}
/*
* Base references the smallest index larger than the supplied DBT's
* data item, potentially both 0 and NUM_ENT.
*/
return (0);
/*
* The duplicate may have already been deleted, if it's a btree page,
* in which case we wander around, hoping to find an entry that hasn't
* been deleted. First, wander in a forwardly direction.
*/
for (++*indxp;;) {
goto check_delete_rev;
return (0);
}
break;
return (ret);
goto pg_err;
h = *pp;
*indxp = 0;
}
/* Go back to where we started, and wander in a backwardly direction. */
return (ret);
goto pg_err;
h = *pp;
}
for (;;) {
while (*indxp > 0) {
--*indxp;
goto check_delete_fail;
return (0);
}
break;
return (ret);
goto pg_err;
h = *pp;
}
return (0);
return (ret);
}