Changeset: 19bd77490b9a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=19bd77490b9a
Modified Files:
        common/utils/msabaoth.c
        common/utils/msabaoth.h
        gdk/gdk_utils.c
        monetdb5/mal/mal_session.c
        sql/backends/monet5/rel_bin.c
        sql/server/rel_exp.c
        sql/server/rel_optimizer.c
        tools/merovingian/client/monetdb.c
        tools/merovingian/daemon/client.c
        tools/merovingian/daemon/controlrunner.c
        tools/merovingian/daemon/discoveryrunner.c
        tools/merovingian/daemon/forkmserver.c
        tools/merovingian/daemon/forkmserver.h
        tools/merovingian/utils/database.c
Branch: default
Log Message:

Merge with Nov2019 branch.


diffs (truncated from 599 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
@@ -671,11 +671,7 @@ msab_getSingleStatus(const char *pathbuf
                }
        }
        snprintf(buf, sizeof(buf), "%s/%s/%s", pathbuf, dbname, 
MAINTENANCEFILE);
-       if (stat(buf, &statbuf) == -1) {
-               sdb->locked = 0;
-       } else {
-               sdb->locked = 1;
-       }
+       sdb->locked = stat(buf, &statbuf) != -1;
 
        /* add scenarios that are supported */
        sdb->scens = NULL;
