Changeset: 6b4e75047166 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6b4e75047166
Modified Files:
        monetdb5/modules/mal/remote.c
        sql/backends/monet5/sql_result.c
        tools/monetdbe/monetdbe.c
Branch: Jul2021
Log Message:

MonetDBe remote fixes. Unlock and error, backport reference count fixes from 
default and don't set reply size on a columnar protocol connection


diffs (138 lines):

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
@@ -248,8 +248,11 @@ static str RMTconnectScen(
        if (columnar && *columnar) {
                char set_protocol_query_buf[50];
                snprintf(set_protocol_query_buf, 50, 
"sql.set_protocol(%d:int);", PROTOCOL_COLUMNAR);
-               if ((msg = RMTquery(&hdl, "remote.connect", m, 
set_protocol_query_buf)))
+               if ((msg = RMTquery(&hdl, "remote.connect", m, 
set_protocol_query_buf))) {
+                       mapi_destroy(m);
+                       MT_lock_unset(&mal_remoteLock);
                        return msg;
+               }
        }
 
        /* connection established, add to list */
@@ -1404,6 +1407,8 @@ static str RMTexec(Client cntxt, MalBlkP
                                        BBPkeepref(results[j].id);
                                assert(rcb->context);
                                tmp = rcb->call(rcb->context, 
mapi_get_table(mhdl, 0), results, fields);
+                               for (int j = 0; j < i; j++)
+                                       BBPrelease(results[j].id);
                        }
                        GDKfree(results);
                }
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1763,7 +1763,8 @@ mvc_export_head(backend *b, stream *s, i
                return -1;
 
        /* row count, min(count, reply_size) */
-       if (!mvc_send_int(s, (m->reply_size >= 0 && (BUN) m->reply_size < 
count) ? m->reply_size : (int) count))
+       /* the columnar protocol ignores the reply size by fetching the entire 
resultset at once, so don't set it */
+       if (!mvc_send_int(s, (b->client->protocol != PROTOCOL_COLUMNAR && 
m->reply_size >= 0 && (BUN) m->reply_size < count) ? m->reply_size : (int) 
count))
                return -1;
 
        // export query id
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -1052,6 +1052,7 @@ struct callback_context {
 static str
 monetdbe_result_cb(void* context, char* tblname, columnar_result* results, 
size_t nr_results) {
        monetdbe_database_internal *mdbe = ((struct callback_context*) 
context)->mdbe;
+       str msg = MAL_SUCCEED;
 
        if (nr_results == 0)
                return MAL_SUCCEED; // No work to do.
@@ -1060,36 +1061,55 @@ monetdbe_result_cb(void* context, char* 
        if ((mdbe->msg = getBackendContext(mdbe->c, &be)) != NULL)
                return mdbe->msg;
 
-       BAT* order = BATdescriptor(results[0].id);
+       BAT *b_0 = BATdescriptor(results[0].id);
+       if (!b_0) {
+               mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY005) "Cannot 
access column descriptor");
+               return mdbe->msg;
+       }
+
+       BAT *order = BATdense(0, 0, BATcount(b_0));
        if (!order) {
-               mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY005) "Cannot 
access column descriptor ");
+               BBPunfix(b_0->batCacheid);
+               mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                return mdbe->msg;
        }
 
-       mvc_result_table(be, 0, (int) nr_results, Q_TABLE, order);
-
-       for (unsigned  i = 0; i < nr_results; i++) {
+       int res = mvc_result_table(be, 0, (int) nr_results, Q_TABLE, order);
+       BBPunfix(order->batCacheid);
+       if (res < 0) {
+               BBPunfix(b_0->batCacheid);
+               mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY013) "Cannot 
create result table");
+               return mdbe->msg;
+       }
+
+       for (size_t i = 0; i < nr_results; i++) {
                BAT *b = NULL;
-               if (i > 0) {
+               if (i > 0)
                        b = BATdescriptor(results[i].id);
-               }
                else
-                       b = order; // We already fetched this first column
+                       b = b_0; // We already fetched this first column
 
                char* colname   = results[i].colname;
                char* tpename   = results[i].tpename;
                int digits              = results[i].digits;
                int scale               = results[i].scale;
 
-               if ( b == NULL)
-                       mdbe->msg= 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY005) "Cannot 
access column descriptor ");
-               else if (mvc_result_column(be, tblname, colname, tpename, 
digits, scale, b))
-                       mdbe->msg = createException(SQL, 
"monetdbe.monetdbe_result_cb", SQLSTATE(42000) "Cannot access column descriptor 
%s.%s",tblname,colname);
-               if( b)
-                       BBPkeepref(b->batCacheid);
+               if (b == NULL) {
+                       msg = mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb",SQLSTATE(HY005) "Cannot 
access column descriptor");
+                       break;
+               }
+
+               int res = mvc_result_column(be, tblname, colname, tpename, 
digits, scale, b);
+               BBPunfix(b->batCacheid);
+               if (res) {
+                       msg = mdbe->msg = 
createException(MAL,"monetdbe.monetdbe_result_cb", SQLSTATE(42000) "Cannot 
access column descriptor %s.%s",tblname,colname);
+                       break;
+               }
        }
 
-       return MAL_SUCCEED;
+       if (msg)
+               res_tables_destroy(be->results);
+       return msg;
 }
 
 struct prepare_callback_context {
@@ -1140,7 +1160,7 @@ monetdbe_prepare_cb(void* context, char*
                !(btable        = BATdescriptor(results[4].id)) ||
                !(bcolumn       = BATdescriptor(results[5].id)))
        {
-               msg = createException(SQL, "monetdbe.monetdbe_prepare_cb", 
SQLSTATE(42000) "Cannot access prepare result");
+               msg = createException(SQL, "monetdbe.monetdbe_prepare_cb", 
SQLSTATE(HY005) "Cannot access column descriptor");
                goto cleanup;
        }
 
@@ -1154,7 +1174,7 @@ monetdbe_prepare_cb(void* context, char*
                nparams + 1 != BATcount(btable) ||
                nparams         != BATcount(bcolumn))
        {
-               msg = createException(SQL, "monetdbe.monetdbe_prepare_cb", 
SQLSTATE(42000) "prepare results are incorrect.");
+               msg = createException(SQL, "monetdbe.monetdbe_prepare_cb", 
SQLSTATE(42000) "Prepare results are incorrect");
                goto cleanup;
        }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to