Changeset: 34a47d169724 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/34a47d169724
Branch: iso
Log Message:

Merged with Jul2021


diffs (truncated from 607 to 300 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -613,14 +613,18 @@ BATclear(BAT *b, bool force)
                if (b->tvheap && b->tvheap->free > 0) {
                        Heap *th = GDKmalloc(sizeof(Heap));
 
-                       if (th == NULL)
+                       if (th == NULL) {
+                               MT_lock_unset(&b->theaplock);
                                return GDK_FAIL;
+                       }
                        *th = (Heap) {
                                .farmid = b->tvheap->farmid,
                        };
                        strcpy_len(th->filename, b->tvheap->filename, 
sizeof(th->filename));
-                       if (ATOMheap(b->ttype, th, 0) != GDK_SUCCEED)
+                       if (ATOMheap(b->ttype, th, 0) != GDK_SUCCEED) {
+                               MT_lock_unset(&b->theaplock);
                                return GDK_FAIL;
+                       }
                        ATOMIC_INIT(&th->refs, 1);
                        th->parentid = b->tvheap->parentid;
                        th->dirty = true;
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -3044,7 +3044,7 @@ BATcount_no_nil(BAT *b, BAT *s)
                break;
        case TYPE_str:
                base = bi.vh->base;
-               switch (b->twidth) {
+               switch (bi.width) {
                case 1:
                        for (i = 0; i < n; i++)
                                cnt += base[(var_t) ((const unsigned char *) 
p)[canditer_next(&ci) - hseq] + GDK_VAROFFSET] != '\200';
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3240,13 +3240,11 @@ BBPsync(int cnt, bat *restrict subcommit
 
                        if (d)
                                MT_lock_set(&d->theaplock);
-//                     else
-//                             MT_lock_set(&GDKswapLock(i));
                        if (BBP_status(i) & BBPPERSISTENT) {
                                BAT *b = dirty_bat(&i, subcommit != NULL);
                                if (i <= 0) {
-//                                     MT_lock_unset(&GDKswapLock(subcommit ? 
subcommit[idx] : idx));
-                                       MT_lock_unset(&BBP_desc(i)->theaplock);
+                                       if (d)
+                                               MT_lock_unset(&d->theaplock);
                                        break;
                                }
                                if (b)
@@ -3257,8 +3255,6 @@ BBPsync(int cnt, bat *restrict subcommit
                        }
                        if (d)
                                MT_lock_unset(&d->theaplock);
-//                     else
-//                             MT_lock_unset(&GDKswapLock(i));
                        if (n == -2)
                                break;
                        /* we once again have a saved heap */
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -770,14 +770,17 @@ BATgroup_internal(BAT **groups, BAT **ex
        if (gn == NULL)
                goto error;
        ngrps = (oid *) Tloc(gn, 0);
+       maxgrps = BUN_NONE;
        MT_rwlock_rdlock(&b->thashlock);
        if (b->thash && b->thash != (Hash *) 1)
                maxgrps = b->thash->nunique;
-       else if ((prop = BATgetprop_nolock(b, GDK_NUNIQUE)) != NULL)
-               maxgrps = prop->val.oval;
-       else
-               maxgrps = cnt / 10;
        MT_rwlock_rdunlock(&b->thashlock);
+       if (maxgrps == BUN_NONE) {
+               if ((prop = BATgetprop(b, GDK_NUNIQUE)) != NULL)
+                       maxgrps = prop->val.oval;
+               else
+                       maxgrps = cnt / 10;
+       }
        if (!is_oid_nil(maxgrp) && maxgrps < maxgrp)
                maxgrps += maxgrp;
        if (e && maxgrps < BATcount(e))
@@ -786,18 +789,20 @@ BATgroup_internal(BAT **groups, BAT **ex
                maxgrps += BATcount(h);
        if (maxgrps < GROUPBATINCR)
                maxgrps = GROUPBATINCR;
-       if (b->twidth <= 2)
-               maxgrps = (BUN) 1 << (8 * b->twidth);
+       bi = bat_iterator(b);
+
+       if (bi.width <= 2)
+               maxgrps = (BUN) 1 << (8 * bi.width);
        if (extents) {
                en = COLnew(0, TYPE_oid, maxgrps, TRANSIENT);
                if (en == NULL)
-                       goto error;
+                       goto error1;
                exts = (oid *) Tloc(en, 0);
        }
        if (histo) {
                hn = COLnew(0, TYPE_lng, maxgrps, TRANSIENT);
                if (hn == NULL)
-                       goto error;
+                       goto error1;
                cnts = (lng *) Tloc(hn, 0);
        }
        ngrp = 0;
@@ -811,8 +816,8 @@ BATgroup_internal(BAT **groups, BAT **ex
        /* for strings we can use the offset instead of the actual
         * string values if we know that the strings in the string
         * heap are unique */
-       if (t == TYPE_str && GDK_ELIMDOUBLES(b->tvheap)) {
-               switch (b->twidth) {
+       if (t == TYPE_str && GDK_ELIMDOUBLES(bi.vh)) {
+               switch (bi.width) {
                case 1:
                        t = TYPE_bte;
                        break;
@@ -832,8 +837,6 @@ BATgroup_internal(BAT **groups, BAT **ex
                }
        }
 
-       bi = bat_iterator(b);
-
        if (subsorted ||
            ((BATordered(b) || BATordered_rev(b)) &&
             (g == NULL || BATordered(g) || BATordered_rev(g)))) {
@@ -899,7 +902,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                /* array to maintain last time we saw each old group */
                pgrp = GDKmalloc(sizeof(BUN) * j);
                if (pgrp == NULL)
-                       goto error;
+                       goto error1;
                /* initialize to impossible position */
                memset(pgrp, ~0, sizeof(BUN) * j);
 
@@ -946,7 +949,7 @@ BATgroup_internal(BAT **groups, BAT **ex
 
                algomsg = "byte-sized groups -- ";
                if (bgrps == NULL)
-                       goto error;
+                       goto error1;
                memset(bgrps, 0xFF, 256);
                if (histo)
                        memset(cnts, 0, maxgrps * sizeof(lng));
@@ -979,7 +982,7 @@ BATgroup_internal(BAT **groups, BAT **ex
 
                algomsg = "short-sized groups -- ";
                if (sgrps == NULL)
-                       goto error;
+                       goto error1;
                memset(sgrps, 0xFF, 65536 * sizeof(short));
                if (histo)
                        memset(cnts, 0, maxgrps * sizeof(lng));
@@ -1025,10 +1028,12 @@ BATgroup_internal(BAT **groups, BAT **ex
                         * calculate the bounds [lo, lo+BATcount(b))
                         * in the parent that b uses */
                        BAT *b2 = BBPdescriptor(parent);
+                       MT_rwlock_rdunlock(&b->thashlock);
                        lo = b->tbaseoff - b2->tbaseoff;
                        b = b2;
                        bat_iterator_end(&bi);
                        bi = bat_iterator(b);
+                       MT_rwlock_rdlock(&b->thashlock);
                        algomsg = "existing parent hash -- ";
                        phash = true;
                }
@@ -1091,7 +1096,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                 * BATassertProps for similar code; we also exploit if
                 * g is clustered */
                algomsg = "new partial hash -- ";
-               nme = GDKinmemory(b->theap->farmid) ? ":memory:" : 
BBP_physical(b->batCacheid);
+               nme = GDKinmemory(bi.h->farmid) ? ":memory:" : 
BBP_physical(b->batCacheid);
                if (grps && !gc) {
                        /* we manipulate the hash value after having
                         * calculated it, and when doing that, we
@@ -1129,7 +1134,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                        GDKfree(hs);
                        hs = NULL;
                        GDKerror("cannot allocate hash table\n");
-                       goto error;
+                       goto error1;
                }
                if (snprintf(hs->heaplink.filename, 
sizeof(hs->heaplink.filename), "%s.thshgrpl%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs->heaplink.filename) ||
                    snprintf(hs->heapbckt.filename, 
sizeof(hs->heapbckt.filename), "%s.thshgrpb%x", nme, (unsigned) THRgettid()) >= 
(int) sizeof(hs->heapbckt.filename) ||
@@ -1137,7 +1142,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                        GDKfree(hs);
                        hs = NULL;
                        GDKerror("cannot allocate hash table\n");
-                       goto error;
+                       goto error1;
                }
                gn->tsorted = true; /* be optimistic */
 
@@ -1275,8 +1280,9 @@ BATgroup_internal(BAT **groups, BAT **ex
                  ALGOOPTBATPAR(gn), ALGOOPTBATPAR(en),
                  ALGOOPTBATPAR(hn), algomsg, GDKusec() - t0);
        return GDK_SUCCEED;
+  error1:
+       bat_iterator_end(&bi);
   error:
-       bat_iterator_end(&bi);
        if (hs != NULL && hs != b->thash) {
                HEAPfree(&hs->heaplink, true);
                HEAPfree(&hs->heapbckt, true);
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -729,7 +729,7 @@ BAThash_impl(BAT *restrict b, struct can
        const char *nme = GDKinmemory(b->theap->farmid) ? ":memory:" : 
BBP_physical(b->batCacheid);
        BATiter bi = bat_iterator(b);
        const ValRecord *prop;
-       bool hascand = ci->tpe != cand_dense || ci->ncand != BATcount(b);
+       bool hascand = ci->tpe != cand_dense || ci->ncand != bi.count;
 
        assert(strcmp(ext, "thash") != 0 || !hascand);
 
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -147,7 +147,7 @@
        do {                                                            \
                uint##B##_t mask, prvmask;                              \
                uint##B##_t *restrict im = (uint##B##_t *) imps;        \
-               const TYPE *restrict col = (TYPE *) bi.base;            \
+               const TYPE *restrict col = (TYPE *) bi->base;           \
                const TYPE *restrict bins = (TYPE *) inbins;            \
                const BUN page = IMPS_PAGE / sizeof(TYPE);              \
                prvmask = 0;                                            \
@@ -209,7 +209,7 @@
        } while (0)
 
 static void
-imprints_create(BAT *b, void *inbins, BUN *stats, bte bits,
+imprints_create(BAT *b, BATiter *bi, void *inbins, BUN *stats, bte bits,
                void *imps, BUN *impcnt, cchdc_t *dict, BUN *dictcnt)
 {
        BUN i;
@@ -225,7 +225,6 @@ imprints_create(BAT *b, void *inbins, BU
 #endif
        memset(cnt_bins, 0, 64 * SIZEOF_BUN);
 
-       BATiter bi = bat_iterator(b);
        switch (ATOMbasetype(b->ttype)) {
        case TYPE_bte:
                BINSIZE(bits, IMPS_CREATE, bte);
@@ -254,7 +253,6 @@ imprints_create(BAT *b, void *inbins, BU
                /* should never reach here */
                assert(0);
        }
-       bat_iterator_end(&bi);
 
        *dictcnt = dcnt;
        *impcnt = icnt;
@@ -301,6 +299,7 @@ bool
 BATcheckimprints(BAT *b)
 {
        bool ret;
+       BATiter bi = bat_iterator(b);
 
        if (/* DISABLES CODE */ (0) && VIEWtparent(b)) {
                assert(b->timprints == NULL);
@@ -313,7 +312,7 @@ BATcheckimprints(BAT *b)
                        Imprints *imprints;
                        const char *nme = BBP_physical(b->batCacheid);
 
-                       assert(!GDKinmemory(b->theap->farmid));
+                       assert(!GDKinmemory(bi.h->farmid));
                        b->timprints = NULL;
                        if ((imprints = GDKzalloc(sizeof(Imprints))) != NULL &&
                            (imprints->imprints.farmid = 
BBPselectfarm(b->batRole, b->ttype, imprintsheap)) >= 0) {
@@ -329,15 +328,15 @@ BATcheckimprints(BAT *b)
                                        struct stat st;
                                        size_t pages;
 
-                                       pages = (((size_t) BATcount(b) * 
b->twidth) + IMPS_PAGE - 1) / IMPS_PAGE;
+                                       pages = (((size_t) bi.count * bi.width) 
+ IMPS_PAGE - 1) / IMPS_PAGE;
                                        if (read(fd, hdata, sizeof(hdata)) == 
sizeof(hdata) &&
                                            hdata[0] & ((size_t) 1 << 16) &&
                                            ((hdata[0] & 0xFF00) >> 8) == 
IMPRINTS_VERSION &&
-                                           hdata[3] == (size_t) BATcount(b) &&
+                                           hdata[3] == (size_t) bi.count &&
                                            fstat(fd, &st) == 0 &&
                                            st.st_size >= (off_t) 
(imprints->imprints.size =
                                                                   
imprints->imprints.free =
-                                                                  64 * 
b->twidth +
+                                                                  64 * 
bi.width +
                                                                   64 * 3 * 
SIZEOF_BUN +
                                                                   pages * 
((bte) hdata[0] / 8) +
                                                                   hdata[2] * 
sizeof(cchdc_t) +
@@ -349,7 +348,7 @@ BATcheckimprints(BAT *b)
                                                imprints->impcnt = (BUN) 
hdata[1];
                                                imprints->dictcnt = (BUN) 
hdata[2];
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to