Changeset: 012c3e1016db for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=012c3e1016db Modified Files: monetdb5/mal/mal_client.c monetdb5/mal/mal_client.h monetdb5/mal/mal_interpreter.c monetdb5/modules/mal/clients.c monetdb5/modules/mal/clients.h sql/backends/monet5/sql.mx sql/scripts/22_clients.sql Branch: default Log Message:
Merge with default diffs (214 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 @@ -228,6 +228,7 @@ MCinitClientRecord(Client c, oid user, b c->father = NULL; c->login = c->lastcmd = time(0); + c->active = 0; c->session = GDKusec(); c->qtimeout = 0; c->stimeout = 0; @@ -367,6 +368,7 @@ freeClient(Client c) } c->father = 0; c->login = c->lastcmd = 0; + c->active = 0; c->qtimeout = 0; c->stimeout = 0; c->user = oid_nil; 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 @@ -94,6 +94,7 @@ typedef struct CLIENT { time_t login; time_t lastcmd; /* set when input is received */ + bit active; /* processing a query or not */ lng session; /* usec since start of server */ lng qtimeout; /* query abort after x usec*/ lng stimeout; /* session abort after x usec */ 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 @@ -344,6 +344,8 @@ str runMAL(Client cntxt, MalBlkPtr mb, M * allocate space for value stack the global stack should be large * enough */ + cntxt->lastcmd= time(0); + cntxt->active = TRUE; if (env != NULL) { stk = env; if (mb != stk->blk) @@ -381,6 +383,7 @@ str runMAL(Client cntxt, MalBlkPtr mb, M stk->cmd = env->cmd; ret = runMALsequence(cntxt, mb, 1, 0, stk, env, 0); + cntxt->active = FALSE; /* pass the new debug mode to the caller */ if (stk->cmd && env && stk->cmd != 'f') env->cmd = stk->cmd; @@ -441,6 +444,8 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS * variable. It is initially set equal to the number of cores, * which may be too coarse. */ + cntxt->lastcmd= time(0); + cntxt->active = TRUE; MT_sema_down(&mal_parallelism,"callMAL"); #ifdef DEBUG_CALLMAL mnstr_printf(cntxt->fdout, "callMAL\n"); @@ -480,6 +485,7 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS throw(MAL, "mal.interpreter", RUNTIME_UNKNOWN_INSTRUCTION); } MT_sema_up(&mal_parallelism,"callMAL"); + cntxt->active = FALSE; if (cntxt->qtimeout && GDKusec()- mb->starttime > cntxt->qtimeout) throw(MAL, "mal.interpreter", RUNTIME_QRY_TIMEOUT); return ret; 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 @@ -35,6 +35,7 @@ #include "mal_instruction.h" #include "mal_client.h" #include "mal_authorize.h" +#include "mtime.h" #ifdef HAVE_LIBREADLINE #include <readline/readline.h> @@ -549,3 +550,69 @@ str CLTshutdown(int *ret, bit *forced) { (void) forced; throw(MAL,"clients.shutdown", PROGRAM_NYI); } + +str +CLTsessions(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + BAT *user = NULL, *login = NULL, *stimeout = NULL, *qtimeout = NULL, *last= NULL, *active= NULL; + int *userId = (int*) getArgReference(stk,pci,0); + int *loginId = (int*) getArgReference(stk,pci,1); + int *stimeoutId = (int*) getArgReference(stk,pci,2); + int *lastId = (int*) getArgReference(stk,pci,3); + int *qtimeoutId = (int*) getArgReference(stk,pci,4); + int *activeId = (int*) getArgReference(stk,pci,5); + Client c; + char usrname[256]= {"monetdb"}; + timestamp ts, ret; + lng clk; + + (void) cntxt; + (void) mb; + + user = BATnew(TYPE_void, TYPE_str, 0); + BATseqbase(user,0); + login = BATnew(TYPE_void, TYPE_lng, 0); + BATseqbase(login,0); + stimeout = BATnew(TYPE_void, TYPE_lng, 0); + BATseqbase(stimeout,0); + last = BATnew(TYPE_void, TYPE_lng, 0); + BATseqbase(last,0); + qtimeout = BATnew(TYPE_void, TYPE_lng, 0); + BATseqbase(qtimeout,0); + active = BATnew(TYPE_void, TYPE_bit, 0); + BATseqbase(active,0); + if ( user == NULL || login == NULL || stimeout == NULL || qtimeout == NULL || active == NULL){ + if ( login) BBPreleaseref(login->batCacheid); + if ( stimeout) BBPreleaseref(stimeout->batCacheid); + if ( qtimeout) BBPreleaseref(qtimeout->batCacheid); + if ( last) BBPreleaseref(last->batCacheid); + if ( active) BBPreleaseref(active->batCacheid); + throw(SQL,"sql.sessions",MAL_MALLOC_FAIL); + } + + MT_lock_set(&mal_contextLock, "clients.sessions"); + + for (c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) + if (c->mode == CLAIMED) { + BUNappend(user, &usrname, FALSE); + (void) MTIMEunix_epoch(&ts); + clk = c->login * 1000; + (void) MTIMEtimestamp_add(&ret,&ts, &clk); + BUNappend(login, &ret, FALSE); + BUNappend(stimeout, &c->stimeout, FALSE); + (void) MTIMEunix_epoch(&ts); + clk = c->lastcmd * 1000; + (void) MTIMEtimestamp_add(&ret,&ts, &clk); + BUNappend(last, &ret, FALSE); + BUNappend(qtimeout, &c->qtimeout, FALSE); + BUNappend(active, &c->active, FALSE); + } + MT_lock_unset(&mal_contextLock, "clients.sessions"); + BBPkeepref(*userId = user->batCacheid); + BBPkeepref(*loginId = login->batCacheid); + BBPkeepref(*stimeoutId = stimeout->batCacheid); + BBPkeepref(*qtimeoutId = qtimeout->batCacheid); + BBPkeepref(*lastId = last->batCacheid); + BBPkeepref(*activeId = active->batCacheid); + return MAL_SUCCEED; +} diff --git a/monetdb5/modules/mal/clients.h b/monetdb5/modules/mal/clients.h --- a/monetdb5/modules/mal/clients.h +++ b/monetdb5/modules/mal/clients.h @@ -71,4 +71,5 @@ clients_export str CLTchangePassword(Cli clients_export str CLTsetPassword(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); clients_export str CLTcheckPermission(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); clients_export str CLTgetUsers(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +clients_export str CLTsessions(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); #endif /* _CLIENTS_H */ diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx --- a/sql/backends/monet5/sql.mx +++ b/sql/backends/monet5/sql.mx @@ -471,6 +471,10 @@ pattern sql_variables():bat[:oid,:str] address sql_variables comment "return the table with session variables"; +pattern sessions() ( user:bat[:oid,:str], start:bat[:oid,:timestamp],stimeout:bat[:oid,:lng], lastcmd:bat[:oid,:timestamp], qtimeout:bat[:oid,:lng], idle:bat[:oid,:bit]) +address sql_sessions_wrap +comment "SQL export table of active sessions, their timeouts and idle status"; + pattern db_users() :bat[:oid,:str] address db_users_wrap comment "return table of users with sql scenario"; @@ -1431,6 +1435,7 @@ sql5_export str second_interval_str( lng sql5_export str dump_cache(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str dump_opt_stats(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str dump_trace(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +sql5_export str sql_sessions_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str sql_querylog_catalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str sql_querylog_calls(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); @@ -1629,6 +1634,7 @@ sql5_export void freeVariables(Client c, #include <cluster.h> #include <opt_dictionary.h> #include <opt_pipes.h> +#include "clients.h" #ifdef HAVE_RAPTOR # include <rdf.h> #endif @@ -6686,6 +6692,12 @@ dump_trace(Client cntxt, MalBlkPtr mb, M } str +sql_sessions_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + return CLTsessions(cntxt,mb,stk,pci); +} + +str sql_querylog_catalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int i; 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 @@ -18,6 +18,10 @@ create function sys.password_hash (usern returns string external name sql.password; +create function sys.sessions() +returns table("user" string, "login" timestamp, "sessiontimeout" bigint, "lastcommand" timestamp, "querytimeout" bigint, "active" bool) +external name sql.sessions; + -- control the query and session time out create procedure sys.settimeout("query" bigint) external name sql.settimeout; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list