diff --git a/common/utils/msabaoth.h b/common/utils/msabaoth.h
--- a/common/utils/msabaoth.h
+++ b/common/utils/msabaoth.h
@@ -27,7 +27,7 @@ typedef enum {
 typedef struct Ssabdb {
        char *dbname;            /* database name */
        char *path;              /* path to this database */
-       int locked;              /* whether this database is under maintenance 
*/
+       bool locked;             /* whether this database is under maintenance 
*/
        SABdbState state;        /* current database state */
        sablist* scens;          /* scenarios available for this database */
        sablist* conns;          /* connections available for this database */
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -408,53 +408,110 @@ MT_init(void)
        fc = fopen("/proc/self/cgroup", "r");
        if (fc != NULL) {
                char buf[1024];
+               /* each line is of the form:
+                * hierarchy-ID:controller-list:cgroup-path
+                *
+                * For cgroup v1, the hierarchy-ID refers to the
+                * second column in /proc/cgroups (which we ignore)
+                * and the controller-list is a comma-separated list
+                * of the controllers bound to the hierarchy.  We look
+                * for the "memory" controller and use its
+                * cgroup-path.  We ignore the other lines.
+                *
+                * For cgroup v2, the hierarchy-ID is 0 and the
+                * controller-list is empty.  We just use the
+                * cgroup-path.
+                *
+                * We use the first line that we can match (either v1
+                * or v2) and for which we can open any of the files
+                * that we are looking for.
+                */
                while (fgets(buf, (int) sizeof(buf), fc) != NULL) {
+                       char pth[1024];
                        char *p, *q;
-                       p = strchr(buf, ':');
-                       if (p == NULL)
-                               break;
-                       q = p + 1;
-                       p = strchr(q, ':');
+                       bool success = false; /* true if we can open any file */
+                       FILE *f;
+                       uint64_t mem;
+                       size_t l;
+
+                       p = strchr(buf, '\n');
                        if (p == NULL)
                                break;
-                       *p++ = 0;
-                       if (strstr(q, "memory") != NULL) {
-                               char pth[1024];
-                               FILE *f;
-                               size_t l;
-                               q = strchr(p, '\n');
-                               if (q == NULL)
+                       *p = 0;
+                       if (strncmp(buf, "0::", 3) == 0) {
+                               /* cgroup v2 entry */
+                               l = strconcat_len(pth, sizeof(pth),
+                                                 "/sys/fs/cgroup",
+                                                 buf + 3, "/", NULL);
+                               /* hard limit */
+                               strcpy(pth + l, "memory.max");
+                               f = fopen(pth, "r");
+                               if (f != NULL) {
+                                       if (fscanf(f, "%" SCNu64, &mem) == 1 && 
mem < (uint64_t) _MT_pagesize * _MT_npages) {
+                                               _MT_npages = (size_t) (mem / 
_MT_pagesize);
+                                       }
+                                       success = true;
+                                       /* assume "max" if not a number */
+                                       fclose(f);
+                               }
+                               /* soft limit */
+                               strcpy(pth + l, "memory.high");
+                               f = fopen(pth, "r");
+                               if (f != NULL) {
+                                       if (fscanf(f, "%" SCNu64, &mem) == 1 && 
mem < (uint64_t) _MT_pagesize * _MT_npages) {
+                                               _MT_npages = (size_t) (mem / 
_MT_pagesize);
+                                       }
+                                       success = true;
+                                       /* assume "max" if not a number */
+                                       fclose(f);
+                               }
+                               /* limit of memory+swap usage
+                                * we use this as maximum virtual memory size */
+                               strcpy(pth + l, "memory.swap.max");
+                               f = fopen(pth, "r");
+                               if (f != NULL) {
+                                       if (fscanf(f, "%" SCNu64, &mem) == 1
+                                           && mem < (uint64_t) GDK_vm_maxsize) 
{
+                                               GDK_vm_maxsize = (size_t) mem;
+                                       }
+                                       success = true;
+                                       fclose(f);
+                               }
+                       } else {
+                               /* cgroup v1 entry */
+                               p = strchr(buf, ':');
+                               if (p == NULL)
                                        break;
-                               *q = 0;
+                               q = p + 1;
+                               p = strchr(q, ':');
+                               if (p == NULL)
+                                       break;
+                               *p++ = 0;
+                               if (strstr(q, "memory") == NULL)
+                                       continue;
                                l = strconcat_len(pth, sizeof(pth),
-                                                 "/sys/fs/cgroup/memory",
-                                                 p, NULL);
-                               /* sometimes the path in
-                                * /proc/self/cgroup ends in "/" (or
-                                * actually, is "/"); in all other
-                                * cases add one */
-                               if (pth[l - 1] != '/')
-                                       pth[l++] = '/';
+                                                 "/sys/fs/cgroup/", q,
+                                                 p, "/", NULL);
                                /* limit of memory usage */
                                strcpy(pth + l, "memory.limit_in_bytes");
                                f = fopen(pth, "r");
                                if (f != NULL) {
-                                       uint64_t mem;
                                        if (fscanf(f, "%" SCNu64, &mem) == 1
                                            && mem < (uint64_t) _MT_pagesize * 
_MT_npages) {
                                                _MT_npages = (size_t) (mem / 
_MT_pagesize);
                                        }
+                                       success = true;
                                        fclose(f);
                                }
                                /* soft limit of memory usage */
                                strcpy(pth + l, "memory.soft_limit_in_bytes");
                                f = fopen(pth, "r");
                                if (f != NULL) {
-                                       uint64_t mem;
                                        if (fscanf(f, "%" SCNu64, &mem) == 1
                                            && mem < (uint64_t) _MT_pagesize * 
_MT_npages) {
                                                _MT_npages = (size_t) (mem / 
_MT_pagesize);
                                        }
+                                       success = true;
                                        fclose(f);
                                }
                                /* limit of memory+swap usage
@@ -462,16 +519,16 @@ MT_init(void)
                                strcpy(pth + l, "memory.memsw.limit_in_bytes");
                                f = fopen(pth, "r");
                                if (f != NULL) {
-                                       uint64_t mem;
                                        if (fscanf(f, "%" SCNu64, &mem) == 1
                                            && mem < (uint64_t) GDK_vm_maxsize) 
{
                                                GDK_vm_maxsize = (size_t) mem;
                                        }
+                                       success = true;
                                        fclose(f);
                                }
+                       }
+                       if (success)
                                break;
-
-                       }
                }
                fclose(fc);
        }
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -295,7 +295,7 @@ MSscheduleClient(str command, str challe
                                GDKfree(command);
                                return;
                        }
-                       if (stats->locked == 1) {
+                       if (stats->locked) {
                                if (uid == 0) {
                                        mnstr_printf(fout, "#server is running 
in "
                                                                 "maintenance 
mode\n");
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1953,7 +1953,7 @@ rel2bin_join(backend *be, sql_rel *rel, 
                        stmt *s = NULL;
                        prop *p;
 
-                       /* only handle simple joins here */             
+                       /* only handle simple joins here */
                        if ((exp_has_func(e) && get_cmp(e) != cmp_filter) ||
                            get_cmp(e) == cmp_or || e->f) {
                                if (!join && !list_length(lje)) {
@@ -2154,7 +2154,6 @@ rel2bin_antijoin(backend *be, sql_rel *r
        right = row2cols(be, right);
 
        if (rel->exps) {
-
                jexps = sa_list(sql->sa);
                mexps = sa_list(sql->sa);
 
@@ -2292,21 +2291,43 @@ rel2bin_semijoin(backend *be, sql_rel *r
 #endif
        if (rel->exps) {
                int idx = 0;
+               list *jexps = sa_list(sql->sa);
                list *lje = sa_list(sql->sa);
                list *rje = sa_list(sql->sa);
 
+               /* get equi-joins/filters first */
+               if (list_length(rel->exps) > 1) {
+                       for( en = rel->exps->h; en; en = en->next ) {
+                               sql_exp *e = en->data;
+                               if (e->type == e_cmp && (e->flag == cmp_equal 
|| e->flag == cmp_filter))
+                                       list_append(jexps, e);
+                       }
+                       for( en = rel->exps->h; en; en = en->next ) {
+                               sql_exp *e = en->data;
+                               if (e->type != e_cmp || (e->flag != cmp_equal 
&& e->flag != cmp_filter))
+                                       list_append(jexps, e);
+                       }
+                       rel->exps = jexps;
+               }
+
                for( en = rel->exps->h; en; en = en->next ) {
                        int join_idx = sql->opt_stats[0];
                        sql_exp *e = en->data;
                        stmt *s = NULL;
 
-                       /* only handle simple joins here */             
-                       if (idx || e->type != e_cmp || (e->flag != cmp_equal && 
e->flag != mark_in))
-                               break;
+                       /* only handle simple joins here */
                        if ((exp_has_func(e) && get_cmp(e) != cmp_filter) ||
-                           (get_cmp(e) == cmp_or)) { 
+                           get_cmp(e) == cmp_or || e->f) {
+                               if (!join && !list_length(lje)) {
+                                       stmt *l = bin_first_column(be, left);
+                                       stmt *r = bin_first_column(be, right);
+                                       join = stmt_join(be, l, r, 0, cmp_all); 
+                               }
                                break;
                        }
+                       if (list_length(lje) && (idx || e->type != e_cmp || 
(e->flag != cmp_equal && e->flag != cmp_filter) ||
+                          (join && e->flag == cmp_filter)))
+                               break;
 
                        s = exp_bin(be, en->data, left, right, NULL, NULL, 
NULL, NULL);
                        if (!s) {
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -964,6 +964,9 @@ exps_match_col_exps( sql_exp *e1, sql_ex
        if (!is_complex_exp(e1->flag) && e1_r && e1_r->card == CARD_ATOM &&
            (e2->flag == cmp_in || e2->flag == cmp_notin))
                return exp_match_exp(e1->l, e2->l); 
+       if ((e1->flag == cmp_in || e1->flag == cmp_notin) &&
+           !is_complex_exp(e2->flag) && e2_r && e2_r->card == CARD_ATOM)
+               return exp_match_exp(e1->l, e2->l); 
 
        if ((e1->flag == cmp_in || e1->flag == cmp_notin) &&
            (e2->flag == cmp_in || e2->flag == cmp_notin))
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -3980,7 +3980,7 @@ rel_merge_rse(int *changes, mvc *sql, sq
        /* only execute once per select */
        (void)*changes;
 
-       if (is_select(rel->op) && rel->exps) { 
+       if ((is_select(rel->op) || is_join(rel->op)) && rel->exps) { 
                node *n, *o;
                list *nexps = new_exp_list(sql->sa);
 
@@ -4541,7 +4541,8 @@ rel_push_select_down(int *changes, mvc *
                for (n = exps->h; n; n = n->next) { 
                        sql_exp *e = n->data;
 
-                       if (exp_is_join_exp(e) == 0) {
+                       //if (exp_is_join_exp(e) == 0) {
+                       if (exp_is_join(e, NULL) == 0) {
                                append(r->exps, e);
                                (*changes)++;
                        } else {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to