Changeset: 957365bf81e3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/957365bf81e3
Modified Files:
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_private.h
        sql/backends/monet5/sql_scenario.c
        tools/merovingian/daemon/merovingian.h
Branch: Aug2024
Log Message:

Merge with Dec2023 branch.


diffs (truncated from 318 to 300 lines):

diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -721,9 +721,15 @@ msab_getSingleStatus(const char *pathbuf
        };
 
        /* store the database name */
-       snprintf(buf, sizeof(buf), "%s/%s", pathbuf, dbname);
+       int dbnamestart;
+#ifdef _MSC_VER
+       dbnamestart = snprintf(buf, sizeof(buf), "%s/", pathbuf);
+       snprintf(buf + dbnamestart, sizeof(buf) - dbnamestart, "%s", dbname);
+#else
+       snprintf(buf, sizeof(buf), "%s/%n%s", pathbuf, &dbnamestart, dbname);
+#endif
        sdb->path = strdup(buf);
-       sdb->dbname = sdb->path + strlen(sdb->path) - strlen(dbname);
+       sdb->dbname = sdb->path + dbnamestart;
 
 
        /* check the state of the server by looking at its gdk lock:
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -53,12 +53,6 @@ mal_version(void)
        return MONETDB5_VERSION;
 }
 
-static void
-MALprintinfo(void)
-{
-       MCprintinfo();
-}
-
 /*
  * Initialization of the MAL context
  */
