Changeset: b4aea51801db for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b4aea51801db
Modified Files:
        clients/mapiclient/dump.c
        gdk/gdk_bbp.c
        monetdb5/extras/rapi/rapi.c
        sql/backends/monet5/UDF/pyapi3/pyapi3.c
        sql/server/sql_scan.c
        sql/test/BugTracker-2022/Tests/All
        sql/test/testdb/Tests/dump-nogeom.stable.out
        sql/test/testdb/Tests/dump.stable.out
Branch: default
Log Message:

Merge with Jan2022 branch.


diffs (truncated from 634 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -2575,29 +2575,32 @@ dump_database(Mapi mid, stream *toConsol
                "SELECT s.name, t.name, "
                       "a.name, "
                       "sum(p.privileges), "
-                      "g.name, p.grantable "
+                      "g.name, go.opt "
                "FROM sys.schemas s, sys.tables t, "
                     "sys.auths a, sys.privileges p, "
-                    "sys.auths g "
+                    "sys.auths g, "
+                    "(VALUES (0, ''), (1, ' WITH GRANT OPTION')) AS go (id, 
opt) "
                "WHERE p.obj_id = t.id "
                  "AND p.auth_id = a.id "
                  "AND t.schema_id = s.id "
                  "AND t.system = FALSE "
                  "AND p.grantor = g.id "
-               "GROUP BY s.name, t.name, a.name, g.name, p.grantable "
-               "ORDER BY s.name, t.name, a.name, g.name, p.grantable";
+                 "AND p.grantable = go.id "
+               "GROUP BY s.name, t.name, a.name, g.name, go.opt "
+               "ORDER BY s.name, t.name, a.name, g.name, go.opt";
        const char *column_grants =
                "SELECT s.name, t.name, "
                       "c.name, a.name, "
                       "pc.privilege_code_name, "
-                      "g.name, p.grantable "
+                      "g.name, go.opt "
                "FROM sys.schemas s, "
                     "sys.tables t, "
                     "sys.columns c, "
                     "sys.auths a, "
                     "sys.privileges p, "
                     "sys.auths g, "
-                    "sys.privilege_codes pc "
+                    "sys.privilege_codes pc, "
+                    "(VALUES (0, ''), (1, ' WITH GRANT OPTION')) AS go (id, 
opt) "
                "WHERE p.obj_id = c.id "
                  "AND c.table_id = t.id "
                  "AND p.auth_id = a.id "
@@ -2605,16 +2608,18 @@ dump_database(Mapi mid, stream *toConsol
                  "AND t.system = FALSE "
                  "AND p.grantor = g.id "
                  "AND p.privileges = pc.privilege_code_id "
+                 "AND p.grantable = go.id "
                "ORDER BY s.name, t.name, c.name, a.name, g.name, p.grantable";
        const char *function_grants =
                "SELECT s.name, f.name, a.name, "
                       "pc.privilege_code_name, "
-                      "g.name, p.grantable, "
+                      "g.name, go.opt, "
                       "ft.function_type_keyword "
                "FROM sys.schemas s, sys.functions f, "
                     "sys.auths a, sys.privileges p, sys.auths g, "
                     "sys.function_types ft, "
-                    "sys.privilege_codes pc "
+                    "sys.privilege_codes pc, "
+                    "(VALUES (0, ''), (1, ' WITH GRANT OPTION')) AS go (id, 
opt) "
                "WHERE s.id = f.schema_id "
                  "AND f.id = p.obj_id "
                  "AND p.auth_id = a.id "
@@ -2622,7 +2627,21 @@ dump_database(Mapi mid, stream *toConsol
                  "AND p.privileges = pc.privilege_code_id "
                  "AND f.type = ft.function_type_id "
                  "AND NOT f.system "
+                 "AND p.grantable = go.id "
                "ORDER BY s.name, f.name, a.name, g.name, p.grantable";
+       const char *global_grants =
+               "SELECT a.name, pc.grnt, g.name, go.opt "
+               "FROM sys.privileges p, "
+                    "sys.auths a, "
+                    "sys.auths g, "
+                    "(VALUES (0, 'COPY INTO'), (1, 'COPY FROM')) AS pc (id, 
grnt), "
+                    "(VALUES (0, ''), (1, ' WITH GRANT OPTION')) AS go (id, 
opt) "
+               "WHERE p.obj_id = 0 "
+                 "AND p.auth_id = a.id "
+                 "AND p.grantor = g.id "
+                 "AND p.privileges = pc.id "
+                 "AND p.grantable = go.id "
+               "ORDER BY a.name, g.name, go.opt";
        const char *schemas =
                "SELECT s.name, a.name, rem.remark "
                "FROM sys.schemas s LEFT OUTER JOIN sys.comments rem ON s.id = 
