From 1df7f8d274a2c44cb7a503ea86a87fededa256b1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 6 Jun 2022 23:06:25 +0800 Subject: [PATCH 01/21] test:update some test scripts. --- tests/script/tsim/query/complex_having.sim | 12 ++++++------ tests/script/tsim/query/crash_sql.sim | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/script/tsim/query/complex_having.sim b/tests/script/tsim/query/complex_having.sim index ef58228f34..6a4aa6ea28 100644 --- a/tests/script/tsim/query/complex_having.sim +++ b/tests/script/tsim/query/complex_having.sim @@ -105,7 +105,7 @@ endi sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> rows: $rows -if $rows != 7 then +if $rows != 8 then return -1 endi @@ -214,9 +214,9 @@ print =================== count all rows sql select count(c1) from stb1 print ====> sql : select count(c1) from stb1 print ====> rows: $data00 -if $data00 != 20 then - print expect 20, actual: $data00 - return -1 +if $data00 != 17 then + print expect 17, actual: $data00 + return -1 endi #================================================= @@ -246,7 +246,7 @@ print =================== count all rows sql select count(c1) from stb1 print ====> sql : select count(c1) from stb1 print ====> rows: $data00 -if $data00 != 20 then +if $data00 != 17 then return -1 endi @@ -279,7 +279,7 @@ endi sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> rows: $rows -if $rows != 7 then +if $rows != 8 then return -1 endi diff --git a/tests/script/tsim/query/crash_sql.sim b/tests/script/tsim/query/crash_sql.sim index 44671fbb0d..b2b9239232 100644 --- a/tests/script/tsim/query/crash_sql.sim +++ b/tests/script/tsim/query/crash_sql.sim @@ -25,7 +25,7 @@ sql connect print =============== create database sql create database db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi @@ -96,8 +96,6 @@ sql insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, print ================ start query ====================== print ================ SQL used to cause taosd or taos shell crash -sql select sum(c1) ,count(c1) from ct4 group by c1 having sum(c10) between 0 and 1 ; - - +sql_error select sum(c1) ,count(c1) from ct4 group by c1 having sum(c10) between 0 and 1 ; #system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From aba3ea28b5f1c1eb1bee319681d221cf96c76fae Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 6 Jun 2022 23:35:25 +0800 Subject: [PATCH 02/21] refactor: do some internal refactor. --- source/client/inc/clientInt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 0630704d93..4ba74af5e6 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -45,7 +45,7 @@ extern "C" { #define ERROR_MSG_BUF_DEFAULT_SIZE 512 #define HEARTBEAT_INTERVAL 1500 // ms -#define SYNC_ON_TOP_OF_ASYNC 0 +#define SYNC_ON_TOP_OF_ASYNC 1 enum { RES_TYPE__QUERY = 1, From 3e6bb0558131d91e414708a94bd1c57bf6eafdb9 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 6 Jun 2022 23:39:54 +0800 Subject: [PATCH 03/21] refactor: do some internal refactor. --- source/client/src/clientMain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index d192b65bf0..bcc9447fb3 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -500,7 +500,11 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { return 0; } - doFetchRows(pRequest, false, true); +#if SYNC_ON_TOP_OF_ASYNC + doAsyncFetchRow(pRequest, false, true); +#else + doFetchRows(pRequest, true, true); +#endif // TODO refactor SReqResultInfo *pResultInfo = &pRequest->body.resInfo; From 9740ccf9fa46e7b8262b81a58e3c75cc6a7973a2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 7 Jun 2022 09:08:44 +0800 Subject: [PATCH 04/21] test:update test case. --- source/client/test/clientTests.cpp | 31 +----------------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index f16baba0e7..853db80b09 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -772,41 +772,12 @@ create table m1(ts timestamp, k int) tags(a int); create table tm0 using m1 tags(1); create table tm1 using m1 tags(2); insert into tm0 values('2021-1-1 1:1:1.120', 1) ('2021-1-1 1:1:2.9', 2) tm1 values('2021-1-1 1:1:1.120', 11) ('2021-1-1 1:1:2.99', 22); - */ TEST(testCase, async_api_test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - taos_query(pConn, "use test"); - - TAOS_RES* pRes = taos_query(pConn, "select * from t1"); - - taos_query(pConn, "alter table t1 add column b int"); - pRes = taos_query(pConn, "insert into t1 values(now, 1, 2)"); - if (taos_errno(pRes) != 0) { - printf("failed, reason:%s\n", taos_errstr(pRes)); - } - -// int32_t n = 0; -// TAOS_ROW pRow = NULL; -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while ((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t* length = taos_fetch_lengths(pRes); -// for(int32_t i = 0; i < numOfFields; ++i) { -// printf("(%d):%d " , i, length[i]); -// } -// printf("\n"); -// -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// memset(str, 0, sizeof(str)); -// } - - taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn); + taos_query_a(pConn, "alter database test keep 2400", queryCallback, pConn); getchar(); taos_close(pConn); } From 6c6259c51b8b398f6868cc90e3aee049cf668698 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 7 Jun 2022 09:27:27 +0800 Subject: [PATCH 05/21] fix: a problem of parser async --- source/libs/parser/src/parAstParser.c | 6 ++++++ source/libs/parser/test/parInitialATest.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index c79820a950..e6a905103a 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -179,6 +179,10 @@ static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* p return cxt.errCode; } +static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterDatabaseStmt* pStmt) { + return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); +} + static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTableStmt* pStmt) { int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTags) { @@ -376,6 +380,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromSetOperator(pCxt, (SSetOperator*)pStmt); case QUERY_NODE_SELECT_STMT: return collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt); + case QUERY_NODE_ALTER_DATABASE_STMT: + return collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt); case QUERY_NODE_CREATE_TABLE_STMT: return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt); case QUERY_NODE_CREATE_MULTI_TABLE_STMT: diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index 784586dfb2..595aa049fd 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -39,6 +39,8 @@ TEST_F(ParserInitialATest, alterDatabase) { useDb("root", "test"); run("ALTER DATABASE wxy_db CACHELAST 1 FSYNC 200 WAL 1"); + + run("ALTER DATABASE wxy_db KEEP 2400"); } // todo ALTER local From fb07e8b73eb67bfc401379f6cbb1c6437e26943b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 7 Jun 2022 11:15:33 +0800 Subject: [PATCH 06/21] refactor:do some internal refactor and add some logs. --- source/client/src/clientImpl.c | 3 ++- source/client/src/clientMain.c | 11 +++++++---- source/libs/catalog/src/ctgAsync.c | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c71c7d3487..7601e082e4 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -580,7 +580,8 @@ void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) { STscObj* pTscObj = pRequest->pTscObj; if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code)) { - tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); + tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), + pRequest->retry, pRequest->requestId); pRequest->prevCode = code; doAsyncQuery(pRequest, true); return; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index bcc9447fb3..3ca93d178c 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -629,8 +629,10 @@ void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) { taosMemoryFree(pWrapper); launchAsyncQuery(pRequest, pQuery); } else { + tscDebug("error happens, code:%d", code); if (NEED_CLIENT_HANDLE_ERROR(code)) { - tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); + tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), + pRequest->retry, pRequest->requestId); pRequest->prevCode = code; doAsyncQuery(pRequest, true); return; @@ -703,13 +705,14 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) { void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) { SParseContext* pCxt = NULL; STscObj *pTscObj = pRequest->pTscObj; + int32_t code = 0; if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) { - pRequest->code = pRequest->prevCode; + code = pRequest->prevCode; goto _error; } - int32_t code = createParseContext(pRequest, &pCxt); + code = createParseContext(pRequest, &pCxt); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -746,7 +749,7 @@ void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) { } _error: - tscError("0x%"PRIx64" error happens, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); + tscError("0x%"PRIx64" error happens, code:%d - %s, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), pRequest->requestId); terrno = code; pRequest->code = code; pRequest->body.queryFp(pRequest->body.param, pRequest, code); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index f43e559244..63df81e73c 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -559,7 +559,7 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { SCtgJob* pJob = pTask->pJob; int32_t code = 0; - qDebug("QID:%" PRIx64 " task %d end with rsp %s", pJob->queryId, pTask->taskId, tstrerror(rspCode)); + qDebug("QID:0x%" PRIx64 " task %d end with rsp %s", pJob->queryId, pTask->taskId, tstrerror(rspCode)); if (rspCode) { int32_t lastCode = atomic_val_compare_exchange_32(&pJob->rspCode, 0, rspCode); @@ -572,7 +572,7 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { int32_t taskDone = atomic_add_fetch_32(&pJob->taskDone, 1); if (taskDone < taosArrayGetSize(pJob->pTasks)) { - qDebug("task done: %d, total: %d", taskDone, (int32_t)taosArrayGetSize(pJob->pTasks)); + qDebug("QID:0x%" PRIx64 " task done: %d, total: %d", pJob->queryId, taskDone, (int32_t)taosArrayGetSize(pJob->pTasks)); return TSDB_CODE_SUCCESS; } From 8a00b3ab86bdf9a5fd0ff85749778208cc72e973 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 7 Jun 2022 11:43:25 +0800 Subject: [PATCH 07/21] test: update test cases. --- source/client/test/clientTests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 853db80b09..0950fc3923 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -772,12 +772,13 @@ create table m1(ts timestamp, k int) tags(a int); create table tm0 using m1 tags(1); create table tm1 using m1 tags(2); insert into tm0 values('2021-1-1 1:1:1.120', 1) ('2021-1-1 1:1:2.9', 2) tm1 values('2021-1-1 1:1:1.120', 11) ('2021-1-1 1:1:2.99', 22); + */ TEST(testCase, async_api_test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - taos_query_a(pConn, "alter database test keep 2400", queryCallback, pConn); + taos_query_a(pConn, "insert into tm0 values(now()+0s, 1)", queryCallback, pConn); getchar(); taos_close(pConn); } From ac0c75ab2dd76d2dddf5e5dc35473b45a6affe50 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 7 Jun 2022 13:28:33 +0800 Subject: [PATCH 08/21] fix: a problem of parser async --- source/libs/parser/src/parAstParser.c | 3 ++- source/libs/parser/src/parInsert.c | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index e6a905103a..f05987c307 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -110,7 +110,8 @@ static EDealRes collectMetaKeyFromFunction(SCollectMetaKeyFromExprCxt* pCxt, SFu if (fmIsBuiltinFunc(pFunc->functionName)) { return TSDB_CODE_SUCCESS; } - return reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache); + pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache); + return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR; } static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, SRealTableNode* pRealTable, diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 8f17d500ab..2cfc06b575 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1006,7 +1006,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint } SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]]; - char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); //todo this can be optimize with parse column + char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); // todo this can be optimize with parse column code = checkAndTrimValue(&sToken, tmpTokenBuf, &pCxt->msg); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(tmpTokenBuf); @@ -1018,7 +1018,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint taosMemoryFree(tmpTokenBuf); goto end; } - if(isNullStr(&sToken)) { + if (isNullStr(&sToken)) { code = tTagNew(pTagVals, 1, true, &pTag); } else { code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg); @@ -1530,10 +1530,13 @@ typedef struct SInsertParseSyntaxCxt { } SInsertParseSyntaxCxt; static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) { - SToken sToken; + SToken sToken; + int32_t expectRightParenthesis = 1; while (1) { NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_RP == sToken.type) { + if (TK_NK_LP == sToken.type) { + ++expectRightParenthesis; + } else if (TK_NK_RP == sToken.type && 0 == --expectRightParenthesis) { break; } if (0 == sToken.n) { From cd90a9fa302837bf9d980d3af8beb63634a818bb Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 7 Jun 2022 14:26:18 +0800 Subject: [PATCH 09/21] add error code for each task --- include/libs/catalog/catalog.h | 23 ++++++----- source/libs/catalog/inc/catalogInt.h | 12 +++--- source/libs/catalog/src/ctgAsync.c | 59 ++++++++++++++++------------ source/libs/catalog/src/ctgUtil.c | 10 ++++- 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index ee237741c3..567719e3f0 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -71,16 +71,21 @@ typedef struct SCatalogReq { bool forceUpdate; } SCatalogReq; +typedef struct SMetaRes { + int32_t code; + void* pRes; +} SMetaRes; + typedef struct SMetaData { - SArray *pDbVgroup; // SArray*> - SArray *pDbCfg; // SArray - SArray *pDbInfo; // SArray - SArray *pTableMeta; // SArray - SArray *pTableHash; // SArray - SArray *pUdfList; // SArray - SArray *pIndex; // SArray - SArray *pUser; // SArray - SArray *pQnodeList; // SArray + SArray *pDbVgroup; // pRes = SArray* + SArray *pDbCfg; // pRes = SDbCfgInfo* + SArray *pDbInfo; // pRes = SDbInfo* + SArray *pTableMeta; // pRes = STableMeta* + SArray *pTableHash; // pRes = SVgroupInfo* + SArray *pUdfList; // pRes = SFuncInfo* + SArray *pIndex; // pRes = SIndexInfo* + SArray *pUser; // pRes = bool* + SArray *pQnodeList; // pRes = SQueryNodeAddr* } SMetaData; typedef struct SCatalogCfg { diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 1eec92f47e..0ea45cdd7e 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -173,7 +173,6 @@ typedef struct SCtgJob { SArray* pTasks; int32_t taskDone; SMetaData jobRes; - int32_t rspCode; uint64_t queryId; SCatalog* pCtg; @@ -201,11 +200,12 @@ typedef struct SCtgMsgCtx { typedef struct SCtgTask { CTG_TASK_TYPE type; - int32_t taskId; - SCtgJob *pJob; - void* taskCtx; - SCtgMsgCtx msgCtx; - void* res; + int32_t taskId; + SCtgJob* pJob; + void* taskCtx; + SCtgMsgCtx msgCtx; + int32_t code; + void* res; } SCtgTask; typedef int32_t (*ctgLanchTaskFp)(SCtgTask*); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 63df81e73c..bc2c8dad7a 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -437,13 +437,14 @@ _return: int32_t ctgDumpTbMetaRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pTableMeta) { - pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, POINTER_BYTES); + pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pTableMeta) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pTableMeta, &pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pTableMeta, &res); return TSDB_CODE_SUCCESS; } @@ -451,14 +452,14 @@ int32_t ctgDumpTbMetaRes(SCtgTask* pTask) { int32_t ctgDumpDbVgRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbVgroup) { - pJob->jobRes.pDbVgroup = taosArrayInit(pJob->dbVgNum, POINTER_BYTES); + pJob->jobRes.pDbVgroup = taosArrayInit(pJob->dbVgNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbVgroup) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbVgroup, &pTask->res); - pTask->res = NULL; + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbVgroup, &res); return TSDB_CODE_SUCCESS; } @@ -466,13 +467,14 @@ int32_t ctgDumpDbVgRes(SCtgTask* pTask) { int32_t ctgDumpTbHashRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pTableHash) { - pJob->jobRes.pTableHash = taosArrayInit(pJob->tbHashNum, sizeof(SVgroupInfo)); + pJob->jobRes.pTableHash = taosArrayInit(pJob->tbHashNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pTableHash) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pTableHash, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pTableHash, &res); return TSDB_CODE_SUCCESS; } @@ -480,21 +482,29 @@ int32_t ctgDumpTbHashRes(SCtgTask* pTask) { int32_t ctgDumpIndexRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pIndex) { - pJob->jobRes.pIndex = taosArrayInit(pJob->indexNum, sizeof(SIndexInfo)); + pJob->jobRes.pIndex = taosArrayInit(pJob->indexNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pIndex) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pIndex, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pIndex, &res); return TSDB_CODE_SUCCESS; } int32_t ctgDumpQnodeRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; + if (NULL == pJob->jobRes.pQnodeList) { + pJob->jobRes.pQnodeList = taosArrayInit(1, sizeof(SMetaRes)); + if (NULL == pJob->jobRes.pQnodeList) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + } - TSWAP(pJob->jobRes.pQnodeList, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pQnodeList, &res); return TSDB_CODE_SUCCESS; } @@ -502,13 +512,14 @@ int32_t ctgDumpQnodeRes(SCtgTask* pTask) { int32_t ctgDumpDbCfgRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbCfg) { - pJob->jobRes.pDbCfg = taosArrayInit(pJob->dbCfgNum, sizeof(SDbCfgInfo)); + pJob->jobRes.pDbCfg = taosArrayInit(pJob->dbCfgNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbCfg) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbCfg, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbCfg, &res); return TSDB_CODE_SUCCESS; } @@ -516,13 +527,14 @@ int32_t ctgDumpDbCfgRes(SCtgTask* pTask) { int32_t ctgDumpDbInfoRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbInfo) { - pJob->jobRes.pDbInfo = taosArrayInit(pJob->dbInfoNum, sizeof(SDbInfo)); + pJob->jobRes.pDbInfo = taosArrayInit(pJob->dbInfoNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbInfo) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbInfo, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbInfo, &res); return TSDB_CODE_SUCCESS; } @@ -530,13 +542,14 @@ int32_t ctgDumpDbInfoRes(SCtgTask* pTask) { int32_t ctgDumpUdfRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pUdfList) { - pJob->jobRes.pUdfList = taosArrayInit(pJob->udfNum, sizeof(SFuncInfo)); + pJob->jobRes.pUdfList = taosArrayInit(pJob->udfNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pUdfList) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pUdfList, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pUdfList, &res); return TSDB_CODE_SUCCESS; } @@ -544,13 +557,14 @@ int32_t ctgDumpUdfRes(SCtgTask* pTask) { int32_t ctgDumpUserRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pUser) { - pJob->jobRes.pUser = taosArrayInit(pJob->userNum, sizeof(bool)); + pJob->jobRes.pUser = taosArrayInit(pJob->userNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pUser) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pUser, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pUser, &res); return TSDB_CODE_SUCCESS; } @@ -561,14 +575,7 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { qDebug("QID:0x%" PRIx64 " task %d end with rsp %s", pJob->queryId, pTask->taskId, tstrerror(rspCode)); - if (rspCode) { - int32_t lastCode = atomic_val_compare_exchange_32(&pJob->rspCode, 0, rspCode); - if (0 == lastCode) { - CTG_ERR_JRET(rspCode); - } - - return TSDB_CODE_SUCCESS; - } + pTask->code = rspCode; int32_t taskDone = atomic_add_fetch_32(&pJob->taskDone, 1); if (taskDone < taosArrayGetSize(pJob->pTasks)) { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 962edf9af1..558d1eb8d6 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -61,10 +61,12 @@ void ctgFreeSMetaData(SMetaData* pData) { taosArrayDestroy(pData->pUdfList); pData->pUdfList = NULL; +/* for (int32_t i = 0; i < taosArrayGetSize(pData->pDbCfg); ++i) { SDbCfgInfo* pInfo = taosArrayGet(pData->pDbCfg, i); taosArrayDestroy(pInfo->pRetensions); } +*/ taosArrayDestroy(pData->pDbCfg); pData->pDbCfg = NULL; @@ -320,8 +322,12 @@ void ctgFreeTask(SCtgTask* pTask) { break; } case CTG_TASK_GET_DB_CFG: { - taosMemoryFreeClear(pTask->taskCtx); - taosMemoryFreeClear(pTask->res); + taosMemoryFreeClear(pTask->taskCtx); + if (pTask->res) { + SDbCfgInfo* pInfo = (SDbCfgInfo*)pTask->res; + taosArrayDestroy(pInfo->pRetensions); + taosMemoryFreeClear(pTask->res); + } break; } case CTG_TASK_GET_DB_INFO: { From d98a4b467db365108a66c2a6da9a20bb23d7e4b1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 7 Jun 2022 15:52:46 +0800 Subject: [PATCH 10/21] fix(query): set the schemaless flag. --- source/client/inc/clientInt.h | 2 +- source/client/src/clientMain.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 4ba74af5e6..3a6f3badc0 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -144,7 +144,7 @@ typedef struct STscObj { int32_t numOfReqs; // number of sqlObj bound to this connection SAppInstInfo* pAppInfo; SHashObj* pRequests; - int8_t schemalessType; + int8_t schemalessType; // todo remove it, this attribute should be move to request } STscObj; typedef struct SResultColumn { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 3ca93d178c..1a1925e244 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -697,6 +697,7 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) { .pTransporter = pTscObj->pAppInfo->pTransporter, .pStmtCb = NULL, .pUser = pTscObj->user, + .schemalessType = pTscObj->schemalessType, .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)), .async = true,}; return TSDB_CODE_SUCCESS; From 4ab552234bb732ef932d2b7900c0c518347ff2c2 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 7 Jun 2022 17:14:20 +0800 Subject: [PATCH 11/21] fix: a problem of parser async --- source/libs/parser/src/parAstParser.c | 2 +- source/libs/parser/src/parUtil.c | 198 ++++++++---------- .../libs/parser/test/mockCatalogService.cpp | 75 +++---- 3 files changed, 118 insertions(+), 157 deletions(-) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index f05987c307..6555ec3a7d 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -108,7 +108,7 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt); static EDealRes collectMetaKeyFromFunction(SCollectMetaKeyFromExprCxt* pCxt, SFunctionNode* pFunc) { if (fmIsBuiltinFunc(pFunc->functionName)) { - return TSDB_CODE_SUCCESS; + return DEAL_RES_CONTINUE; } pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache); return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index f30cc1111f..192a4baf80 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -482,20 +482,6 @@ static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) { return TSDB_CODE_SUCCESS; } -static int32_t buildTableMetaReq(SHashObj* pTableMetaHash, SArray** pTableMeta) { - return buildTableReq(pTableMetaHash, pTableMeta); -} - -static int32_t buildDbVgroupReq(SHashObj* pDbVgroupHash, SArray** pDbVgroup) { - return buildDbReq(pDbVgroupHash, pDbVgroup); -} - -static int32_t buildTableVgroupReq(SHashObj* pTableVgroupHash, SArray** pTableVgroup) { - return buildTableReq(pTableVgroupHash, pTableVgroup); -} - -static int32_t buildDbCfgReq(SHashObj* pDbCfgHash, SArray** pDbCfg) { return buildDbReq(pDbCfgHash, pDbCfg); } - static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) { if (NULL != pUserAuthHash) { *pUserAuth = taosArrayInit(taosHashGetSize(pUserAuthHash), sizeof(SUserAuthInfo)); @@ -535,15 +521,18 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) { } int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { - int32_t code = buildTableMetaReq(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta); + int32_t code = buildTableReq(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta); if (TSDB_CODE_SUCCESS == code) { - code = buildDbVgroupReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup); + code = buildDbReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = buildTableVgroupReq(pMetaCache->pTableVgroup, &pCatalogReq->pTableHash); + code = buildTableReq(pMetaCache->pTableVgroup, &pCatalogReq->pTableHash); } if (TSDB_CODE_SUCCESS == code) { - code = buildDbCfgReq(pMetaCache->pDbCfg, &pCatalogReq->pDbCfg); + code = buildDbReq(pMetaCache->pDbCfg, &pCatalogReq->pDbCfg); + } + if (TSDB_CODE_SUCCESS == code) { + code = buildDbReq(pMetaCache->pDbInfo, &pCatalogReq->pDbInfo); } if (TSDB_CODE_SUCCESS == code) { code = buildUserAuthReq(pMetaCache->pUserAuth, &pCatalogReq->pUser); @@ -554,51 +543,39 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog return code; } -static int32_t putTableMetaToCache(const SArray* pTableMetaReq, const SArray* pTableMetaData, SHashObj* pTableMeta) { - int32_t ntables = taosArrayGetSize(pTableMetaReq); +static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pData, int32_t index, SHashObj* pHash) { + SMetaRes* pRes = taosArrayGet(pData, index); + return taosHashPut(pHash, pKey, len, &pRes, POINTER_BYTES); +} + +static int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput) { + SMetaRes** pRes = taosHashGet(pHash, pKey, len); + if (NULL == pRes || NULL == *pRes) { + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + if (TSDB_CODE_SUCCESS == (*pRes)->code) { + *pOutput = (*pRes)->pRes; + } + return (*pRes)->code; +} + +static int32_t putTableDataToCache(const SArray* pTableReq, const SArray* pTableData, SHashObj* pTable) { + int32_t ntables = taosArrayGetSize(pTableReq); for (int32_t i = 0; i < ntables; ++i) { char fullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(taosArrayGet(pTableMetaReq, i), fullName); - if (TSDB_CODE_SUCCESS != - taosHashPut(pTableMeta, fullName, strlen(fullName), taosArrayGet(pTableMetaData, i), POINTER_BYTES)) { + tNameExtractFullName(taosArrayGet(pTableReq, i), fullName); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(fullName, strlen(fullName), pTableData, i, pTable)) { return TSDB_CODE_OUT_OF_MEMORY; } } return TSDB_CODE_SUCCESS; } -static int32_t putDbVgroupToCache(const SArray* pDbVgroupReq, const SArray* pDbVgroupData, SHashObj* pDbVgroup) { - int32_t nvgs = taosArrayGetSize(pDbVgroupReq); +static int32_t putDbDataToCache(const SArray* pDbReq, const SArray* pDbData, SHashObj* pDb) { + int32_t nvgs = taosArrayGetSize(pDbReq); for (int32_t i = 0; i < nvgs; ++i) { - char* pDbFName = taosArrayGet(pDbVgroupReq, i); - if (TSDB_CODE_SUCCESS != - taosHashPut(pDbVgroup, pDbFName, strlen(pDbFName), taosArrayGet(pDbVgroupData, i), POINTER_BYTES)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t putTableVgroupToCache(const SArray* pTableVgroupReq, const SArray* pTableVgroupData, - SHashObj* pTableVgroup) { - int32_t ntables = taosArrayGetSize(pTableVgroupReq); - for (int32_t i = 0; i < ntables; ++i) { - char fullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(taosArrayGet(pTableVgroupReq, i), fullName); - SVgroupInfo* pInfo = taosArrayGet(pTableVgroupData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pTableVgroup, fullName, strlen(fullName), &pInfo, POINTER_BYTES)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t putDbCfgToCache(const SArray* pDbCfgReq, const SArray* pDbCfgData, SHashObj* pDbCfg) { - int32_t nvgs = taosArrayGetSize(pDbCfgReq); - for (int32_t i = 0; i < nvgs; ++i) { - char* pDbFName = taosArrayGet(pDbCfgReq, i); - SDbCfgInfo* pInfo = taosArrayGet(pDbCfgData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pDbCfg, pDbFName, strlen(pDbFName), &pInfo, POINTER_BYTES)) { + char* pDbFName = taosArrayGet(pDbReq, i); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(pDbFName, strlen(pDbFName), pDbData, i, pDb)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -611,7 +588,7 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i); char key[USER_AUTH_KEY_MAX_LEN] = {0}; int32_t len = userAuthToStringExt(pUser->user, pUser->dbFName, pUser->type, key); - if (TSDB_CODE_SUCCESS != taosHashPut(pUserAuth, key, len, taosArrayGet(pUserAuthData, i), sizeof(bool))) { + if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -621,9 +598,8 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHashObj* pUdf) { int32_t num = taosArrayGetSize(pUdfReq); for (int32_t i = 0; i < num; ++i) { - char* pFunc = taosArrayGet(pUdfReq, i); - SFuncInfo* pInfo = taosArrayGet(pUdfData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pUdf, pFunc, strlen(pFunc), &pInfo, POINTER_BYTES)) { + char* pFunc = taosArrayGet(pUdfReq, i); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(pFunc, strlen(pFunc), pUdfData, i, pUdf)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -631,15 +607,18 @@ static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHas } int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache) { - int32_t code = putTableMetaToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, pMetaCache->pTableMeta); + int32_t code = putTableDataToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, pMetaCache->pTableMeta); if (TSDB_CODE_SUCCESS == code) { - code = putDbVgroupToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, pMetaCache->pDbVgroup); + code = putDbDataToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, pMetaCache->pDbVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = putTableVgroupToCache(pCatalogReq->pTableHash, pMetaData->pTableHash, pMetaCache->pTableVgroup); + code = putTableDataToCache(pCatalogReq->pTableHash, pMetaData->pTableHash, pMetaCache->pTableVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = putDbCfgToCache(pCatalogReq->pDbCfg, pMetaData->pDbCfg, pMetaCache->pDbCfg); + code = putDbDataToCache(pCatalogReq->pDbCfg, pMetaData->pDbCfg, pMetaCache->pDbCfg); + } + if (TSDB_CODE_SUCCESS == code) { + code = putDbDataToCache(pCatalogReq->pDbInfo, pMetaData->pDbInfo, pMetaCache->pDbInfo); } if (TSDB_CODE_SUCCESS == code) { code = putUserAuthToCache(pCatalogReq->pUser, pMetaData->pUser, pMetaCache->pUserAuth); @@ -679,16 +658,15 @@ int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCac int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) { char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); - STableMeta** pRes = taosHashGet(pMetaCache->pTableMeta, fullName, strlen(fullName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getTableMetaFromCache error: %s", fullName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + STableMeta* pTableMeta = NULL; + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableMeta, (void**)&pTableMeta); + if (TSDB_CODE_SUCCESS == code) { + *pMeta = tableMetaDup(pTableMeta); + if (NULL == *pMeta) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } - *pMeta = tableMetaDup(*pRes); - if (NULL == *pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; - } - return TSDB_CODE_SUCCESS; + return code; } static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) { @@ -708,19 +686,16 @@ int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* } int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo) { - SArray** pRes = taosHashGet(pMetaCache->pDbVgroup, pDbFName, strlen(pDbFName)); - if (NULL == pRes) { - parserError("getDbVgInfoFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; - } - // *pRes is null, which is a legal value, indicating that the user DB has not been created - if (NULL != *pRes) { - *pVgInfo = taosArrayDup(*pRes); + SArray* pVgList = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbVgroup, (void**)&pVgList); + // pVgList is null, which is a legal value, indicating that the user DB has not been created + if (TSDB_CODE_SUCCESS == code && NULL != pVgList) { + *pVgInfo = taosArrayDup(pVgList); if (NULL == *pVgInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; } } - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) { @@ -736,30 +711,28 @@ int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaC int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) { char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); - SVgroupInfo** pRes = taosHashGet(pMetaCache->pTableVgroup, fullName, strlen(fullName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getTableVgroupFromCache error: %s", fullName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SVgroupInfo* pVg = NULL; + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableVgroup, (void**)&pVg); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pVgroup, pVg, sizeof(SVgroupInfo)); } - memcpy(pVgroup, *pRes, sizeof(SVgroupInfo)); - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) { - return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbCfg); + return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbInfo); } int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) { - SDbInfo** pRes = taosHashGet(pMetaCache->pDbCfg, pDbFName, strlen(pDbFName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getDbVgVersionFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SDbInfo* pDbInfo = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbInfo, (void**)&pDbInfo); + if (TSDB_CODE_SUCCESS == code) { + *pVersion = pDbInfo->vgVer; + *pDbId = pDbInfo->dbId; + *pTableNum = pDbInfo->tbNum; } - *pVersion = (*pRes)->vgVer; - *pDbId = (*pRes)->dbId; - *pTableNum = (*pRes)->tbNum; - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) { @@ -767,13 +740,12 @@ int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pM } int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo) { - SDbCfgInfo** pRes = taosHashGet(pMetaCache->pDbCfg, pDbFName, strlen(pDbFName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getDbCfgFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SDbCfgInfo* pDbCfg = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbCfg, (void**)&pDbCfg); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pInfo, pDbCfg, sizeof(SDbCfgInfo)); } - memcpy(pInfo, *pRes, sizeof(SDbCfgInfo)); - return TSDB_CODE_SUCCESS; + return code; } static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseMetaCache* pMetaCache) { @@ -806,13 +778,12 @@ int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, con bool* pPass) { char key[USER_AUTH_KEY_MAX_LEN] = {0}; int32_t len = userAuthToStringExt(pUser, pDbFName, type, key); - bool* pRes = taosHashGet(pMetaCache->pUserAuth, key, len); - if (NULL == pRes) { - parserError("getUserAuthFromCache error: %s, %s, %d", pUser, pDbFName, type); - return TSDB_CODE_PAR_INTERNAL_ERROR; + bool* pRes = NULL; + int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pRes); + if (TSDB_CODE_SUCCESS == code) { + *pPass = *pRes; } - *pPass = *pRes; - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) { @@ -826,11 +797,10 @@ int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) { } int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo) { - SFuncInfo** pRes = taosHashGet(pMetaCache->pUdf, pFunc, strlen(pFunc)); - if (NULL == pRes || NULL == *pRes) { - parserError("getUdfInfoFromCache error: %s", pFunc); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SFuncInfo* pFuncInfo = NULL; + int32_t code = getMetaDataFromHash(pFunc, strlen(pFunc), pMetaCache->pUdf, (void**)&pFuncInfo); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pInfo, pFuncInfo, sizeof(SFuncInfo)); } - memcpy(pInfo, *pRes, sizeof(SFuncInfo)); - return TSDB_CODE_SUCCESS; + return code; } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 4834d2d377..0c37c875c0 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -367,49 +367,40 @@ class MockCatalogServiceImpl { } int32_t getAllTableMeta(SArray* pTableMetaReq, SArray** pTableMetaData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pTableMetaReq) { int32_t ntables = taosArrayGetSize(pTableMetaReq); - *pTableMetaData = taosArrayInit(ntables, POINTER_BYTES); + *pTableMetaData = taosArrayInit(ntables, sizeof(SMetaRes)); for (int32_t i = 0; i < ntables; ++i) { - STableMeta* pMeta = NULL; - code = catalogGetTableMeta((const SName*)taosArrayGet(pTableMetaReq, i), &pMeta); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pTableMetaData, &pMeta); - } else { - break; - } + SMetaRes res = {0}; + res.code = catalogGetTableMeta((const SName*)taosArrayGet(pTableMetaReq, i), (STableMeta**)&res.pRes); + taosArrayPush(*pTableMetaData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } int32_t getAllTableVgroup(SArray* pTableVgroupReq, SArray** pTableVgroupData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pTableVgroupReq) { int32_t ntables = taosArrayGetSize(pTableVgroupReq); - *pTableVgroupData = taosArrayInit(ntables, sizeof(SVgroupInfo)); + *pTableVgroupData = taosArrayInit(ntables, sizeof(SMetaRes)); for (int32_t i = 0; i < ntables; ++i) { - SVgroupInfo vgInfo = {0}; - code = catalogGetTableHashVgroup((const SName*)taosArrayGet(pTableVgroupReq, i), &vgInfo); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pTableVgroupData, &vgInfo); - } else { - break; - } + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SVgroupInfo)); + res.code = catalogGetTableHashVgroup((const SName*)taosArrayGet(pTableVgroupReq, i), (SVgroupInfo*)res.pRes); + taosArrayPush(*pTableVgroupData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } int32_t getAllDbVgroup(SArray* pDbVgroupReq, SArray** pDbVgroupData) const { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbVgroupReq) { int32_t ndbs = taosArrayGetSize(pDbVgroupReq); - *pDbVgroupData = taosArrayInit(ndbs, POINTER_BYTES); + *pDbVgroupData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - int64_t zeroVg = 0; - taosArrayPush(*pDbVgroupData, &zeroVg); + SMetaRes res = {0}; + taosArrayPush(*pDbVgroupData, &res); } } return code; @@ -419,10 +410,11 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbCfgReq) { int32_t ndbs = taosArrayGetSize(pDbCfgReq); - *pDbCfgData = taosArrayInit(ndbs, sizeof(SDbCfgInfo)); + *pDbCfgData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - SDbCfgInfo dbCfg = {0}; - taosArrayPush(*pDbCfgData, &dbCfg); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); + taosArrayPush(*pDbCfgData, &res); } } return code; @@ -432,10 +424,11 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbInfoReq) { int32_t ndbs = taosArrayGetSize(pDbInfoReq); - *pDbInfoData = taosArrayInit(ndbs, sizeof(SDbCfgInfo)); + *pDbInfoData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - SDbInfo dbInfo = {0}; - taosArrayPush(*pDbInfoData, &dbInfo); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SDbInfo)); + taosArrayPush(*pDbInfoData, &res); } } return code; @@ -445,31 +438,29 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pUserAuthReq) { int32_t num = taosArrayGetSize(pUserAuthReq); - *pUserAuthData = taosArrayInit(num, sizeof(bool)); + *pUserAuthData = taosArrayInit(num, sizeof(SMetaRes)); for (int32_t i = 0; i < num; ++i) { - bool pass = true; - taosArrayPush(*pUserAuthData, &pass); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(bool)); + *(bool*)(res.pRes) = true; + taosArrayPush(*pUserAuthData, &res); } } return code; } int32_t getAllUdf(SArray* pUdfReq, SArray** pUdfData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pUdfReq) { int32_t num = taosArrayGetSize(pUdfReq); - *pUdfData = taosArrayInit(num, sizeof(SFuncInfo)); + *pUdfData = taosArrayInit(num, sizeof(SMetaRes)); for (int32_t i = 0; i < num; ++i) { - SFuncInfo info = {0}; - code = catalogGetUdfInfo((char*)taosArrayGet(pUdfReq, i), &info); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pUdfData, &info); - } else { - break; - } + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SFuncInfo)); + res.code = catalogGetUdfInfo((char*)taosArrayGet(pUdfReq, i), (SFuncInfo*)res.pRes); + taosArrayPush(*pUdfData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } uint64_t id_; From aecc8ce9bcdf97bce2f0d9eed9e4ea9b1a8b351f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 08:48:29 +0800 Subject: [PATCH 12/21] fix double free issue --- source/libs/catalog/src/ctgUtil.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 558d1eb8d6..b5160fe8de 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -47,11 +47,13 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) { void ctgFreeSMetaData(SMetaData* pData) { taosArrayDestroy(pData->pTableMeta); pData->pTableMeta = NULL; - + +/* for (int32_t i = 0; i < taosArrayGetSize(pData->pDbVgroup); ++i) { SArray** pArray = taosArrayGet(pData->pDbVgroup, i); taosArrayDestroy(*pArray); } +*/ taosArrayDestroy(pData->pDbVgroup); pData->pDbVgroup = NULL; From a552e1fcca580e645dd1bb10e978c2d4173f3d0b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 8 Jun 2022 09:30:59 +0800 Subject: [PATCH 13/21] test(query): fix a typo. --- source/libs/scheduler/src/schJob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 7a0272a4d0..bf14032669 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -535,7 +535,7 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("set %dth condidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); + SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); ++addNum; } From 8dcd05301eb9fc84093d9a829443c4b5269ec274 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 09:47:50 +0800 Subject: [PATCH 14/21] add assert --- source/libs/parser/src/parUtil.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 192a4baf80..e5902dff1d 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -714,6 +714,8 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVg = NULL; int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableVgroup, (void**)&pVg); if (TSDB_CODE_SUCCESS == code) { + ASSERT(0 != pVg->vgId); + ASSERT(0 != pVg->epSet.eps[pVg->epSet.inUse].fqdn[0]); memcpy(pVgroup, pVg, sizeof(SVgroupInfo)); } return code; From 9cfdf922974c034241ae97a6f772fca77ffeda64 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 10:24:24 +0800 Subject: [PATCH 15/21] fix rc issue --- source/libs/scheduler/src/schJob.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index bf14032669..a0903d94bf 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -887,6 +887,7 @@ int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCod if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) { schNotifyUserQueryRes(pJob); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); schNotifyUserFetchRes(pJob); } } @@ -915,6 +916,7 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { } else if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) { schNotifyUserQueryRes(pJob); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); schNotifyUserFetchRes(pJob); } @@ -935,6 +937,8 @@ void schProcessOnDataFetched(SSchJob *job) { if (job->attr.syncSchedule) { tsem_post(&job->rspSem); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&job->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&job->userFetch, 1, 0); + schNotifyUserFetchRes(job); } } @@ -1673,9 +1677,9 @@ int32_t schAsyncFetchRows(SSchJob *pJob) { } if (pJob->attr.explainMode == EXPLAIN_MODE_STATIC) { - SCH_ERR_JRET(schNotifyUserFetchRes(pJob)); - atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); + + SCH_ERR_JRET(schNotifyUserFetchRes(pJob)); } else { pJob->userCb = SCH_FETCH_CB; From cd56e3b11f78edd85904770f2ac1b5b668c5d6f9 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 15:30:57 +0800 Subject: [PATCH 16/21] collect db table list --- include/util/taoserror.h | 6 +-- source/client/src/clientImpl.c | 1 + source/libs/parser/src/parTranslater.c | 67 ++++++++++++-------------- source/libs/qcom/src/querymsg.c | 10 ++-- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 842c8a44e1..1729122765 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -339,9 +339,9 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE TAOS_DEF_ERROR_CODE(0, 0x060D) #define TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x060E) #define TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x060F) -#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0600) -#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0601) -#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0602) +#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0610) +#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0611) +#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0612) #define TSDB_CODE_TDB_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0613) #define TSDB_CODE_TDB_TABLE_RECONFIGURE TAOS_DEF_ERROR_CODE(0, 0x0614) #define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0615) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 7601e082e4..0cc4b2f5d8 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -593,6 +593,7 @@ void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) { pRequest->code = code; } + tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type)); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { removeMeta(pTscObj, pRequest->tableList); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 1ba47d0d15..2a2f664120 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -103,15 +103,14 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) { static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getTableMetaFromCache(pCxt->pMetaCache, pName, pMeta); - } else { - code = collectUseDatabase(pName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { - code = collectUseTable(pName, pCxt->pTables); - } - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabase(pName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(pName, pCxt->pTables); + } + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getTableMetaFromCache(pCxt->pMetaCache, pName, pMeta); + } else { code = catalogGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pMeta); } } @@ -150,12 +149,11 @@ static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArr SParseContext* pParCxt = pCxt->pParseCxt; char fullDbName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pName, fullDbName); - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbVgInfoFromCache(pCxt->pMetaCache, fullDbName, pVgInfo); - } else { - code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbVgInfoFromCache(pCxt->pMetaCache, fullDbName, pVgInfo); + } else { code = catalogGetDBVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, fullDbName, pVgInfo); } } @@ -175,15 +173,14 @@ static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray* static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pName, SVgroupInfo* pInfo) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); - } else { - code = collectUseDatabase(pName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { - code = collectUseTable(pName, pCxt->pTables); - } - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabase(pName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(pName, pCxt->pTables); + } + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); + } else { code = catalogGetTableHashVgroup(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pInfo); } } @@ -203,12 +200,11 @@ static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName, static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbVgVersionFromCache(pCxt->pMetaCache, pDbFName, pVersion, pDbId, pTableNum); - } else { - code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbVgVersionFromCache(pCxt->pMetaCache, pDbFName, pVersion, pDbId, pTableNum); + } else { code = catalogGetDBVgVersion(pParCxt->pCatalog, pDbFName, pVersion, pDbId, pTableNum); } } @@ -224,12 +220,11 @@ static int32_t getDBCfg(STranslateContext* pCxt, const char* pDbName, SDbCfgInfo tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); char dbFname[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(&name, dbFname); - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbCfgFromCache(pCxt->pMetaCache, dbFname, pInfo); - } else { - code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbCfgFromCache(pCxt->pMetaCache, dbFname, pInfo); + } else { code = catalogGetDBCfg(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, dbFname, pInfo); } } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 949a58c2fa..db58c9bf56 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -294,10 +294,6 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; - if (isStb) { - qDebug("stable %s meta returned, suid:%" PRIx64, msg->stbName, pTableMeta->suid); - } - pTableMeta->tableInfo.numOfTags = msg->numOfTags; pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; @@ -308,6 +304,12 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; } + qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId %d db %s stb %s suid %" PRIx64 " sver %d tver %d" PRIx64 + " tagNum %d colNum %d precision %d rowSize %d", + msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, pTableMeta->suid, + pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, pTableMeta->tableInfo.numOfColumns, + pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize); + *pMeta = pTableMeta; return TSDB_CODE_SUCCESS; } From e8a3a0395268f254f1b7257e686a4ddc03a18c7b Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 15:34:22 +0800 Subject: [PATCH 17/21] add retry error code --- include/libs/qcom/query.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index a717a6b333..94e68ad48a 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -210,8 +210,8 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \ (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \ - (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code == TSDB_CODE_PAR_VALUE_TOO_LONG) || \ - (_code == TSDB_CODE_PAR_INVALID_DROP_COL)) + (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \ + (_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID)) #define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) From 9b70420b3c5efeb52d864ff0912b8af3a343e6e4 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 18:58:52 +0800 Subject: [PATCH 18/21] fix case issue --- tests/test/c/tmqSim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index d0b582f375..e4ad4a466c 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -515,13 +515,13 @@ void* consumeThreadFunc(void* param) { if (err) { pError("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); pInfo->consumeMsgCnt = -1; - return NULL; + //return NULL; } err = tmq_consumer_close(pInfo->tmq); if (err) { pError("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); - exit(-1); + //exit(-1); } pInfo->tmq = NULL; From 9eb8444373c17304319678776db370295034b0d3 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 19:03:10 +0800 Subject: [PATCH 19/21] fix tmq issue --- source/dnode/mnode/impl/src/mndConsumer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 1f8bf06993..6f2ac354f7 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -92,6 +92,11 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) { SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId); ASSERT(pConsumer); + if (pConsumer->status != MQ_CONSUMER_STATUS__READY) { + mndReleaseConsumer(pMnode, pConsumer); + return -1; + } + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); pConsumerNew->updateType = CONSUMER_UPDATE__LOST; From 9e9381a6c51a4f1d6634b1a5ceabc7e34a5fd98c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 20:28:24 +0800 Subject: [PATCH 20/21] fix bug --- source/client/src/clientImpl.c | 3 ++- source/libs/parser/src/parUtil.c | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 0cc4b2f5d8..6e86dc6522 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -704,7 +704,8 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { break; } case QUERY_EXEC_MODE_EMPTY_RESULT: - pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + pRequest->body.queryFp(pRequest->body.param, pRequest, 0); break; default: break; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index e5902dff1d..192a4baf80 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -714,8 +714,6 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVg = NULL; int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableVgroup, (void**)&pVg); if (TSDB_CODE_SUCCESS == code) { - ASSERT(0 != pVg->vgId); - ASSERT(0 != pVg->epSet.eps[pVg->epSet.inUse].fqdn[0]); memcpy(pVgroup, pVg, sizeof(SVgroupInfo)); } return code; From 594c370543dd0ea82fa23cf17293fe84261d92de Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 8 Jun 2022 20:39:46 +0800 Subject: [PATCH 21/21] fix error handle issue --- source/client/src/clientImpl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 6e86dc6522..60dfaf1278 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -697,6 +697,8 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { if (TSDB_CODE_SUCCESS == code) { schedulerAsyncExecJob(pAppInfo->pTransporter, pNodeList, pRequest->body.pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, schedulerExecCb, pRequest); + } else { + pRequest->body.queryFp(pRequest->body.param, pRequest, code); } //todo not to be released here