Changeset: 7450987b4dba for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/7450987b4dba
Modified Files:
clients/mapiclient/mclient.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_scenario.c
Branch: client_interrupts
Log Message:
More interrupt handling.
When interrupted after query was sent but before a response comes in, we
can now also abort.
Clean up out-of-band messages before starting to read a new query on the
server side.
diffs (135 lines):
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1405,6 +1405,7 @@ SQLpagemove(int *len, int fields, int *p
if (sz < 0 && mnstr_errnr(fromConsole) == MNSTR_INTERRUPT) {
/* interrupted, equivalent to typing 'q' */
mnstr_clearerr(fromConsole);
+ mnstr_printf(toConsole, "\n");
*skiprest = true;
} else if (sz > 0) {
if (buf[0] == 'c')
@@ -1422,14 +1423,16 @@ SQLpagemove(int *len, int fields, int *p
static volatile sig_atomic_t state;
#define READING 1
#define WRITING 2
+#define QUERYING 3
#define IDLING 0
+#define INTERRUPT (-1)
static void
sigint_handler(int signum)
{
(void) signum;
- state = IDLING;
+ state = INTERRUPT;
#ifdef HAVE_LIBREADLINE
readline_int_handler();
#endif
@@ -1469,6 +1472,13 @@ SQLrenderer(MapiHdl hdl)
exit(2);
}
+ if (state == INTERRUPT) {
+ free(len);
+ free(hdr);
+ free(rest);
+ free(numeric);
+ return;
+ }
state = WRITING;
total = 0;
@@ -1651,14 +1661,15 @@ SQLrenderer(MapiHdl hdl)
if (ps > 0 && lines >= ps && fromConsole != NULL) {
SQLpagemove(len, printfields, &ps, &skiprest);
- lines = 0;
if (skiprest) {
mapi_finish(hdl);
break;
}
+ lines = 0;
}
- if (state == IDLING) {
+ if (state == INTERRUPT) {
+ skiprest = true;
mapi_finish(hdl);
break;
}
@@ -1666,6 +1677,7 @@ SQLrenderer(MapiHdl hdl)
nrows++;
lines += SQLrow(len, numeric, rest, printfields, 2, 0);
}
+ state = IDLING;
if (fields && !skiprest)
SQLseparator(len, printfields, '-');
if (skiprest)
@@ -1970,6 +1982,8 @@ format_result(Mapi mid, MapiHdl hdl, boo
SQLdebugRendering(hdl);
continue;
}
+ if (state == INTERRUPT)
+ break;
if (debugMode())
RAWrenderer(hdl);
else {
@@ -2014,7 +2028,7 @@ format_result(Mapi mid, MapiHdl hdl, boo
timerHuman(sqloptimizer, maloptimizer, querytime,
singleinstr, false);
}
- } while (mnstr_errnr(toConsole) == MNSTR_NO__ERROR && (rc =
mapi_next_result(hdl)) == 1);
+ } while (state != INTERRUPT && mnstr_errnr(toConsole) ==
MNSTR_NO__ERROR && (rc = mapi_next_result(hdl)) == 1);
/*
* in case we called timerHuman() in the loop above with "total ==
false",
* call it again with "total == true" to get the total wall-clock time
@@ -2031,6 +2045,10 @@ format_result(Mapi mid, MapiHdl hdl, boo
end_pager(saveFD);
#endif
+ if (state == INTERRUPT)
+ mnstr_printf(toConsole, "\n");
+ state = IDLING;
+
return rc;
}
@@ -2395,7 +2413,7 @@ doFile(Mapi mid, stream *fp, bool useins
char *newbuf;
state = READING;
l = mnstr_readline(fp, buf + length, bufsiz - length);
- if (l == -1 && state == IDLING) {
+ if (l == -1 && state == INTERRUPT) {
/* we were interrupted */
mnstr_clearerr(fp);
mnstr_write(toConsole, "\n", 1, 1);
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
@@ -2480,8 +2480,10 @@ mvc_result_set_wrap( Client cntxt, MalBl
bat_iterator_end(&iterdig);
bat_iterator_end(&iterscl);
/* now send it to the channel cntxt->fdout */
- if (!msg && (ok = mvc_export_result(cntxt->sqlcontext, cntxt->fdout,
res, true, cntxt->qryctx.starttime, mb->optimize)) < 0)
- msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(cntxt->sqlcontext,
cntxt->fdout, ok));
+ if (bstream_getoob(cntxt->fdin))
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY000)
"Query aboted");
+ else if (!msg && (ok = mvc_export_result(be, cntxt->fdout, res, true,
cntxt->qryctx.starttime, mb->optimize)) < 0)
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(be, cntxt->fdout, ok));
wrapup_result_set:
cntxt->qryctx.starttime = 0;
cntxt->qryctx.endtime = 0;
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1069,6 +1069,8 @@ SQLreader(Client c, backend *be)
}
in->eof = false;
}
+ while (bstream_getoob(in) > 0)
+ ;
if (in->buf == NULL) {
more = false;
go = false;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]