Changeset: 2a99a5423302 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2a99a5423302
Modified Files:
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_exception.h
monetdb5/mal/mal_interpreter.c
monetdb5/modules/mal/tablet.c
sql/backends/monet5/sql_result.c
Branch: Dec2025
Log Message:
No need to copy exceptions to allocated memory in most cases.
We do need to do something in the tablet code, but only when we're about
done.
diffs (165 lines):
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
@@ -371,11 +371,3 @@ getExceptionMessage(const char *exceptio
msg += 6;
return msg;
}
-
-inline str
-copyException(allocator *ma, const char *exception)
-{
- if (exception)
- return ma ? ma_strdup(ma, exception) : (char *)exception;
- return 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
@@ -69,7 +69,6 @@ mal_export enum malexception getExceptio
mal_export str getExceptionPlace(allocator *ma, const char *);
mal_export str getExceptionMessageAndState(const char *);
mal_export str getExceptionMessage(const char *);
-mal_export str copyException(allocator *, const char *);
#include "mal_errors.h"
#endif /* _MAL_EXCEPTION_H */
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
@@ -366,7 +366,7 @@ runMAL(Client cntxt, MalBlkPtr mb, MalBl
* been observed due the small size of the function).
*/
}
- ret = copyException(mb->ma, runMALsequence(cntxt, mb, 1, 0, stk, env,
0));
+ ret = runMALsequence(cntxt, mb, 1, 0, stk, env, 0);
if (!stk->keepAlive && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, env != stk);
@@ -403,7 +403,7 @@ reenterMAL(Client cntxt, MalBlkPtr mb, i
if (stk == NULL)
throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
keepAlive = stk->keepAlive;
- ret = copyException(mb->ma, runMALsequence(cntxt, mb, startpc, stoppc,
stk, 0, 0));
+ ret = runMALsequence(cntxt, mb, startpc, stoppc, stk, 0, 0);
if (keepAlive == 0 && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, stk != 0);
@@ -459,7 +459,7 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
if (lhs->bat)
BBPretain(lhs->val.bval);
}
- ret = copyException(mb->ma, runMALsequence(cntxt, mb, 1, 0,
stk, 0, 0));
+ ret = runMALsequence(cntxt, mb, 1, 0, stk, 0, 0);
break;
case PATcall:
case CMDcall:
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -664,28 +664,28 @@ tablet_error(READERtask *task, lng idx,
} else if (!is_lng_nil(lineno)) {
if (!is_int_nil(col)) {
if (colnam)
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
+ task->as->error = createException(MAL,
"sql.copy_from",
"line " LLFMT ": column %d %s: %s",
-
lineno, col + 1, colnam, msg));
+
lineno, col + 1, colnam, msg);
else
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
+ task->as->error = createException(MAL,
"sql.copy_from",
"line " LLFMT ": column %d: %s",
-
lineno, col + 1, msg));
+
lineno, col + 1, msg);
} else {
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
-
"line " LLFMT ": %s", lineno, msg));
+ task->as->error = createException(MAL,
"sql.copy_from",
+
"line " LLFMT ": %s", lineno, msg);
}
} else {
if (!is_int_nil(col)) {
if (colnam)
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
+ task->as->error = createException(MAL,
"sql.copy_from",
"column %d %s: %s", col + 1, colnam,
-
msg));
+
msg);
else
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
-
"column %d: %s", col + 1, msg));
+ task->as->error = createException(MAL,
"sql.copy_from",
+
"column %d: %s", col + 1, msg);
} else {
- task->as->error = copyException(ma,
createException(MAL, "sql.copy_from", "%s", msg));
+ task->as->error = createException(MAL,
"sql.copy_from", "%s", msg);
}
}
}
@@ -1603,7 +1603,6 @@ SQLload_file(Client cntxt, Tablet *as, b
int threads = 1;
lng tio, t1 = 0;
char name[MT_NAME_LEN];
- allocator *ma = cntxt->curprg->def->ma;
allocator *ta = MT_thread_getallocator();
allocator_state ta_state = ma_open(ta);
@@ -1692,8 +1691,8 @@ SQLload_file(Client cntxt, Tablet *as, b
task.fields[i] = ma_alloc(ta, sizeof(char *) * task.limit);
if (task.fields[i] == NULL) {
if (task.as->error == NULL)
- as->error = copyException(ma,
createException(MAL, "sql.copy_from",
-
SQLSTATE(HY013) MAL_MALLOC_FAIL));
+ as->error = createException(MAL,
"sql.copy_from",
+
SQLSTATE(HY013) MAL_MALLOC_FAIL);
goto bailout;
}
task.cols[i] = (int) (i + 1); /* to distinguish non
initialized later with zero */
@@ -1934,7 +1933,6 @@ SQLload_file(Client cntxt, Tablet *as, b
/* TRC_DEBUG(MAL_SERVER, "Shut down reader\n");*/
MT_sema_up(&task.producer);
}
- MT_join_thread(task.tid);
/* TRC_DEBUG(MAL_SERVER, "Activate endofcopy\n");*/
@@ -1946,8 +1944,21 @@ SQLload_file(Client cntxt, Tablet *as, b
for (j = 0; j < threads; j++)
MT_sema_down(&ptask[j].reply);
+ /* it may be that there was an error which may have been produced by
+ * one of the worker threads; if so, copy the error message to our
+ * own exception buffer since the worker thread's exception buffer
+ * will be destroyed when we join the thread */
+ if (as->error) {
+ char *msg = MT_thread_get_exceptbuf();
+ if (as->error != msg) {
+ strcpy_len(msg, as->error, GDKMAXERRLEN);
+ as->error = msg;
+ }
+ }
+
/* TRC_DEBUG(MAL_SERVER, "Kill the workers\n");*/
+ MT_join_thread(task.tid);
for (j = 0; j < threads; j++) {
MT_join_thread(ptask[j].tid);
// GDKfree(ptask[j].cols);
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
@@ -707,7 +707,12 @@ mvc_import_table(Client cntxt, BAT ***ba
}
}
if (as.error) {
- if( !best) msg = createException(SQL, "sql.copy_from",
SQLSTATE(42000) "Failed to import table '%s', %s", t->base.name,
getExceptionMessage(as.error));
+ if (!best) {
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
+ msg = createException(SQL, "sql.copy_from",
SQLSTATE(42000) "Failed to import table '%s', %s", t->base.name, ma_strdup(ta,
getExceptionMessage(as.error)));
+ ma_close(ta, &ta_state);
+ }
freeException(as.error);
as.error = NULL;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]