Changeset: 74363423a95a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/74363423a95a
Modified Files:
        clients/mapilib/mapi.c
        sql/server/sql_mvc.c
Branch: default
Log Message:

Merge with Dec2023 branch.


diffs (174 lines):

diff --git a/clients/ChangeLog.Dec2023 b/clients/ChangeLog.Dec2023
--- a/clients/ChangeLog.Dec2023
+++ b/clients/ChangeLog.Dec2023
@@ -1,3 +1,8 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Wed Mar  6 2024 Sjoerd Mullender <sjo...@acm.org>
+- Fixed an issue where mclient wouldn't exit if the server it had
+  connected to exited for whatever reason while the client was waiting
+  for a query result.
+
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -1673,7 +1673,7 @@ finish_handle(MapiHdl hdl)
        if (hdl == NULL)
                return MERROR;
        mid = hdl->mid;
-       if (mid->active == hdl && !hdl->needmore &&
+       if (mid->active == hdl && !hdl->needmore && !mnstr_eof(mid->from) &&
            read_into_cache(hdl, 0) != MOK)
                return MERROR;
        if (mid->to) {
@@ -3421,7 +3421,7 @@ read_into_cache(MapiHdl hdl, int lookahe
                line = read_line(mid);
                if (line == NULL) {
                        if (mid->from && mnstr_eof(mid->from)) {
-                               return mapi_setError(mid, "unexpected end of 
file", __func__, MERROR);
+                               return mapi_setError(mid, "unexpected end of 
file", __func__, MTIMEOUT);
                        }
 
                        return mid->error;
diff --git a/gdk/gdk_strimps.c b/gdk/gdk_strimps.c
--- a/gdk/gdk_strimps.c
+++ b/gdk/gdk_strimps.c
@@ -838,10 +838,10 @@ BATsetstrimps(BAT *b)
  * in the BAT.
  */
 #define STRIMP_COMPLETE(b)                                             \
-       (b)->tstrimps != NULL &&                                        \
-               (b)->tstrimps != (Strimps *)1 &&                        \
-               (b)->tstrimps != (Strimps *)2 &&                        \
-               (((b)->tstrimps->strimps.free - ((char 
*)(b)->tstrimps->bitstrings_base - (b)->tstrimps->strimps.base)) == 
(b)->batCount*sizeof(uint64_t))
+       ((b)->tstrimps != NULL &&                                       \
+        (b)->tstrimps != (Strimps *)1 &&                               \
+        (b)->tstrimps != (Strimps *)2 &&                               \
+        (((b)->tstrimps->strimps.free - ((char 
*)(b)->tstrimps->bitstrings_base - (b)->tstrimps->strimps.base)) == 
(b)->batCount*sizeof(uint64_t)))
 
 
 /* Strimp creation.
@@ -886,16 +886,17 @@ STRMPcreate(BAT *b, BAT *s)
                pb = b;
        }
 
+       /* First thread to take the lock will read the strimp from disk
+        * or construct the strimp header.
+        */
+       MT_lock_set(&pb->batIdxLock);
+
        /* Strimp creation was requested. There are three cases:
         *  - The strimp is on disk (pb->tstrimps == 1)
         *  - The strimp needs to be created (pb->tstrimps == 2)
         *  - Finally the pointer might have been changed to NULL in another 
thread.
         */
        if (pb->tstrimps == NULL || pb->tstrimps == (Strimps*)1 || pb->tstrimps 
== (Strimps*)2) {
-               /* First thread to take the lock will read the strimp
-                * from disk or construct the strimp header.
-                */
-               MT_lock_set(&pb->batIdxLock);
                /* The strimp needs to be created. The rest of the
                 * creation code assumes that the pointer to the strimps
                 * is NULL. Make it so.
@@ -933,10 +934,10 @@ STRMPcreate(BAT *b, BAT *s)
                        }
                        pb->tstrimps = r;
                }
-               MT_lock_unset(&pb->batIdxLock);
        }
 
        if (STRIMP_COMPLETE(pb)) {
+               MT_lock_unset(&pb->batIdxLock);
                if (pb != b)
                        BBPunfix(pb->batCacheid);
                return GDK_SUCCEED;
@@ -947,6 +948,10 @@ STRMPcreate(BAT *b, BAT *s)
        MT_thread_setalgorithm("create strimp index");
        r = pb->tstrimps;
        STRMPincref(r);
+       if (pb != b) {
+               MT_lock_unset(&pb->batIdxLock);
+               MT_lock_set(&b->batIdxLock);
+       }
        dh = (uint64_t *)r->bitstrings_base + b->hseqbase;
        canditer_init(&ci, b, s);
 
@@ -961,13 +966,16 @@ STRMPcreate(BAT *b, BAT *s)
        }
        bat_iterator_end(&bi);
 
-       MT_lock_set(&b->batIdxLock);
+       if (pb != b) {
+               MT_lock_unset(&b->batIdxLock);
+               MT_lock_set(&pb->batIdxLock);
+       }
        r->strimps.free += b->batCount*sizeof(uint64_t);
        /* The thread that reaches this point last needs to write the strimp to 
disk. */
        if ((r->strimps.free - ((char *)r->bitstrings_base - r->strimps.base)) 
== b->batCount*sizeof(uint64_t)) {
                persistStrimp(pb);
        }
-       MT_lock_unset(&b->batIdxLock);
+       MT_lock_unset(&pb->batIdxLock);
        STRMPdecref(r, false);
 
        TRC_DEBUG(ACCELERATOR, "strimp creation took " LLFMT " usec\n", 
GDKusec()-t0);
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -1296,8 +1296,9 @@ mvc_create_remote(sql_table **t, mvc *m,
 }
 
 static str
-remote_drop(mvc *m, sqlid id)
+remote_drop(mvc *m, sql_table *t)
 {
+       sqlid id = t->base.id;
        int log_res = 0;
        sql_trans *tr = m->session->tr;
        sqlstore *store = tr->store;
@@ -1305,7 +1306,9 @@ remote_drop(mvc *m, sqlid id)
        sql_table *remote_user_info = find_sql_table(tr, sys, REMOTE_USER_INFO);
        sql_column *remote_user_info_id = find_sql_column(remote_user_info, 
"table_id");
        oid rid = store->table_api.column_find_row(tr, remote_user_info_id, 
&id, NULL);
-       if (is_oid_nil(rid) || (log_res = store->table_api.table_delete(tr, 
remote_user_info, rid)) != 0)
+       if (is_oid_nil(rid)) {
+               TRC_WARNING(SQL_TRANS, "Drop table: %s %s no remote info\n", 
t->s->base.name, t->base.name);
+       } else if ((log_res = store->table_api.table_delete(tr, 
remote_user_info, rid)) != 0)
                throw(SQL, "sql.drop_table", SQLSTATE(42000) "Drop table 
failed%s", log_res == LOG_CONFLICT ? " due to conflict with another 
transaction" : "");
        return MAL_SUCCEED;
 }
@@ -1316,7 +1319,7 @@ mvc_drop_table(mvc *m, sql_schema *s, sq
        char *msg = NULL;
        TRC_DEBUG(SQL_TRANS, "Drop table: %s %s\n", s->base.name, t->base.name);
 
-       if (isRemote(t) && (msg = remote_drop(m, t->base.id)) != NULL)
+       if (isRemote(t) && (msg = remote_drop(m, t)) != NULL)
                return msg;
 
        switch (sql_trans_drop_table(m->session->tr, s, t->base.name, 
drop_action ? DROP_CASCADE_START : DROP_RESTRICT)) {
diff --git a/sql/test/remote/Tests/All b/sql/test/remote/Tests/All
--- a/sql/test/remote/Tests/All
+++ b/sql/test/remote/Tests/All
@@ -3,3 +3,4 @@ HAVE_DATA_PATH?creds
 HAVE_DATA_PATH?invalid_creds
 HAVE_DATA_PATH?different_user
 THREADS>=2?partition_elim
+remote_info_missing
diff --git a/sql/test/remote/Tests/remote_info_missing.test 
b/sql/test/remote/Tests/remote_info_missing.test
new file mode 100644
--- /dev/null
+++ b/sql/test/remote/Tests/remote_info_missing.test
@@ -0,0 +1,12 @@
+statement ok
+create remote table t1234 (c int) on 'mapi:monetdb://localhost:50000/demo/t1'
+
+statement ok
+delete from remote_user_info where table_id = (select id from sys._tables 
where name = 't1234')
+
+statement ok
+drop table t1234;
+
+query T
+select name from sys._tables where name = 't1234';
+----
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to