Changeset: c75653dffe50 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c75653dffe50
Modified Files:
        gdk/gdk_system.h
        monetdb5/mal/mal_pipelines.c
        monetdb5/modules/mal/pipeline.c
Branch: pp_hashjoin
Log Message:

fixed issue where the garbage collector cleans up the sources too early 
(incombination with concat sources)
concat sources now keep references too the sources


diffs (135 lines):

diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -152,7 +152,6 @@ typedef int64_t lng;
 typedef struct QryCtx {
        lng starttime;
        lng endtime;
-       int wid;
        struct bstream *bs;
        ATOMIC_TYPE datasize;
        ATOMIC_BASE_TYPE maxmem;
diff --git a/monetdb5/mal/mal_pipelines.c b/monetdb5/mal/mal_pipelines.c
--- a/monetdb5/mal/mal_pipelines.c
+++ b/monetdb5/mal/mal_pipelines.c
@@ -215,8 +215,7 @@ PIPELINEworker(void *T)
                                .seqnr = -1,
                                .wls = NULL,
                        };
-                       QryCtx *qc = MT_thread_get_qry_ctx();
-                       qc->wid = p->wid;
+                       MT_thread_setdata(p);
                        stk->stk[s->mb->stmt[s->start]->argv[1]].val.ival = 
PIPELINEnext_counter(p);
                        stk->stk[s->mb->stmt[s->start]->argv[2]].val.pval = p;
                        /* the maxparts (arg 3) is generated ie constant value 
on the stack */
diff --git a/monetdb5/modules/mal/pipeline.c b/monetdb5/modules/mal/pipeline.c
--- a/monetdb5/modules/mal/pipeline.c
+++ b/monetdb5/modules/mal/pipeline.c
@@ -210,10 +210,8 @@ PPcounter_get(Client cntxt, MalBlkPtr mb
                assert(c->scnt == (int)p->p->nr_workers);
                MT_lock_unset(&c->l);
        }
-       if (!c->cur) {
+       if (!c->cur)
                c->s.done(c, p->wid, p->p->nr_workers, false);
-               //counter_done(c, p->wid, p->p->nr_workers, false);
-       }
        *cur = c->cur[p->wid];
        BBPreclaim(b);
        return MAL_SUCCEED;
@@ -488,18 +486,21 @@ typedef struct pp_concat_t {
        Sink s;
 
        MT_Lock l;
-       /* TODO per worker ? */
        int current;
        int max;
        bool started;
        int *cur;
-       Sink *srcs[];
+       BAT *srcs[];
 } pp_concat;
 
 static void
 concat_free( pp_concat *pcat )
 {
        MT_lock_destroy(&pcat->l);
+       for(int i = 0; i<pcat->max; i++) {
+               if (pcat->srcs[i])
+                       BBPreclaim(pcat->srcs[i]);
+       }
        GDKfree(pcat->cur);
        GDKfree(pcat);
 }
@@ -514,8 +515,9 @@ concat_done( pp_concat *c, int wid, int 
                c->cur = (int*)GDKzalloc(sizeof(int) * nr_workers);
                c->started = true;
        }
-       Sink *s = c->srcs[c->cur[wid]];
-       if (s) {
+       BAT *sb = c->srcs[c->cur[wid]];
+       if (sb) {
+               Sink *s = sb->tsink;
                MT_lock_unset(&c->l);
                if (s->type == SUBCONCAT_SINK)
                        res = concat_done( (pp_concat*)s, wid, nr_workers, 
redo);
@@ -524,9 +526,10 @@ concat_done( pp_concat *c, int wid, int 
                }
                MT_lock_set(&c->l);
                while(res && ++c->cur[wid] < c->max) {
-                       s = c->srcs[c->cur[wid]];
-                       if (!s)
+                       sb = c->srcs[c->cur[wid]];
+                       if (!sb)
                                break;
+                       s = sb->tsink;
                        MT_lock_unset(&c->l);
                        if (s->type == SUBCONCAT_SINK)
                                res = concat_done( (pp_concat*)s, wid, 
nr_workers, false);
@@ -547,8 +550,9 @@ concat_next( pp_concat *c, int wid)
        assert(c->s.type == CONCAT_SINK || c->s.type == SUBCONCAT_SINK);
        MT_lock_set(&c->l);
        assert(c->started);
-       Sink *s = c->srcs[c->cur[wid]];
-       if (s) {
+       BAT *sb = c->srcs[c->cur[wid]];
+       if (sb) {
+               Sink *s = sb->tsink;
                MT_lock_unset(&c->l);
                if (s->type == SUBCONCAT_SINK)
                        res = concat_next( (pp_concat*)s, wid);
@@ -567,8 +571,9 @@ concat_next_bat( pp_concat *c, int wid)
        assert(c->s.type == CONCAT_SINK || c->s.type == SUBCONCAT_SINK);
        MT_lock_set(&c->l);
        assert(c->started);
-       Sink *s = c->srcs[c->cur[wid]];
-       if (s) {
+       BAT *sb = c->srcs[c->cur[wid]];
+       if (sb) {
+               Sink *s = sb->tsink;
                MT_lock_unset(&c->l);
                if (s->type == SUBCONCAT_SINK)
                        res = concat_next_bat( (pp_concat*)s, wid);
@@ -638,10 +643,9 @@ PPconcat_add(Client cntxt, MalBlkPtr mb,
                BBPreclaim(i);
                throw(MAL, "pipeline.concat_add", SQLSTATE(HY002) "Concat too 
many sources (%d)", pcat->current);
        }
-       pcat->srcs[pcat->current++] = i->tsink;
+       pcat->srcs[pcat->current++] = i;
        if (i->tsink->type == CONCAT_SINK)
                i->tsink->type = SUBCONCAT_SINK;
-       BBPreclaim(i);
        *rb = b->batCacheid;
        BBPkeepref(b);
        return MAL_SUCCEED;
@@ -833,8 +837,8 @@ source_next(Client cntxt, MalBlkPtr mb, 
                BBPreclaim(s);
                throw(MAL, "source.next", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
        }
-       QryCtx *qc = MT_thread_get_qry_ctx();
-       BAT *r = src->next_bat(src, qc->wid);
+       Pipeline *p = MT_thread_getdata();
+       BAT *r = src->next_bat(src, p->wid);
        if (!r) {
                BBPreclaim(s);
                throw(SQL, "source.next",  SQLSTATE(HY013) MAL_MALLOC_FAIL);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to