Changeset: d1b95282d0f0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d1b95282d0f0
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_exception.h
        monetdb5/modules/mal/remote.c
        monetdb5/optimizer/opt_oltp.c
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_execute.h
        sql/backends/monet5/sql_gencode.c
        sql/test/BugTracker-2015/Tests/local-remotetable-crash.Bug-3754.SQL.py
        sql/test/BugTracker-2015/Tests/schemadiff.Bug-3778.SQL.py
        
sql/test/BugTracker-2019/Tests/remote-table-non-existent-column.Bug-6750.py
        sql/test/BugTracker-2020/Tests/table-udf-on-remote.Bug-6971.py
Branch: iso
Log Message:

Always finish the remote plan transaction, so the pending dependencies can get 
a chance to be cleaned

At the moment I changed the remote plan to throw an error to check the remote 
server log, because I can't figure out how to rethrow a MAL error. Please a MAL 
expert review this an make it throw the original exception.


diffs (truncated from 482 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -9169,6 +9169,7 @@ stdout of test 'MAL-signatures` in direc
 [ "rapi",      "eval_aggr",    "pattern rapi.eval_aggr(X_0:ptr, X_1:str, 
X_2:any...):any... ", "RAPIevalAggr;",        ""      ]
 [ "rapi",      "prelude",      "command rapi.prelude():void ", "RAPIprelude;", 
""      ]
 [ "rapi",      "subeval_aggr", "pattern rapi.subeval_aggr(X_0:ptr, X_1:str, 
X_2:any...):any... ",      "RAPIevalAggr;",        ""      ]
+[ "remote",    "assert",       "pattern remote.assert(X_0:bit, X_1:str):void 
",        "RMTassert;",   ""      ]
 [ "remote",    "batbincopy",   "pattern remote.batbincopy():bat[:any] ",       
"RMTbincopyfrom;",      ""      ]
 [ "remote",    "batbincopy",   "pattern remote.batbincopy(X_0:bat[:any]):void 
",       "RMTbincopyto;",        ""      ]
 [ "remote",    "batload",      "pattern remote.batload(X_0:any_1, 
X_1:int):bat[:any_1] ",      "RMTbatload;",  ""      ]
@@ -9270,6 +9271,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "deltas",       "pattern sql.deltas(X_0:str, X_1:str) 
(X_2:bat[:int], X_3:bat[:lng], X_4:bat[:lng], X_5:bat[:lng], X_6:bat[:lng], 
X_7:bat[:lng], X_8:bat[:int]) ",      "mvc_delta_values;",    ""      ]
 [ "sql",       "deltas",       "pattern sql.deltas(X_0:str, X_1:str, X_2:str) 
(X_3:bat[:int], X_4:bat[:lng], X_5:bat[:lng], X_6:bat[:lng], X_7:bat[:lng], 
X_8:bat[:lng], X_9:bat[:int]) ",     "mvc_delta_values;",    ""      ]
 [ "sql",       "dense_rank",   "pattern sql.dense_rank(X_0:any_1, X_1:bit, 
X_2:bit):int ",     "SQLdense_rank;",       ""      ]
+[ "sql",       "deregister",   "pattern sql.deregister():int ",        
"RAstatementEnd;",      ""      ]
 [ "sql",       "diff", "pattern sql.diff(X_0:any_1):bit ",     "SQLdiff;",     
""      ]
 [ "sql",       "diff", "pattern sql.diff(X_0:bit, X_1:any_1):bit ",    
"SQLdiff;",     ""      ]
 [ "sql",       "drop_hash",    "unsafe pattern sql.drop_hash(X_0:str, 
X_1:str):void ", "SQLdrop_hash;",        ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -12470,6 +12470,7 @@ stdout of test 'MAL-signatures` in direc
 [ "rapi",      "eval_aggr",    "pattern rapi.eval_aggr(X_0:ptr, X_1:str, 
X_2:any...):any... ", "RAPIevalAggr;",        ""      ]
 [ "rapi",      "prelude",      "command rapi.prelude():void ", "RAPIprelude;", 
""      ]
 [ "rapi",      "subeval_aggr", "pattern rapi.subeval_aggr(X_0:ptr, X_1:str, 
X_2:any...):any... ",      "RAPIevalAggr;",        ""      ]
+[ "remote",    "assert",       "pattern remote.assert(X_0:bit, X_1:str):void 
",        "RMTassert;",   ""      ]
 [ "remote",    "batbincopy",   "pattern remote.batbincopy():bat[:any] ",       
"RMTbincopyfrom;",      ""      ]
 [ "remote",    "batbincopy",   "pattern remote.batbincopy(X_0:bat[:any]):void 
",       "RMTbincopyto;",        ""      ]
 [ "remote",    "batload",      "pattern remote.batload(X_0:any_1, 
X_1:int):bat[:any_1] ",      "RMTbatload;",  ""      ]
@@ -12576,6 +12577,7 @@ stdout of test 'MAL-signatures` in direc
 [ "sql",       "deltas",       "pattern sql.deltas(X_0:str, X_1:str) 
(X_2:bat[:int], X_3:bat[:lng], X_4:bat[:lng], X_5:bat[:lng], X_6:bat[:lng], 
X_7:bat[:lng], X_8:bat[:int]) ",      "mvc_delta_values;",    ""      ]
 [ "sql",       "deltas",       "pattern sql.deltas(X_0:str, X_1:str, X_2:str) 
(X_3:bat[:int], X_4:bat[:lng], X_5:bat[:lng], X_6:bat[:lng], X_7:bat[:lng], 
X_8:bat[:lng], X_9:bat[:int]) ",     "mvc_delta_values;",    ""      ]
 [ "sql",       "dense_rank",   "pattern sql.dense_rank(X_0:any_1, X_1:bit, 
X_2:bit):int ",     "SQLdense_rank;",       ""      ]
+[ "sql",       "deregister",   "pattern sql.deregister():int ",        
"RAstatementEnd;",      ""      ]
 [ "sql",       "diff", "pattern sql.diff(X_0:any_1):bit ",     "SQLdiff;",     
""      ]
 [ "sql",       "diff", "pattern sql.diff(X_0:bit, X_1:any_1):bit ",    
"SQLdiff;",     ""      ]
 [ "sql",       "drop_hash",    "unsafe pattern sql.drop_hash(X_0:str, 
X_1:str):void ", "SQLdrop_hash;",        ""      ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -934,6 +934,7 @@ const char *deleteRef;
 void deleteSymbol(Module scope, Symbol prg);
 const char *deltaRef;
 const char *dense_rankRef;
+const char *deregisterRef;
 malType destinationType(MalBlkPtr mb, InstrPtr p);
 const char *diffRef;
 const char *diffcandRef;
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -29,7 +29,8 @@ static char *exceptionNames[] = {
 /*11 */        "ArithmeticException",
 /*12 */        "PermissionDeniedException",
 /*13 */        "SQLException",
-/*14 */        "Deprecated operation",
+/*14 */        "RemoteException",
+/*15 */        "Deprecated operation",
 /*EOE*/        NULL
 };
 
diff --git a/monetdb5/mal/mal_exception.h b/monetdb5/mal/mal_exception.h
--- a/monetdb5/mal/mal_exception.h
+++ b/monetdb5/mal/mal_exception.h
@@ -26,7 +26,8 @@ enum malexception {
        PARSE,
        ARITH,
        PERMD,
-       SQL
+       SQL,
+       REMOTE
 };
 
 #define MAL_SUCCEED ((str) 0) /* no error */
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -1662,10 +1662,39 @@ RMTregisterSupervisor(int *ret, str *sup
        return MAL_SUCCEED;
 }
 
+/* this is needed in remote plans */
+static str
+RMTassert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+       bool flg = (bool) *getArgReference_bit(stk, pci, 1);
+       str msg = *getArgReference_str(stk, pci, 2);
+
+       (void) cntxt;
+       (void) mb;
+       if (flg) {
+               if (strlen(msg) > 6 &&
+                   msg[5] == '!' &&
+                   (isdigit((unsigned char) msg[0]) ||
+                    isupper((unsigned char) msg[0])) &&
+                   (isdigit((unsigned char) msg[1]) ||
+                    isupper((unsigned char) msg[1])) &&
+                   (isdigit((unsigned char) msg[2]) ||
+                    isupper((unsigned char) msg[2])) &&
+                   (isdigit((unsigned char) msg[3]) ||
+                    isupper((unsigned char) msg[3])) &&
+                   (isdigit((unsigned char) msg[4]) ||
+                    isupper((unsigned char) msg[4])))
+                       throw(REMOTE, "assert", "%s", msg); /* includes state */
+               throw(REMOTE, "assert", SQLSTATE(M0M29) "%s", msg);
+       }
+       return MAL_SUCCEED;
+}
+
 #include "mel.h"
 mel_func remote_init_funcs[] = {
  command("remote", "prelude", RMTprelude, false, "initialise the remote 
module", args(1,1, arg("",void))),
  command("remote", "epilogue", RMTepilogue, false, "release the resources held 
by the remote module", args(1,1, arg("",void))),
+ pattern("remote", "assert", RMTassert, false, "Generate an exception when 
b==true", args(1,3, arg("",void),arg("b",bit),arg("msg",str))),
  command("remote", "resolve", RMTresolve, false, "resolve a pattern against 
Merovingian and return the URIs", args(1,2, batarg("",str),arg("pattern",str))),
  pattern("remote", "connect", RMTconnect, false, "returns a newly created 
connection for uri, using user name and password", args(1,5, 
arg("",str),arg("uri",str),arg("user",str),arg("passwd",str),arg("scen",str))),
  command("remote", "connect", RMTconnectScen, false, "returns a newly created 
connection for uri, using user name, password and scenario", args(1,6, 
arg("",str),arg("uri",str),arg("user",str),arg("passwd",str),arg("scen",str),arg("columnar",bit))),
diff --git a/monetdb5/optimizer/opt_oltp.c b/monetdb5/optimizer/opt_oltp.c
--- a/monetdb5/optimizer/opt_oltp.c
+++ b/monetdb5/optimizer/opt_oltp.c
@@ -106,10 +106,10 @@ OPToltpImplementation(Client cntxt, MalB
                p = old[i];
                if( p->token == ENDsymbol){
                        // unlock all if there is an error
-                       q= newCatchStmt(mb,"MALexception");
-                       q= newExitStmt(mb,"MALexception");
-                       q= newCatchStmt(mb,"SQLexception");
-                       q= newExitStmt(mb,"SQLexception");
+                       q= newCatchStmt(mb,"MALException");
+                       q= newExitStmt(mb,"MALException");
+                       q= newCatchStmt(mb,"SQLException");
+                       q= newExitStmt(mb,"SQLException");
                        q= copyInstruction(lcks);
                        if( q == NULL){
                                for(; i<slimit; i++)
diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -106,6 +106,7 @@ const char *defineRef;
 const char *deleteRef;
 const char *deltaRef;
 const char *dense_rankRef;
+const char *deregisterRef;
 const char *diffcandRef;
 const char *differenceRef;
 const char *disconnectRef;
@@ -412,6 +413,7 @@ void optimizerInit(void)
        deleteRef = putName("delete");
        deltaRef = putName("delta");
        dense_rankRef = putName("dense_rank");
+       deregisterRef = putName("deregister");
        diffcandRef= putName("diffcand");
        differenceRef = putName("difference");
        disconnectRef= putName("disconnect");
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -102,6 +102,7 @@ mal_export  const char *defineRef;
 mal_export  const char *deleteRef;
 mal_export  const char *deltaRef;
 mal_export  const char *dense_rankRef;
+mal_export  const char *deregisterRef;
 mal_export  const char *diffcandRef;
 mal_export  const char *differenceRef;
 mal_export  const char *diffRef;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4983,6 +4983,7 @@ static mel_func sql_init_funcs[] = {
  pattern("sql", "evalAlgebra", RAstatement, false, "Compile and execute a 
single 'relational algebra' statement", args(1,3, 
arg("",void),arg("cmd",str),arg("optimize",bit))),
  pattern("sql", "register", RAstatement2, false, "", args(1,5, 
arg("",int),arg("mod",str),arg("fname",str),arg("rel_stmt",str),arg("sig",str))),
  pattern("sql", "register", RAstatement2, false, "Compile the relational 
statement (rel_smt) and register it as mal function, mod.fname(signature)", 
args(1,6, 
arg("",int),arg("mod",str),arg("fname",str),arg("rel_stmt",str),arg("sig",str),arg("typ",str))),
+ pattern("sql", "deregister", RAstatementEnd, false, "Finish running 
transaction", args(1,1, arg("",int))),
  pattern("sql", "hot_snapshot", SQLhot_snapshot, true, "Write db snapshot to 
the given tar(.gz) file", args(1,2, arg("",void),arg("tarfile",str))),
  pattern("sql", "resume_log_flushing", SQLresume_log_flushing, true, "Resume 
WAL log flushing", args(1,1, arg("",void))),
  pattern("sql", "suspend_log_flushing", SQLsuspend_log_flushing, true, 
"Suspend WAL log flushing", args(1,1, arg("",void))),
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
@@ -726,6 +726,16 @@ SQLdestroyResult(res_table *destroy)
        res_table_destroy(destroy);
 }
 
+static str
+RAcommit_statement(backend *be, str msg)
+{
+       mvc *m = be->mvc;
+       /* if an error already exists set the session status to dirty */
+       if (msg != MAL_SUCCEED && m->session->tr->active && !m->session->status)
+               m->session->status = -1;
+       return msg;
+}
+
 /* a hook is provided to execute relational algebra expressions */
 str
 RAstatement(Client c, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
@@ -733,13 +743,13 @@ RAstatement(Client c, MalBlkPtr mb, MalS
        int pos = 0;
        str *expr = getArgReference_str(stk, pci, 1);
        bit *opt = getArgReference_bit(stk, pci, 2);
-       backend *b = NULL;
+       backend *be = NULL;
        mvc *m = NULL;
-       str msg;
+       str msg = MAL_SUCCEED;
        sql_rel *rel;
        list *refs;
 
-       if ((msg = getSQLContext(c, mb, &m, &b)) != NULL)
+       if ((msg = getSQLContext(c, mb, &m, &be)) != NULL)
                return msg;
        if ((msg = checkSQLContext(c)) != NULL)
                return msg;
@@ -748,10 +758,15 @@ RAstatement(Client c, MalBlkPtr mb, MalS
        if (!m->sa)
                m->sa = sa_create(m->pa);
        if (!m->sa)
-               return createException(SQL,"RAstatement",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               return RAcommit_statement(be, 
createException(SQL,"RAstatement",SQLSTATE(HY013) MAL_MALLOC_FAIL));
        refs = sa_list(m->sa);
        rel = rel_read(m, *expr, &pos, refs);
-       if (rel) {
+       if (!rel) {
+               if (strlen(m->errstr) > 6 && m->errstr[5] == '!')
+                       msg = createException(SQL, "RAstatement", "%s", 
m->errstr);
+               else
+                       msg = createException(SQL, "RAstatement", 
SQLSTATE(42000) "%s", m->errstr);
+       } else {
                int oldvtop = c->curprg->def->vtop, oldstop = 
c->curprg->def->stop, oldvid = c->curprg->def->vid;
 
                if (*opt && rel)
@@ -759,12 +774,12 @@ RAstatement(Client c, MalBlkPtr mb, MalS
 
                if ((msg = MSinitClientPrg(c, sql_private_module_name, "test")) 
!= MAL_SUCCEED) {
                        rel_destroy(rel);
-                       return msg;
+                       return RAcommit_statement(be, msg);
                }
 
                /* generate MAL code, ignoring any code generation error */
                setVarType(c->curprg->def, 0, 0);
-               if (backend_dumpstmt(b, c->curprg->def, rel, 0, 1, NULL) < 0) {
+               if (backend_dumpstmt(be, c->curprg->def, rel, 0, 1, NULL) < 0) {
                        msg = createException(SQL,"RAstatement","Program 
contains errors"); // TODO: use macro definition.
                } else {
                        SQLaddQueryToCache(c);
@@ -777,12 +792,8 @@ RAstatement(Client c, MalBlkPtr mb, MalS
                        resetMalBlk(c->curprg->def, oldstop);
                        freeVariables(c, c->curprg->def, NULL, oldvtop, oldvid);
                }
-               if (!msg)
-                       msg = mvc_commit(m, 0, NULL, false);
-               else
-                       msg = mvc_rollback(m, 0, NULL, false);
        }
-       return msg;
+       return RAcommit_statement(be, msg);
 }
 
 static int
@@ -820,18 +831,14 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                return msg;
        if (!m->sa)
                m->sa = sa_create(m->pa);
-       if (!m->sa) {
-               sqlcleanup(be, 0);
-               return createException(SQL,"RAstatement2",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-       }
+       if (!m->sa)
+               return RAcommit_statement(be, 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL));
 
        /* keep copy of signature and relational expression */
        snprintf(buf, BUFSIZ, "%s %s", sig, expr);
 
-       if (!stack_push_frame(m, NULL)) {
-               sqlcleanup(be, 0);
-               return createException(SQL,"RAstatement2",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-       }
+       if (!stack_push_frame(m, NULL))
+               return RAcommit_statement(be, 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL));
        ops = sa_list(m->sa);
        while (sig && *sig && !isspace((unsigned char) *sig)) {
                char *vnme = sig, *tnme;
@@ -850,10 +857,8 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                p = strchr(p, (int)'(');
                *p++ = 0;
                tnme = sa_strdup(m->sa, tnme);
-               if (!tnme) {
-                       sqlcleanup(be, 0);
-                       return 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL);
-               }
+               if (!tnme)
+                       return RAcommit_statement(be, 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL));
                d = strtol(p, &p, 10);
                p++; /* skip , */
                s = strtol(p, &p, 10);
@@ -872,10 +877,8 @@ RAstatement2(Client cntxt, MalBlkPtr mb,
                        //      return 
createException(SQL,"RAstatement2",SQLSTATE(HY013) MAL_MALLOC_FAIL);
                        //}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to