Changeset: 77836e534545 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/77836e534545
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk.h
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_logger.c
        gdk/gdk_storage.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_debugger.c
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_resource.c
        monetdb5/mal/mal_session.c
        monetdb5/mal/mal_session.h
        monetdb5/modules/mal/clients.c
        monetdb5/optimizer/opt_wrapper.c
        sql/backends/monet5/sql.c
        testing/Mtest.py.in
Branch: default
Log Message:

Fix data races.


diffs (truncated from 675 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
@@ -775,7 +775,6 @@ void MSresetInstructions(MalBlkPtr mb, i
 void MSresetStack(Client cntxt, MalBlkPtr mb, MalStkPtr glb);
 void MSresetVariables(MalBlkPtr mb);
 void MSscheduleClient(str command, str challenge, bstream *fin, stream *fout, 
protocol_version protocol, size_t blocksize);
-str MSserveClient(Client cntxt);
 str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces);
 str OIDXdropImplementation(Client cntxt, BAT *b);
 str QLOGcalls(BAT **r);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -963,6 +963,8 @@ typedef struct BATiter {
        int8_t type;
        oid tseq;
        BUN hfree, vhfree;
+       BUN nokey[2];
+       BUN nosorted, norevsorted;
        BUN minpos, maxpos;
        double unique_est;
        bool key:1,
@@ -1009,6 +1011,10 @@ bat_iterator_nolock(BAT *b)
                                  (size_t) b->batCount << b->tshift :
                                 0,
                        .vhfree = b->tvheap ? b->tvheap->free : 0,
+                       .nokey[0] = b->tnokey[0],
+                       .nokey[1] = b->tnokey[1],
+                       .nosorted = b->tnosorted,
+                       .norevsorted = b->tnorevsorted,
                        .minpos = isview ? BUN_NONE : b->tminpos,
                        .maxpos = isview ? BUN_NONE : b->tmaxpos,
                        .unique_est = b->tunique_est,
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -940,14 +940,14 @@ COLcopy(BAT *b, int tt, bool writable, r
                bn->tsorted = bi.sorted;
                bn->trevsorted = bi.revsorted;
                bn->batDirtydesc = true;
-               bn->tnorevsorted = b->tnorevsorted;
-               if (b->tnokey[0] != b->tnokey[1]) {
-                       bn->tnokey[0] = b->tnokey[0];
-                       bn->tnokey[1] = b->tnokey[1];
+               bn->tnorevsorted = bi.norevsorted;
+               if (bi.nokey[0] != bi.nokey[1]) {
+                       bn->tnokey[0] = bi.nokey[0];
+                       bn->tnokey[1] = bi.nokey[1];
                } else {
                        bn->tnokey[0] = bn->tnokey[1] = 0;
                }
-               bn->tnosorted = b->tnosorted;
+               bn->tnosorted = bi.nosorted;
                bn->tnonil = bi.nonil;
                bn->tnil = bi.nil;
                bn->tminpos = bi.minpos;
@@ -962,19 +962,19 @@ COLcopy(BAT *b, int tt, bool writable, r
                        BATkey(bn, true);
                bn->tnonil = bi.nonil;
                bn->tnil = bi.nil;
-               if (b->tnosorted > 0 && b->tnosorted < h)
-                       bn->tnosorted = b->tnosorted;
+               if (bi.nosorted > 0 && bi.nosorted < h)
+                       bn->tnosorted = bi.nosorted;
                else
                        bn->tnosorted = 0;
-               if (b->tnorevsorted > 0 && b->tnorevsorted < h)
-                       bn->tnorevsorted = b->tnorevsorted;
+               if (bi.norevsorted > 0 && bi.norevsorted < h)
+                       bn->tnorevsorted = bi.norevsorted;
                else
                        bn->tnorevsorted = 0;
-               if (b->tnokey[0] < h &&
-                   b->tnokey[1] < h &&
-                   b->tnokey[0] != b->tnokey[1]) {
-                       bn->tnokey[0] = b->tnokey[0];
-                       bn->tnokey[1] = b->tnokey[1];
+               if (bi.nokey[0] < h &&
+                   bi.nokey[1] < h &&
+                   bi.nokey[0] != bi.nokey[1]) {
+                       bn->tnokey[0] = bi.nokey[0];
+                       bn->tnokey[1] = bi.nokey[1];
                } else {
                        bn->tnokey[0] = bn->tnokey[1] = 0;
                }
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -432,12 +432,12 @@ append_varsized_bat(BAT *b, BATiter *ni,
                b->tnil = ni->nil;
                b->tnonil = ni->nonil;
                b->tsorted = ni->sorted;
-               b->tnosorted = ni->b->tnosorted;
+               b->tnosorted = ni->nosorted;
                b->trevsorted = ni->revsorted;
-               b->tnorevsorted = ni->b->tnorevsorted;
+               b->tnorevsorted = ni->norevsorted;
                b->tkey = ni->key;
-               b->tnokey[0] = ni->b->tnokey[0];
-               b->tnokey[1] = ni->b->tnokey[1];
+               b->tnokey[0] = ni->nokey[0];
+               b->tnokey[1] = ni->nokey[1];
                b->tminpos = ni->minpos;
                b->tmaxpos = ni->maxpos;
                b->tunique_est = ni->unique_est;
@@ -772,8 +772,8 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool 
                b->tnonil = ni.nonil;
                b->tnil = ni.nil && ci.ncand == BATcount(n);
                if (ci.tpe == cand_dense) {
-                       b->tnosorted = ci.seq - hseq <= n->tnosorted && 
n->tnosorted < ci.seq + ci.ncand - hseq ? n->tnosorted + hseq - ci.seq : 0;
-                       b->tnorevsorted = ci.seq - hseq <= n->tnorevsorted && 
n->tnorevsorted < ci.seq + ci.ncand - hseq ? n->tnorevsorted + hseq - ci.seq : 
0;
+                       b->tnosorted = ci.seq - hseq <= ni.nosorted && 
ni.nosorted < ci.seq + ci.ncand - hseq ? ni.nosorted + hseq - ci.seq : 0;
+                       b->tnorevsorted = ci.seq - hseq <= ni.norevsorted && 
ni.norevsorted < ci.seq + ci.ncand - hseq ? ni.norevsorted + hseq - ci.seq : 0;
                        if (BATtdensebi(&ni)) {
                                b->tseqbase = n->tseqbase + ci.seq - hseq;
                        }
@@ -783,8 +783,8 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool 
                }
                b->tkey = ni.key;
                if (ci.ncand == BATcount(n)) {
-                       b->tnokey[0] = n->tnokey[0];
-                       b->tnokey[1] = n->tnokey[1];
+                       b->tnokey[0] = ni.nokey[0];
+                       b->tnokey[1] = ni.nokey[1];
                } else {
                        b->tnokey[0] = b->tnokey[1] = 0;
                }
@@ -1780,19 +1780,19 @@ BATslice(BAT *b, BUN l, BUN h)
                bn->trevsorted = bi.revsorted;
                bn->tkey = bi.key;
                bn->tnonil = bi.nonil;
-               if (b->tnosorted > l && b->tnosorted < h)
-                       bn->tnosorted = b->tnosorted - l;
+               if (bi.nosorted > l && bi.nosorted < h)
+                       bn->tnosorted = bi.nosorted - l;
                else
                        bn->tnosorted = 0;
-               if (b->tnorevsorted > l && b->tnorevsorted < h)
-                       bn->tnorevsorted = b->tnorevsorted - l;
+               if (bi.norevsorted > l && bi.norevsorted < h)
+                       bn->tnorevsorted = bi.norevsorted - l;
                else
                        bn->tnorevsorted = 0;
-               if (b->tnokey[0] >= l && b->tnokey[0] < h &&
-                   b->tnokey[1] >= l && b->tnokey[1] < h &&
-                   b->tnokey[0] != b->tnokey[1]) {
-                       bn->tnokey[0] = b->tnokey[0] - l;
-                       bn->tnokey[1] = b->tnokey[1] - l;
+               if (bi.nokey[0] >= l && bi.nokey[0] < h &&
+                   bi.nokey[1] >= l && bi.nokey[1] < h &&
+                   bi.nokey[0] != bi.nokey[1]) {
+                       bn->tnokey[0] = bi.nokey[0] - l;
+                       bn->tnokey[1] = bi.nokey[1] - l;
                } else {
                        bn->tnokey[0] = bn->tnokey[1] = 0;
                }
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1866,10 +1866,10 @@ heap_entry(FILE *fp, BATiter *bi, BUN si
                           ((unsigned short) BATtdensebi(bi) << 9) |
                           ((unsigned short) bi->nonil << 10) |
                           ((unsigned short) bi->nil << 11),
-                      b->tnokey[0] >= size || b->tnokey[1] >= size ? 0 : 
b->tnokey[0],
-                      b->tnokey[0] >= size || b->tnokey[1] >= size ? 0 : 
b->tnokey[1],
-                      b->tnosorted >= size ? 0 : b->tnosorted,
-                      b->tnorevsorted >= size ? 0 : b->tnorevsorted,
+                      bi->nokey[0] >= size || bi->nokey[1] >= size ? 0 : 
bi->nokey[0],
+                      bi->nokey[0] >= size || bi->nokey[1] >= size ? 0 : 
bi->nokey[1],
+                      bi->nosorted >= size ? 0 : bi->nosorted,
+                      bi->norevsorted >= size ? 0 : bi->norevsorted,
                       bi->tseq,
                       free,
                       bi->minpos < size ? (uint64_t) bi->minpos : (uint64_t) 
oid_nil,
@@ -3354,6 +3354,7 @@ BBPquickdesc(bat bid)
                }
                return NULL;
        }
+       BBPspin(bid, __func__, BBPWAITING);
        b = BBP_desc(bid);
        if (b && b->ttype < 0) {
                const char *aname = ATOMunknown_name(b->ttype);
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -162,7 +162,7 @@ log_find(BAT *b, BAT *d, int val)
 static log_bid
 internal_find_bat(logger *lg, log_id id, int tid)
 {
-       BATiter cni = bat_iterator_nolock(lg->catalog_id);
+       BATiter cni = bat_iterator(lg->catalog_id);
        BUN p;
 
        if (BAThash(lg->catalog_id) == GDK_SUCCEED) {
@@ -172,6 +172,7 @@ internal_find_bat(logger *lg, log_id id,
                                oid pos = p;
                                if (BUNfnd(lg->dcatalog, &pos) == BUN_NONE) {
                                        MT_rwlock_rdunlock(&cni.b->thashlock);
+                                       bat_iterator_end(&cni);
                                        return *(log_bid *) 
Tloc(lg->catalog_bid, p);
                                }
                        }
@@ -186,11 +187,13 @@ internal_find_bat(logger *lg, log_id id,
                        }
                        if (cp != BUN_NONE) {
                                MT_rwlock_rdunlock(&cni.b->thashlock);
+                               bat_iterator_end(&cni);
                                return *(log_bid *) Tloc(lg->catalog_bid, cp);
                        }
                }
                MT_rwlock_rdunlock(&cni.b->thashlock);
        }
+       bat_iterator_end(&cni);
        return 0;
 }
 
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -652,11 +652,13 @@ DESCload(int i)
        }
 
        tt = b->ttype;
-       if ((tt < 0 && (tt = ATOMindex(s = ATOMunknown_name(tt))) < 0)) {
-               GDKerror("atom '%s' unknown, in BAT '%s'.\n", s, nme);
-               return NULL;
+       if (tt < 0) {
+               if ((tt = ATOMindex(s = ATOMunknown_name(tt))) < 0) {
+                       GDKerror("atom '%s' unknown, in BAT '%s'.\n", s, nme);
+                       return NULL;
+               }
+               b->ttype = tt;
        }
-       b->ttype = tt;
 
        /* reconstruct mode from BBP status (BATmode doesn't flush
         * descriptor, so loaded mode may be stale) */
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -85,6 +85,7 @@ MCinit(void)
        }
        for (int i = 0; i < MAL_MAXCLIENTS; i++){
                ATOMIC_INIT(&mal_clients[i].lastprint, 0);
+               mal_clients[i].idx = -1; /* indicate it's available */
        }
        return true;
 }
@@ -138,14 +139,15 @@ MCnewClient(void)
        Client c;
 
        for (c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
-               if (c->mode == FREECLIENT) {
-                       c->mode = RUNCLIENT;
+               if (c->idx == -1)
                        break;
-               }
        }
 
        if (c == mal_clients + MAL_MAXCLIENTS)
                return NULL;
+
+       assert(c->mode == FREECLIENT);
+       c->mode = RUNCLIENT;
        c->idx = (int) (c - mal_clients);
        return c;
 }
@@ -222,6 +224,7 @@ MCinitClientRecord(Client c, oid user, b
        c->fdin = fin ? fin : bstream_create(GDKstdin, 0);
        if ( c->fdin == NULL){
                c->mode = FREECLIENT;
+               c->idx = -1;
                TRC_ERROR(MAL_SERVER, "No stdin channel available\n");
                return NULL;
        }
@@ -255,8 +258,9 @@ MCinitClientRecord(Client c, oid user, b
                if (fin == NULL) {
                        c->fdin->s = NULL;
                        bstream_destroy(c->fdin);
-                       c->mode = FREECLIENT;
                }
+               c->mode = FREECLIENT;
+               c->idx = -1;
                return NULL;
        }
        c->promptlength = strlen(prompt);
@@ -387,6 +391,16 @@ MCforkClient(Client father)
        return son;
 }
 
+static bool shutdowninprogress = false;
+
+bool
+MCshutdowninprogress(void){
+       MT_lock_set(&mal_contextLock);
+       bool ret = shutdowninprogress;
+       MT_lock_unset(&mal_contextLock);
+       return ret;
+}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to