Changeset: c58a7621a96a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c58a7621a96a
Modified Files:
monetdb5/mal/mal_client.c
monetdb5/mal/mal_runtime.c
monetdb5/optimizer/opt_mitosis.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_scenario.c
Branch: Sep2022
Log Message:
Use mal_contextLock to protect cntxt->idle.
diffs (159 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
@@ -550,9 +550,11 @@ MCactiveClients(void)
int active = 0;
Client cntxt = mal_clients;
+ MT_lock_set(&mal_contextLock);
for(cntxt = mal_clients; cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++){
active += (cntxt->idle == 0 && cntxt->mode == RUNCLIENT);
}
+ MT_lock_unset(&mal_contextLock);
return active;
}
@@ -567,14 +569,19 @@ MCmemoryClaim(void)
Client cntxt = mal_clients;
- for(cntxt = mal_clients; cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++)
- if( cntxt->idle == 0 && cntxt->mode == RUNCLIENT){
- if(cntxt->memorylimit){
- claim += cntxt->memorylimit;
- active ++;
- } else
- return GDK_mem_maxsize;
+ MT_lock_set(&mal_contextLock);
+ for(cntxt = mal_clients; cntxt<mal_clients+MAL_MAXCLIENTS; cntxt++) {
+ if( cntxt->idle == 0 && cntxt->mode == RUNCLIENT){
+ if(cntxt->memorylimit){
+ claim += cntxt->memorylimit;
+ active ++;
+ } else {
+ MT_lock_unset(&mal_contextLock);
+ return GDK_mem_maxsize;
+ }
+ }
}
+ MT_lock_unset(&mal_contextLock);
if(active == 0 || claim * LL_CONSTANT(1048576) >= GDK_mem_maxsize)
return GDK_mem_maxsize;
return claim * LL_CONSTANT(1048576);
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -228,7 +228,6 @@ runtimeProfileInit(Client cntxt, MalBlkP
}
// add new invocation
- cntxt->idle = 0;
for (i = 0; i < qsize; i++) {
size_t j = qlast;
if (++qlast >= qsize)
@@ -259,6 +258,9 @@ runtimeProfileInit(Client cntxt, MalBlkP
}
}
MT_lock_unset(&mal_delayLock);
+ MT_lock_set(&mal_contextLock);
+ cntxt->idle = 0;
+ MT_lock_unset(&mal_contextLock);
}
/*
@@ -290,7 +292,10 @@ runtimeProfileFinish(Client cntxt, MalBl
QRYqueue[i].ticks = GDKusec() - QRYqueue[i].ticks;
updateUserStats(cntxt, mb, QRYqueue[i].ticks,
QRYqueue[i].start, QRYqueue[i].finished, QRYqueue[i].query);
// assume that the user is now idle
+ MT_lock_unset(&mal_delayLock);
+ MT_lock_set(&mal_contextLock);
cntxt->idle = time(0);
+ MT_lock_unset(&mal_contextLock);
found = true;
break;
}
@@ -313,9 +318,9 @@ runtimeProfileFinish(Client cntxt, MalBl
}
}
}
+ MT_lock_unset(&mal_delayLock);
}
- MT_lock_unset(&mal_delayLock);
}
/* Used by mal_reset to do the grand final clean up of this area before
MonetDB exits */
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -152,7 +152,9 @@ OPTmitosisImplementation(Client cntxt, M
* Take into account the number of client connections,
* because all user together are responsible for resource contentions
*/
+ MT_lock_set(&mal_contextLock);
cntxt->idle = 0; // this one is definitely not idle
+ MT_lock_unset(&mal_contextLock);
/* This code was used to experiment with block sizes, mis-using the
memorylimit variable
if (cntxt->memorylimit){
diff --git a/sql/backends/monet5/sql_execute.c
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -243,22 +243,28 @@ SQLrun(Client c, mvc *m)
if( m->emod & mod_trace){
if((msg = SQLsetTrace(c,mb)) == MAL_SUCCEED) {
setVariableScope(mb);
+ MT_lock_set(&mal_contextLock);
c->idle = 0;
c->lastcmd = time(0);
+ MT_lock_unset(&mal_contextLock);
msg = runMAL(c, mb, 0, 0);
stopTrace(c);
}
} else {
setVariableScope(mb);
+ MT_lock_set(&mal_contextLock);
c->idle = 0;
c->lastcmd = time(0);
+ MT_lock_unset(&mal_contextLock);
msg = runMAL(c, mb, 0, 0);
}
resetMalBlk(mb);
}
/* after the query has been finished we enter the idle state */
+ MT_lock_set(&mal_contextLock);
c->idle = time(0);
c->lastcmd = 0;
+ MT_lock_unset(&mal_contextLock);
MT_thread_setworking(NULL);
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
@@ -863,8 +863,11 @@ SQLreader(Client c)
break;
commit_done = true;
}
- if (m->session->tr && m->session->tr->active)
+ if (m->session->tr && m->session->tr->active) {
+ MT_lock_set(&mal_contextLock);
c->idle = 0;
+ MT_lock_unset(&mal_contextLock);
+ }
if (go && in->pos >= in->len) {
ssize_t rd;
@@ -887,10 +890,12 @@ SQLreader(Client c)
if (msg)
break;
commit_done = true;
+ MT_lock_set(&mal_contextLock);
if (c->idle == 0 && (m->session->tr ==
NULL || !m->session->tr->active)) {
/* now the session is idle */
c->idle = time(0);
}
+ MT_lock_unset(&mal_contextLock);
}
if (go && ((!blocked && mnstr_write(c->fdout,
c->prompt, c->promptlength, 1) != 1) || mnstr_flush(c->fdout,
MNSTR_FLUSH_DATA))) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]