Changeset: 126e69f481bd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/126e69f481bd
Modified Files:
clients/Tests/MAL-signatures-hge.test
clients/Tests/MAL-signatures.test
clients/Tests/exports.stable.out
monetdb5/mal/mal_pipelines.c
monetdb5/mal/mal_pipelines.h
monetdb5/modules/mal/pipeline.c
monetdb5/modules/mal/pp_hash.c
monetdb5/modules/mal/pp_mat.c
sql/backends/monet5/bin_partition_by_slice.c
sql/backends/monet5/rel_physical.c
sql/backends/monet5/rel_pphash.c
sql/backends/monet5/sql_pp_statement.c
sql/backends/monet5/vaults/parquet/parquet.c
sql/backends/monet5/vaults/parquet/pqc_reader.c
Branch: pp_hashjoin
Log Message:
global sync is now handled via the condition variable in the pipelines
structure,
allowing for one global broadcast in case of errors.
pp_counter* now use this same lock/condition variable and check for errors
cleanup old synchronisation code.
fixed mat partitioning code.
diffs (truncated from 687 to 300 lines):
diff --git a/clients/Tests/MAL-signatures-hge.test
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -48540,12 +48540,12 @@ MATnew
Create mat for partitioning
mat
new
-pattern mat.new(X_0:any_1, X_1:int, X_2:int):bat[:any_1]
+pattern mat.new(X_0:any_1, X_1:int, X_2:lng):bat[:any_1]
MATnew
Create mat for partitioning
mat
new
-pattern mat.new(X_0:any_1, X_1:int, X_2:int, X_3:bat[:any_2]):bat[:any_1]
+pattern mat.new(X_0:any_1, X_1:int, X_2:lng, X_3:bat[:any_2]):bat[:any_1]
MATnew
Create mat for partitioning
mat
@@ -50039,11 +50039,6 @@ command pcre.sql2pcre(X_0:str, X_1:str):
PCREsql2pcre
Convert a SQL like pattern with the given escape character into a PCRE pattern.
pipeline
-channel
-unsafe pattern pipeline.channel(X_0:any_1) (X_1:any_1, X_2:int)
-PPchannel
-create a new channel
-pipeline
claim
pattern pipeline.claim(X_0:bat[:bte], X_1:lng):lng
PPclaim
@@ -50099,20 +50094,10 @@ pattern pipeline.identity(X_0:bat[:bte],
PPidentity
Return next set of unique object identifiers
pipeline
-recv
-unsafe pattern pipeline.recv(X_0:ptr, X_1:any_1, X_2:int):any_1
-PPrecv
-receive from channel
-pipeline
resultset
pattern pipeline.resultset():bat[:bte]
PPresultset
return sink for synchronizing appends into resultset
-pipeline
-send
-unsafe pattern pipeline.send(X_0:ptr, X_1:any_1, X_2:int, X_3:any_1):bit
-PPsend
-send through channel
profiler
cpuload
command profiler.cpuload(X_0:lng, X_1:lng, X_2:lng, X_3:lng, X_4:lng)
(X_5:int, X_6:int)
diff --git a/clients/Tests/MAL-signatures.test
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -38409,11 +38409,6 @@ command pcre.sql2pcre(X_0:str, X_1:str):
PCREsql2pcre
Convert a SQL like pattern with the given escape character into a PCRE pattern.
pipeline
-channel
-unsafe pattern pipeline.channel(X_0:any_1) (X_1:any_1, X_2:int)
-PPchannel
-create a new channel
-pipeline
claim
pattern pipeline.claim(X_0:bat[:bte], X_1:lng):lng
PPclaim
@@ -38469,20 +38464,10 @@ pattern pipeline.identity(X_0:bat[:bte],
PPidentity
Return next set of unique object identifiers
pipeline
-recv
-unsafe pattern pipeline.recv(X_0:ptr, X_1:any_1, X_2:int):any_1
-PPrecv
-receive from channel
-pipeline
resultset
pattern pipeline.resultset():bat[:bte]
PPresultset
return sink for synchronizing appends into resultset
-pipeline
-send
-unsafe pattern pipeline.send(X_0:ptr, X_1:any_1, X_2:int, X_3:any_1):bit
-PPsend
-send through channel
profiler
cpuload
command profiler.cpuload(X_0:lng, X_1:lng, X_2:lng, X_3:lng, X_4:lng)
(X_5:int, X_6:int)
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
@@ -808,8 +808,6 @@ void MSresetStack(Client cntxt, MalBlkPt
void MSresetVariables(MalBlkPtr mb);
str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces);
str OIDXdropImplementation(Client cntxt, BAT *b);
-void PIPELINEclear_counter(Pipeline *p);
-int PIPELINEnext_counter(Pipeline *p);
str QLOGcalls(BAT **r);
str QLOGcatalog(BAT **r);
str QLOGdisable(void *ret);
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
@@ -182,6 +182,16 @@ thread_runoncpu(int cpu)
}
#endif
+static int
+PIPELINEnext_counter(Pipeline *p)
+{
+ MT_lock_set(&p->p->l);
+ int n = (int) p->p->master_counter++;
+ //p->p->counters[p->wid] = n;
+ MT_lock_unset(&p->p->l);
+ return n;
+}
+
static void
PIPELINEworker(void *T)
{
@@ -220,14 +230,16 @@ PIPELINEworker(void *T)
stk->stk[s->mb->stmt[s->start]->argv[2]].val.pval = p;
/* the maxparts (arg 3) is generated ie constant value
on the stack */
str error = runMALsequence(s->cntxt, s->mb, s->start+1,
s->stop, stk, 0, 0);
- PIPELINEclear_counter(p);
+ //PIPELINEclear_counter(p);
if (error) {
- void *null = NULL;
+ MT_lock_set(&p->p->l);
/* only collect one error (from one thread,
needed for stable testing) */
- if (ATOMIC_PTR_CAS(&s->error, &null, error)) {
+ if (p->p->error == NULL) {
strcpy(s->errbuf, error);
- ATOMIC_PTR_CAS(&s->error,
(void**)&error, s->errbuf);
+ p->p->error = s->errbuf;
}
+ MT_cond_broadcast(&p->p->cond); /* deblock all
workers */
+ MT_lock_unset(&p->p->l);
}
freeStack(stk);
ma_close(&ma_state);
@@ -304,15 +316,15 @@ runMALpipelines(Client cntxt, MalBlkPtr
cntxt->sqlprofiler = false;
/* initialize with direct increment of all threads at once */
ATOMIC_INIT(&s->workers, -1);
- ATOMIC_PTR_INIT(&s->error, NULL);
+ s->error = NULL;
s->errbuf = GDKgetbuf();
char name[MT_NAME_LEN];
snprintf(name, sizeof(name), "PIPELINE%d", cntxt->idx);
MT_sema_init(&s->s, 0, name);
MT_lock_init(&s->l, name);
- for (size_t i = 0; i < sizeof(s->counters) / sizeof(s->counters[0]);
i++)
- s->counters[i] = -1;
+ //for (size_t i = 0; i < sizeof(s->counters) / sizeof(s->counters[0]);
i++)
+ //s->counters[i] = -1;
MT_cond_init(&s->cond, "pipeline-workers");
/* somehow get number of workers from statement/barrier */
for (int i = 0; i < s->nr_workers; i++)
@@ -324,7 +336,7 @@ runMALpipelines(Client cntxt, MalBlkPtr
MT_sema_destroy(&s->s);
MT_lock_destroy(&s->l);
bool has_sink = (s->sink != 0);
- str err = ATOMIC_PTR_GET(&s->error);
+ str err = s->error;
if (err) {
QryCtx *qc = MT_thread_get_qry_ctx();
allocator *ma = qc->errorallocator;
@@ -384,22 +396,12 @@ stopMALpipelines(void)
MT_lock_unset(&pipelineLock);
}
-int
-PIPELINEnext_counter(Pipeline *p)
-{
- MT_lock_set(&p->p->l);
- int n = (int) p->p->master_counter++;
- p->p->counters[p->wid] = n;
- MT_cond_broadcast(&p->p->cond);
- MT_lock_unset(&p->p->l);
- return n;
-}
-
-void
+/*
+static void
PIPELINEclear_counter(Pipeline *p)
{
MT_lock_set(&p->p->l);
p->p->counters[p->wid] = -1;
- MT_cond_broadcast(&p->p->cond);
MT_lock_unset(&p->p->l);
}
+*/
diff --git a/monetdb5/mal/mal_pipelines.h b/monetdb5/mal/mal_pipelines.h
--- a/monetdb5/mal/mal_pipelines.h
+++ b/monetdb5/mal/mal_pipelines.h
@@ -19,17 +19,17 @@ typedef struct Pipelines {
MalBlkPtr mb; /* carry the context */
MalStkPtr stk;
int start, stop; /* guarded block under consideration*/
- ATOMIC_PTR_TYPE error; /* error encountered */
+ char *error; /* error encountered */
char *errbuf; /* parent errbuf */
MT_Sema s; /* threads wait on empty queues */
MT_Lock l;
+ MT_Cond cond; /* condition variable for full worker synchronisation
and worker execution order */
int maxparts;
int nr_workers;
ATOMIC_TYPE workers;
ATOMIC_TYPE master_counter;
- int counters[THREADS];
+ //int counters[THREADS];
int status;
- MT_Cond cond;
bat sink;
} Pipelines;
@@ -41,7 +41,7 @@ typedef struct Pipeline {
} Pipeline;
mal_export str runMALpipelines(Client cntxt, MalBlkPtr mb, int startpc, int
stoppc, int maxparts, bat sink, MalStkPtr stk);
-mal_export int PIPELINEnext_counter(Pipeline *p);
-mal_export void PIPELINEclear_counter(Pipeline *p);
+//mal_export int PIPELINEnext_counter(Pipeline *p);
+//mal_export void PIPELINEclear_counter(Pipeline *p);
#endif /* _MAL_PIPELINES_H*/
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
@@ -126,7 +126,6 @@ typedef struct pp_counter_t {
int current;
bool sync;
int scnt;
- MT_Cond c;
int *cur; /* nr per worker */
} pp_counter;
@@ -144,21 +143,22 @@ sync_counter_done(pp_counter *c, int wid
{
(void)redo;
int res = 0, cur;
- MT_lock_set(&c->l);
+ Pipeline *p = MT_thread_getdata();
+ MT_lock_set(&p->p->l);
if (!c->cur)
c->cur = (int*)GDKzalloc(sizeof(int) * nr_workers);
cur = c->current++;
if (cur >= c->nr)
res = 1;
- if (res && c->scnt != nr_workers) {
+ if (res && c->scnt != nr_workers && !p->p->error) {
c->scnt++;
if (c->scnt != nr_workers)
- MT_cond_wait(&c->c, &c->l);
+ MT_cond_wait(&p->p->cond, &p->p->l);
else
- MT_cond_broadcast(&c->c);
+ MT_cond_broadcast(&p->p->cond);
assert(c->scnt == nr_workers);
}
- MT_lock_unset(&c->l);
+ MT_lock_unset(&p->p->l);
assert(c->cur);
c->cur[wid] = cur;
return res;
@@ -189,6 +189,7 @@ PPcounter_get(Client cntxt, MalBlkPtr mb
int *cur = getArgReference_int(stk, pci, 0);
bat cb = *getArgReference_bat(stk, pci, 1);
Pipeline *p = (Pipeline*)*getArgReference_ptr(stk, pci, 2);
+ // Pipeline *p = MT_thread_getdata();
BAT *b = BATdescriptor(cb);
if (!b)
@@ -199,16 +200,16 @@ PPcounter_get(Client cntxt, MalBlkPtr mb
throw(MAL, "pipeline.counter_get", SQLSTATE(HY002) "Invalid
source %d", c->s.type);
}
if (c->sync && c->scnt != (int)p->p->nr_workers) {
- MT_lock_set(&c->l);
+ MT_lock_set(&p->p->l);
if (c->scnt != (int)p->p->nr_workers) {
c->scnt++;
if (c->scnt != p->p->nr_workers)
- MT_cond_wait(&c->c, &c->l);
+ MT_cond_wait(&p->p->cond, &p->p->l);
else
- MT_cond_broadcast(&c->c);
+ MT_cond_broadcast(&p->p->cond);
}
assert(c->scnt == (int)p->p->nr_workers);
- MT_lock_unset(&c->l);
+ MT_lock_unset(&p->p->l);
}
if (!c->cur)
c->s.done(c, p->wid, p->p->nr_workers, false);
@@ -278,7 +279,6 @@ PPcounter(Client cntxt, MalBlkPtr mb, Ma
if (sync) {
c->sync = true;
c->scnt = 0;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]