From c65c9c72c47afd7ff4c57f2af6a4734f9503a08c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 14 Nov 2023 19:25:54 +0800 Subject: [PATCH] fix: change query killed error msg --- include/util/taoserror.h | 1 + source/libs/scheduler/src/schStatus.c | 2 +- source/util/src/terror.c | 1 + tools/shell/src/shellEngine.c | 26 +++++++++++++++++++------- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 04c6c0cbaf..a3ee294338 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -640,6 +640,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SCH_IGNORE_ERROR TAOS_DEF_ERROR_CODE(0, 0x2503) #define TSDB_CODE_SCH_TIMEOUT_ERROR TAOS_DEF_ERROR_CODE(0, 0x2504) #define TSDB_CODE_SCH_JOB_IS_DROPPING TAOS_DEF_ERROR_CODE(0, 0x2505) +#define TSDB_CODE_SCH_JOB_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x2506) //parser #define TSDB_CODE_PAR_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x2600) diff --git a/source/libs/scheduler/src/schStatus.c b/source/libs/scheduler/src/schStatus.c index 9d0ad30e2a..d37393137f 100644 --- a/source/libs/scheduler/src/schStatus.c +++ b/source/libs/scheduler/src/schStatus.c @@ -68,7 +68,7 @@ int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SS SSchJob* pJob = schAcquireJob(jobId); if (NULL == pJob) { qDebug("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, jobId); - SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); + SCH_ERR_RET(TSDB_CODE_SCH_JOB_NOT_EXISTS); } *job = pJob; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b4448c36c2..21022f2016 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -504,6 +504,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SCH_STATUS_ERROR, "scheduler status erro TAOS_DEFINE_ERROR(TSDB_CODE_SCH_INTERNAL_ERROR, "scheduler internal error") TAOS_DEFINE_ERROR(TSDB_CODE_SCH_TIMEOUT_ERROR, "Task timeout") TAOS_DEFINE_ERROR(TSDB_CODE_SCH_JOB_IS_DROPPING, "Job is dropping") +TAOS_DEFINE_ERROR(TSDB_CODE_SCH_JOB_NOT_EXISTS, "Job no longer exist") // parser TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYNTAX_ERROR, "syntax error near") diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 8926d21534..115abdcd36 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -62,6 +62,8 @@ static void shellCleanup(void *arg); static void *shellCancelHandler(void *arg); static void *shellThreadLoop(void *arg); +static bool shellCmdkilled = false; + bool shellIsEmptyCommand(const char *cmd) { for (char c = *cmd++; c != 0; c = *cmd++) { if (c != ' ' && c != '\t' && c != ';') { @@ -72,6 +74,8 @@ bool shellIsEmptyCommand(const char *cmd) { } int32_t shellRunSingleCommand(char *command) { + shellCmdkilled = false; + if (shellIsEmptyCommand(command)) { return 0; } @@ -257,7 +261,8 @@ void shellRunSingleCommandImp(char *command) { if (error_no == 0) { printf("Query OK, %"PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { - printf("Query interrupted (%s), %"PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); + terrno = error_no; + printf("Query interrupted (%s), %"PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, (et - st) / 1E6); } taos_free_result(pSql); } else { @@ -952,7 +957,11 @@ void shellDumpResultCallback(void *param, TAOS_RES *tres, int num_of_rows) { } } dump_info->numOfAllRows += num_of_rows; - taos_fetch_rows_a(tres, shellDumpResultCallback, param); + if (!shellCmdkilled) { + taos_fetch_rows_a(tres, shellDumpResultCallback, param); + } else { + tsem_post(&dump_info->sem); + } } else { if (num_of_rows < 0) { printf("\033[31masync retrieve failed, code: %d\033[0m\n", num_of_rows); @@ -967,13 +976,15 @@ int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool ver num_of_rows = shellDumpResultToFile(fname, tres); } else { tsDumpInfo dump_info; - init_dump_info(&dump_info, tres, sql, vertical); - taos_fetch_rows_a(tres, shellDumpResultCallback, &dump_info); - tsem_wait(&dump_info.sem); - num_of_rows = dump_info.numOfAllRows; + if (!shellCmdkilled) { + init_dump_info(&dump_info, tres, sql, vertical); + taos_fetch_rows_a(tres, shellDumpResultCallback, &dump_info); + tsem_wait(&dump_info.sem); + num_of_rows = dump_info.numOfAllRows; + } } - *error_no = taos_errno(tres); + *error_no = shellCmdkilled ? TSDB_CODE_TSC_QUERY_KILLED : taos_errno(tres); return num_of_rows; } @@ -1197,6 +1208,7 @@ void *shellCancelHandler(void *arg) { } else { #endif if (shell.conn) { + shellCmdkilled = true; taos_kill_query(shell.conn); } #ifdef WEBSOCKET