Changeset: bb1386cf532e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bb1386cf532e
Modified Files:
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_resource.c
        monetdb5/modules/mal/clients.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/sql_user.c
        sql/backends/monet5/sql_user.h
Branch: default
Log Message:

Use db_user_info max_workers/max_memory as upper limit for the user.


diffs (157 lines):

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
@@ -68,8 +68,9 @@ typedef struct CLIENT {
         */
        char    optimizer[IDLENGTH];/* The optimizer pipe preferred for this 
session */
        int     workerlimit;            /* maximum number of workthreads 
processing a query */
+       int maxworkers;                         /* max_workers from 
db_user_info table */
        int             memorylimit;            /* maximum memory currently 
allowed in MB */
-       lng maxmem;                                     /* maximum memory from 
db_user_info table */
+       lng maxmem;                                     /* max_memory from 
db_user_info table */
        lng         sessiontimeout;             /* session abort after x usec, 
0 = no limit */
        QryCtx  qryctx;                         /* per query limitations */
 
diff --git a/monetdb5/mal/mal_resource.c b/monetdb5/mal/mal_resource.c
--- a/monetdb5/mal/mal_resource.c
+++ b/monetdb5/mal/mal_resource.c
@@ -123,7 +123,7 @@ MALadmission_claim(Client cntxt, MalBlkP
         * A way out is to attach the thread count to the MAL stacks, which 
just limits the level
         * of parallism for a single dataflow graph.
         */
-       if (cntxt->workerlimit && (int) ATOMIC_GET(&cntxt->workers) >= 
cntxt->workerlimit) {
+       if (cntxt->workerlimit > 0 && (int) ATOMIC_GET(&cntxt->workers) >= 
cntxt->workerlimit) {
                return -1;
        }
        if (argclaim == 0)
@@ -137,11 +137,11 @@ MALadmission_claim(Client cntxt, MalBlkP
        }
 
        /* the argument claim is based on the input for an instruction */
-       if ( memorypool > argclaim ) {
+       if ( memorypool > argclaim || ATOMIC_GET(&cntxt->workers) == 0) {
                /* If we are low on memory resources, limit the user if he 
exceeds his memory budget
                 * but make sure there is at least one worker thread active */
                if ( cntxt->memorylimit) {
-                       if (argclaim + stk->memory > (lng) cntxt->memorylimit * 
LL_CONSTANT(1048576)){
+                       if (argclaim + stk->memory > (lng) cntxt->memorylimit * 
LL_CONSTANT(1048576) && ATOMIC_GET(&cntxt->workers) > 0){
                                MT_lock_unset(&admissionLock);
                                return -1;
                        }
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
@@ -304,8 +304,17 @@ CLTsetworkerlimit(Client cntxt, MalBlkPt
        MT_lock_set(&mal_contextLock);
        if (mal_clients[idx].mode == FREECLIENT)
                msg = createException(MAL,"clients.setworkerlimit","Session not 
active anymore");
-       else
+       else {
+               if (limit == 0) {
+                       if (mal_clients[idx].maxworkers > 0)
+                               limit = mal_clients[idx].maxworkers;
+               } else if (cntxt->user != MAL_ADMIN &&
+                                  mal_clients[idx].maxworkers > 0 &&
+                                  mal_clients[idx].maxworkers < limit) {
+                       limit = mal_clients[idx].maxworkers;
+               }
                mal_clients[idx].workerlimit = limit;
+       }
        MT_lock_unset(&mal_contextLock);
        return msg;
 }
@@ -335,16 +344,22 @@ CLTsetmemorylimit(Client cntxt, MalBlkPt
        if( limit < 0)
                throw(MAL, "clients.setmemorylimit", "The memmory limit cannot 
be negative");
 
+       lng mlimit = (lng) limit << 20;
+
        MT_lock_set(&mal_contextLock);
        if (mal_clients[idx].mode == FREECLIENT)
                msg = createException(MAL,"clients.setmemorylimit","Session not 
active anymore");
-       else if (cntxt->user != MAL_ADMIN &&
-                        mal_clients[idx].maxmem > 0 &&
-                        mal_clients[idx].maxmem < (lng) limit << 20)
-               msg = createException(MAL, "clients.setmemorylimit","Cannot 
increase memory limit");
        else {
-               mal_clients[idx].memorylimit = limit;
-               mal_clients[idx].qryctx.maxmem = (ATOMIC_BASE_TYPE) limit << 20;
+               if (mlimit == 0) {
+                       if (mal_clients[idx].maxmem > 0)
+                               mlimit = mal_clients[idx].maxmem;
+               } else if (cntxt->user != MAL_ADMIN &&
+                                  mal_clients[idx].maxmem > 0 &&
+                                  mal_clients[idx].maxmem < mlimit) {
+                       mlimit = mal_clients[idx].maxmem;
+               }
+               mal_clients[idx].memorylimit = (int) (mlimit >> 20);
+               mal_clients[idx].qryctx.maxmem = (ATOMIC_BASE_TYPE) mlimit;
        }
        MT_lock_unset(&mal_contextLock);
        return msg;
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -270,11 +270,12 @@ SQLprepareClient(Client c, int login)
                        default:
                                break;
                }
-               if (monet5_user_get_max_memory(m, m->user_id, &c->maxmem) == 0) 
{
+               if (monet5_user_get_limits(m, m->user_id, &c->maxmem, 
&c->maxworkers) == 0) {
                        c->qryctx.maxmem = (ATOMIC_BASE_TYPE) (c->maxmem > 0 ? 
c->maxmem : 0);
                } else {
                        c->maxmem = 0;
                        c->qryctx.maxmem = 0;
+                       c->maxworkers = 0;
                }
                if (c->memorylimit > 0 && c->qryctx.maxmem > 
((ATOMIC_BASE_TYPE) c->memorylimit << 20))
                        c->qryctx.maxmem = (ATOMIC_BASE_TYPE) c->memorylimit << 
20;
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
@@ -970,7 +970,7 @@ monet5_user_set_def_schema(mvc *m, oid u
 }
 
 int
-monet5_user_get_max_memory(mvc *m, int user, lng *maxmem)
+monet5_user_get_limits(mvc *m, int user, lng *maxmem, int *maxwrk)
 {
        oid rid;
        sql_schema *sys = NULL;
@@ -979,6 +979,7 @@ monet5_user_get_max_memory(mvc *m, int u
        str username = NULL;
        sqlstore *store = m->session->tr->store;
        lng max_memory = 0;
+       int max_workers = 0;
 
        if (!m->session->tr->active) {
                switch (mvc_trans(m)) {
@@ -1002,12 +1003,15 @@ monet5_user_get_max_memory(mvc *m, int u
                rid = store->table_api.column_find_row(m->session->tr, 
find_sql_column(user_info, "name"), username, NULL);
                _DELETE(username);
 
-               if (!is_oid_nil(rid))
+               if (!is_oid_nil(rid)) {
                        max_memory = 
store->table_api.column_find_lng(m->session->tr, find_sql_column(user_info, 
"max_memory"), rid);
+                       max_workers = 
store->table_api.column_find_lng(m->session->tr, find_sql_column(user_info, 
"max_workers"), rid);
+               }
                mvc_rollback(m, 0, NULL, false);
        }
 
        *maxmem = max_memory > 0 ? max_memory : 0;
+       *maxwrk = max_workers > 0 ? max_workers : 0;
 
        return 0;
 }
diff --git a/sql/backends/monet5/sql_user.h b/sql/backends/monet5/sql_user.h
--- a/sql/backends/monet5/sql_user.h
+++ b/sql/backends/monet5/sql_user.h
@@ -15,7 +15,7 @@
 extern void monet5_user_init(backend_functions *be_funcs);
 extern int monet5_user_set_def_schema(mvc *m, oid user /* mal user id */);
 extern int monet5_user_get_def_schema(mvc *m, int user /* sql user id */, str 
*schema);
-extern int monet5_user_get_max_memory(mvc *m, int user /* sql user id */, lng 
*maxmem);
+extern int monet5_user_get_limits(mvc *m, int user /* sql user id */, lng 
*maxmem, int *maxwrk);
 
 extern str monet5_password_hash(mvc *m, const char *username);
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to