Changeset: b0ab3915cdc9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b0ab3915cdc9
Modified Files:
monetdb5/mal/mal_client.c
Branch: sql_profiler
Log Message:
merge with default
diffs (300 lines):
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -68,11 +68,15 @@ getClientContext(void)
}
/* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
setClientContext(Client cntxt)
{
+ Client old = getClientContext();
+
if (pthread_setspecific(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+ return old;
}
#elif defined(Win32)
@@ -103,11 +107,15 @@ getClientContext(void)
}
/* declared in mal_private.h so only the MAL interpreter core can access it */
-void
+Client
setClientContext(Client cntxt)
{
+ Client old = getClientContext();
+
if (TlsSetValue(tl_client_key, cntxt) != 0)
GDKfatal("Failed to set thread local Client context");
+
+ return old;
}
#else
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
@@ -44,6 +44,7 @@
#include "mal_parser.h"
#include "mal_namespace.h"
#include "mal_private.h"
+#include "mal_interpreter.h"
#include "mal_runtime.h"
#include "mal_authorize.h"
#include "mapi_prompt.h"
@@ -207,6 +208,7 @@ MCexitClient(Client c)
c->fdin = NULL;
}
// TODO PROFILER: EVENT("end of client connection", "client_id",
TYPE_int, c->id)
+ setClientContext(NULL);
}
static Client
@@ -298,9 +300,10 @@ MCinitClient(oid user, bstream *fin, str
MT_lock_set(&mal_contextLock);
c = MCnewClient();
// TODO PROFILER: EVENT("start of client connection", "client_id",
TYPE_int, c->id)
-
- if (c)
+ if (c) {
+ assert(NULL == setClientContext(c));
c = MCinitClientRecord(c, user, fin, fout);
+ }
MT_lock_unset(&mal_contextLock);
return c;
}
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -43,7 +43,7 @@ static bool embeddedinitialized = false;
str
malEmbeddedBoot(int workerlimit, int memorylimit, int querytimeout, int
sessiontimeout, bool with_mapi_server)
{
- Client c;
+ Client c, c_old;
str msg = MAL_SUCCEED;
if( embeddedinitialized )
@@ -99,7 +99,7 @@ malEmbeddedBoot(int workerlimit, int mem
initParser();
initHeartbeat();
// initResource();
-
+ c_old = setClientContext(NULL); //save context
c = MCinitClient((oid) 0, 0, 0);
if(c == NULL)
throw(MAL, "malEmbeddedBoot", "Failed to initialize client");
@@ -110,31 +110,37 @@ malEmbeddedBoot(int workerlimit, int mem
c->curmodule = c->usermodule = userModule();
if(c->usermodule == NULL) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
throw(MAL, "malEmbeddedBoot", "Failed to initialize client MAL
module");
}
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
if ((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
char *modules[5] = { "embedded", "sql", "generator", "udf" };
if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server)) !=
MAL_SUCCEED) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
pushEndInstruction(c->curprg->def);
msg = chkProgram(c->usermodule, c->curprg->def);
if ( msg != MAL_SUCCEED || (msg= c->curprg->def->errors) != MAL_SUCCEED
) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
msg = MALengine(c);
if (msg == MAL_SUCCEED)
embeddedinitialized = true;
MCcloseClient(c);
+ setClientContext(c_old); // restore context
initProfiler();
return msg;
}
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -274,7 +274,7 @@ malInclude(Client c, const char *name, i
str
evalFile(str fname, int listing)
{
- Client c;
+ Client c, c_old;
stream *fd;
str filename;
str msg = MAL_SUCCEED;
@@ -295,13 +295,15 @@ evalFile(str fname, int listing)
close_stream(fd);
throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
- c= MCinitClient(MAL_ADMIN, bs, 0);
+ c_old = setClientContext(NULL); // save context
+ c = MCinitClient(MAL_ADMIN, bs, 0);
if( c == NULL){
throw(MAL,"mal.eval","Can not create user context");
}
c->curmodule = c->usermodule = userModule();
if(c->curmodule == NULL) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
c->promptlength = 0;
@@ -309,15 +311,18 @@ evalFile(str fname, int listing)
if ( (msg = defaultScenario(c)) ) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
if((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
msg = runScenario(c,0);
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
@@ -341,7 +346,7 @@ mal_cmdline(char *s, size_t *len)
str
compileString(Symbol *fcn, Client cntxt, str s)
{
- Client c;
+ Client c, c_old;
size_t len = strlen(s);
buffer *b;
str msg = MAL_SUCCEED;
@@ -380,8 +385,9 @@ compileString(Symbol *fcn, Client cntxt,
}
strncpy(fdin->buf, qry, len+1);
+ c_old = setClientContext(NULL); // save context
// compile in context of called for
- c= MCinitClient(MAL_ADMIN, fdin, 0);
+ c = MCinitClient(MAL_ADMIN, fdin, 0);
if( c == NULL){
GDKfree(qry);
GDKfree(b);
@@ -396,6 +402,7 @@ compileString(Symbol *fcn, Client cntxt,
GDKfree(b);
c->usermodule= 0;
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
@@ -410,6 +417,7 @@ compileString(Symbol *fcn, Client cntxt,
c->usermodule= 0;
/* restore IO channel */
MCcloseClient(c);
+ setClientContext(c_old); // restore context
GDKfree(qry);
GDKfree(b);
return msg;
@@ -418,7 +426,7 @@ compileString(Symbol *fcn, Client cntxt,
str
callString(Client cntxt, str s, int listing)
{
- Client c;
+ Client c, c_old;
int i;
size_t len = strlen(s);
buffer *b;
@@ -448,6 +456,7 @@ callString(Client cntxt, str s, int list
GDKfree(qry);
throw(MAL,"callstring", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
+ c_old = setClientContext(NULL); // save context
c= MCinitClient(MAL_ADMIN, bs, cntxt->fdout);
if( c == NULL){
GDKfree(b);
@@ -464,6 +473,7 @@ callString(Client cntxt, str s, int list
GDKfree(b);
GDKfree(qry);
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
@@ -473,6 +483,7 @@ callString(Client cntxt, str s, int list
GDKfree(qry);
c->fdout = GDKstdout;
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
msg = runScenario(c,1);
@@ -482,6 +493,7 @@ callString(Client cntxt, str s, int list
GDKfree(b);
GDKfree(qry);
MCcloseClient(c);
+ setClientContext(c_old); // restore context
return msg;
}
// The command may have changed the environment of the calling client.
@@ -507,6 +519,7 @@ callString(Client cntxt, str s, int list
bstream_destroy(c->fdin);
c->fdin = 0;
MCcloseClient(c);
+ setClientContext(c_old); // restore context
GDKfree(qry);
GDKfree(b);
return msg;
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -523,8 +523,7 @@ str runMALsequence(Client cntxt, MalBlkP
/* save, in case this function is called recursively */
QryCtx *qry_ctx_save = MT_thread_get_qry_ctx();
MT_thread_set_qry_ctx(&qry_ctx);
- Client outer_cntxt = getClientContext();
- setClientContext(cntxt);
+ Client outer_cntxt = setClientContext(cntxt);
while (stkpc < mb->stop && stkpc != stoppc) {
// incomplete block being executed, requires at least signature
and end statement
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -42,7 +42,7 @@ str yieldFactory(MalBlkPtr mb, InstrPtr
str callFactory(Client cntxt, MalBlkPtr mb, ValPtr argv[],char flag)
__attribute__((__visibility__("hidden")));
-void setClientContext(Client cntxt)
+Client setClientContext(Client cntxt)
__attribute__((__visibility__("hidden")));
#endif
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -280,8 +280,8 @@ MSscheduleClient(str command, str challe
if (!GDKembedded()) {
/* access control: verify the credentials supplied by
the user,
- * no need to check for database stuff, because that is
done per
- * database itself (one gets a redirect) */
+ * no need to check for database stuff, because that is
done per
+ * database itself (one gets a redirect) */
err = AUTHcheckCredentials(&uid, NULL, user, passwd,
challenge, algo);
if (err != MAL_SUCCEED) {
mnstr_printf(fout, "!%s\n", err);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]