Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/db Merge the recursive tree traversal changes from ...



details:   https://anonhg.NetBSD.org/src/rev/d19220e3bc41
branches:  trunk
changeset: 347939:d19220e3bc41
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Sep 24 20:11:12 2016 +0000

description:
Merge the recursive tree traversal changes from the mit kerberos tree. This
Also make the tracefile customizable. Unfortunately we can't merge any of
the hash changes because they have a different on-disk format. That does not
matter really because we've fixed most of the problems...

diffstat:

 lib/libc/db/btree/bt_close.c    |    6 +-
 lib/libc/db/btree/bt_conv.c     |   13 +-
 lib/libc/db/btree/bt_debug.c    |  128 +++++++++++++++++---------
 lib/libc/db/btree/bt_delete.c   |   33 +++---
 lib/libc/db/btree/bt_open.c     |   21 ++-
 lib/libc/db/btree/bt_overflow.c |   10 +-
 lib/libc/db/btree/bt_page.c     |    6 +-
 lib/libc/db/btree/bt_put.c      |    8 +-
 lib/libc/db/btree/bt_search.c   |  123 +++++++++++++++++++++---
 lib/libc/db/btree/bt_seq.c      |  195 +++++++++++++++++++++++++++++++++------
 lib/libc/db/btree/bt_split.c    |   10 +-
 lib/libc/db/btree/extern.h      |    3 +-
 lib/libc/db/mpool/mpool.c       |   95 +++++++++++++++++--
 lib/libc/db/recno/rec_open.c    |    6 +-
 lib/libc/db/recno/rec_search.c  |    8 +-
 15 files changed, 502 insertions(+), 163 deletions(-)

diffs (truncated from 1560 to 300 lines):

diff -r 569bf1eae15a -r d19220e3bc41 lib/libc/db/btree/bt_close.c
--- a/lib/libc/db/btree/bt_close.c      Sat Sep 24 20:08:29 2016 +0000
+++ b/lib/libc/db/btree/bt_close.c      Sat Sep 24 20:11:12 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $   */
+/*     $NetBSD: bt_close.c,v 1.16 2016/09/24 20:11:12 christos Exp $   */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $");
+__RCSID("$NetBSD: bt_close.c,v 1.16 2016/09/24 20:11:12 christos Exp $");
 
 #include "namespace.h"
 
@@ -164,7 +164,7 @@
        BTMETA m;
        void *p;
 
-       if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL)
+       if ((p = mpool_getf(t->bt_mp, P_META, 0)) == NULL)
                return (RET_ERROR);
 
        /* Fill in metadata. */
diff -r 569bf1eae15a -r d19220e3bc41 lib/libc/db/btree/bt_conv.c
--- a/lib/libc/db/btree/bt_conv.c       Sat Sep 24 20:08:29 2016 +0000
+++ b/lib/libc/db/btree/bt_conv.c       Sat Sep 24 20:11:12 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $       */
+/*     $NetBSD: bt_conv.c,v 1.15 2016/09/24 20:11:12 christos Exp $    */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,10 +37,11 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $");
+__RCSID("$NetBSD: bt_conv.c,v 1.15 2016/09/24 20:11:12 christos Exp $");
 
 #include <assert.h>
 #include <stdio.h>
+#include <memory.h>
 
 #include <db.h>
 #include "btree.h"
@@ -64,6 +65,7 @@
        indx_t i, top;
        uint8_t flags;
        char *p;
+       uint32_t ksize;
 
        if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
                return;
@@ -101,6 +103,7 @@
                        M_16_SWAP(h->linp[i]);
                        p = (char *)(void *)GETBLEAF(h, i);
                        P_32_SWAP(p);
+                       memcpy(&ksize, p, sizeof(ksize));
                        p += sizeof(uint32_t);
                        P_32_SWAP(p);
                        p += sizeof(uint32_t);