rem.id, "
@@ -2870,6 +2889,23 @@ dump_database(Mapi mid, stream *toConsol
                if (mapi_error(mid))
                        goto bailout;
                mapi_close_handle(hdl);
+
+               /* grant global privileges */
+               if ((hdl = mapi_query(mid, global_grants)) == NULL || 
mapi_error(mid))
+                       goto bailout;
+
+               while (mapi_fetch_row(hdl) != 0) {
+                       const char *uname = mapi_fetch_field(hdl, 0);
+                       const char *grant = mapi_fetch_field(hdl, 1);
+                       //const char *gname = mapi_fetch_field(hdl, 2);
+                       const char *grantable = mapi_fetch_field(hdl, 3);
+                       mnstr_printf(toConsole, "GRANT %s TO ", grant);
+                       dquoted_print(toConsole, uname, grantable);
+                       mnstr_printf(toConsole, ";\n");
+               }
+               if (mapi_error(mid))
+                       goto bailout;
+               mapi_close_handle(hdl);
        }
 
        /* dump types */
@@ -3267,9 +3303,7 @@ dump_database(Mapi mid, stream *toConsol
                mnstr_printf(toConsole, " ON TABLE ");
                dquoted_print(toConsole, schema, ".");
                dquoted_print(toConsole, tname, " TO ");
-               dquoted_print(toConsole, aname, NULL);
-               if (strcmp(grantable, "1") == 0)
-                       mnstr_printf(toConsole, " WITH GRANT OPTION");
+               dquoted_print(toConsole, aname, grantable);
                mnstr_printf(toConsole, ";\n");
        }
        if (mapi_error(mid))
@@ -3293,9 +3327,7 @@ dump_database(Mapi mid, stream *toConsol
                dquoted_print(toConsole, cname, ") ON ");
                dquoted_print(toConsole, schema, ".");
                dquoted_print(toConsole, tname, " TO ");
-               dquoted_print(toConsole, aname, NULL);
-               if (strcmp(grantable, "1") == 0)
-                       mnstr_printf(toConsole, " WITH GRANT OPTION");
+               dquoted_print(toConsole, aname, grantable);
                mnstr_printf(toConsole, ";\n");
        }
        if (mapi_error(mid))
@@ -3319,9 +3351,7 @@ dump_database(Mapi mid, stream *toConsol
                mnstr_printf(toConsole, "GRANT %s ON %s ", priv, ftype);
                dquoted_print(toConsole, schema, ".");
                dquoted_print(toConsole, fname, " TO ");
-               dquoted_print(toConsole, aname, NULL);
-               if (strcmp(grantable, "1") == 0)
-                       mnstr_printf(toConsole, " WITH GRANT OPTION");
+               dquoted_print(toConsole, aname, grantable);
                mnstr_printf(toConsole, ";\n");
        }
        if (mapi_error(mid))
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3382,7 +3382,7 @@ dirty_bat(bat *i, bool subcommit)
                        if ((BBP_status(*i) & BBPNEW) &&
                            BATcheckmodes(b, false) != GDK_SUCCEED) /* check 
mmap modes */
                                *i = -*i;       /* error */
