Changeset: dc6677e2dbcc for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dc6677e2dbcc Modified Files: monetdb5/optimizer/opt_pipes.c monetdb5/optimizer/optimizer.c monetdb5/optimizer/optimizer_private.h Branch: Jun2016 Log Message:
Don't initialize optimizer pipes concurrently: that causes memory leaks. diffs (140 lines): diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c --- a/monetdb5/optimizer/opt_pipes.c +++ b/monetdb5/optimizer/opt_pipes.c @@ -238,6 +238,17 @@ static struct PIPELINES { * as it is intended for internal use.", */ #include "opt_pipes.h" +#include "optimizer_private.h" + +static MT_Lock pipeLock MT_LOCK_INITIALIZER("pipeLock"); + +void +optPipeInit(void) +{ +#ifdef NEED_MT_LOCK_INIT + MT_lock_init(&pipeLock, "pipeLock"); +#endif +} /* the session_pipe is the one defined by the user */ str @@ -247,14 +258,19 @@ addPipeDefinition(Client cntxt, str name str msg; struct PIPELINES oldpipe; + MT_lock_set(&pipeLock); for (i = 0; i < MAXOPTPIPES && pipes[i].name; i++) if (strcmp(name, pipes[i].name) == 0) break; - if (i == MAXOPTPIPES) + if (i == MAXOPTPIPES) { + MT_lock_unset(&pipeLock); throw(MAL, "optimizer.addPipeDefinition", "Out of slots"); - if (pipes[i].name && pipes[i].builtin) + } + if (pipes[i].name && pipes[i].builtin) { + MT_lock_unset(&pipeLock); throw(MAL, "optimizer.addPipeDefinition", "No overwrite of built in allowed"); + } /* save old value */ oldpipe = pipes[i]; @@ -262,15 +278,18 @@ addPipeDefinition(Client cntxt, str name pipes[i].def = GDKstrdup(pipe); pipes[i].status = GDKstrdup("experimental"); pipes[i].mb = NULL; + MT_lock_unset(&pipeLock); msg = compileOptimizer(cntxt, name); if (msg) { /* failed: restore old value */ + MT_lock_set(&pipeLock); GDKfree(pipes[i].name); GDKfree(pipes[i].def); if (pipes[i].mb) freeMalBlk(pipes[i].mb); GDKfree(pipes[i].status); pipes[i] = oldpipe; + MT_lock_unset(&pipeLock); } else { /* succeeded: destroy old value */ if (oldpipe.name) @@ -281,11 +300,6 @@ addPipeDefinition(Client cntxt, str name freeMalBlk(oldpipe.mb); if (oldpipe.status) GDKfree(oldpipe.status); - if (++i < MAXOPTPIPES) { - pipes[i].name = pipes[i].def = pipes[i].status = pipes[i].prerequisite = NULL; - pipes[i].mb = NULL; - pipes[i].builtin = 0; - } } return msg; } @@ -430,6 +444,7 @@ compileOptimizer(Client cntxt, str name) ClientRec c; memset((char*)&c, 0, sizeof(c)); + MT_lock_set(&pipeLock); for (i = 0; i < MAXOPTPIPES && pipes[i].name; i++) { if (strcmp(pipes[i].name, name) == 0 && pipes[i].mb == 0) { /* precompile the pipeline as MAL string */ @@ -437,8 +452,10 @@ compileOptimizer(Client cntxt, str name) c.nspace = newModule(NULL, putName("user")); c.father = cntxt; /* to avoid conflicts on GDKin */ c.fdout = cntxt->fdout; - if (setScenario(&c, "mal")) + if (setScenario(&c, "mal")) { + MT_lock_unset(&pipeLock); throw(MAL, "optimizer.addOptimizerPipe", "failed to set scenario"); + } (void) MCinitClientThread(&c); for (j = 0; j < MAXOPTPIPES && pipes[j].def; j++) { if (pipes[j].mb == NULL) { @@ -466,12 +483,13 @@ compileOptimizer(Client cntxt, str name) c.nspace = 0; } MCcloseClient(&c); - if (msg != MAL_SUCCEED || - (msg = validateOptimizerPipes()) != MAL_SUCCEED) - return msg; + if (msg != MAL_SUCCEED || + (msg = validateOptimizerPipes()) != MAL_SUCCEED) + break; } } - return MAL_SUCCEED; + MT_lock_unset(&pipeLock); + return msg; } str @@ -486,7 +504,7 @@ addOptimizerPipe(Client cntxt, MalBlkPtr break; if (i == MAXOPTPIPES) - throw(MAL, "optimizer.addOptimizerPipe", "Out of slots");; + throw(MAL, "optimizer.addOptimizerPipe", "Out of slots"); if (pipes[i].mb == NULL) msg = compileOptimizer(cntxt, name); diff --git a/monetdb5/optimizer/optimizer.c b/monetdb5/optimizer/optimizer.c --- a/monetdb5/optimizer/optimizer.c +++ b/monetdb5/optimizer/optimizer.c @@ -36,6 +36,7 @@ optimizer_prelude(Client cntxt, MalBlkPt (void) mb; (void) p; updateScenario("mal", "MALoptimizer", (MALfcn) MALoptimizer); + optPipeInit(); optimizerInit(); return MAL_SUCCEED; } diff --git a/monetdb5/optimizer/optimizer_private.h b/monetdb5/optimizer/optimizer_private.h --- a/monetdb5/optimizer/optimizer_private.h +++ b/monetdb5/optimizer/optimizer_private.h @@ -13,3 +13,4 @@ #endif void optimizerInit(void); +void optPipeInit(void); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list