Changeset: 2a51cac20c38 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2a51cac20c38
Modified Files:
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/modules/mal/clients.c
        sql/backends/monet5/sql.mal
        sql/backends/monet5/sql_upgrades.c
        sql/scripts/22_clients.sql
Branch: default
Log Message:

Export the new session table to SQL


diffs (258 lines):

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
@@ -249,6 +249,8 @@ MCinitClientRecord(Client c, oid user, b
        c->memorylimit = 0;
        c->querytimeout = 0;
        c->sessiontimeout = 0;
+       c->workers = 0;
+       c->memoryclaim = 0;
        c->itrace = 0;
        c->errbuf = 0;
 
@@ -370,6 +372,8 @@ MCforkClient(Client father)
                son->memorylimit = father->memorylimit;
                son->querytimeout = father->querytimeout;
                son->sessiontimeout = father->sessiontimeout;
+               son->workers = father->workers;
+               son->memoryclaim = father->memoryclaim;
 
                if (son->prompt)
                        GDKfree(son->prompt);
@@ -439,6 +443,8 @@ MCfreeClient(Client c)
        c->memorylimit = 0;
        c->querytimeout = 0;
        c->sessiontimeout = 0;
+       c->workers = 0;
+       c->memoryclaim = 0;
        c->user = oid_nil;
        if( c->username){
                GDKfree(c->username);
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
@@ -61,6 +61,7 @@ typedef struct CLIENT {
        MALfcn  phase[SCENARIO_PROPERTIES], oldphase[SCENARIO_PROPERTIES];
        char    itrace;    /* trace execution using interactive mdb */
                                                /* if set to 'S' it will put 
the process to sleep */
+       bit             sqlprofiler;            /* control off-line sql 
performance monitoring */
        /*
         * Each session comes with resource limitations and predefined settings.
         */
@@ -69,13 +70,12 @@ typedef struct CLIENT {
        lng             memorylimit;            /* Memory claim highwater mark, 
0 = no limit */
        lng     querytimeout;           /* query abort after x usec, 0 = no 
limit*/
        lng         sessiontimeout;             /* session abort after x usec, 
0 = no limit */
-       bit             sqlprofiler;            /* control off-line sql 
performance monitoring */
 
        /*
         * For program debugging and performance trace we keep the actual 
resource claims.
         */
        int             workers;                /* Actual number of concurrent 
workers */
-       lng             memory;                 /* Actual memory claim 
highwater mark */
+       lng             memoryclaim;    /* Actual memory claim highwater mark */
 
        time_t      login;  
        time_t      lastcmd;    /* set when input is received */
diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c
--- a/monetdb5/modules/mal/clients.c
+++ b/monetdb5/modules/mal/clients.c
@@ -648,19 +648,23 @@ CLTshutdown(Client cntxt, MalBlkPtr mb, 
 str
 CLTsessions(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       BAT *id = NULL, *user = NULL, *login = NULL, *sessiontimeout = NULL, 
*querytimeout = NULL, *last= NULL, *active= NULL;
+       BAT *id = NULL, *user = NULL, *login = NULL, *sessiontimeout = NULL, 
*querytimeout = NULL, *lastcmd= NULL;
+       BAT *opt = NULL, *wlimit = NULL, *mlimit = NULL, *workers = NULL, 
*memoryclaim = NULL;
        bat *idId = getArgReference_bat(stk,pci,0);
        bat *userId = getArgReference_bat(stk,pci,1);
        bat *loginId = getArgReference_bat(stk,pci,2);
-       bat *sessiontimeoutId = getArgReference_bat(stk,pci,3);
-       bat *lastId = getArgReference_bat(stk,pci,4);
+       bat *optId = getArgReference_bat(stk,pci,3);
+       bat *sessiontimeoutId = getArgReference_bat(stk,pci,4);
        bat *querytimeoutId = getArgReference_bat(stk,pci,5);
-       bat *activeId = getArgReference_bat(stk,pci,6);
+       bat *wlimitId = getArgReference_bat(stk,pci,6);
+       bat *mlimitId = getArgReference_bat(stk,pci,7);
+       bat *lastcmdId = getArgReference_bat(stk,pci,8);
+       bat *workersId = getArgReference_bat(stk,pci,9);
+       bat *memoryclaimId = getArgReference_bat(stk,pci,10);
     Client c;
        timestamp ret;
        lng timeout;
        str msg = NULL;
-       int i, cnt;
 
        (void) cntxt;
        (void) mb;
@@ -668,18 +672,29 @@ CLTsessions(Client cntxt, MalBlkPtr mb, 
        id = COLnew(0, TYPE_int, 0, TRANSIENT);
        user = COLnew(0, TYPE_str, 0, TRANSIENT);
        login = COLnew(0, TYPE_timestamp, 0, TRANSIENT);
+       opt = COLnew(0, TYPE_str, 0, TRANSIENT);
        sessiontimeout = COLnew(0, TYPE_lng, 0, TRANSIENT);
-       last = COLnew(0, TYPE_timestamp, 0, TRANSIENT);
        querytimeout = COLnew(0, TYPE_lng, 0, TRANSIENT);
-       active = COLnew(0, TYPE_int, 0, TRANSIENT);
-       if (id == NULL || user == NULL || login == NULL || sessiontimeout == 
NULL || last == NULL || querytimeout == NULL || active == NULL){
+       wlimit = COLnew(0, TYPE_int, 0, TRANSIENT);
+       mlimit = COLnew(0, TYPE_lng, 0, TRANSIENT);
+       lastcmd = COLnew(0, TYPE_timestamp, 0, TRANSIENT);
+       workers = COLnew(0, TYPE_int, 0, TRANSIENT);
+       memoryclaim = COLnew(0, TYPE_lng, 0, TRANSIENT);
+
+       if (id == NULL || user == NULL || login == NULL || sessiontimeout == 
NULL || lastcmd == NULL || querytimeout == NULL ||
+          opt == NULL || wlimit == NULL || mlimit == NULL || workers == NULL 
|| memoryclaim == NULL){
                if ( id) BBPunfix(id->batCacheid);
                if ( user) BBPunfix(user->batCacheid);
                if ( login) BBPunfix(login->batCacheid);
                if ( sessiontimeout) BBPunfix(sessiontimeout->batCacheid);
                if ( querytimeout) BBPunfix(querytimeout->batCacheid);
-               if ( last) BBPunfix(last->batCacheid);
-               if ( active) BBPunfix(active->batCacheid);
+               if ( lastcmd) BBPunfix(lastcmd->batCacheid);
+
+               if ( opt) BBPunfix(opt->batCacheid);
+               if ( wlimit) BBPunfix(wlimit->batCacheid);
+               if ( mlimit) BBPunfix(mlimit->batCacheid);
+               if ( workers) BBPunfix(workers->batCacheid);
+               if ( memoryclaim) BBPunfix(memoryclaim->batCacheid);
                throw(SQL,"sql.sessions", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        }
 
@@ -702,27 +717,27 @@ CLTsessions(Client cntxt, MalBlkPtr mb, 
                    timeout = c->sessiontimeout / 1000000;
                    if (BUNappend(sessiontimeout, &timeout, false) != 
GDK_SUCCEED)
                            goto bailout;
+                   timeout = c->querytimeout / 1000000;
+                   if (BUNappend(querytimeout, &timeout, false) != GDK_SUCCEED)
+                               goto bailout;
                    ret = timestamp_fromtime(c->lastcmd);
                    if (is_timestamp_nil(ret)) {
                            msg = createException(SQL, "sql.sessions",
                                                  SQLSTATE(22003) "cannot 
convert time");
                            goto bailout;
                    }
-                   if (BUNappend(last, &ret, false) != GDK_SUCCEED)
+                   if (BUNappend(lastcmd, &ret, false) != GDK_SUCCEED)
+                           goto bailout;
+                   if (BUNappend(opt, c->optimizer, false) != GDK_SUCCEED)
                            goto bailout;
-                   timeout = c->querytimeout / 1000000;
-                   if (BUNappend(querytimeout, &timeout, false) != GDK_SUCCEED)
-                               goto bailout;
-                       MT_lock_set(&mal_delayLock);
-                       cnt = 0;
-                       for( i = 0; i < THREADS; i++)
-                               if ( workingset[i].cntxt == c){
-                                       cnt ++;
-                                       break;
-                               }
-                       MT_lock_unset(&mal_delayLock);
-                       if( BUNappend(active, &cnt, false) != GDK_SUCCEED)
-                           goto bailout;
+            if (BUNappend(wlimit, &c->workerlimit, false) != GDK_SUCCEED)
+                goto bailout;
+            if (BUNappend(workers, &c->workers, false) != GDK_SUCCEED)
+                goto bailout;
+            if (BUNappend(mlimit, &c->memorylimit, false) != GDK_SUCCEED)
+                goto bailout;
+            if (BUNappend(memoryclaim, &c->memoryclaim, false) != GDK_SUCCEED)
+                goto bailout;
            }
     }
     MT_lock_unset(&mal_contextLock);
@@ -731,8 +746,13 @@ CLTsessions(Client cntxt, MalBlkPtr mb, 
        BBPkeepref(*loginId = login->batCacheid);
        BBPkeepref(*sessiontimeoutId = sessiontimeout->batCacheid);
        BBPkeepref(*querytimeoutId = querytimeout->batCacheid);
-       BBPkeepref(*lastId = last->batCacheid);
-       BBPkeepref(*activeId = active->batCacheid);
+       BBPkeepref(*lastcmdId = lastcmd->batCacheid);
+
+       BBPkeepref(*optId = opt->batCacheid);
+       BBPkeepref(*wlimitId = wlimit->batCacheid);
+       BBPkeepref(*mlimitId = mlimit->batCacheid);
+       BBPkeepref(*workersId = workers->batCacheid);
+       BBPkeepref(*memoryclaimId = memoryclaim->batCacheid);
        return MAL_SUCCEED;
 
   bailout:
@@ -742,7 +762,12 @@ CLTsessions(Client cntxt, MalBlkPtr mb, 
        BBPunfix(login->batCacheid);
        BBPunfix(sessiontimeout->batCacheid);
        BBPunfix(querytimeout->batCacheid);
-       BBPunfix(last->batCacheid);
-       BBPunfix(active->batCacheid);
+       BBPunfix(lastcmd->batCacheid);
+
+       BBPunfix(opt->batCacheid);
+       BBPunfix(wlimit->batCacheid);
+       BBPunfix(mlimit->batCacheid);
+       BBPunfix(workers->batCacheid);
+       BBPunfix(memoryclaim->batCacheid);
        return msg;
 }
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -470,7 +470,10 @@ pattern sql_variables():bat[:str]
 address sql_variables
 comment "return the table with session variables";
 
-pattern sessions() (id:bat[:int], user:bat[:str], 
start:bat[:timestamp],stimeout:bat[:lng], lastcmd:bat[:timestamp], 
qtimeout:bat[:lng], idle:bat[:int])
+pattern sessions() (id:bat[:int], user:bat[:str], 
+start:bat[:timestamp], optmizer:bat[:str], stimeout:bat[:lng], 
qtimeout:bat[:lng],
+wlimit:bat[:int], mlimit:bat[:lng], 
+lstcmd:bat[:timestamp], workers:bat[:int], memoryclaim:bat[:lng])
 address sql_sessions_wrap
 comment "SQL export table of active sessions, their timeouts and idle status";
 
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -2301,7 +2301,18 @@ sql_update_default(Client c, mvc *sql, c
                        "drop view sys.sessions;\n"
                        "drop function sys.sessions;\n"
                        "create function sys.sessions()\n"
-                       " returns table (\"sessionid\" int, \"user\" string, 
\"login\" timestamp, \"sessiontimeout\" bigint, \"lastcommand\" timestamp, 
\"querytimeout\" bigint, \"threads\" int)\n"
+                       "returns table(\n"
+                               "\"sessionid\" int,\n"
+                               "\"user\" string,\n"
+                               "\"login\" timestamp,\n"
+                               "\"optimizer\" string,\n"
+                               "\"sessiontimeout\" bigint,\n"
+                               "\"querytimeout\" bigint,\n"
+                               "\"workerlimit\" int,\n"
+                               "\"memorylimit\" bigint,\n"
+                               "\"lastcommand\" timestamp,\n"
+                               "\"workers\" int,\n"
+                               "\"memoryclaim\" bigint)\n"
                        " external name sql.sessions;\n"
                        "create view sys.sessions as select * from 
sys.sessions();\n");
 
diff --git a/sql/scripts/22_clients.sql b/sql/scripts/22_clients.sql
--- a/sql/scripts/22_clients.sql
+++ b/sql/scripts/22_clients.sql
@@ -13,7 +13,19 @@ returns table ("uri" string, "username" 
 external name sql.rt_credentials;
 
 create function sys.sessions()
-returns table("sessionid" int, "user" string, "login" timestamp, 
"sessiontimeout" bigint, "lastcommand" timestamp, "querytimeout" bigint, 
"threads" int)
+returns table(
+       "sessionid" int, 
+       "user" string, 
+       "login" timestamp, 
+       "optimizer" string,
+       "sessiontimeout" bigint, 
+       "querytimeout" bigint, 
+       "workerlimit" int,
+       "memorylimit" bigint,
+       "lastcommand" timestamp, 
+       "workers" int,
+       "memoryclaim" bigint
+       )
 external name sql.sessions;
 create view sys.sessions as select * from sys.sessions();
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to