[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) {
|
for (int i = 0; i < pSql->numOfSubs; ++i) {
|
||||||
|
// NOTE: pSub may have been released already here
|
||||||
SSqlObj *pSub = pSql->pSubs[i];
|
SSqlObj *pSub = pSql->pSubs[i];
|
||||||
if (pSub == NULL) {
|
if (pSub == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pSub->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||||
if (pSub->pRpcCtx != NULL) {
|
if (pSub->pRpcCtx != NULL) {
|
||||||
rpcCancelRequest(pSub->pRpcCtx);
|
rpcCancelRequest(pSub->pRpcCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pSub->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
|
||||||
tscQueueAsyncRes(pSub);
|
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);
|
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.
|
// It may have been released by the other thread already.
|
||||||
// The ref count may fix this problem.
|
// The ref count may fix this problem.
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
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) {
|
if (pSql->cmd.command < TSDB_SQL_LOCAL) {
|
||||||
rpcCancelRequest(pSql->pRpcCtx);
|
rpcCancelRequest(pSql->pRpcCtx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
|
||||||
tscDebug("%p query is cancelled", res);
|
tscDebug("%p query is cancelled", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1463,9 +1463,14 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||||
static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
||||||
tscDebug("%p start to free subquery result", 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);
|
taos_free_result(pSql);
|
||||||
taosTFree(trsupport->localBuffer);
|
taosTFree(trsupport->localBuffer);
|
||||||
|
|
||||||
taosTFree(trsupport);
|
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) {
|
static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t code) {
|
||||||
// set no disk space error info
|
// 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));
|
tscError("sub:%p failed to flush data to disk, reason:%s", tres, tstrerror(code));
|
||||||
#endif
|
|
||||||
|
|
||||||
SSqlObj* pParentSql = trsupport->pParentSql;
|
SSqlObj* pParentSql = trsupport->pParentSql;
|
||||||
|
|
||||||
pParentSql->res.code = code;
|
pParentSql->res.code = code;
|
||||||
|
@ -1548,14 +1543,14 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
|
||||||
*/
|
*/
|
||||||
pSql->res.numOfRows = 0;
|
pSql->res.numOfRows = 0;
|
||||||
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts
|
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,
|
tscDebug("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%s", pParentSql, pSql,
|
||||||
subqueryIndex, pParentSql->res.code);
|
subqueryIndex, tstrerror(pParentSql->res.code));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOfRows >= 0) { // current query is successful, but other sub query failed, still abort current query.
|
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);
|
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,
|
tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%s", pParentSql, pSql,
|
||||||
subqueryIndex, pParentSql->res.code);
|
subqueryIndex, tstrerror(pParentSql->res.code));
|
||||||
} else {
|
} else {
|
||||||
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) {
|
if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) {
|
||||||
if (tscReissueSubquery(trsupport, pSql, numOfRows) == TSDB_CODE_SUCCESS) {
|
if (tscReissueSubquery(trsupport, pSql, numOfRows) == TSDB_CODE_SUCCESS) {
|
||||||
|
|
Loading…
Reference in New Issue