Changeset: aa8eb19bb2a5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/aa8eb19bb2a5
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk.h
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_hash.c
        gdk/gdk_heap.c
        gdk/gdk_private.h
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_runtime.c
        monetdb5/modules/kernel/alarm.c
        monetdb5/modules/mal/pcre.c
        monetdb5/modules/mal/wlc.c
        sql/backends/monet5/sql.c
Branch: default
Log Message:

Merge with Jul2021 branch.


diffs (truncated from 3541 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -207,7 +207,6 @@ gdk_return BATupdate(BAT *b, BAT *p, BAT
 gdk_return BATupdatepos(BAT *b, const oid *positions, BAT *n, bool autoincr, 
bool force) __attribute__((__warn_unused_result__));
 BBPrec *BBP[N_BBPINIT];
 gdk_return BBPaddfarm(const char *dirname, uint32_t rolemask, bool logerror);
-void BBPclear(bat bid);
 void BBPcold(bat i);
 BAT *BBPdescriptor(bat b);
 int BBPfix(bat b);
@@ -215,7 +214,7 @@ bat BBPindex(const char *nme);
 void BBPkeepref(bat i);
 bat BBPlimit;
 void BBPlock(void);
-BAT *BBPquickdesc(bat b, bool delaccess);
+BAT *BBPquickdesc(bat b);
 int BBPreclaim(BAT *b);
 int BBPrelease(bat b);
 int BBPrename(bat bid, const char *nme);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -918,6 +918,7 @@ typedef struct BATiter {
        uint8_t shift;
        int8_t type;
        oid tseq;
+       BUN hfree, vhfree;
        union {
                oid tvid;
                bool tmsk;
@@ -944,6 +945,8 @@ bat_iterator(BAT *b)
                        .shift = b->tshift,
                        .type = b->ttype,
                        .tseq = b->tseqbase,
+                       .hfree = b->theap->free,
+                       .vhfree = b->tvheap ? b->tvheap->free : 0,
 #ifndef NDEBUG
                        .locked = true,
 #endif
@@ -991,6 +994,8 @@ bat_iterator_nolock(BAT *b)
                        .shift = b->tshift,
                        .type = b->ttype,
                        .tseq = b->tseqbase,
+                       .hfree = b->theap->free,
+                       .vhfree = b->tvheap ? b->tvheap->free : 0,
 #ifndef NDEBUG
                        .locked = false,
 #endif
@@ -1574,7 +1579,7 @@ gdk_export void BBPlock(void);
 
 gdk_export void BBPunlock(void);
 
-gdk_export BAT *BBPquickdesc(bat b, bool delaccess);
+gdk_export BAT *BBPquickdesc(bat b);
 
 /*
  * @- GDK error handling
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -148,7 +148,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
        bn->batDirtydesc = true;
        return bn;
       bailout:
-       BBPclear(bn->batCacheid);
+       BBPclear(bn->batCacheid, true);
        if (bn->theap)
                HEAPdecref(bn->theap, true);
        if (bn->tvheap)
@@ -293,7 +293,7 @@ COLnew_intern(oid hseq, int tt, BUN cap,
        TRC_DEBUG(ALGO, "-> " ALGOBATFMT "\n", ALGOBATPAR(bn));
        return bn;
   bailout:
-       BBPclear(bn->batCacheid);
+       BBPclear(bn->batCacheid, true);
        if (bn->theap)
                HEAPdecref(bn->theap, true);
        if (bn->tvheap)
@@ -738,23 +738,6 @@ BATdestroy(BAT *b)
  * which ensures that the original cannot be modified or destroyed
  * (which could affect the shared heaps).
  */
-static void
-heapmove(Heap *dst, Heap *src)
-{
-       HEAPfree(dst, strcmp(dst->filename, src->filename) != 0);
-       /* copy all fields of src except refs */
-       strcpy_len(dst->filename, src->filename, sizeof(dst->filename));
-       dst->free = src->free;
-       dst->size = src->size;
-       dst->base = src->base;
-       dst->farmid = src->farmid;
-       dst->cleanhash = src->cleanhash;
-       dst->storage = src->storage;
-       dst->newstorage = src->newstorage;
-       dst->parentid = src->parentid;
-       dst->dirty = true;
-}
-
 static bool
 wrongtype(int t1, int t2)
 {
@@ -848,48 +831,39 @@ COLcopy(BAT *b, int tt, bool writable, r
                        return NULL;
                }
 
-               if (bn->tvarsized && bn->ttype && bunstocopy == BUN_NONE) {
-                       bn->tshift = bi.shift;
-                       bn->twidth = bi.width;
-                       if (HEAPextend(bn->theap, BATcapacity(bn) << 
bn->tshift, true) != GDK_SUCCEED)
-                               goto bunins_failed;
-               }
-
                if (tt == TYPE_void) {
                        /* case (2): a void,void result => nothing to
                         * copy! */
                        bn->theap->free = 0;
                } else if (bunstocopy == BUN_NONE) {
-                       /* case (3): just copy the heaps; if possible
-                        * with copy-on-write VM support */
-                       Heap bthp, thp;
-
-                       bthp = (Heap) {
-                               .farmid = BBPselectfarm(role, bi.type, offheap),
-                               .parentid = bn->batCacheid,
-                       };
-                       thp = (Heap) {
-                               .farmid = BBPselectfarm(role, bi.type, varheap),
-                               .parentid = bn->batCacheid,
-                       };
-                       settailname(&bthp, BBP_physical(bn->batCacheid),
-                                   bn->ttype, bn->twidth);
-                       strconcat_len(thp.filename, sizeof(thp.filename),
-                                     BBP_physical(bn->batCacheid),
-                                     ".theap", NULL);
-                       if ((bi.type && HEAPcopy(&bthp, bi.h, (size_t) ((char 
*) bi.base - bi.h->base)) != GDK_SUCCEED) ||
-                           (bn->tvheap && HEAPcopy(&thp, bi.vh, 0) != 
GDK_SUCCEED)) {
-                               HEAPfree(&thp, true);
-                               HEAPfree(&bthp, true);
-                               BBPreclaim(bn);
-                               bat_iterator_end(&bi);
-                               return NULL;
+                       /* case (3): just copy the heaps */
+                       if (bn->tvarsized && bn->ttype && bn->twidth != 
bi.width) {
+                               /* widen the string offset heap */
+                               bn->tshift = bi.shift;
+                               bn->twidth = bi.width;
+                               settailname(bn->theap,
+                                           BBP_physical(bn->batCacheid),
+                                           bn->ttype, bn->twidth);
+                               /* file name change in mmapped file:
+                                * just free and create new */
+                               if (bn->theap->storage != STORE_MEM) {
+                                       HEAPfree(bn->theap, true);
+                                       if (HEAPalloc(bn->theap, bi.hfree, 1, 
1) != GDK_SUCCEED)
+                                               goto bunins_failed;
+                               }
                        }
-                       /* succeeded; replace dummy small heaps by the
-                        * real ones */
-                       heapmove(bn->theap, &bthp);
-                       if (bn->tvheap)
-                               heapmove(bn->tvheap, &thp);
+                       if (HEAPextend(bn->theap, bi.hfree, true) != 
GDK_SUCCEED ||
+                           (bn->tvheap && HEAPextend(bn->tvheap, bi.vhfree, 
true) != GDK_SUCCEED)) {
+                               goto bunins_failed;
+                       }
+                       memcpy(bn->theap->base, bi.base, bi.hfree);
+                       bn->theap->free = bi.hfree;
+                       bn->theap->dirty = true;
+                       if (bn->tvheap) {
+                               memcpy(bn->tvheap->base, bi.vh->base, 
bi.vhfree);
+                               bn->tvheap->free = bi.vhfree;
+                               bn->tvheap->dirty = true;
+                       }
 
                        /* make sure we use the correct capacity */
                        if (ATOMstorage(bn->ttype) == TYPE_msk)
@@ -906,7 +880,6 @@ COLcopy(BAT *b, int tt, bool writable, r
                                const void *t = BUNtail(bi, p);
 
                                if (bunfastapp_nocheck(bn, t) != GDK_SUCCEED) {
-                                       bat_iterator_end(&bi);
                                        goto bunins_failed;
                                }
                                r++;
@@ -1353,75 +1326,109 @@ BUNinplacemulti(BAT *b, const oid *posit
                         BATgetId(b));
                return GDK_FAIL;
        }
+       MT_rwlock_wrlock(&b->thashlock);
        for (BUN i = 0; i < count; i++) {
                BUN p = autoincr ? positions[0] - b->hseqbase + i : 
positions[i] - b->hseqbase;
                const void *t = b->ttype && b->tvarsized ?
                        ((const void **) values)[i] :
                        (const void *) ((const char *) values + (i << 
b->tshift));
 
-               val = BUNtail(bi, p);   /* old value */
-               if (ATOMcmp(b->ttype, val, t) == 0)
-                       continue; /* nothing to do */
-               if (b->tnil &&
-                   ATOMcmp(b->ttype, val, ATOMnilptr(b->ttype)) == 0 &&
-                   ATOMcmp(b->ttype, t, ATOMnilptr(b->ttype)) != 0) {
-                       /* if old value is nil and new value isn't, we're not
-                        * sure anymore about the nil property, so we must
-                        * clear it */
-                       b->tnil = false;
+               /* retrieve old value, but if this comes from the
+                * logger, we need to deal with offsets that point
+                * outside of the valid vheap */
+               if (b->tvarsized) {
+                       if (b->ttype) {
+                               size_t off = BUNtvaroff(bi, p);
+                               if (off < bi.vhfree)
+                                       val = bi.vh->base + off;
+                               else
+                                       val = NULL; /* bad offset */
+                       } else {
+                               val = BUNtpos(bi, p);
+                       }
+               } else {
+                       val = BUNtloc(bi, p);
                }
-               if (b->ttype != TYPE_void && ATOMlinear(b->ttype)) {
-                       const ValRecord *prop;
 
-                       MT_lock_set(&b->theaplock);
-                       if ((prop = BATgetprop_nolock(b, GDK_MAX_VALUE)) != 
NULL) {
-                               if (ATOMcmp(b->ttype, t, ATOMnilptr(b->ttype)) 
!= 0 &&
-                                   ATOMcmp(b->ttype, VALptr(prop), t) < 0) {
-                                       /* new value is larger than previous
-                                        * largest */
-                                       BATsetprop_nolock(b, GDK_MAX_VALUE, 
b->ttype, t);
-                                       BATsetprop_nolock(b, GDK_MAX_POS, 
TYPE_oid, &(oid){p});
-                               } else if (ATOMcmp(b->ttype, t, val) != 0 &&
-                                          ATOMcmp(b->ttype, VALptr(prop), val) 
== 0) {
-                                       /* old value is equal to largest and
-                                        * new value is smaller (see above),
-                                        * so we don't know anymore which is
-                                        * the largest */
-                                       BATrmprop_nolock(b, GDK_MAX_VALUE);
+               if (val) {
+                       if (ATOMcmp(b->ttype, val, t) == 0)
+                               continue; /* nothing to do */
+                       if (b->tnil &&
+                           ATOMcmp(b->ttype, val, ATOMnilptr(b->ttype)) == 0 &&
+                           ATOMcmp(b->ttype, t, ATOMnilptr(b->ttype)) != 0) {
+                               /* if old value is nil and new value
+                                * isn't, we're not sure anymore about
+                                * the nil property, so we must clear
+                                * it */
+                               b->tnil = false;
+                       }
+                       if (b->ttype != TYPE_void && ATOMlinear(b->ttype)) {
+                               const ValRecord *prop;
+
+                               MT_lock_set(&b->theaplock);
+                               if ((prop = BATgetprop_nolock(b, 
GDK_MAX_VALUE)) != NULL) {
+                                       if (ATOMcmp(b->ttype, t, 
ATOMnilptr(b->ttype)) != 0 &&
+                                           ATOMcmp(b->ttype, VALptr(prop), t) 
< 0) {
+                                               /* new value is larger
+                                                * than previous
+                                                * largest */
+                                               BATsetprop_nolock(b, 
GDK_MAX_VALUE, b->ttype, t);
+                                               BATsetprop_nolock(b, 
GDK_MAX_POS, TYPE_oid, &(oid){p});
+                                       } else if (ATOMcmp(b->ttype, t, val) != 
0 &&
+                                                  ATOMcmp(b->ttype, 
VALptr(prop), val) == 0) {
+                                               /* old value is equal to
+                                                * largest and new value
+                                                * is smaller (see
+                                                * above), so we don't
+                                                * know anymore which is
+                                                * the largest */
+                                               BATrmprop_nolock(b, 
GDK_MAX_VALUE);
+                                               BATrmprop_nolock(b, 
GDK_MAX_POS);
+                                       }
+                               } else {
                                        BATrmprop_nolock(b, GDK_MAX_POS);
                                }
-                       } else {
-                               BATrmprop_nolock(b, GDK_MAX_POS);
-                       }
-                       if ((prop = BATgetprop_nolock(b, GDK_MIN_VALUE)) != 
NULL) {
-                               if (ATOMcmp(b->ttype, t, ATOMnilptr(b->ttype)) 
!= 0 &&
-                                   ATOMcmp(b->ttype, VALptr(prop), t) > 0) {
-                                       /* new value is smaller than previous
-                                        * smallest */
-                                       BATsetprop_nolock(b, GDK_MIN_VALUE, 
b->ttype, t);
-                                       BATsetprop_nolock(b, GDK_MIN_POS, 
TYPE_oid, &(oid){p});
-                               } else if (ATOMcmp(b->ttype, t, val) != 0 &&
-                                          ATOMcmp(b->ttype, VALptr(prop), val) 
<= 0) {
-                                       /* old value is equal to smallest and
-                                        * new value is larger (see above), so
-                                        * we don't know anymore which is the
-                                        * smallest */
-                                       BATrmprop_nolock(b, GDK_MIN_VALUE);
+                               if ((prop = BATgetprop_nolock(b, 
GDK_MIN_VALUE)) != NULL) {
+                                       if (ATOMcmp(b->ttype, t, 
ATOMnilptr(b->ttype)) != 0 &&
+                                           ATOMcmp(b->ttype, VALptr(prop), t) 
> 0) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to