-                       if ((BBP_status(*i) & BBPPERSISTENT) &&
+                       else if ((BBP_status(*i) & BBPPERSISTENT) &&
                            (subcommit || BATdirty(b))) {
                                MT_lock_unset(&b->theaplock);
                                return b;       /* the bat is loaded, 
persistent and dirty */
@@ -3826,19 +3826,12 @@ BBPsync(int cnt, bat *restrict subcommit
                        if (BBP_status(i) & BBPEXISTING) {
                                if (b != NULL) {
                                        if (BBPbackup(b, subcommit != NULL) != 
GDK_SUCCEED) {
-                                               BBP_status_off(i, BBPSYNCING);
                                                if (lock)
                                                        
MT_lock_unset(&GDKswapLock(i));
                                                break;
                                        }
-                               } else {
-                                       /* file has not been moved to
-                                        * backup dir, so no need for
-                                        * other threads to wait */
-                                       BBP_status_off(i, BBPSYNCING);
                                }
                        } else {
-                               BBP_status_off(i, BBPSYNCING);
                                if (subcommit && (b = BBP_desc(i)) && 
BBP_status(i) & BBPDELETED) {
                                        char o[10];
                                        char *f;
@@ -3890,12 +3883,8 @@ BBPsync(int cnt, bat *restrict subcommit
                        BATiter bi;
 
                        if (BBP_status(i) & BBPPERSISTENT) {
-                               /* add a fix so that BBPmanager doesn't
-                                * interfere */
-                               BBPfix(i);
                                BAT *b = dirty_bat(&i, subcommit != NULL);
                                if (i <= 0) {
-                                       decref(-i, false, false, true, 
locked_by == 0 || locked_by != MT_getpid(), __func__);
                                        break;
                                }
                                bi = bat_iterator(BBP_desc(i));
@@ -3932,16 +3921,9 @@ BBPsync(int cnt, bat *restrict subcommit
                                n = BBPdir_step(i, size, n, buf, sizeof(buf), 
&obbpf, nbbpf, subcommit != NULL, &bi);
                        }
                        bat_iterator_end(&bi);
-                       if (BBP_status(i) & BBPPERSISTENT) {
-                               /* can't use BBPunfix because of the
-                                * "lock" argument: locked_by may be
-                                * set here */
-                               decref(i, false, false, true, lock, __func__);
-                       }
                        if (n == -2)
                                break;
                        /* we once again have a saved heap */
-                       BBP_status_off(i, BBPSYNCING);
                }
                if (idx < cnt)
                        ret = GDK_FAIL;
@@ -3990,6 +3972,14 @@ BBPsync(int cnt, bat *restrict subcommit
                  ret == GDK_SUCCEED ? "" : " failed",
                  (t0 = GDKms()) - t1);
   bailout:
+       /* turn off the BBPSYNCING bits for all bats, even when things
+        * didn't go according to plan (i.e., don't check for ret ==
+        * GDK_SUCCEED) */
+       for (int idx = 1; idx < cnt; idx++) {
+               bat i = subcommit ? subcommit[idx] : idx;
+               BBP_status_off(i, BBPSYNCING);
+       }
+
        GDKfree(bakdir);
        GDKfree(deldir);
        return ret;
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -339,6 +339,7 @@ static BAT* sexp_to_bat(SEXP s, int type
                                }
                        }
                }
+               BATsetcount(b, cnt);
                break;
        }
        default:
@@ -350,10 +351,6 @@ static BAT* sexp_to_bat(SEXP s, int type
                }
        }
 
-       if (b) {
-               BATsetcount(b, cnt);
-               BBPkeepref(b);
-       }
        return b;
 }
 
@@ -821,6 +818,7 @@ static str RAPIeval(Client cntxt, MalBlk
                // bat return
                if (isaBatType(getArgType(mb,pci,i))) {
                        *getArgReference_bat(stk, pci, i) = b->batCacheid;
+                       BBPkeepref(b);
                } else { // single value return, only for non-grouped 
aggregations
                        BATiter li = bat_iterator(b);
                        if (VALinit(&stk->stk[pci->argv[i]], bat_type,
@@ -830,6 +828,7 @@ static str RAPIeval(Client cntxt, MalBlk
                                goto wrapup;
                        }
                        bat_iterator_end(&li);
+                       BBPunfix(b->batCacheid);
                }
                msg = MAL_SUCCEED;
        }
diff --git a/sql/backends/monet5/UDF/pyapi3/pyapi3.c 
b/sql/backends/monet5/UDF/pyapi3/pyapi3.c
--- a/sql/backends/monet5/UDF/pyapi3/pyapi3.c
+++ b/sql/backends/monet5/UDF/pyapi3/pyapi3.c
@@ -1249,6 +1249,10 @@ returnvalues:
                                        msg = createException(MAL, 
"pyapi3.eval", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                        }
                        bat_iterator_end(&li);
+                       BBPunfix(b->batCacheid);
+                       b = NULL;
+                       if (msg != MAL_SUCCEED)
+                               goto wrapup;
                }
                if (argnode) {
                        argnode = argnode->next;
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -564,7 +564,7 @@ scanner_error(mvc *lc, int cur)
        switch (cur) {
        case EOF:
                (void) sql_error(lc, 1, SQLSTATE(42000) "Unexpected end of 
input");
-               return -1;      /* EOF needs -1 result */
+               return EOF;
        default:
                /* on Windows at least, iswcntrl returns TRUE for
                 * U+FEFF, but we just want consistent error
@@ -763,8 +763,8 @@ scanner_string(mvc *c, int quote, bool e
                        cur = scanner_getc(lc);
                }
        }
-       (void) sql_error(c, 2, "%s", lc->errstr ? lc->errstr : SQLSTATE(42000) 
"unexpected end of input");
-       return LEX_ERROR;
+       (void) sql_error(c, 2, "%s", lc->errstr ? lc->errstr : SQLSTATE(42000) 
"Unexpected end of input");
+       return EOF;
 }
 
 /* scan a structure {blah} into a string. We only count the matching {}
@@ -811,7 +811,7 @@ scanner_body(mvc *c)
                }
        }
        (void) sql_error(c, 2, SQLSTATE(42000) "Unexpected end of input");
-       return LEX_ERROR;
+       return EOF;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to