@@ -113,7 +116,7 @@
                                        P_32_SWAP(p);
                                }
                                if (flags & P_BIGDATA) {
-                                       p += sizeof(uint32_t);
+                                       p += ksize;
                                        P_32_SWAP(p);
                                        p += sizeof(pgno_t);
                                        P_32_SWAP(p);
@@ -129,6 +132,7 @@
        indx_t i, top;
        uint8_t flags;
        char *p;
+       uint32_t ksize;
 
        if (!F_ISSET(((BTREE *)t), B_NEEDSWAP))
                return;
@@ -157,6 +161,7 @@
        else if ((h->flags & P_TYPE) == P_BLEAF)
                for (i = 0; i < top; i++) {
                        p = (char *)(void *)GETBLEAF(h, i);
+                       ksize = GETBLEAF(h, i)->ksize;
                        P_32_SWAP(p);
                        p += sizeof(uint32_t);
                        P_32_SWAP(p);
@@ -170,7 +175,7 @@
                                        P_32_SWAP(p);
                                }
                                if (flags & P_BIGDATA) {
-                                       p += sizeof(uint32_t);
+                                       p += ksize;
                                        P_32_SWAP(p);
                                        p += sizeof(pgno_t);
                                        P_32_SWAP(p);
diff -r 569bf1eae15a -r d19220e3bc41 lib/libc/db/btree/bt_debug.c
--- a/lib/libc/db/btree/bt_debug.c      Sat Sep 24 20:08:29 2016 +0000
+++ b/lib/libc/db/btree/bt_debug.c      Sat Sep 24 20:11:12 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bt_debug.c,v 1.16 2011/07/17 20:47:39 christos Exp $   */
+/*     $NetBSD: bt_debug.c,v 1.17 2016/09/24 20:11:12 christos Exp $   */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bt_debug.c,v 1.16 2011/07/17 20:47:39 christos Exp $");
+__RCSID("$NetBSD: bt_debug.c,v 1.17 2016/09/24 20:11:12 christos Exp $");
 
 #include <assert.h>
 #include <stdio.h>
@@ -47,6 +47,29 @@
 #include <db.h>
 #include "btree.h"
 
+#if defined(DEBUG) || defined(STATISTICS)
+
+static FILE *tracefp;
+
+/*
+ * __bt_dinit --
+ *     initialize debugging.
+ */
+static void
+__bt_dinit(void)
+{
+       if (tracefp != NULL)
+               return;
+
+#ifndef TRACE_TO_STDERR
+       if ((tracefp = fopen("/tmp/__bt_debug", "w")) != NULL)
+               return;
+#endif
+       tracefp = stderr;
+}
+#endif
+
+
 #ifdef DEBUG
 /*
  * BT_DUMP -- Dump the tree
@@ -62,15 +85,17 @@
        pgno_t i;
        const char *sep;
 
+       __bt_dinit();
+
        t = dbp->internal;
-       (void)fprintf(stderr, "%s: pgsz %d",
+       (void)fprintf(tracefp, "%s: pgsz %d",
            F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize);
        if (F_ISSET(t, R_RECNO))
-               (void)fprintf(stderr, " keys %lu", (unsigned long) t->bt_nrecs);
+               (void)fprintf(tracefp, " keys %lu", (unsigned long) t->bt_nrecs);
 #undef X
 #define        X(flag, name) \
        if (F_ISSET(t, flag)) { \
-               (void)fprintf(stderr, "%s%s", sep, name); \
+               (void)fprintf(tracefp, "%s%s", sep, name); \
                sep = ", "; \
        }
        if (t->flags != 0) {
@@ -81,14 +106,15 @@
                X(B_RDONLY,     "RDONLY");
                X(R_RECNO,      "RECNO");
                X(B_METADIRTY,"METADIRTY");
-               (void)fprintf(stderr, ")\n");
+               (void)fprintf(tracefp, ")\n");
        }
 #undef X
 
-       for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) {
+       for (i = P_ROOT; i < t->bt_mp->npages &&
+           (h = mpool_getf(t->bt_mp, i, MPOOL_IGNOREPIN)) != NULL; ++i)
                __bt_dpage(h);
-               (void)mpool_put(t->bt_mp, h, 0);
-       }
+
+       (void)fflush(tracefp);
 }
 
 /*
@@ -104,24 +130,26 @@
        const char *sep;
 
        m = (BTMETA *)(void *)h;
-       (void)fprintf(stderr, "magic %lx\n", (unsigned long) m->magic);
-       (void)fprintf(stderr, "version %lu\n", (unsigned long) m->version);
-       (void)fprintf(stderr, "psize %lu\n", (unsigned long) m->psize);
-       (void)fprintf(stderr, "free %lu\n", (unsigned long) m->free);
-       (void)fprintf(stderr, "nrecs %lu\n", (unsigned long) m->nrecs);
-       (void)fprintf(stderr, "flags %lu", (unsigned long) m->flags);
+       (void)fprintf(tracefp, "magic %lx\n", (unsigned long) m->magic);
+       (void)fprintf(tracefp, "version %lu\n", (unsigned long) m->version);
+       (void)fprintf(tracefp, "psize %lu\n", (unsigned long) m->psize);
+       (void)fprintf(tracefp, "free %lu\n", (unsigned long) m->free);
+       (void)fprintf(tracefp, "nrecs %lu\n", (unsigned long) m->nrecs);
+       (void)fprintf(tracefp, "flags %lu", (unsigned long) m->flags);
 #undef X
 #define        X(flag, name) \
        if (m->flags & flag) { \
-               (void)fprintf(stderr, "%s%s", sep, name); \
+               (void)fprintf(tracefp, "%s%s", sep, name); \
                sep = ", "; \
        }
        if (m->flags) {
                sep = " (";
                X(B_NODUPS,     "NODUPS");
                X(R_RECNO,      "RECNO");
-               (void)fprintf(stderr, ")");
+               (void)fprintf(tracefp, ")");
        }
+       (void)fprintf(tracefp, "\n");
+       (void)fflush(tracefp);
 }
 
 static pgno_t
@@ -152,11 +180,14 @@
        BTREE *t;
        PAGE *h;
 
+       __bt_dinit();
+
        t = dbp->internal;
-       if ((h = mpool_get(t->bt_mp, pgno, 0)) != NULL) {
+       if ((h = mpool_getf(t->bt_mp, pgno, MPOOL_IGNOREPIN)) != NULL) {
                __bt_dpage(h);
                (void)mpool_put(t->bt_mp, h, 0);
        }
+       (void)fflush(tracefp);
 }
 
 /*
@@ -175,11 +206,13 @@
        indx_t cur, top;
        const char *sep;
 
-       (void)fprintf(stderr, "    page %d: (", h->pgno);
+       __bt_dinit();
+
+       (void)fprintf(tracefp, "    page %d: (", h->pgno);
 #undef X
 #define        X(flag, name) \
        if (h->flags & flag) { \
-               (void)fprintf(stderr, "%s%s", sep, name); \
+               (void)fprintf(tracefp, "%s%s", sep, name); \
                sep = ", "; \
        }
        sep = "";
@@ -189,68 +222,69 @@
        X(P_RLEAF,      "RLEAF")
        X(P_OVERFLOW,   "OVERFLOW")
        X(P_PRESERVE,   "PRESERVE");
-       (void)fprintf(stderr, ")\n");
+       (void)fprintf(tracefp, ")\n");
 #undef X
 
-       (void)fprintf(stderr, "\tprev %2d next %2d", h->prevpg, h->nextpg);
+       (void)fprintf(tracefp, "\tprev %2d next %2d", h->prevpg, h->nextpg);
        if (h->flags & P_OVERFLOW)
                return;
 
        top = NEXTINDEX(h);
-       (void)fprintf(stderr, " lower %3d upper %3d nextind %d\n",
+       (void)fprintf(tracefp, " lower %3d upper %3d nextind %d\n",
            h->lower, h->upper, top);
        for (cur = 0; cur < top; cur++) {
-               (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]);
+               (void)fprintf(tracefp, "\t[%03d] %4d ", cur, h->linp[cur]);
                switch (h->flags & P_TYPE) {
                case P_BINTERNAL:
                        bi = GETBINTERNAL(h, cur);
-                       (void)fprintf(stderr,
+                       (void)fprintf(tracefp,
                            "size %03d pgno %03d", bi->ksize, bi->pgno);
                        if (bi->flags & P_BIGKEY)
-                               (void)fprintf(stderr, " (indirect)");
+                               (void)fprintf(tracefp, " (indirect)");
                        else if (bi->ksize)
-                               (void)fprintf(stderr,
+                               (void)fprintf(tracefp,
                                    " {%.*s}", (int)bi->ksize, bi->bytes);
                        break;
                case P_RINTERNAL:
                        ri = GETRINTERNAL(h, cur);
-                       (void)fprintf(stderr, "entries %03d pgno %03d",
+                       (void)fprintf(tracefp, "entries %03d pgno %03d",
                                ri->nrecs, ri->pgno);
                        break;
                case P_BLEAF:
                        bl = GETBLEAF(h, cur);
                        if (bl->flags & P_BIGKEY)
-                               (void)fprintf(stderr,
+                               (void)fprintf(tracefp,



Home | Main Index | Thread Index | Old Index