summaryrefslogtreecommitdiff
path: root/db/btree/bt_method.c
diff options
context:
space:
mode:
Diffstat (limited to 'db/btree/bt_method.c')
-rw-r--r--db/btree/bt_method.c274
1 files changed, 199 insertions, 75 deletions
diff --git a/db/btree/bt_method.c b/db/btree/bt_method.c
index 5e3af27d0..84abe96a2 100644
--- a/db/btree/bt_method.c
+++ b/db/btree/bt_method.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2003
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: bt_method.c,v 11.20 2000/11/30 00:58:28 ubell Exp $";
+static const char revid[] = "$Id: bt_method.c,v 11.34 2003/06/30 17:19:32 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -16,19 +16,22 @@ static const char revid[] = "$Id: bt_method.c,v 11.20 2000/11/30 00:58:28 ubell
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "btree.h"
-#include "qam.h"
+#include "dbinc/db_page.h"
+#include "dbinc/btree.h"
+#include "dbinc/qam.h"
-static int __bam_set_bt_compare
- __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
static int __bam_set_bt_maxkey __P((DB *, u_int32_t));
+static int __bam_get_bt_minkey __P((DB *, u_int32_t *));
static int __bam_set_bt_minkey __P((DB *, u_int32_t));
static int __bam_set_bt_prefix
__P((DB *, size_t(*)(DB *, const DBT *, const DBT *)));
+static int __ram_get_re_delim __P((DB *, int *));
static int __ram_set_re_delim __P((DB *, int));
+static int __ram_get_re_len __P((DB *, u_int32_t *));
static int __ram_set_re_len __P((DB *, u_int32_t));
+static int __ram_get_re_pad __P((DB *, int *));
static int __ram_set_re_pad __P((DB *, int));
+static int __ram_get_re_source __P((DB *, const char **));
static int __ram_set_re_source __P((DB *, const char *));
/*
@@ -55,6 +58,7 @@ __bam_db_create(dbp)
dbp->set_bt_compare = __bam_set_bt_compare;
dbp->set_bt_maxkey = __bam_set_bt_maxkey;
+ dbp->get_bt_minkey = __bam_get_bt_minkey;
dbp->set_bt_minkey = __bam_set_bt_minkey;
dbp->set_bt_prefix = __bam_set_bt_prefix;
@@ -62,9 +66,13 @@ __bam_db_create(dbp)
t->re_delim = '\n';
t->re_eof = 1;
+ dbp->get_re_delim = __ram_get_re_delim;
dbp->set_re_delim = __ram_set_re_delim;
+ dbp->get_re_len = __ram_get_re_len;
dbp->set_re_len = __ram_set_re_len;
+ dbp->get_re_pad = __ram_get_re_pad;
dbp->set_re_pad = __ram_set_re_pad;
+ dbp->get_re_source = __ram_get_re_source;
dbp->set_re_source = __ram_set_re_source;
return (0);
@@ -82,7 +90,8 @@ __bam_db_close(dbp)
{
BTREE *t;
- t = dbp->bt_internal;
+ if ((t = dbp->bt_internal) == NULL)
+ return (0);
/* Recno */
/* Close any backing source file descriptor. */
if (t->re_fp != NULL)
@@ -90,15 +99,46 @@ __bam_db_close(dbp)
/* Free any backing source file name. */
if (t->re_source != NULL)
- __os_freestr(t->re_source);
+ __os_free(dbp->dbenv, t->re_source);
- __os_free(t, sizeof(BTREE));
+ __os_free(dbp->dbenv, t);
dbp->bt_internal = NULL;
return (0);
}
/*
+ * __bam_map_flags --
+ * Map Btree specific flags from public to the internal values.
+ *
+ * PUBLIC: void __bam_map_flags __P((DB *, u_int32_t *, u_int32_t *));
+ */
+void
+__bam_map_flags(dbp, inflagsp, outflagsp)
+ DB *dbp;
+ u_int32_t *inflagsp, *outflagsp;
+{
+ COMPQUIET(dbp, NULL);
+
+ if (FLD_ISSET(*inflagsp, DB_DUP)) {
+ FLD_SET(*outflagsp, DB_AM_DUP);
+ FLD_CLR(*inflagsp, DB_DUP);
+ }
+ if (FLD_ISSET(*inflagsp, DB_DUPSORT)) {
+ FLD_SET(*outflagsp, DB_AM_DUP | DB_AM_DUPSORT);
+ FLD_CLR(*inflagsp, DB_DUPSORT);
+ }
+ if (FLD_ISSET(*inflagsp, DB_RECNUM)) {
+ FLD_SET(*outflagsp, DB_AM_RECNUM);
+ FLD_CLR(*inflagsp, DB_RECNUM);
+ }
+ if (FLD_ISSET(*inflagsp, DB_REVSPLITOFF)) {
+ FLD_SET(*outflagsp, DB_AM_REVSPLITOFF);
+ FLD_CLR(*inflagsp, DB_REVSPLITOFF);
+ }
+}
+
+/*
* __bam_set_flags --
* Set Btree specific flags.
*
@@ -112,50 +152,31 @@ __bam_set_flags(dbp, flagsp)
u_int32_t flags;
flags = *flagsp;
- if (LF_ISSET(DB_DUP | DB_DUPSORT | DB_RECNUM | DB_REVSPLITOFF)) {
+ if (LF_ISSET(DB_DUP | DB_DUPSORT | DB_RECNUM | DB_REVSPLITOFF))
DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_flags");
- /*
- * The DB_DUP and DB_DUPSORT flags are shared by the Hash
- * and Btree access methods.
- */
- if (LF_ISSET(DB_DUP | DB_DUPSORT))
- DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE | DB_OK_HASH);
-
- if (LF_ISSET(DB_RECNUM | DB_REVSPLITOFF))
- DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
-
- if (LF_ISSET(DB_DUP | DB_DUPSORT)) {
- /* DB_DUP/DB_DUPSORT is incompatible with DB_RECNUM. */
- if (F_ISSET(dbp, DB_BT_RECNUM))
- goto incompat;
-
- if (LF_ISSET(DB_DUPSORT)) {
- if (dbp->dup_compare == NULL)
- dbp->dup_compare = __bam_defcmp;
- F_SET(dbp, DB_AM_DUPSORT);
- }
-
- F_SET(dbp, DB_AM_DUP);
- LF_CLR(DB_DUP | DB_DUPSORT);
- }
-
- if (LF_ISSET(DB_RECNUM)) {
- /* DB_RECNUM is incompatible with DB_DUP/DB_DUPSORT. */
- if (F_ISSET(dbp, DB_AM_DUP))
- goto incompat;
-
- F_SET(dbp, DB_BT_RECNUM);
- LF_CLR(DB_RECNUM);
- }
-
- if (LF_ISSET(DB_REVSPLITOFF)) {
- F_SET(dbp, DB_BT_REVSPLIT);
- LF_CLR(DB_REVSPLITOFF);
- }
-
- *flagsp = flags;
- }
+ /*
+ * The DB_DUP and DB_DUPSORT flags are shared by the Hash
+ * and Btree access methods.
+ */
+ if (LF_ISSET(DB_DUP | DB_DUPSORT))
+ DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE | DB_OK_HASH);
+
+ if (LF_ISSET(DB_RECNUM | DB_REVSPLITOFF))
+ DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
+
+ /* DB_DUP/DB_DUPSORT is incompatible with DB_RECNUM. */
+ if (LF_ISSET(DB_DUP | DB_DUPSORT) && F_ISSET(dbp, DB_AM_RECNUM))
+ goto incompat;
+
+ /* DB_RECNUM is incompatible with DB_DUP/DB_DUPSORT. */
+ if (LF_ISSET(DB_RECNUM) && F_ISSET(dbp, DB_AM_DUP))
+ goto incompat;
+
+ if (LF_ISSET(DB_DUPSORT) && dbp->dup_compare == NULL)
+ dbp->dup_compare = __bam_defcmp;
+
+ __bam_map_flags(dbp, flagsp, &dbp->flags);
return (0);
incompat:
@@ -165,15 +186,18 @@ incompat:
/*
* __bam_set_bt_compare --
* Set the comparison function.
+ *
+ * PUBLIC: int __bam_set_bt_compare
+ * PUBLIC: __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
*/
-static int
+int
__bam_set_bt_compare(dbp, func)
DB *dbp;
int (*func) __P((DB *, const DBT *, const DBT *));
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_bt_compare");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_bt_compare");
DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
t = dbp->bt_internal;
@@ -200,7 +224,7 @@ __bam_set_bt_maxkey(dbp, bt_maxkey)
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_bt_maxkey");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_bt_maxkey");
DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
t = dbp->bt_internal;
@@ -215,6 +239,24 @@ __bam_set_bt_maxkey(dbp, bt_maxkey)
}
/*
+ * __db_get_bt_minkey --
+ * Get the minimum keys per page.
+ */
+static int
+__bam_get_bt_minkey(dbp, bt_minkeyp)
+ DB *dbp;
+ u_int32_t *bt_minkeyp;
+{
+ BTREE *t;
+
+ DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
+
+ t = dbp->bt_internal;
+ *bt_minkeyp = t->bt_minkey;
+ return (0);
+}
+
+/*
* __bam_set_bt_minkey --
* Set the minimum keys per page.
*/
@@ -225,7 +267,7 @@ __bam_set_bt_minkey(dbp, bt_minkey)
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_bt_minkey");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_bt_minkey");
DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
t = dbp->bt_internal;
@@ -250,7 +292,7 @@ __bam_set_bt_prefix(dbp, func)
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_bt_prefix");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_bt_prefix");
DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE);
t = dbp->bt_internal;
@@ -260,6 +302,29 @@ __bam_set_bt_prefix(dbp, func)
}
/*
+ * __ram_map_flags --
+ * Map Recno specific flags from public to the internal values.
+ *
+ * PUBLIC: void __ram_map_flags __P((DB *, u_int32_t *, u_int32_t *));
+ */
+void
+__ram_map_flags(dbp, inflagsp, outflagsp)
+ DB *dbp;
+ u_int32_t *inflagsp, *outflagsp;
+{
+ COMPQUIET(dbp, NULL);
+
+ if (FLD_ISSET(*inflagsp, DB_RENUMBER)) {
+ FLD_SET(*outflagsp, DB_AM_RENUMBER);
+ FLD_CLR(*inflagsp, DB_RENUMBER);
+ }
+ if (FLD_ISSET(*inflagsp, DB_SNAPSHOT)) {
+ FLD_SET(*outflagsp, DB_AM_SNAPSHOT);
+ FLD_CLR(*inflagsp, DB_SNAPSHOT);
+ }
+}
+
+/*
* __ram_set_flags --
* Set Recno specific flags.
*
@@ -275,21 +340,27 @@ __ram_set_flags(dbp, flagsp)
flags = *flagsp;
if (LF_ISSET(DB_RENUMBER | DB_SNAPSHOT)) {
DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_flags");
-
DB_ILLEGAL_METHOD(dbp, DB_OK_RECNO);
+ }
- if (LF_ISSET(DB_RENUMBER)) {
- F_SET(dbp, DB_RE_RENUMBER);
- LF_CLR(DB_RENUMBER);
- }
+ __ram_map_flags(dbp, flagsp, &dbp->flags);
+ return (0);
+}
- if (LF_ISSET(DB_SNAPSHOT)) {
- F_SET(dbp, DB_RE_SNAPSHOT);
- LF_CLR(DB_SNAPSHOT);
- }
+/*
+ * __db_get_re_delim --
+ * Get the variable-length input record delimiter.
+ */
+static int
+__ram_get_re_delim(dbp, re_delimp)
+ DB *dbp;
+ int *re_delimp;
+{
+ BTREE *t;
- *flagsp = flags;
- }
+ DB_ILLEGAL_METHOD(dbp, DB_OK_RECNO);
+ t = dbp->bt_internal;
+ *re_delimp = t->re_delim;
return (0);
}
@@ -304,18 +375,35 @@ __ram_set_re_delim(dbp, re_delim)
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_re_delim");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_re_delim");
DB_ILLEGAL_METHOD(dbp, DB_OK_RECNO);
t = dbp->bt_internal;
t->re_delim = re_delim;
- F_SET(dbp, DB_RE_DELIMITER);
+ F_SET(dbp, DB_AM_DELIMITER);
return (0);
}
/*
+ * __db_get_re_len --
+ * Get the variable-length input record length.
+ */
+static int
+__ram_get_re_len(dbp, re_lenp)
+ DB *dbp;
+ u_int32_t *re_lenp;
+{
+ BTREE *t;
+
+ DB_ILLEGAL_METHOD(dbp, DB_OK_QUEUE | DB_OK_RECNO);
+ t = dbp->bt_internal;
+ *re_lenp = t->re_len;
+ return (0);
+}
+
+/*
* __ram_set_re_len --
* Set the variable-length input record length.
*/
@@ -327,7 +415,7 @@ __ram_set_re_len(dbp, re_len)
BTREE *t;
QUEUE *q;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_re_len");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_re_len");
DB_ILLEGAL_METHOD(dbp, DB_OK_QUEUE | DB_OK_RECNO);
t = dbp->bt_internal;
@@ -336,12 +424,30 @@ __ram_set_re_len(dbp, re_len)
q = dbp->q_internal;
q->re_len = re_len;
- F_SET(dbp, DB_RE_FIXEDLEN);
+ F_SET(dbp, DB_AM_FIXEDLEN);
return (0);
}
/*
+ * __db_get_re_pad --
+ * Get the fixed-length record pad character.
+ */
+static int
+__ram_get_re_pad(dbp, re_padp)
+ DB *dbp;
+ int *re_padp;
+{
+ BTREE *t;
+
+ DB_ILLEGAL_METHOD(dbp, DB_OK_QUEUE | DB_OK_RECNO);
+
+ t = dbp->bt_internal;
+ *re_padp = t->re_pad;
+ return (0);
+}
+
+/*
* __ram_set_re_pad --
* Set the fixed-length record pad character.
*/
@@ -353,7 +459,7 @@ __ram_set_re_pad(dbp, re_pad)
BTREE *t;
QUEUE *q;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_re_pad");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_re_pad");
DB_ILLEGAL_METHOD(dbp, DB_OK_QUEUE | DB_OK_RECNO);
t = dbp->bt_internal;
@@ -362,8 +468,26 @@ __ram_set_re_pad(dbp, re_pad)
q = dbp->q_internal;
q->re_pad = re_pad;
- F_SET(dbp, DB_RE_PAD);
+ F_SET(dbp, DB_AM_PAD);
+
+ return (0);
+}
+
+/*
+ * __db_get_re_source --
+ * Get the backing source file name.
+ */
+static int
+__ram_get_re_source(dbp, re_sourcep)
+ DB *dbp;
+ const char **re_sourcep;
+{
+ BTREE *t;
+ DB_ILLEGAL_METHOD(dbp, DB_OK_RECNO);
+
+ t = dbp->bt_internal;
+ *re_sourcep = t->re_source;
return (0);
}
@@ -378,7 +502,7 @@ __ram_set_re_source(dbp, re_source)
{
BTREE *t;
- DB_ILLEGAL_AFTER_OPEN(dbp, "set_re_source");
+ DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_re_source");
DB_ILLEGAL_METHOD(dbp, DB_OK_RECNO);
t = dbp->bt_internal;