@@ -100,8 +94,6 @@ mal_init(char *modules[], bool embedded,
                return -1;
        initNamespace();
 
-       GDKprintinforegister(MALprintinfo);
-
        err = malBootstrap(modules, embedded, initpasswd);
        if (err != MAL_SUCCEED) {
                mal_client_reset();
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
@@ -616,40 +616,6 @@ MCvalid(Client tc)
 }
 
 void
-MCprintinfo(void)
-{
-       int nrun = 0, nfinish = 0, nblock = 0;
-
-       MT_lock_set(&mal_contextLock);
-       for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
-               switch (c->mode) {
-               case RUNCLIENT:
-                       /* running */
-                       nrun++;
-                       if (c->idle)
-                               printf("client %d, user %s, using %"PRIu64" 
bytes of transient space, idle since %s", c->idx, c->username, (uint64_t) 
ATOMIC_GET(&c->qryctx.datasize), ctime(&c->idle));
-                       else
-                               printf("client %d, user %s, using %"PRIu64" 
bytes of transient space\n", c->idx, c->username, (uint64_t) 
ATOMIC_GET(&c->qryctx.datasize));
-                       break;
-               case FINISHCLIENT:
-                       /* finishing */
-                       nfinish++;
-                       break;
-               case BLOCKCLIENT:
-                       /* blocked */
-                       nblock++;
-                       break;
-               case FREECLIENT:
-                       break;
-               }
-       }
-       MT_lock_unset(&mal_contextLock);
-       printf("%d active clients, %d finishing clients, %d blocked clients\n",
-                  nrun, nfinish, nblock);
-}
-
-
-void
 MCsetClientInfo(Client c, const char *property, const char *value)
 {
        if (strlen(property) < 7)
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -81,9 +81,6 @@ void mal_runtime_reset(void)
 char *dupError(const char *err)
        __attribute__((__visibility__("hidden"), __returns_nonnull__));
 
-void MCprintinfo(void)
-       __attribute__((__visibility__("hidden")));
-
 void
 setPoly(mel_func *f, malType tpe)
        __attribute__((__visibility__("hidden")));
diff --git a/sql/backends/monet5/UDF/pyapi3/pytypes3.c 
b/sql/backends/monet5/UDF/pyapi3/pytypes3.c
--- a/sql/backends/monet5/UDF/pyapi3/pytypes3.c
+++ b/sql/backends/monet5/UDF/pyapi3/pytypes3.c
@@ -243,8 +243,10 @@ bool PyType_IsNumpyMaskedArray(PyObject 
 {
        PyObject *type = PyObject_Type(object);
        PyObject *str = PyObject_Str(type);
-       bool ret = strcmp(PyUnicode_AsUTF8(str),
-                                         "<class 
'numpy.ma.core.MaskedArray'>") == 0;
+       bool ret = strcmp(PyUnicode_AsUTF8(str), /* numpy < 2.0 */
+                                         "<class 
'numpy.ma.core.MaskedArray'>") == 0 ||
+               strcmp(PyUnicode_AsUTF8(str), /* numpy >= 2.0 */
+                          "<class 'numpy.ma.MaskedArray'>") == 0;
        Py_DECREF(str);
        Py_DECREF(type);
        return ret;
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
@@ -87,10 +87,60 @@ static MT_Lock sql_contextLock = MT_LOCK
 static str SQLinit(Client c, const char *initpasswd);
 static str master_password = NULL;
 
+#include "mal.h"
+#include "mal_client.h"
+
+static void
+CLIENTprintinfo(void)
+{
+       int nrun = 0, nfinish = 0, nblock = 0;
+       char mmbuf[64];
+       char tmbuf[64];
+       char trbuf[64];
+       struct tm tm;
+
+       MT_lock_set(&mal_contextLock);
+       for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
+               switch (c->mode) {
+               case RUNCLIENT:
+                       /* running */
+                       nrun++;
+                       if (c->qryctx.maxmem)
+                               snprintf(mmbuf, sizeof(mmbuf), " (max 
%"PRIu64")", (uint64_t) c->qryctx.maxmem);
+                       else
+                               mmbuf[0] = 0;
+                       if (c->idle) {
+                               localtime_r(&c->idle, &tm);
+                               strftime(tmbuf, sizeof(tmbuf), ", idle since %F 
%H:%M:%S%z", &tm);
+                       } else
+                               tmbuf[0] = 0;
+                       if (c->sqlcontext && ((backend *) c->sqlcontext)->mvc 
&& ((backend *) c->sqlcontext)->mvc->session && ((backend *) 
c->sqlcontext)->mvc->session->tr && ((backend *) 
c->sqlcontext)->mvc->session->tr->active)
+                               snprintf(trbuf, sizeof(trbuf), ", active 
transaction, ts: "ULLFMT, ((backend *) c->sqlcontext)->mvc->session->tr->ts);
+                       else
+                               trbuf[0] = 0;
+                       printf("client %d, user %s, thread %s, using %"PRIu64" 
bytes of transient space%s%s%s\n", c->idx, c->username, c->mythread ? 
c->mythread : "?", (uint64_t) ATOMIC_GET(&c->qryctx.datasize), mmbuf, tmbuf, 
trbuf);
+                       break;
+               case FINISHCLIENT:
+                       /* finishing */
+                       nfinish++;
+                       break;
+               case BLOCKCLIENT:
+                       /* blocked */
+                       nblock++;
+                       break;
+               case FREECLIENT:
+                       break;
+               }
+       }
+       MT_lock_unset(&mal_contextLock);
+       printf("%d active clients, %d finishing clients, %d blocked clients; 
max: %d\n",
+                  nrun, nfinish, nblock, MAL_MAXCLIENTS);
+}
+
 static void
 SQLprintinfo(void)
 {
-       /* we need to start printing SQL info here... */
+       CLIENTprintinfo();
        store_printinfo(SQLstore);
 }
 
diff --git a/tools/merovingian/daemon/discoveryrunner.c 
b/tools/merovingian/daemon/discoveryrunner.c
--- a/tools/merovingian/daemon/discoveryrunner.c
+++ b/tools/merovingian/daemon/discoveryrunner.c
@@ -189,21 +189,21 @@ getRemoteDB(const char *database)
                        } else {
                                walk = stats = malloc(sizeof(sabdb));
                        }
-                       walk->dbname = strdup(rdb->dbname);
+                       *walk = (sabdb) {
+                               .dbname = strdup(rdb->dbname),
+                               .locked = false,
+                               .state = SABdbRunning,
+                               .pid = -1,
+                               .scens = malloc(sizeof(sablist)),
+                               .conns = malloc(sizeof(sablist)),
+                       };
+                       *walk->scens = (sablist) {
+                               .val = strdup("sql"),
+                       };
+                       *walk->conns = (sablist) {
+                               .val = strdup(rdb->conn),
+                       };
                        walk->path = walk->dbname; /* only freed by sabaoth */
-                       walk->locked = false;
-                       walk->state = SABdbRunning;
-                       walk->pid = 0;
-                       walk->scens = malloc(sizeof(sablist));
-                       walk->scens->val = strdup("sql");
-                       walk->scens->next = NULL;
-                       walk->conns = malloc(sizeof(sablist));
-                       walk->conns->val = strdup(rdb->conn);
-                       walk->conns->next = NULL;
-                       walk->uri = NULL;
-                       walk->secret = NULL;
-                       walk->next = NULL;
-                       walk->uplog = NULL;
 
                        /* cut out first returned entry, put it down the list
                         * later, as to implement a round-robin DNS-like
diff --git a/tools/merovingian/daemon/forkmserver.c 
b/tools/merovingian/daemon/forkmserver.c
--- a/tools/merovingian/daemon/forkmserver.c
+++ b/tools/merovingian/daemon/forkmserver.c
@@ -236,6 +236,10 @@ forkMserver(const char *database, sabdb*
                        *dp = (struct _dpair) {
                                .dbname = strdup(database),
                                .fork_lock = PTHREAD_MUTEX_INITIALIZER,
+                               .input[0].fd = -1,
+                               .input[1].fd = -1,
+                               .type = NODB,
+                               .pid = -1,
                        };
                        break;
                }
@@ -723,7 +727,6 @@ forkMserver(const char *database, sabdb*
                (void) fcntl(pfdo[0], F_SETFD, FD_CLOEXEC);
                (void) fcntl(pfde[0], F_SETFD, FD_CLOEXEC);
 #endif
-               pthread_mutex_unlock(&_mero_topdp_lock);
 
                while (argv[freec] != NULL) {
                        free(argv[freec++]);
@@ -735,6 +738,8 @@ forkMserver(const char *database, sabdb*
                 * and if it hangs, we're just doomed, with the drawback that we
                 * completely kill the functionality of monetdbd too */
                do {
+                       pthread_mutex_unlock(&_mero_topdp_lock);
+
                        /* give the database a break */
                        sleep_ms(500);
 
@@ -756,12 +761,7 @@ forkMserver(const char *database, sabdb*
                         * waited for), the pid will have been set to -1, so 
check
                         * that. */
                        pthread_mutex_lock(&_mero_topdp_lock);
-                       if (dp->pid == -1) {
-                               pthread_mutex_unlock(&_mero_topdp_lock);
-                               break;
-                       }
-                       pthread_mutex_unlock(&_mero_topdp_lock);
-               } while ((*stats)->state != SABdbRunning);
+               } while (dp->pid != -1 && (*stats)->state != SABdbRunning);
 
                /* check if the SQL scenario was loaded */
                if (dp->pid != -1 && (*stats)->state == SABdbRunning &&
@@ -777,14 +777,18 @@ forkMserver(const char *database, sabdb*
                        if (scen == NULL) {
                                /* we don't know what it's doing, but we don't 
like it
                                 * any case, so kill it */
-                               (void) terminateProcess(dp->dbname, dp->pid, 
MERODB);
+                               pid_t pid = dp->pid;
+                               pthread_mutex_unlock(&_mero_topdp_lock);
+                               (void) terminateProcess(dp->dbname, pid, 
MERODB);
                                msab_freeStatus(stats);
                                pthread_mutex_unlock(&dp->fork_lock);
                                return(newErr("database '%s' did not initialise 
the sql "
                                                          "scenario", 
database));
                        }
                } else if (dp->pid != -1) {
-                       (void) terminateProcess(dp->dbname, dp->pid, MERODB);
+                       pid_t pid = dp->pid;
+                       pthread_mutex_unlock(&_mero_topdp_lock);
+                       (void) terminateProcess(dp->dbname, pid, MERODB);
                        msab_freeStatus(stats);
                        pthread_mutex_unlock(&dp->fork_lock);
                        return(newErr(
@@ -796,6 +800,7 @@ forkMserver(const char *database, sabdb*
                if (dp->pid == -1) {
                        state = (*stats)->state;
 
+                       pthread_mutex_unlock(&_mero_topdp_lock);
                        pthread_mutex_unlock(&dp->fork_lock);
 
                        /* starting failed */
@@ -837,6 +842,7 @@ forkMserver(const char *database, sabdb*
                        }
                }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to