Changeset: fab8ca44919f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fab8ca44919f
Modified Files:
        monetdb5/mal/mal_authorize.c
        sql/backends/monet5/sql_user.c
Branch: userprofile
Log Message:

Reuse client context and only start transaction when needed.


diffs (81 lines):

diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -25,6 +25,7 @@
 #include "mcrypt.h"
 #include "msabaoth.h"
 #include "mal_scenario.h"
+#include "mal_interpreter.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -1226,21 +1227,9 @@ AUTHaddRemoteTableCredentials(const char
 
        if (pass == NULL) {
                // init client to have SQL callback hooks
-               Client c = NULL;
-               if ((c = MCinitClient(MAL_ADMIN, NULL, NULL)) == NULL)
-                       throw(MAL, "addRemoteTableCredentials", "!maximum 
concurrent client limit reached (%d), please try again later\n", 
MAL_MAXCLIENTS);
-               Scenario scenario = findScenario("sql");
-               if ((output = scenario->initClientCmd(c)) != MAL_SUCCEED) {
-                       return output;
-               }
+               Client c = getClientContext();
                if((output = AUTHgetPasswordHash(&pwhash, c, local_user)) != 
MAL_SUCCEED)
                        return output;
-
-               if((output = scenario->exitClientCmd(c)) != MAL_SUCCEED) {
-                       GDKfree(pwhash);
-                       return output;
-               }
-               MCfreeClient(c);
        }
        else {
                free_pw = true;
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
@@ -101,9 +101,11 @@ getUserNameCallback(Client c)
        backend *be = (backend *) c->sqlcontext;
        if (be) {
                mvc *m = be->mvc;
-               if (mvc_trans(m) == 0) {
+               int active = m->session->tr->active;
+               if (active || mvc_trans(m) == 0) {
                        res = getUserName(m, c->user);
-                       sql_trans_end(m->session, SQL_OK);
+                       if (!active)
+                               sql_trans_end(m->session, SQL_OK);
                }
        }
        return res;
@@ -117,11 +119,13 @@ getUserPasswordCallback(Client c, const 
        backend *be = (backend *) c->sqlcontext;
        if (be) {
                mvc *m = be->mvc;
+               int active = m->session->tr->active;
                // this starts new transaction
-               if (mvc_trans(m) == 0) {
+               if (active || mvc_trans(m) == 0) {
                        oid rid = getUserOIDByName(m, user);
                        res = getUserPassword(m, rid);
-                       sql_trans_end(m->session, SQL_OK);
+                       if (!active)
+                               sql_trans_end(m->session, SQL_OK);
                }
        }
        return res;
@@ -204,9 +208,11 @@ getUserOIDCallback(Client c, const char 
        backend *be = (backend *) c->sqlcontext;
        if (be) {
                mvc *m = be->mvc;
-               if (mvc_trans(m) == 0) {
+               int active = m->session->tr->active;
+               if (active || mvc_trans(m) == 0) {
                        res = getUserOIDByName(m, user);
-                       sql_trans_end(m->session, SQL_OK);
+                       if (!active)
+                               sql_trans_end(m->session, SQL_OK);
                        return res;
                }
        }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to