From b6d40d3ebff37a5d50cb24e0595d7c4ef8254c1d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 5 Nov 2020 22:27:01 +0800 Subject: [PATCH 1/4] [TD-1941]: fix client crash in join query while connection broken. --- src/client/src/tscAsync.c | 16 +++++++++++++++- src/client/src/tscParseInsert.c | 2 +- src/client/src/tscSubquery.c | 2 +- src/vnode/src/vnodeRead.c | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index e70cd11fbe..99c03c6580 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -428,6 +428,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { } else { assert(code == TSDB_CODE_SUCCESS); } + // param already freed by other routine and pSql in tscCache when ctrl + c if (atomic_load_ptr(&pSql->param) == NULL) { return; @@ -441,6 +442,20 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex && pTableMetaInfo->vgroupIndex >= 0 && pTableMetaInfo->vgroupList != NULL); + // tscProcessSql can add error into async res + tscProcessSql(pSql); + return; + } else if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) { + tscDebug("%p update table meta in local cache, continue to process sql and send corresponding tid_tag query", pSql); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + code = tscGetTableMeta(pSql, pTableMetaInfo); + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + return; + } else { + assert(code == TSDB_CODE_SUCCESS); + } + + assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0)); // tscProcessSql can add error into async res tscProcessSql(pSql); return; @@ -465,7 +480,6 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { tscResetSqlCmdObj(pCmd, false); code = tsParseSql(pSql, true); - if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { return; } else if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 5e65126ef6..f960beb5d9 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1309,7 +1309,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) { if ((!pCmd->parseFinished) && (!initial)) { tscDebug("%p resume to parse sql: %s", pSql, pCmd->curSql); } - + ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); if (TSDB_CODE_SUCCESS != ret) { return ret; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index fd56001174..4b6dde902c 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -523,7 +523,7 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) { assert(pSqlObj->subState.numOfRemain > 0); if (atomic_sub_fetch_32(&pSqlObj->subState.numOfRemain, 1) <= 0) { - tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code); + tscError("%p all subquery return and query failed, global code:%s", pSqlObj, tstrerror(pSqlObj->res.code)); freeJoinSubqueryObj(pSqlObj); } } diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index faa35b0e02..dd38a2d9c5 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -298,7 +298,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) { } if (code != TSDB_CODE_SUCCESS) { - vDebug("vgId:%d, invalid handle in retrieving result, code:0x%08x, QInfo:%p", pVnode->vgId, code, (void *)pRetrieve->qhandle); + vError("vgId:%d, invalid handle in retrieving result, code:0x%08x, QInfo:%p", pVnode->vgId, code, (void *)pRetrieve->qhandle); vnodeBuildNoResultQueryRsp(pRet); return code; } From bd87ba990ca74daccaa2a3ae21b607e70e7e7e28 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 5 Nov 2020 23:08:42 +0800 Subject: [PATCH 2/4] [TD-225] fix memory leak. --- src/query/src/qAst.c | 1 - src/query/src/qExecutor.c | 3 ++- src/query/src/qFill.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/query/src/qAst.c b/src/query/src/qAst.c index 847a8b8eb6..bc2866fb6f 100644 --- a/src/query/src/qAst.c +++ b/src/query/src/qAst.c @@ -32,7 +32,6 @@ #include "tstoken.h" #include "ttokendef.h" #include "tulog.h" -#include "tutil.h" /* * diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index b365dc4283..b992a037ed 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1609,7 +1609,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order pRuntimeEnv->pCtx = (SQLFunctionCtx *)calloc(pQuery->numOfOutput, sizeof(SQLFunctionCtx)); pRuntimeEnv->rowCellInfoOffset = calloc(pQuery->numOfOutput, sizeof(int32_t)); - pRuntimeEnv->pResultRow = getNewResultRow(pRuntimeEnv->pool);//calloc(1, sizeof(SResultRow)); + pRuntimeEnv->pResultRow = getNewResultRow(pRuntimeEnv->pool); if (pRuntimeEnv->pResultRow == NULL || pRuntimeEnv->pCtx == NULL || pRuntimeEnv->rowCellInfoOffset == NULL) { goto _clean; @@ -1745,6 +1745,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { pRuntimeEnv->pTSBuf = tsBufDestroy(pRuntimeEnv->pTSBuf); taosTFree(pRuntimeEnv->keyBuf); + taosTFree(pRuntimeEnv->rowCellInfoOffset); taosHashCleanup(pRuntimeEnv->pResultRowHashTable); pRuntimeEnv->pResultRowHashTable = NULL; diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index a219bd6abd..788779b2bb 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -170,7 +170,7 @@ int64_t getFilledNumOfRes(SFillInfo* pFillInfo, TSKEY ekey, int32_t maxNumOfRows int32_t numOfRows = taosNumOfRemainRows(pFillInfo); TSKEY ekey1 = ekey; - if (pFillInfo->order != TSDB_ORDER_ASC) { + if (!FILL_IS_ASC_FILL(pFillInfo)) { pFillInfo->endKey = taosTimeTruncate(ekey, &pFillInfo->interval, pFillInfo->precision); } From 2b07f83bbea9ca9610f21973bb7ddc45ed7fb4e4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 6 Nov 2020 10:27:19 +0800 Subject: [PATCH 3/4] [TD-225] --- src/query/inc/tsqlfunction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index 3bd4aad276..84ca78d822 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -149,7 +149,7 @@ typedef struct SResultRowCellInfo { int8_t hasResult; // result generated, not NULL value bool initialized; // output buffer has been initialized bool complete; // query has completed - uint16_t numOfRes; // num of output result in current buffer + uint32_t numOfRes; // num of output result in current buffer } SResultRowCellInfo; #define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo))) From 1fed1db16a9dcce63f62139c8b9cf636cfaae710 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 6 Nov 2020 11:02:33 +0800 Subject: [PATCH 4/4] [TD-225] --- src/client/src/tscSubquery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 4b6dde902c..b3d151ba27 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -565,7 +565,7 @@ int32_t tagValCompar(const void* p1, const void* p2) { return (tag1->len > tag2->len)? 1: -1; } - return strncmp(tag1->data, tag2->data, tag1->len); + return memcmp(tag1->data, tag2->data, tag1->len); } void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArray* tables) {