Changeset: b9908b634a56 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b9908b634a56
Modified Files:
        gdk/gdk_aggr.c
        gdk/gdk_calc.c
Branch: Jan2022
Log Message:

Clean bat iterators if operator times out


diffs (truncated from 440 to 300 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -1746,10 +1746,8 @@ BATprod(void *res, int tp, BAT *b, BAT *
        do {                                                            \
                const TYPE *restrict vals = (const TYPE *) bi.base;     \
                TYPE *restrict avgs = GDKzalloc(ngrp * sizeof(TYPE));   \
-               if (avgs == NULL) {                                     \
-                       bat_iterator_end(&bi);                          \
-                       goto alloc_fail;                                \
-               }                                                       \
+               if (avgs == NULL)                       \
+                       goto bailout;                           \
                TIMEOUT_LOOP(ncand, timeoffset) {                       \
                        i = canditer_next(&ci) - b->hseqbase;           \
                        if (gids == NULL ||                             \
@@ -1770,7 +1768,7 @@ BATprod(void *res, int tp, BAT *b, BAT *
                        }                                               \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             GOTO_LABEL_TIMEOUT_HANDLER(alloc_fail));  \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                for (i = 0; i < ngrp; i++) {                            \
                        if (cnts[i] == 0 || is_lng_nil(cnts[i])) {      \
                                dbls[i] = dbl_nil;                      \
@@ -1807,7 +1805,7 @@ BATprod(void *res, int tp, BAT *b, BAT *
                        }                                               \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             GOTO_LABEL_TIMEOUT_HANDLER(alloc_fail));  \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                for (i = 0; i < ngrp; i++) {                            \
                        if (cnts[i] == 0 || is_lng_nil(cnts[i])) {      \
                                dbls[i] = dbl_nil;                      \
@@ -1834,6 +1832,7 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -1906,25 +1905,25 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
 #endif
                rems = GDKzalloc(ngrp * sizeof(lng));
                if (rems == NULL)
-                       goto alloc_fail;
+                       goto bailout;
                break;
        default:
                break;
        }
        if (cntsp) {
                if ((cn = COLnew(min, TYPE_lng, ngrp, TRANSIENT)) == NULL)
-                       goto alloc_fail;
+                       goto bailout;
                cnts = (lng *) Tloc(cn, 0);
                memset(cnts, 0, ngrp * sizeof(lng));
        } else {
                cnts = GDKzalloc(ngrp * sizeof(lng));
                if (cnts == NULL)
-                       goto alloc_fail;
+                       goto bailout;
        }
 
        bn = COLnew(min, TYPE_dbl, ngrp, TRANSIENT);
        if (bn == NULL)
-               goto alloc_fail;
+               goto bailout;
        dbls = (dbl *) Tloc(bn, 0);
 
        if (BATtdense(g))
@@ -1932,7 +1931,6 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
        else
                gids = (const oid *) Tloc(g, 0);
 
-       BATiter bi;
        bi = bat_iterator(b);
        switch (b->ttype) {
        case TYPE_bte:
@@ -1959,15 +1957,8 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
                AGGR_AVG_FLOAT(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
-               GDKfree(rems);
-               if (cn)
-                       BBPreclaim(cn);
-               else
-                       GDKfree(cnts);
-               BBPunfix(bn->batCacheid);
                GDKerror("type (%s) not supported.\n", ATOMname(b->ttype));
-               return GDK_FAIL;
+               goto bailout;
        }
        bat_iterator_end(&bi);
        GDKfree(rems);
@@ -2003,8 +1994,8 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
                  ALGOOPTBATPAR(s), ALGOOPTBATPAR(bn),
                  ci.seq, ncand, GDKusec() - t0);
        return GDK_SUCCEED;
-
-  alloc_fail:
+  bailout:
+       bat_iterator_end(&bi);
        if (bn)
                BBPunfix(bn->batCacheid);
        GDKfree(rems);
@@ -3107,6 +3098,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -3170,7 +3162,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
                atomcmp = ATOMcompare(t);
                t = ATOMbasetype(t);
 
-               BATiter bi = bat_iterator(b);
+               bi = bat_iterator(b);
 
                switch (t) {
                case TYPE_bte:
@@ -3230,6 +3222,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        return bn;
 
   bailout:
+       bat_iterator_end(&bi);
        BBPreclaim(bn);
        return NULL;
 }
@@ -4051,7 +4044,7 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
        struct canditer ci;
        BUN ncand;
        BAT *t1, *t2;
-       BATiter bi;
+       BATiter bi = {0};
        const void *v;
        const void *nil = ATOMnilptr(tp);
        const void *dnil = nil;
@@ -4232,10 +4225,8 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
                                if (!skip_nils && !b->tnonil)
                                        nils += (*atomcmp)(v, dnil) == 0;
                        }
-                       if (bunfastapp_nocheck(bn, v) != GDK_SUCCEED) {
-                               bat_iterator_end(&bi);
+                       if (bunfastapp_nocheck(bn, v) != GDK_SUCCEED)
                                goto bunins_failed;
-                       }
                }
                bat_iterator_end(&bi);
                nils += ngrp - BATcount(bn);
@@ -4378,6 +4369,7 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
        return bn;
 
   bunins_failed:
+       bat_iterator_end(&bi);
        if (b && b != origb)
                BBPunfix(b->batCacheid);
        if (g && g != origg)
@@ -4805,6 +4797,7 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
        BUN ncand;
        const char *err;
        lng t0 = 0;
+       BATiter bi = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -4873,7 +4866,6 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                m2[i] = 0;
        }
 
-       BATiter bi;
        bi = bat_iterator(b);
        if (BATtdense(g))
                gids = NULL;
@@ -4905,18 +4897,9 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                AGGR_STDEV(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
-               if (an)
-                       BBPreclaim(an);
-               else
-                       GDKfree(mean);
-               GDKfree(delta);
-               GDKfree(m2);
-               GDKfree(cnts);
-               BBPunfix(bn->batCacheid);
                GDKerror("%s: type (%s) not supported.\n",
                         func, ATOMname(b->ttype));
-               return NULL;
+               goto alloc_fail;
        }
        bat_iterator_end(&bi);
        if (an) {
@@ -4954,9 +4937,9 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
                  func, GDKusec() - t0);
        return bn;
   overflow:
-       bat_iterator_end(&bi);
        GDKerror("22003!overflow in calculation.\n");
   alloc_fail:
+       bat_iterator_end(&bi);
        if (an)
                BBPreclaim(an);
        else
@@ -5059,6 +5042,7 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
        struct canditer ci;
        const char *err;
        lng t0 = 0;
+       BATiter b1i = {0}, b2i = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -5123,7 +5107,6 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
        else
                gids = (const oid *) Tloc(g, 0);
 
-       BATiter b1i, b2i;
        b1i = bat_iterator(b1);
        b2i = bat_iterator(b2);
        switch (b1->ttype) {
@@ -5151,8 +5134,6 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
                AGGR_COVARIANCE(dbl);
                break;
        default:
-               bat_iterator_end(&b1i);
-               bat_iterator_end(&b2i);
                GDKerror("%s: type (%s) not supported.\n", func, 
ATOMname(b1->ttype));
                goto alloc_fail;
        }
@@ -5186,10 +5167,10 @@ dogroupcovariance(BAT *b1, BAT *b2, BAT 
                  func, GDKusec() - t0);
        return bn;
   overflow:
+       GDKerror("22003!overflow in calculation.\n");
+  alloc_fail:
        bat_iterator_end(&b1i);
        bat_iterator_end(&b2i);
-       GDKerror("22003!overflow in calculation.\n");
-  alloc_fail:
        BBPreclaim(bn);
        GDKfree(mean1);
        GDKfree(mean2);
@@ -5271,6 +5252,7 @@ BATgroupcorrelation(BAT *b1, BAT *b2, BA
        struct canditer ci;
        const char *err;
        lng t0 = 0;
+       BATiter b1i = {0}, b2i = {0};
 
        lng timeoffset = 0;
        QryCtx *qry_ctx = MT_thread_get_qry_ctx();
@@ -5336,7 +5318,6 @@ BATgroupcorrelation(BAT *b1, BAT *b2, BA
        else
                gids = (const oid *) Tloc(g, 0);
 
-       BATiter b1i, b2i;
        b1i = bat_iterator(b1);
        b2i = bat_iterator(b2);
        switch (b1->ttype) {
@@ -5364,8 +5345,6 @@ BATgroupcorrelation(BAT *b1, BAT *b2, BA
                AGGR_CORRELATION(dbl);
                break;
        default:
-               bat_iterator_end(&b1i);
-               bat_iterator_end(&b2i);
                GDKerror("type (%s) not supported.\n", ATOMname(b1->ttype));
                goto alloc_fail;
        }
@@ -5397,10 +5376,10 @@ BATgroupcorrelation(BAT *b1, BAT *b2, BA
                  GDKusec() - t0);
        return bn;
   overflow:
+       GDKerror("22003!overflow in calculation.\n");
+  alloc_fail:
        bat_iterator_end(&b1i);
        bat_iterator_end(&b2i);
-       GDKerror("22003!overflow in calculation.\n");
-  alloc_fail:
        BBPreclaim(bn);
        GDKfree(mean1);
        GDKfree(mean2);
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -450,10 +450,8 @@ BATcalcnot(BAT *b, BAT *s)
                break;
 #endif
        default:
-               bat_iterator_end(&bi);
-               BBPunfix(bn->batCacheid);
                GDKerror("type %s not supported.\n", ATOMname(b->ttype));
-               return NULL;
+               goto bailout;
        }
        bat_iterator_end(&bi);
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to