Changeset: 4b12b002d471 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4b12b002d471
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/server/rel_exp.c
        sql/server/rel_optimizer.c
        sql/storage/store.c
Branch: mangled
Log Message:

Merge with default.


diffs (truncated from 4138 to 300 lines):

diff --git a/clients/ChangeLog.Jul2021 b/clients/ChangeLog.Jul2021
--- a/clients/ChangeLog.Jul2021
+++ b/clients/ChangeLog.Jul2021
@@ -1,3 +1,7 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Mon Dec 13 2021 Sjoerd Mullender <[email protected]>
+- Dumping the database now also dumps the read-only and insert-only
+  states of tables.
+
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1942,6 +1942,7 @@ dump_table_alters(Mapi mid, const char *
        }
        rc = 0;                                         /* success */
   bailout:
+       free(query);
        free(s);
        free(t);
        mapi_close_handle(hdl);         /* may be NULL */
diff --git a/common/utils/matomic.h b/common/utils/matomic.h
--- a/common/utils/matomic.h
+++ b/common/utils/matomic.h
@@ -62,6 +62,22 @@
  * Windows since otherwise we can't compile this at all in C99 mode */
 #if defined(HAVE_STDATOMIC_H) && (!defined(__STDC_NO_ATOMICS__) || 
(defined(__INTEL_COMPILER) && defined(_WINDOWS))) && 
!defined(NO_ATOMIC_INSTRUCTIONS)
 
+#ifdef __cplusplus
+
+#include <atomic>
+
+#if SIZEOF_LONG_LONG == 8
+typedef atomic_ullong ATOMIC_TYPE;
+typedef unsigned long long ATOMIC_BASE_TYPE;
+#elif SIZEOF_LONG == 8
+typedef atomic_ulong ATOMIC_TYPE;
+typedef unsigned long ATOMIC_BASE_TYPE;
+#else
+#error "we need a 64 bit atomic type"
+#endif
+
+#else
+
 #include <stdatomic.h>
 
 #if SIZEOF_LONG_LONG == 8
@@ -105,6 +121,8 @@ typedef volatile atomic_flag ATOMIC_FLAG
 #define ATOMIC_CLEAR(var)      atomic_flag_clear(var)
 #define ATOMIC_TAS(var)                atomic_flag_test_and_set(var)
 
+#endif /* __cplusplus */
+
 #elif defined(_MSC_VER) && !defined(NO_ATOMIC_INSTRUCTIONS)
 
 typedef uint64_t ATOMIC_BASE_TYPE;
diff --git a/gdk/ChangeLog.Jul2021 b/gdk/ChangeLog.Jul2021
--- a/gdk/ChangeLog.Jul2021
+++ b/gdk/ChangeLog.Jul2021
@@ -1,3 +1,8 @@
 # ChangeLog file for GDK
 # This file is updated with Maddlog
 
+* Mon Dec 13 2021 Sjoerd Mullender <[email protected]>
+- Sometimes when the server was restarted, it wouldn't start anymore due
+  to an error from BBPcheckbats.  We finally found and fixed a (hopefully
+  "the") cause of this problem.
+
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);
@@ -2938,7 +2929,7 @@ BATgroupavg3combine(BAT *avg, BAT *rem, 
                        n++;                                            \
                }                                                       \
                TIMEOUT_CHECK(timeoffset,                               \
-                             TIMEOUT_HANDLER(GDK_FAIL));               \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));             
\
                /* the sum fit, so now we can calculate the average */  \
                *avg = n > 0 ? (dbl) sum / n : dbl_nil;                 \
                if (0) {                                                \
@@ -2997,7 +2988,7 @@ BATgroupavg3combine(BAT *avg, BAT *rem, 
                        AVERAGE_ITER_FLOAT(TYPE, x, a, n);      \
                }                                               \
                TIMEOUT_CHECK(timeoffset,                       \
-                             TIMEOUT_HANDLER(GDK_FAIL));       \
+                             GOTO_LABEL_TIMEOUT_HANDLER(bailout));     \
                *avg = n > 0 ? a : dbl_nil;                     \
        } while (0)
 
@@ -3054,10 +3045,9 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
                AVERAGE_FLOATTYPE(dbl);
                break;
        default:
-               bat_iterator_end(&bi);
                GDKerror("average of type %s unsupported.\n",
                         ATOMname(b->ttype));
-               return GDK_FAIL;
+               goto bailout;
        }
        bat_iterator_end(&bi);
        if (scale != 0 && !is_dbl_nil(*avg))
@@ -3065,6 +3055,9 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
        if (vals)
                *vals = (BUN) n;
        return GDK_SUCCEED;
+bailout:
+       bat_iterator_end(&bi);
+       return GDK_FAIL;
 }
 
 /* ---------------------------------------------------------------------- */
@@ -3107,6 +3100,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 +3164,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 +3224,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        return bn;
 
   bailout:
+       bat_iterator_end(&bi);
        BBPreclaim(bn);
        return NULL;
 }
@@ -3824,7 +3819,21 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
                if (is_oid_nil(pos)) {
                        res = ATOMnilptr(b->ttype);
                } else {
-                       res = BUNtail(bi, pos - b->hseqbase);
+                       bi.minpos = pos - b->hseqbase;
+                       res = BUNtail(bi, bi.minpos);
+                       MT_lock_set(&b->theaplock);
+                       if (bi.count == BATcount(b) && bi.h == b->theap)
+                               b->tminpos = bi.minpos;
+                       MT_lock_unset(&b->theaplock);
+                       bat pbid = VIEWtparent(b);
+                       if (pbid) {
+                               BAT *pb = BBP_cache(pbid);
+                               MT_lock_set(&pb->theaplock);
+                               if (bi.count == BATcount(pb) &&
+                                   bi.h == pb->theap)
+                                       pb->tminpos = bi.minpos;
+                               MT_lock_unset(&pb->theaplock);
+                       }
                }
        }
        if (aggr == NULL) {
@@ -3964,7 +3973,21 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
                if (is_oid_nil(pos)) {
                        res = ATOMnilptr(b->ttype);
                } else {
-                       res = BUNtail(bi, pos - b->hseqbase);
+                       bi.maxpos = pos - b->hseqbase;
+                       res = BUNtail(bi, bi.maxpos);
+                       MT_lock_set(&b->theaplock);
+                       if (bi.count == BATcount(b) && bi.h == b->theap)
+                               b->tmaxpos = bi.maxpos;
+                       MT_lock_unset(&b->theaplock);
+                       bat pbid = VIEWtparent(b);
+                       if (pbid) {
+                               BAT *pb = BBP_cache(pbid);
+                               MT_lock_set(&pb->theaplock);
+                               if (bi.count == BATcount(pb) &&
+                                   bi.h == pb->theap)
+                                       pb->tmaxpos = bi.maxpos;
+                               MT_lock_unset(&pb->theaplock);
+                       }
                }
        }
        if (aggr == NULL) {
@@ -4023,7 +4046,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;
@@ -4204,10 +4227,8 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
                                if (!skip_nils && !b->tnonil)
                                        nils += (*atomcmp)(v, dnil) == 0;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to