Changeset: 1703562efa30 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1703562efa30
Modified Files:
        gdk/gdk.h
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
        gdk/gdk_storage.c
        sql/storage/bat/bat_logger.c
        sql/storage/bat/bat_storage.c
Branch: persistent_sketches
Log Message:

Going from tail sketch to more general tail stats. Tail stats contains sketches.

Still missing setting the version and stats age. (WIP).


diffs (truncated from 840 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1550,7 +1550,7 @@ typedef struct pipeline_io {
 
 #define ORDERIDXOFF            3
 
-/* tail stats */
+/* tail stats and sketch */
 #define SKETCH_BITS        6 /* choice */
 #define SKETCH_BITS_MASK   ((1ULL << SKETCH_BITS) - 1)
 #define SKETCH_MAX_CLZ     (64 - SKETCH_BITS) /* CLZ = count leading zeros */
@@ -1573,15 +1573,34 @@ atom_sketchable(int type)
        return true;
 }
 
+#define TSTATS_VER       (uint32_t)1
+#define TSTATS_HEADER_SZ (2 * sizeof(uint32_t))
+#define TSTATS_SZ        (TSTATS_HEADER_SZ + SKETCH_SZ)
+
 static inline bool
 bat_needstats(int bat_type, int bat_role)
 {
        return atom_sketchable(bat_type) && (bat_role == PERSISTENT);
 }
 
-#define STATS_VER (uint32_t)1
-#define STATS_SZ  (2 * sizeof(uint32_t) + SKETCH_SZ)
-/* tail stats end */
+static inline uint32_t *
+tstats_version(void *tstats)
+{
+       return (uint32_t *)tstats;
+}
+
+static inline uint32_t *
+tstats_age(void *tstats)
+{
+       return (uint32_t *)tstats + 1;
+}
+
+static inline void *
+tstats_sketch(void *tstats)
+{
+       return (uint32_t *)tstats + 2;
+}
+/* tail stats and sketch end */
 
 /* assert that atom width is power of 2, i.e., width == 1<<shift */
 #define assert_shift_width(shift,width)                                \
@@ -1658,7 +1677,7 @@ typedef struct BAT {
        Heap *theap;            /* space for the column. */
        BUN tbaseoff;           /* offset in heap->base (in whole items) */
        Heap *tvheap;           /* space for the varsized data. */
-       Heap *tsketch;          /* probabilistic counting sketch */
+       Heap *tstats;           /* probabilistic counting sketch */
        Hash *thash;            /* hash table */
 #ifdef HAVE_RTREE
        RTree *trtree;          /* rtree geometric index */
@@ -2335,7 +2354,7 @@ typedef struct BATiter {
        Heap *h;
        void *base;
        Heap *vh;
-       Heap *skh;
+       Heap *sh;
        Hash *hash;             /* if non-NULL, there's a read lock */
        BUN count;
        BUN baseoff;
@@ -2357,7 +2376,7 @@ typedef struct BATiter {
                revsorted:1,
                hdirty:1,
                vhdirty:1,
-               skhdirty:1,
+               shdirty:1,
                copiedtodisk:1,
                transient:1,
                ascii:1;
@@ -2388,7 +2407,7 @@ bat_iterator_nolock(BAT *b)
                                : NULL,
                        .baseoff = b->tbaseoff,
                        .vh = b->tvheap,
-                       .skh = b->tsketch,
+                       .sh = b->tstats,
                        .count = b->batCount,
                        .width = b->twidth,
                        .shift = b->tshift,
@@ -2429,10 +2448,10 @@ bat_iterator_nolock(BAT *b)
                        .vhdirty = b->tvheap &&
                                b->tvheap->parentid == b->batCacheid &&
                                b->tvheap->dirty,
-                       /* also, if there is no tsketch, it's not dirty */
-                       .skhdirty = b->tsketch &&
-                               b->tsketch->parentid == b->batCacheid &&
-                               b->tsketch->dirty,
+                       /* also, if there is no stats heap, it's not dirty */
+                       .shdirty = b->tstats &&
+                               b->tstats->parentid == b->batCacheid &&
+                               b->tstats->dirty,
                        .copiedtodisk = b->batCopiedtodisk,
                        .transient = b->batTransient,
                        .restricted = b->batRestricted,
@@ -2453,8 +2472,8 @@ bat_iterator_incref(BATiter *bi)
        HEAPincref(bi->h);
        if (bi->vh)
                HEAPincref(bi->vh);
-       if (bi->skh)
-               HEAPincref(bi->skh);
+       if (bi->sh)
+               HEAPincref(bi->sh);
 }
 
 static inline BATiter
@@ -2530,8 +2549,8 @@ bat_iterator_copy(const BATiter *bip)
                HEAPincref(bip->h);
        if (bip->vh)
                HEAPincref(bip->vh);
-       if (bip->skh)
-               HEAPincref(bip->skh);
+       if (bip->sh)
+               HEAPincref(bip->sh);
        if (bip->hash)
                MT_rwlock_rdlock(&bip->b->thashlock);
        return *bip;
@@ -2549,8 +2568,8 @@ bat_iterator_end(BATiter *bip)
                HEAPdecref(bip->h, false);
        if (bip->vh)
                HEAPdecref(bip->vh, false);
-       if (bip->skh)
-               HEAPdecref(bip->skh, false);
+       if (bip->sh)
+               HEAPdecref(bip->sh, false);
        *bip = (BATiter) {0};
 }
 
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -190,7 +190,7 @@ VIEWcreate(oid seq, BAT *b, BUN l, BUN h
        bn->theap = bi.h;
        bn->tbaseoff = bi.baseoff;
        bn->tvheap = bi.vh;
-       bn->tsketch = bi.skh;
+       bn->tstats = bi.sh;
 
        tp = VIEWtparent(b);
        if (tp == 0 && b->ttype != TYPE_void)
@@ -199,8 +199,8 @@ VIEWcreate(oid seq, BAT *b, BUN l, BUN h
        HEAPincref(bi.h);
        if (bi.vh)
                HEAPincref(bi.vh);
-       if (bi.skh)
-               HEAPincref(bi.skh);
+       if (bi.sh)
+               HEAPincref(bi.sh);
        if (l != 0 || h < bi.count)
                VIEWboundsbi(&bi, bn, l, h);
        MT_lock_unset(&b->theaplock);
@@ -209,8 +209,8 @@ VIEWcreate(oid seq, BAT *b, BUN l, BUN h
        BBPretain(bn->theap->parentid);
        if (bn->tvheap)
                BBPretain(bn->tvheap->parentid);
-       if (bn->tsketch)
-               BBPretain(bn->tsketch->parentid);
+       if (bn->tstats)
+               BBPretain(bn->tstats->parentid);
        if (bn->ustr)
                BBPfix(bn->ustr);
        TRC_DEBUG(ALGO, ALGOBATFMT " " BUNFMT "," BUNFMT " -> " ALGOBATFMT "\n",
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -117,7 +117,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
 {
        bat bid;
        BAT *bn;
-       Heap *h = NULL, *vh = NULL, *skh = NULL;
+       Heap *h = NULL, *vh = NULL, *sh = NULL;
 
        /*
         * Alloc space for the BAT and its dependent records.
@@ -149,12 +149,12 @@ BATcreatedesc(oid hseq, int tt, bool hea
                }
 
                if (bat_needstats(tt, role)) {
-                       if ((skh = GDKmalloc(sizeof(Heap))) == NULL) {
+                       if ((sh = GDKmalloc(sizeof(Heap))) == NULL) {
                                GDKfree(h);
                                GDKfree(vh);
                                return NULL;
                        }
-                       *skh = (Heap) {
+                       *sh = (Heap) {
                                .farmid = BBPselectfarm(role, tt, sketchheap),
                                .dirty = true,
                                .refs = ATOMIC_VAR_INIT(1),
@@ -166,7 +166,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
        if (bid == 0) {
                GDKfree(h);
                GDKfree(vh);
-               GDKfree(skh);
+               GDKfree(sh);
                return NULL;
        }
        bn = BBP_desc(bid);
@@ -196,7 +196,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
                .batRestricted = BAT_WRITE,
                .theap = h,
                .tvheap = vh,
-               .tsketch = skh,
+               .tstats = sh,
                .creator_tid = MT_getpid(),
                .qc = role == TRANSIENT ? MT_thread_get_qry_ctx() : NULL,
        };
@@ -211,11 +211,11 @@ BATcreatedesc(oid hseq, int tt, bool hea
                                   sizeof(bn->tvheap->filename),
                                   nme, ".theap", NULL);
                }
-               if (bn->tsketch) {
-                       bn->tsketch->parentid = bn->batCacheid;
-                       strtconcat(bn->tsketch->filename,
-                                  sizeof(bn->tsketch->filename),
-                                  nme, ".tsketch", NULL);
+               if (bn->tstats) {
+                       bn->tstats->parentid = bn->batCacheid;
+                       strtconcat(bn->tstats->filename,
+                                  sizeof(bn->tstats->filename),
+                                  nme, ".tstats", NULL);
                }
        }
        char name[MT_NAME_LEN];
@@ -359,15 +359,15 @@ COLnew2(oid hseq, int tt, BUN cap, role_
        }
 
        if (bat_needstats(tt, role)) {
-               assert(bn->tsketch);
-               if (HEAPalloc(bn->tsketch, SKETCH_SZ, sizeof(uint8_t)) != 
GDK_SUCCEED) {
+               assert(bn->tstats);
+               if (HEAPalloc(bn->tstats, TSTATS_SZ, 1) != GDK_SUCCEED) {
                        HEAPfree(bn->theap, true);
                        if (bn->tvheap)
                                HEAPfree(bn->tvheap, true);
                        goto bailout;
                }
-               memset(bn->tsketch->base, 0, SKETCH_SZ);
-               bn->tsketch->free = SKETCH_SZ;
+               memset(bn->tstats->base, 0, TSTATS_SZ);
+               bn->tstats->free = TSTATS_SZ;
        }
 
        BBPcacheit(bn, true);
@@ -571,9 +571,9 @@ BATclear(BAT *b, bool force)
                }
        }
 
-       if (b->tsketch) {
-               memset(b->tsketch->base, 0, SKETCH_SZ);
-               b->tsketch->dirty = true;
+       if (b->tstats) {
+               memset(b->tstats->base, 0, TSTATS_SZ);
+               b->tstats->dirty = true;
        }
 
        b->batInserted = 0;
@@ -650,15 +650,15 @@ BATfree(BAT *b)
        /* wait until there are no other references to the heap; a
         * reference is possible in e.g. BBPsync that uses a
         * bat_iterator directly on the BBP_desc, i.e. without fix */
-       while (b->tsketch && (ATOMIC_GET(&b->tsketch->refs) & HEAPREFS) > 1) {
+       while (b->tstats && (ATOMIC_GET(&b->tstats->refs) & HEAPREFS) > 1) {
                MT_lock_unset(&b->theaplock);
                MT_sleep_ms(1);
                MT_lock_set(&b->theaplock);
        }
-       if (b->tsketch) {
-               assert((ATOMIC_GET(&b->tsketch->refs) & HEAPREFS) == 1);
-               assert(b->tsketch->parentid == b->batCacheid);
-               HEAPfree(b->tsketch, false);
+       if (b->tstats) {
+               assert((ATOMIC_GET(&b->tstats->refs) & HEAPREFS) == 1);
+               assert(b->tstats->parentid == b->batCacheid);
+               HEAPfree(b->tstats, false);
        }
        MT_lock_unset(&b->theaplock);
 }
@@ -677,8 +677,8 @@ BATdestroy(BAT *b)
        if (b->theap) {
                GDKfree(b->theap);
        }
-       if (b->tsketch) {
-               GDKfree(b->tsketch);
+       if (b->tstats) {
+               GDKfree(b->tstats);
        }
        if (b->oldtail) {
                ATOMIC_AND(&b->oldtail->refs, ~DELAYEDREMOVE);
@@ -925,10 +925,10 @@ COLcopy2(BAT *b, int tt, bool writable, 
                memcpy(bn->theap->base, bi.base, bi.hfree);
                bn->theap->free = bi.hfree;
                bn->theap->dirty = true;
-               if (bn->tsketch && b->tsketch && bi.count) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to