[td-225] refactor shell code to support ctrl+c.
This commit is contained in:
parent
f22098b6dd
commit
74fdb1c2aa
|
@ -455,35 +455,20 @@ void tscKillSTableQuery(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < pSql->numOfSubs; ++i) {
|
||||
// NOTE: pSub may have been released already here
|
||||
SSqlObj *pSub = pSql->pSubs[i];
|
||||
if (pSub == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pSub->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
if (pSub->pRpcCtx != NULL) {
|
||||
rpcCancelRequest(pSub->pRpcCtx);
|
||||
}
|
||||
|
||||
pSub->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
tscQueueAsyncRes(pSub);
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. if the subqueries are not launched or partially launched, we need to waiting the launched
|
||||
* query return to successfully free allocated resources.
|
||||
* 2. if no any subqueries are launched yet, which means the super table query only in parse sql stage,
|
||||
* set the res.code, and return.
|
||||
*/
|
||||
const int64_t MAX_WAITING_TIME = 10000; // 10 Sec.
|
||||
int64_t stime = taosGetTimestampMs();
|
||||
|
||||
while (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command != TSDB_SQL_RETRIEVE_EMPTY_RESULT) {
|
||||
taosMsleep(100);
|
||||
if (taosGetTimestampMs() - stime > MAX_WAITING_TIME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tscDebug("%p super table query cancelled", pSql);
|
||||
}
|
||||
|
||||
|
|
|
@ -669,15 +669,19 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
// It may have been released by the other thread already.
|
||||
// The ref count may fix this problem.
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
tscKillSTableQuery(pSql);
|
||||
}
|
||||
|
||||
// set the error code for master pSqlObj firstly
|
||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
assert(pSql->pRpcCtx == NULL);
|
||||
tscKillSTableQuery(pSql);
|
||||
} else {
|
||||
if (pSql->cmd.command < TSDB_SQL_LOCAL) {
|
||||
rpcCancelRequest(pSql->pRpcCtx);
|
||||
}
|
||||
}
|
||||
|
||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
tscDebug("%p query is cancelled", res);
|
||||
}
|
||||
|
||||
|
|
|
@ -1463,9 +1463,14 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
|||
static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
||||
tscDebug("%p start to free subquery result", pSql);
|
||||
|
||||
int32_t index = trsupport->subqueryIndex;
|
||||
SSqlObj *pParentSql = trsupport->pParentSql;
|
||||
|
||||
assert(pSql == pParentSql->pSubs[index]);
|
||||
pParentSql->pSubs[index] = NULL;
|
||||
|
||||
taos_free_result(pSql);
|
||||
taosTFree(trsupport->localBuffer);
|
||||
|
||||
taosTFree(trsupport);
|
||||
}
|
||||
|
||||
|
@ -1474,17 +1479,7 @@ static void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, i
|
|||
|
||||
static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t code) {
|
||||
// set no disk space error info
|
||||
#ifdef WINDOWS
|
||||
LPVOID lpMsgBuf;
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
||||
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||
(LPTSTR)&lpMsgBuf, 0, NULL);
|
||||
tscError("sub:%p failed to flush data to disk:reason:%s", tres, lpMsgBuf);
|
||||
LocalFree(lpMsgBuf);
|
||||
#else
|
||||
tscError("sub:%p failed to flush data to disk, reason:%s", tres, tstrerror(code));
|
||||
#endif
|
||||
|
||||
SSqlObj* pParentSql = trsupport->pParentSql;
|
||||
|
||||
pParentSql->res.code = code;
|
||||
|
@ -1548,14 +1543,14 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
|
|||
*/
|
||||
pSql->res.numOfRows = 0;
|
||||
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts
|
||||
tscDebug("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d", pParentSql, pSql,
|
||||
subqueryIndex, pParentSql->res.code);
|
||||
tscDebug("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%s", pParentSql, pSql,
|
||||
subqueryIndex, tstrerror(pParentSql->res.code));
|
||||
}
|
||||
|
||||
if (numOfRows >= 0) { // current query is successful, but other sub query failed, still abort current query.
|
||||
tscDebug("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pParentSql, pSql, numOfRows, subqueryIndex);
|
||||
tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pParentSql, pSql,
|
||||
subqueryIndex, pParentSql->res.code);
|
||||
tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%s", pParentSql, pSql,
|
||||
subqueryIndex, tstrerror(pParentSql->res.code));
|
||||
} else {
|
||||
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) {
|
||||
if (tscReissueSubquery(trsupport, pSql, numOfRows) == TSDB_CODE_SUCCESS) {
|
||||
|
|
Loading…
Reference in New Issue