Changeset: d2cde196016d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d2cde196016d
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_scenario.c
        monetdb5/mal/mal_scenario.h
        monetdb5/mal/mal_session.c
        monetdb5/mal/mal_session.h
        monetdb5/modules/mal/mal_mapi.c
        sql/backends/monet5/sql_scenario.c
        tools/monetdbe/monetdbe.c
Branch: default
Log Message:

pushed authenication into mal_mapi
mal program creation moved into scenairo->initClient.
the scenario main loop no manages clients only.
clients should take care of the program/stack etc
creation and destruction


diffs (truncated from 854 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
@@ -793,7 +793,6 @@ str MSinitClientPrg(Client cntxt, const 
 void MSresetInstructions(MalBlkPtr mb, int start);
 void MSresetStack(Client cntxt, MalBlkPtr mb, MalStkPtr glb);
 void MSresetVariables(MalBlkPtr mb);
-void MSscheduleClient(str command, str peer, str challenge, bstream *fin, 
stream *fout, protocol_version protocol, size_t blocksize);
 str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces);
 str OIDXdropImplementation(Client cntxt, BAT *b);
 str QLOGcalls(BAT **r);
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -199,4 +199,9 @@ mal_export int MCpushClientInput(Client 
 mal_export int MCvalid(Client c);
 mal_export void MCsetClientInfo(Client c, const char *property, const char 
*value);
 
+#ifdef LIBMONETDB5
+extern int MCinitClientThread(Client c);
+extern bool MCshutdowninprogress(void);
+#endif
+
 #endif /* _MAL_CLIENT_H_ */
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
@@ -20,16 +20,10 @@
 /* _MAL_CLIENT_H_ is defined in the same file as Client */
 bool MCinit(void)
        __attribute__((__visibility__("hidden")));
-int MCinitClientThread(Client c)
-       __attribute__((__visibility__("hidden")));
 void MCpopClientInput(Client c)
        __attribute__((__visibility__("hidden")));
 int MCreadClient(Client c)
        __attribute__((__visibility__("hidden")));
-bool MCshutdowninprogress(void)
-       __attribute__((__visibility__("hidden")));
-str defaultScenario(Client c)  /* used in src/mal/mal_session.c */
-       __attribute__((__visibility__("hidden")));
 #endif
 
 str malAtomDefinition(const char *name,int tpe)
diff --git a/monetdb5/mal/mal_scenario.c b/monetdb5/mal/mal_scenario.c
--- a/monetdb5/mal/mal_scenario.c
+++ b/monetdb5/mal/mal_scenario.c
@@ -282,7 +282,7 @@ runScenarioBody(Client c)
        MT_thread_setworking("engine");
        while (c->mode > FINISHCLIENT && !GDKexiting()) {
                c->engine(c);
-               assert(c->curprg->def->errors == NULL);
+               assert(!c->curprg || c->curprg->def->errors == NULL);
        }
        if (!GDKexiting() && GDKerrbuf && GDKerrbuf[0])
                mnstr_printf(c->fdout, "!GDKerror: %s\n", GDKerrbuf);
diff --git a/monetdb5/mal/mal_scenario.h b/monetdb5/mal/mal_scenario.h
--- a/monetdb5/mal/mal_scenario.h
+++ b/monetdb5/mal/mal_scenario.h
@@ -48,6 +48,7 @@ extern void showScenarioByName(stream *f
 extern void showScenario(stream *f, Scenario s);
 extern void showAllScenarios(stream *f);
 extern void resetScenario(Client c);
+extern str defaultScenario(Client c);
 #endif
 
 #endif /* _MAL_SCENARIO_H */
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
@@ -138,249 +138,6 @@ MSinitClientPrg(Client cntxt, const char
 }
 
 /*
- * The default method to interact with the database server is to connect
- * using a port number. The first line received should contain
- * authorization information, such as user name.
- *
- * The scheduleClient receives a challenge response consisting of
- * endian:user:password:lang:database:
- */
-static void
-exit_streams(bstream *fin, stream *fout)
-{
-       if (fout && fout != GDKstdout) {
-               mnstr_flush(fout, MNSTR_FLUSH_DATA);
-               close_stream(fout);
-       }
-       if (fin)
-               bstream_destroy(fin);
-}
-
-static const char mal_enableflag[] = "mal_for_all";
-
-static bool
-is_exiting(void *data)
-{
-       (void) data;
-       return GDKexiting();
-}
-
-static str MSserveClient(Client cntxt);
-
-
-static inline void
-cleanUpScheduleClient(Client c, str *command, str *err)
-{
-       if (c) {
-               MCcloseClient(c);
-       }
-       if (command) {
-               GDKfree(*command);
-               *command = NULL;
-       }
-       if (err) {
-               freeException(*err);
-               *err = NULL;
-       }
-}
-
-
-void
-MSscheduleClient(str command, str peer, str challenge, bstream *fin, stream 
*fout,
-                                protocol_version protocol, size_t blocksize)
-{
-       char *user = command, *algo = NULL, *passwd = NULL, *lang = NULL,
-               *handshake_opts = NULL;
-       char *database = NULL, *s;
-       const char *dbname;
-       str msg = MAL_SUCCEED;
-       bool filetrans = false;
-       Client c;
-
-       MT_thread_set_qry_ctx(NULL);
-
-       /* decode BIG/LIT:user:{cypher}passwordchal:lang:database: line */
-
-       /* byte order */
-       s = strchr(user, ':');
-       if (s) {
-               *s = 0;
-               mnstr_set_bigendian(fin->s, strcmp(user, "BIG") == 0);
-               user = s + 1;
-       } else {
-               mnstr_printf(fout, "!incomplete challenge '%s'\n", user);
-               exit_streams(fin, fout);
-               GDKfree(command);
-               return;
-       }
-
-       /* passwd */
-       s = strchr(user, ':');
-       if (s) {
-               *s = 0;
-               passwd = s + 1;
-               /* decode algorithm, i.e. {plain}mypasswordchallenge */
-               if (*passwd != '{') {
-                       mnstr_printf(fout, "!invalid password entry\n");
-                       exit_streams(fin, fout);
-                       GDKfree(command);
-                       return;
-               }
-               algo = passwd + 1;
-               s = strchr(algo, '}');
-               if (!s) {
-                       mnstr_printf(fout, "!invalid password entry\n");
-                       exit_streams(fin, fout);
-                       GDKfree(command);
-                       return;
-               }
-               *s = 0;
-               passwd = s + 1;
-       } else {
-               mnstr_printf(fout, "!incomplete challenge '%s'\n", user);
-               exit_streams(fin, fout);
-               GDKfree(command);
-               return;
-       }
-
-       /* lang */
-       s = strchr(passwd, ':');
-       if (s) {
-               *s = 0;
-               lang = s + 1;
-       } else {
-               mnstr_printf(fout, "!incomplete challenge, missing language\n");
-               exit_streams(fin, fout);
-               GDKfree(command);
-               return;
-       }
-
-       /* database */
-       s = strchr(lang, ':');
-       if (s) {
-               *s = 0;
-               database = s + 1;
-               /* we can have stuff following, make it void */
-               s = strchr(database, ':');
-               if (s)
-                       *s++ = 0;
-       }
-
-       if (s && strncmp(s, "FILETRANS:", 10) == 0) {
-               s += 10;
-               filetrans = true;
-       } else if (s && s[0] == ':') {
-               s += 1;
-               filetrans = false;
-       }
-
-       if (s && strchr(s, ':') != NULL) {
-               handshake_opts = s;
-               s = strchr(s, ':');
-               *s++ = '\0';
-       }
-       dbname = GDKgetenv("gdk_dbname");
-       if (database != NULL && database[0] != '\0' &&
-               strcmp(database, dbname) != 0) {
-               mnstr_printf(fout, "!request for database '%s', "
-                                        "but this is database '%s', "
-                                        "did you mean to connect to monetdbd 
instead?\n",
-                                        database, dbname);
-               /* flush the error to the client, and abort further execution */
-               exit_streams(fin, fout);
-               GDKfree(command);
-               return;
-       } else {
-               c = MCinitClient(0, fin, fout);
-               if (c == NULL) {
-                       if (MCshutdowninprogress())
-                               mnstr_printf(fout,
-                                                        "!system shutdown in 
progress, please try again later\n");
-                       else
-                               mnstr_printf(fout, "!maximum concurrent client 
limit reached "
-                                                        "(%d), please try 
again later\n", MAL_MAXCLIENTS);
-                       exit_streams(fin, fout);
-                       GDKfree(command);
-                       return;
-               }
-               c->filetrans = filetrans;
-               c->handshake_options = handshake_opts ? strdup(handshake_opts) 
: NULL;
-               /* move this back !! */
-               if (c->usermodule == 0) {
-                       c->curmodule = c->usermodule = userModule();
-                       if (c->curmodule == NULL) {
-                               mnstr_printf(fout, "!could not allocate 
space\n");
-                               cleanUpScheduleClient(c, &command, &msg);
-                               return;
-                       }
-               }
-
-               if ((msg = setScenario(c, lang)) != NULL) {
-                       mnstr_printf(c->fdout, "!%s\n", msg);
-                       mnstr_flush(c->fdout, MNSTR_FLUSH_DATA);
-                       cleanUpScheduleClient(c, &command, &msg);
-                       return;
-               }
-               if (strncasecmp("sql", lang, strlen(lang)) != 0
-                       && strncasecmp("msql", lang, strlen(lang)) != 0
-                       && strcmp(user, "monetdb") != 0) {
-                       mnstr_printf(fout,
-                                                "!only the 'monetdb' user can 
use non-sql languages. "
-                                                "run mserver5 with --set 
%s=yes to change this.\n",
-                                                mal_enableflag);
-                       cleanUpScheduleClient(c, &command, &msg);
-                       return;
-               }
-       }
-
-       if ((msg = MSinitClientPrg(c, userRef, mainRef)) != MAL_SUCCEED) {
-               mnstr_printf(fout, "!could not allocate space\n");
-               cleanUpScheduleClient(c, &command, &msg);
-               return;
-       }
-
-       // at this point username should have being verified
-       c->username = GDKstrdup(user);
-       if (peer)
-               c->peer = GDKstrdup(peer);
-
-       /* NOTE ABOUT STARTING NEW THREADS
-        * At this point we have conducted experiments (Jun 2012) with
-        * reusing threads.  The implementation used was a lockless array of
-        * semaphores to wake up threads to do work.  Experimentation on
-        * Linux, Solaris and Darwin showed no significant improvements, in
-        * most cases no improvements at all.  Hence the following
-        * conclusion: thread reuse doesn't save up on the costs of just
-        * forking new threads.  Since the latter means no difficulties of
-        * properly maintaining a pool of threads and picking the workers
-        * out of them, it is favourable just to start new threads on
-        * demand. */
-
-       /* fork a new thread to handle this client */
-
-       c->protocol = protocol;
-       c->blocksize = blocksize;
-
-       mnstr_settimeout(c->fdin->s, 50, is_exiting, NULL);
-       if (c->initClient) {
-               if ((msg = c->initClient(c, passwd, challenge, algo)) != 
MAL_SUCCEED) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to