Changeset: 0293d138e85e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0293d138e85e
Modified Files:
        gdk/gdk.h
        gdk/gdk_calc.c
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/modules/atoms/uuid.c
Branch: Aug2024
Log Message:

A little timeout cleanup; also timeout in bulk generation of UUIDs.


diffs (171 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2349,29 +2349,33 @@ gdk_export BAT *BATsample_with_seed(BAT 
 #define QRY_INTERRUPT (-2)     /* client indicated interrupt */
 #define QRY_DISCONNECT (-3)    /* client disconnected */
 
+static const char *
+TIMEOUT_MESSAGE(QryCtx *qc)
+{
+       if (GDKexiting())
+               return EXITING_MSG;
+       if (qc) {
+               switch (qc->endtime) {
+               case QRY_TIMEOUT:
+                       return TIMEOUT_MSG;
+               case QRY_INTERRUPT:
+                       return INTERRUPT_MSG;
+               case QRY_DISCONNECT:
+                       return DISCONNECT_MSG;
+               default:
+                       MT_UNREACHABLE();
+               }
+       }
+       return NULL;
+}
+
 static inline void
 TIMEOUT_ERROR(QryCtx *qc, const char *file, const char *func, int lineno)
 {
-       if (GDKexiting()) {
+       const char *e = TIMEOUT_MESSAGE(qc);
+       if (e) {
                GDKtracer_log(file, func, lineno, M_ERROR, GDK, NULL,
-                             "%s\n", EXITING_MSG);
-       } else if (qc) {
-               switch (qc->endtime) {
-               case QRY_TIMEOUT:
-                       GDKtracer_log(file, func, lineno, M_ERROR, GDK, NULL,
-                                     "%s\n", TIMEOUT_MSG);
-                       break;
-               case QRY_INTERRUPT:
-                       GDKtracer_log(file, func, lineno, M_ERROR, GDK, NULL,
-                                     "%s\n", INTERRUPT_MSG);
-                       break;
-               case QRY_DISCONNECT:
-                       GDKtracer_log(file, func, lineno, M_ERROR, GDK, NULL,
-                                     "%s\n", DISCONNECT_MSG);
-                       break;
-               default:
-                       MT_UNREACHABLE();
-               }
+                             "%s\n", e);
        }
 }
 
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -3957,9 +3957,9 @@ bailout:
        return NULL;
 }
 
-#define HANDLE_TIMEOUT                                                 \
+#define HANDLE_TIMEOUT(qry_ctx)                                                
\
        do {                                                            \
-               GDKerror("%s\n", GDKexiting() ? EXITING_MSG : TIMEOUT_MSG); \
+               GDKerror("%s\n", TIMEOUT_MESSAGE(qry_ctx));             \
                BBPreclaim(bn);                                         \
                bn = NULL;                                              \
        } while (0)
@@ -4022,7 +4022,7 @@ BATcalcbetween(BAT *b, BAT *lo, BAT *hi,
                        bn->tkey = ci.ncand <= 1;
                        bn->tnil = nils != 0;
                        bn->tnonil = nils == 0;
-                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT);
+                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT(qry_ctx));
                }
        } else {
                bn = BATcalcbetween_intern(bi.base, 1,
@@ -4096,7 +4096,7 @@ BATcalcbetweencstcst(BAT *b, const ValRe
                        bn->tkey = ci.ncand <= 1;
                        bn->tnil = nils != 0;
                        bn->tnonil = nils == 0;
-                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT);
+                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT(qry_ctx));
                }
        } else {
                bn = BATcalcbetween_intern(bi.base, 1,
@@ -4170,7 +4170,7 @@ BATcalcbetweenbatcst(BAT *b, BAT *lo, co
                        bn->tkey = ci.ncand <= 1;
                        bn->tnil = nils != 0;
                        bn->tnonil = nils == 0;
-                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT);
+                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT(qry_ctx));
                }
        } else {
                bn = BATcalcbetween_intern(bi.base, 1,
@@ -4250,7 +4250,7 @@ BATcalcbetweencstbat(BAT *b, const ValRe
                        bn->tkey = ci.ncand <= 1;
                        bn->tnil = nils != 0;
                        bn->tnonil = nils == 0;
-                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT);
+                       TIMEOUT_CHECK(qry_ctx, HANDLE_TIMEOUT(qry_ctx));
                }
        } else {
                bn = BATcalcbetween_intern(bi.base, 1,
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
@@ -169,9 +169,7 @@ createException(enum malexception type, 
                }
                if (ret == NULL)
                        ret = createException(type, fcn, "GDK reported%s: %s",
-                                                                 strstr(p,
-                                                                               
 EXITING_MSG) == NULL ? " error" : "",
-                                                                 p);
+                                                                 strstr(p, 
EXITING_MSG) ? "" : " error", p);
                GDKclrerr();
                assert(ret);
                return ret;
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -590,11 +590,11 @@ runMALsequence(Client cntxt, MalBlkPtr m
                //Ensure we spread system resources over multiple users as well.
                runtimeProfileBegin(cntxt, mb, stk, pci, &runtimeProfile);
                if (runtimeProfile.ticks > lastcheck + CHECKINTERVAL) {
-                       if (cntxt->fdin && !mnstr_isalive(cntxt->fdin->s)) {
+                       if (cntxt->fdin && TIMEOUT_TEST(&cntxt->qryctx)) {
                                cntxt->mode = FINISHCLIENT;
                                stkpc = stoppc;
-                               ret = createException(MAL, "mal.interpreter",
-                                                                         
"prematurely stopped client");
+                               ret = createException(MAL, "mal.interpreter", 
"%s",
+                                                                         
TIMEOUT_MESSAGE(&cntxt->qryctx));
                                break;
                        }
                        lastcheck = runtimeProfile.ticks;
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -121,6 +121,7 @@ UUIDgenerateUuidInt_bulk(Client cntxt, M
        str msg = MAL_SUCCEED;
        uuid *restrict bnt = NULL;
        bat *ret = getArgReference_bat(stk, pci, 0);
+       QryCtx *qry_ctx = MT_thread_get_qry_ctx();
 
        (void) cntxt;
        if (isaBatType(getArgType(mb, pci, 1))) {
@@ -139,8 +140,9 @@ UUIDgenerateUuidInt_bulk(Client cntxt, M
                          SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
        bnt = Tloc(bn, 0);
-       for (BUN i = 0; i < n; i++)
+       TIMEOUT_LOOP_IDX_DECL(i, n, qry_ctx)
                UUIDgenerateUuid_internal(&(bnt[i]));
+       TIMEOUT_CHECK(qry_ctx, GOTO_LABEL_TIMEOUT_HANDLER(bailout, qry_ctx));
        BATsetcount(bn, n);
        bn->tnonil = true;
        bn->tnil = false;
@@ -150,6 +152,9 @@ UUIDgenerateUuidInt_bulk(Client cntxt, M
        *ret = bn->batCacheid;
        BBPkeepref(bn);
        return msg;
+  bailout:
+       BBPreclaim(bn);
+       throw(MAL, "uuid.generateuuidint_bulk", "%s", TIMEOUT_MESSAGE(qry_ctx));
 }
 
 static str
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to