From b91eb6b80b3c8ffbd771ea0e157c24d14661adaf Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 15:19:09 +0800 Subject: [PATCH] [td-11818] refactor APIs, and fix bug in show tables; --- include/common/tmsg.h | 6 +- include/libs/catalog/catalog.h | 4 +- include/libs/parser/parsenodes.h | 1 + source/client/inc/clientInt.h | 11 +- source/client/src/clientImpl.c | 24 +- source/client/src/clientMsgHandler.c | 39 +- source/client/test/clientTests.cpp | 581 +++++++++++----------- source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/dnode/mnode/impl/src/mndShow.c | 48 +- source/libs/catalog/src/catalog.c | 13 +- source/libs/catalog/test/catalogTests.cpp | 2 +- source/libs/parser/inc/parserInt.h | 2 +- source/libs/parser/src/astToMsg.c | 23 +- source/libs/parser/src/dCDAstProcess.c | 28 +- source/libs/parser/src/parser.c | 8 +- source/libs/parser/test/parserTests.cpp | 26 +- source/libs/parser/test/plannerTest.cpp | 4 +- source/libs/parser/test/tokenizerTest.cpp | 2 +- source/libs/planner/test/plannerTests.cpp | 2 +- source/libs/qworker/src/qworker.c | 33 +- 21 files changed, 440 insertions(+), 421 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 93d83eb419..0df910b399 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -503,7 +503,7 @@ typedef struct { typedef struct { SMsgHead header; union { - int32_t showId; + int64_t showId; int64_t qhandle; int64_t qId; }; // query handle @@ -823,7 +823,7 @@ typedef struct { } SCompactMsg; typedef struct SShowRsp { - int32_t showId; + int64_t showId; STableMetaMsg tableMeta; } SShowRsp; @@ -1330,7 +1330,7 @@ typedef struct SVShowTablesReq { } SVShowTablesReq; typedef struct SVShowTablesRsp { - int32_t id; + int64_t id; STableMetaMsg metaInfo; } SVShowTablesRsp; diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 8f4b9e1807..1bd29ce396 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -54,11 +54,11 @@ int32_t catalogInit(SCatalogCfg *cfg); /** * Get a cluster's catalog handle for all later operations. - * @param clusterId (input, end with \0) + * @param clusterId * @param catalogHandle (output, NO need to free it) * @return error code */ -int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle); +int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle); int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version); diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index 980219a4e9..041adbb582 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -169,6 +169,7 @@ typedef struct SDclStmtInfo { SEpSet epSet; char* pMsg; int32_t msgLen; + void* pExtension; // todo remove it soon } SDclStmtInfo; #ifdef __cplusplus diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 021f650254..165ea9b62f 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -101,10 +101,17 @@ typedef struct SReqResultInfo { uint32_t current; } SReqResultInfo; +typedef struct SShowReqInfo { + int64_t execId; // showId/queryId + int32_t vgId; + SArray *pArray; // SArray + int32_t currentIndex; // current accessed vgroup index. +} SShowReqInfo; + typedef struct SRequestSendRecvBody { tsem_t rspSem; // not used now void* fp; - int64_t execId; // showId/queryId + SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed. SDataBuf requestMsg; SReqResultInfo resInfo; } SRequestSendRecvBody; @@ -131,7 +138,7 @@ extern int32_t clientConnRefPool; extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code); -SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj*); +SMsgSendInfo* buildMsgInfoImpl(SRequestObj*); int taos_init(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index efe327242a..62ef63c858 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -156,19 +156,12 @@ int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) { }; cxt.ctx.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); - - // todo OPT performance - char buf[12] = {0}; - sprintf(buf, "%"PRId64, pTscObj->pAppInfo->clusterId); - - struct SCatalog* pCatalog = NULL; - int32_t code = catalogGetHandle(buf, &pCatalog); + int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &cxt.ctx.pCatalog); if (code != TSDB_CODE_SUCCESS) { tfree(cxt.ctx.db); return code; } - cxt.ctx.pCatalog = pCatalog; code = qParseQuerySql(&cxt, pQuery); tfree(cxt.ctx.db); @@ -181,10 +174,17 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen}; STscObj* pTscObj = pRequest->pTscObj; - SMsgSendInfo* pSendMsg = buildSendMsgInfoImpl(pRequest); + SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); int64_t transporterId = 0; - if (pDcl->msgType == TDMT_VND_CREATE_TABLE) { + if (pDcl->msgType == TDMT_VND_CREATE_TABLE || pDcl->msgType == TDMT_VND_SHOW_TABLES) { + if (pDcl->msgType == TDMT_VND_SHOW_TABLES) { + SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; + if (pShowReqInfo->pArray == NULL) { + pShowReqInfo->currentIndex = 0; + pShowReqInfo->pArray = pDcl->pExtension; + } + } asyncSendMsgToServer(pTscObj->pTransporter, &pDcl->epSet, &transporterId, pSendMsg); } else { SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; @@ -243,7 +243,7 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen }; - SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest); + SMsgSendInfo* body = buildMsgInfoImpl(pRequest); SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; int64_t transporterId = 0; @@ -498,7 +498,7 @@ void* doFetchRow(SRequestObj* pRequest) { // do nothing } - SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest); + SMsgSendInfo* body = buildMsgInfoImpl(pRequest); int64_t transporterId = 0; STscObj *pTscObj = pRequest->pTscObj; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 6575102f81..e402403496 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -77,7 +77,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { return 0; } -SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { +SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo)); pMsgSendInfo->requestObjRefId = pRequest->self; @@ -92,7 +92,7 @@ SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { return NULL; } - pRetrieveMsg->showId = htonl(pRequest->body.execId); + pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId); pMsgSendInfo->msgInfo.pData = pRetrieveMsg; pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg); } else { @@ -101,8 +101,9 @@ SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { return NULL; } - pFetchMsg->id = htonl(pRequest->body.execId); - pFetchMsg->head.vgId = htonl(13); + pFetchMsg->id = htobe64(pRequest->body.showInfo.execId); + pFetchMsg->head.vgId = htonl(pRequest->body.showInfo.vgId); + pMsgSendInfo->msgInfo.pData = pFetchMsg; pMsgSendInfo->msgInfo.len = sizeof(SVShowTablesFetchReq); } @@ -124,7 +125,7 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { } SShowRsp* pShow = (SShowRsp *)pMsg->pData; - pShow->showId = htonl(pShow->showId); + pShow->showId = htobe64(pShow->showId); STableMetaMsg *pMetaMsg = &(pShow->tableMeta); pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns); @@ -154,7 +155,17 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES); pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t)); - pRequest->body.execId = pShow->showId; + pRequest->body.showInfo.execId = pShow->showId; + + // todo + if (pRequest->type == TDMT_VND_SHOW_TABLES) { + SShowReqInfo* pShowInfo = &pRequest->body.showInfo; + + int32_t index = pShowInfo->currentIndex; + SVgroupInfo* pInfo = taosArrayGet(pShowInfo->pArray, index); + pShowInfo->vgId = pInfo->vgId; + } + tsem_post(&pRequest->body.rspSem); return 0; } @@ -184,17 +195,17 @@ int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows, - pRetrieve->completed, pRequest->body.execId); + pRetrieve->completed, pRequest->body.showInfo.execId); tsem_post(&pRequest->body.rspSem); return 0; } int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { - assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - SRequestObj* pRequest = param; - tfree(pRequest->body.resInfo.pRspMsg); + + SReqResultInfo* pResInfo = &pRequest->body.resInfo; + tfree(pResInfo->pRspMsg); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); @@ -202,14 +213,14 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { return code; } - pRequest->body.resInfo.pRspMsg = pMsg->pData; + assert(pMsg->len >= sizeof(SRetrieveTableRsp)); + + pResInfo->pRspMsg = pMsg->pData; SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *) pMsg->pData; pFetchRsp->numOfRows = htonl(pFetchRsp->numOfRows); pFetchRsp->precision = htons(pFetchRsp->precision); - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - pResInfo->pRspMsg = pMsg->pData; pResInfo->numOfRows = pFetchRsp->numOfRows; pResInfo->pData = pFetchRsp->data; @@ -218,7 +229,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows, - pFetchRsp->completed, pRequest->body.execId); + pFetchRsp->completed, pRequest->body.showInfo.execId); tsem_post(&pRequest->body.rspSem); return 0; diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index be6e048378..d6d71d5fc3 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -49,51 +49,52 @@ int main(int argc, char** argv) { TEST(testCase, driverInit_Test) { taos_init(); } -#if 0 TEST(testCase, connect_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - taos_close(pConn); -} - -TEST(testCase, create_user_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + if (pConn == NULL) { + printf("failed to connect to server, reason:%s\n", taos_errstr(NULL)); } - - taos_free_result(pRes); taos_close(pConn); } -TEST(testCase, create_account_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); - } - - taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, drop_account_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); - } - - taos_free_result(pRes); - taos_close(pConn); -} +//TEST(testCase, create_user_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +//TEST(testCase, create_account_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +//TEST(testCase, drop_account_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} TEST(testCase, show_user_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -114,18 +115,18 @@ TEST(testCase, show_user_Test) { taos_close(pConn); } -TEST(testCase, drop_user_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "drop user abc"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); - } - - taos_free_result(pRes); - taos_close(pConn); -} +//TEST(testCase, drop_user_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} TEST(testCase, show_db_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -146,260 +147,259 @@ TEST(testCase, show_db_Test) { taos_close(pConn); } -TEST(testCase, create_db_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create database abc1"); - if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); - } - - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); - - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); - - taos_free_result(pRes); - - pRes = taos_query(pConn, "create database abc1 vgroups 4"); - if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); - } - taos_close(pConn); -} - -TEST(testCase, create_dnode_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); - if (taos_errno(pRes) != 0) { - printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); - if (taos_errno(pRes) != 0) { - printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - taos_close(pConn); -} - -TEST(testCase, drop_dnode_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); - if (taos_errno(pRes) != 0) { - printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); - } - - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); - - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); - - taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, use_db_test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); - } - - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); - - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); - - taos_close(pConn); -} - -TEST(testCase, drop_db_test) { +//TEST(testCase, create_db_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // -// showDB(pConn); -// -// TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); +// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); // if (taos_errno(pRes) != 0) { -// printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); +// printf("error in create db, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "create database abc1 vgroups 4"); +// if (taos_errno(pRes) != 0) { +// printf("error in create db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_close(pConn); +//} +// +//TEST(testCase, create_dnode_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); +// if (taos_errno(pRes) != 0) { +// printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // -// showDB(pConn); -// -// pRes = taos_query(pConn, "create database abc1"); +// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); // if (taos_errno(pRes) != 0) { -// printf("create to drop db, reason:%s\n", taos_errstr(pRes)); +// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); +// +// taos_close(pConn); +//} +// +//TEST(testCase, drop_dnode_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); +// if (taos_errno(pRes) != 0) { +// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// +// taos_free_result(pRes); // taos_close(pConn); -} - - TEST(testCase, create_stable_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create database abc1"); - if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); - if (taos_errno(pRes) != 0) { - printf("error in create stable, reason:%s\n", taos_errstr(pRes)); - } - - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); - - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); - - taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, create_table_Test) { - // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - // assert(pConn != NULL); - // - // TAOS_RES* pRes = taos_query(pConn, "use abc1"); - // taos_free_result(pRes); - // - // pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); - // taos_free_result(pRes); - // - // taos_close(pConn); -} - -TEST(testCase, create_ctable_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - -// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); +//} +// +//TEST(testCase, use_db_test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); // if (taos_errno(pRes) != 0) { -// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); +// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// +// taos_close(pConn); +//} + +//TEST(testCase, drop_db_test) { +//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +//// assert(pConn != NULL); +//// +//// showDB(pConn); +//// +//// TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); +//// if (taos_errno(pRes) != 0) { +//// printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); +//// } +//// taos_free_result(pRes); +//// +//// showDB(pConn); +//// +//// pRes = taos_query(pConn, "create database abc1"); +//// if (taos_errno(pRes) != 0) { +//// printf("create to drop db, reason:%s\n", taos_errstr(pRes)); +//// } +//// taos_free_result(pRes); +//// taos_close(pConn); +//} + +// TEST(testCase, create_stable_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in create db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); +// if (taos_errno(pRes) != 0) { +// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); +// } +// +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// ASSERT_TRUE(pFields == NULL); +// +// int32_t numOfFields = taos_num_fields(pRes); +// ASSERT_EQ(numOfFields, 0); +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +//TEST(testCase, create_table_Test) { +// // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// // assert(pConn != NULL); +// // +// // TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// // taos_free_result(pRes); +// // +// // pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); +// // taos_free_result(pRes); +// // +// // taos_close(pConn); +//} +// +//TEST(testCase, create_ctable_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +//// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); +//// if (taos_errno(pRes) != 0) { +//// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); +//// } +//// +//// taos_free_result(pRes); +// taos_close(pConn); +//} +// +//TEST(testCase, show_stable_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "show stables"); +// if (taos_errno(pRes) != 0) { +// printf("failed to show stables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// 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 code = taos_print_row(str, pRow, pFields, numOfFields); +// printf("%s\n", str); // } // // taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, show_stable_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "show stables"); - if (taos_errno(pRes) != 0) { - printf("failed to show stables, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - 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 code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); - } - - taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, show_vgroup_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "show vgroups"); - if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - 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 code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); - } - - taos_free_result(pRes); - - taos_close(pConn); -} - -TEST(testCase, drop_stable_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "create database abc1"); - if (taos_errno(pRes) != 0) { - printf("error in creating db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("error in using db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - pRes = taos_query(pConn, "drop stable st1"); - if (taos_errno(pRes) != 0) { - printf("failed to drop stable, reason:%s\n", taos_errstr(pRes)); - } - - taos_free_result(pRes); - taos_close(pConn); -} -#endif +// taos_close(pConn); +//} +// +//TEST(testCase, show_vgroup_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "show vgroups"); +// if (taos_errno(pRes) != 0) { +// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// 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 code = taos_print_row(str, pRow, pFields, numOfFields); +// printf("%s\n", str); +// } +// +// taos_free_result(pRes); +// +// taos_close(pConn); +//} +// +//TEST(testCase, drop_stable_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in creating db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "use abc1"); +// if (taos_errno(pRes) != 0) { +// printf("error in using db, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "drop stable st1"); +// if (taos_errno(pRes) != 0) { +// printf("failed to drop stable, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} //TEST(testCase, create_topic_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -450,7 +450,6 @@ TEST(testCase, show_table_Test) { } TAOS_ROW pRow = NULL; - TAOS_FIELD* pFields = taos_fetch_fields(pRes); int32_t numOfFields = taos_num_fields(pRes); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index b93fc0951c..419af6df88 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -293,7 +293,7 @@ typedef struct { } SFuncObj; typedef struct { - int32_t id; + int64_t id; int8_t type; int8_t replica; int16_t numOfColumns; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index daa87af1f5..15ff65a8fc 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -41,7 +41,7 @@ typedef struct { } SMnodeStep; typedef struct { - int32_t showId; + int64_t showId; ShowMetaFp metaFps[TSDB_MGMT_TABLE_MAX]; ShowRetrieveFp retrieveFps[TSDB_MGMT_TABLE_MAX]; ShowFreeIterFp freeIterFps[TSDB_MGMT_TABLE_MAX]; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index af633355ef..d4b4459176 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -20,7 +20,7 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg); static void mndFreeShowObj(SShowObj *pShow); -static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId); +static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId); static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove); static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg); @@ -52,8 +52,8 @@ void mndCleanupShow(SMnode *pMnode) { static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { SShowMgmt *pMgmt = &pMnode->showMgmt; - int32_t showId = atomic_add_fetch_32(&pMgmt->showId, 1); - if (showId == 0) atomic_add_fetch_32(&pMgmt->showId, 1); + int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1); + if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1); int32_t size = sizeof(SShowObj) + pMsg->payloadLen; SShowObj showObj = {0}; @@ -65,14 +65,14 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen); int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000; - SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int32_t), &showObj, size, keepTime); + SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime); if (pShow == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:%d, failed to put into cache since %s", showId, terrstr()); + mError("show:0x%"PRIx64", failed to put into cache since %s", showId, terrstr()); return NULL; } - mTrace("show:%d, is created, data:%p", showId, pShow); + mTrace("show:0x%"PRIx64", is created, data:%p", showId, pShow); return pShow; } @@ -87,25 +87,25 @@ static void mndFreeShowObj(SShowObj *pShow) { } } - mTrace("show:%d, is destroyed, data:%p", pShow->id, pShow); + mTrace("show:0x%d, is destroyed, data:%p", pShow->id, pShow); } -static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) { +static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) { SShowMgmt *pMgmt = &pMnode->showMgmt; - SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(int32_t)); + SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId)); if (pShow == NULL) { - mError("show:%d, already destroyed", showId); + mError("show:0x%"PRIx64", already destroyed", showId); return NULL; } - mTrace("show:%d, acquired from cache, data:%p", pShow->id, pShow); + mTrace("show:0x%"PRIx64", acquired from cache, data:%p", pShow->id, pShow); return pShow; } static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { if (pShow == NULL) return; - mTrace("show:%d, released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); + mTrace("show:0x%"PRIx64", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); // A bug in tcache.c forceRemove = 0; @@ -146,18 +146,18 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, true); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:%d, failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type)); + mError("show:0x%"PRIx64", failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type)); return -1; } int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:%d, get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + mDebug("show:0x%"PRIx64", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; - pMnodeMsg->pCont = pRsp; - pRsp->showId = htonl(pShow->id); + pMnodeMsg->pCont = pRsp; + pRsp->showId = htobe64(pShow->id); mndReleaseShowObj(pShow, false); return TSDB_CODE_SUCCESS; } else { @@ -175,7 +175,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { int32_t rowsRead = 0; SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont; - int32_t showId = htonl(pRetrieve->showId); + int64_t showId = htobe64(pRetrieve->showId); SShowObj *pShow = mndAcquireShowObj(pMnode, showId); if (pShow == NULL) { @@ -188,15 +188,15 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (retrieveFp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:%d, start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, + mDebug("show:0x%"PRIx64", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, pShow->numOfRows, mndShowStr(pShow->type)); if (mndCheckRetrieveFinished(pShow)) { - mDebug("show:%d, read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows); + mDebug("show:0x%"PRIx64", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows); pShow->numOfReads = pShow->numOfRows; } @@ -219,7 +219,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } @@ -228,7 +228,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead); } - mDebug("show:%d, stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); + mDebug("show:0x%"PRIx64", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision @@ -238,10 +238,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; - mDebug("show:%d, retrieve completed", pShow->id); + mDebug("show:0x%"PRIx64", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); } else { - mDebug("show:%d, retrieve not completed yet", pShow->id); + mDebug("show:0x%"PRIx64", retrieve not completed yet", pShow->id); mndReleaseShowObj(pShow, false); } diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index b632ac772c..43f613f654 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -465,7 +465,7 @@ int32_t catalogInit(SCatalogCfg *cfg) { ctgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TABLEMETA_NUMBER; } - ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); if (NULL == ctgMgmt.pCluster) { CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CACHE_CLUSTER_NUMBER); } @@ -473,8 +473,8 @@ int32_t catalogInit(SCatalogCfg *cfg) { return TSDB_CODE_SUCCESS; } -int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle) { - if (NULL == clusterId || NULL == catalogHandle) { +int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle) { + if (NULL == catalogHandle) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } @@ -483,8 +483,7 @@ int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle CTG_ERR_RET(TSDB_CODE_CTG_NOT_READY); } - size_t clen = strlen(clusterId); - SCatalog **ctg = (SCatalog **)taosHashGet(ctgMgmt.pCluster, clusterId, clen); + SCatalog **ctg = (SCatalog **)taosHashGet(ctgMgmt.pCluster, (char*)&clusterId, sizeof(clusterId)); if (ctg && (*ctg)) { *catalogHandle = *ctg; @@ -497,8 +496,8 @@ int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } - if (taosHashPut(ctgMgmt.pCluster, clusterId, clen, &clusterCtg, POINTER_BYTES)) { - ctgError("put cluster %s cache to hash failed", clusterId); + if (taosHashPut(ctgMgmt.pCluster, &clusterId, sizeof(clusterId), &clusterCtg, POINTER_BYTES)) { + ctgError("put cluster %"PRIx64" cache to hash failed", clusterId); tfree(clusterCtg); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 0ad00046cd..aa35e56552 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -47,7 +47,7 @@ int32_t ctgTestTagNum = 1; int32_t ctgTestSVersion = 1; int32_t ctgTestTVersion = 1; -char *ctgTestClusterId = "cluster1"; +uint64_t ctgTestClusterId = 0x1; char *ctgTestDbname = "1.db1"; char *ctgTestTablename = "table1"; char *ctgTestCTablename = "ctable1"; diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 186a4869e6..4bbe6ab907 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -102,7 +102,7 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* p * Destroy the meta data request structure. * @param pMetaInfo */ -void qParserClearupMetaRequestInfo(SCatalogReq* pMetaInfo); +void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaInfo); #ifdef __cplusplus } diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 6b0e0ed828..792c0db266 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -26,15 +26,13 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in } SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateAcctMsg* pMsg = (SCreateAcctMsg*)calloc(1, sizeof(SCreateAcctMsg)); - if (pMsg == NULL) { - // tscError("0x%" PRIx64 " failed to malloc for query msg", id); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + SCreateAcctMsg *pCreateMsg = (SCreateAcctMsg *) calloc(1, sizeof(SCreateAcctMsg)); + if (pCreateMsg == NULL) { + qError("0x%" PRIx64 " failed to malloc for query msg", id); + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } - SCreateAcctMsg *pCreateMsg = (SCreateAcctMsg *) calloc(1, sizeof(SCreateAcctMsg)); - SToken *pName = &pInfo->pMiscInfo->user.user; SToken *pPwd = &pInfo->pMiscInfo->user.passwd; @@ -67,17 +65,18 @@ SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in } *outputLen = sizeof(SCreateAcctMsg); - return pMsg; + return pCreateMsg; } + SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); if (pName->n >= TSDB_USER_LEN) { return NULL; } - SDropUserMsg* pMsg = calloc(1, sizeof(SDropUserMsg)); if (pMsg == NULL) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -338,7 +337,7 @@ SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* p SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { const char* msg1 = "invalid host name (name too long, maximum length 128)"; const char* msg2 = "dnode name can not be string"; - const char* msg3 = "port should be an integer that is less than 65535"; + const char* msg3 = "port should be an integer that is less than 65535 and greater than 0"; const char* msg4 = "failed prepare create dnode message"; if (taosArrayGetSize(pInfo->pMiscInfo->a) != 2) { @@ -362,7 +361,7 @@ SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMs int64_t val = 0; toInteger(port->z, port->n, 10, &val, &isSign); - if (val >= UINT16_MAX) { + if (val >= UINT16_MAX || val <= 0) { buildInvalidOperationMsg(pMsgBuf, msg3); return NULL; } @@ -383,7 +382,6 @@ SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMs SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0); - char* end = NULL; SDropDnodeMsg * pDrop = (SDropDnodeMsg *)calloc(1, sizeof(SDropDnodeMsg)); pDrop->dnodeId = strtoll(pzName->z, &end, 10); @@ -397,5 +395,4 @@ SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf } return pDrop; -} - +} \ No newline at end of file diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 8a09ea9ed8..6aa4ad8275 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -18,7 +18,7 @@ static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { } static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** output, int32_t* outputLen, - SEpSet* pEpSet, SMsgBuf* pMsgBuf) { + SEpSet* pEpSet, void** pExtension, SMsgBuf* pMsgBuf) { const char* msg1 = "invalid name"; const char* msg2 = "wildcard string should be less than %d characters"; const char* msg3 = "database name too long"; @@ -33,12 +33,30 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** ou int16_t showType = pShowInfo->showType; if (showType == TSDB_MGMT_TABLE_TABLE) { SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); - *pEpSet = pCtx->mgmtEpSet; - // catalogGetDBVgroupVersion() - pShowReq->head.vgId = htonl(13); + SArray* array = NULL; + SName name = {0}; + tNameSetDbName(&name, pCtx->acctId, pCtx->db, strlen(pCtx->db)); + + char dbFname[TSDB_DB_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, dbFname); + + catalogGetDBVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, dbFname, 0, &array); + + SVgroupInfo* info = taosArrayGet(array, 0); + pShowReq->head.vgId = htonl(info->vgId); + pEpSet->numOfEps = info->numOfEps; + pEpSet->inUse = info->inUse; + + for(int32_t i = 0; i < pEpSet->numOfEps; ++i) { + strncpy(pEpSet->fqdn[i], info->epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); + pEpSet->port[i] = info->epAddr[i].port; + } + *outputLen = sizeof(SVShowTablesReq); *output = pShowReq; + + *pExtension = array; } else { if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP) { SToken* pDbPrefixToken = &pShowInfo->prefix; @@ -621,7 +639,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_SHOW: { SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; - code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, pMsgBuf); + code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, &pDcl->pExtension, pMsgBuf); pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE)? TDMT_VND_SHOW_TABLES:TDMT_MND_SHOW; break; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 2ccd76723b..710cf4b5d0 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -58,13 +58,11 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } else { SQueryStmtInfo* pQueryInfo = calloc(1, sizeof(SQueryStmtInfo)); if (pQueryInfo == NULL) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code. + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; // set correct error code. return terrno; } - struct SCatalog* pCatalog = NULL; - int32_t code = catalogGetHandle(NULL, &pCatalog); - code = qParserValidateSqlNode(pCatalog, &info, pQueryInfo, pCxt->ctx.requestId, pCxt->pMsg, pCxt->msgLen); + int32_t code = qParserValidateSqlNode(pCxt->ctx.pCatalog, &info, pQueryInfo, pCxt->ctx.requestId, pCxt->pMsg, pCxt->msgLen); if (code == TSDB_CODE_SUCCESS) { *pQuery = (SQueryNode*)pQueryInfo; } @@ -220,7 +218,7 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* p return code; } -void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) { +void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaReq) { if (pMetaReq == NULL) { return; } diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index 423aa1a7be..a67a9a8be8 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -99,7 +99,7 @@ void sqlCheck(const char* sql, bool valid) { } destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -159,7 +159,7 @@ TEST(testCase, validateAST_test) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 3); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -205,7 +205,7 @@ TEST(testCase, function_Test) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -251,7 +251,7 @@ TEST(testCase, function_Test2) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -296,7 +296,7 @@ TEST(testCase, function_Test3) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 6); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -342,7 +342,7 @@ TEST(testCase, function_Test4) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -393,7 +393,7 @@ TEST(testCase, function_Test5) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -507,7 +507,7 @@ TEST(testCase, function_Test6) { ASSERT_STREQ(p2->pExpr->_function.pChild[0]->pSchema->name, "t.1abc.b*a"); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -569,7 +569,7 @@ TEST(testCase, function_Test6) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, numOfCols); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -625,7 +625,7 @@ TEST(testCase, function_Test6) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 2); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -648,7 +648,7 @@ TEST(testCase, function_Test6) { ASSERT_EQ(ret, 0); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } @@ -678,7 +678,7 @@ TEST(testCase, function_Test6) { ASSERT_NE(ret, 0); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); //=============================================================================================================== info1 = doGenerateAST("select top(a*b, ABC) from `t.1abc` interval(10s, 1s)"); @@ -700,7 +700,7 @@ TEST(testCase, function_Test6) { ASSERT_NE(ret, 0); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } diff --git a/source/libs/parser/test/plannerTest.cpp b/source/libs/parser/test/plannerTest.cpp index f9b1722106..04c3a7d81a 100644 --- a/source/libs/parser/test/plannerTest.cpp +++ b/source/libs/parser/test/plannerTest.cpp @@ -102,7 +102,7 @@ void generateLogicplan(const char* sql) { printf("%s\n", str); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } } @@ -163,7 +163,7 @@ TEST(testCase, planner_test) { printf("%s\n", str); destroyQueryInfo(pQueryInfo); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } diff --git a/source/libs/parser/test/tokenizerTest.cpp b/source/libs/parser/test/tokenizerTest.cpp index 23c0aae15f..3ab6a6531c 100644 --- a/source/libs/parser/test/tokenizerTest.cpp +++ b/source/libs/parser/test/tokenizerTest.cpp @@ -714,7 +714,7 @@ TEST(testCase, extractMeta_test) { ASSERT_EQ(ret, 0); ASSERT_EQ(taosArrayGetSize(req.pTableName), 1); - qParserClearupMetaRequestInfo(&req); + qParserCleanupMetaRequestInfo(&req); destroySqlInfo(&info1); } diff --git a/source/libs/planner/test/plannerTests.cpp b/source/libs/planner/test/plannerTests.cpp index 11a31d15eb..4b408e67db 100644 --- a/source/libs/planner/test/plannerTests.cpp +++ b/source/libs/planner/test/plannerTests.cpp @@ -100,6 +100,6 @@ TEST(testCase, planner_test) { // ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 2); // // destroyQueryInfo(pQueryInfo); -// qParserClearupMetaRequestInfo(&req); +// qParserCleanupMetaRequestInfo(&req); // destroySqlInfo(&info1); } \ No newline at end of file diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index d5ecd40ccd..808c1e19f9 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -137,7 +137,6 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId, return TSDB_CODE_SUCCESS; } - static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId, SQWSchStatus **sch, int32_t nOpt) { QW_LOCK(rwType, &mgmt->schLock); *sch = taosHashGet(mgmt->schHash, &sId, sizeof(sId)); @@ -156,8 +155,6 @@ static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t s return TSDB_CODE_SUCCESS; } - - static FORCE_INLINE void qwReleaseScheduler(int32_t rwType, SQWorkerMgmt *mgmt) { QW_UNLOCK(rwType, &mgmt->schLock); } @@ -181,12 +178,10 @@ static int32_t qwAcquireTask(int32_t rwType, SQWSchStatus *sch, uint64_t qId, ui return qwAcquireTaskImpl(rwType, sch, qId, tId, task); } - static FORCE_INLINE void qwReleaseTask(int32_t rwType, SQWSchStatus *sch) { QW_UNLOCK(rwType, &sch->tasksLock); } - int32_t qwAddTaskToSch(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t tId, int8_t status, int32_t eOpt, SQWTaskStatus **task) { int32_t code = 0; @@ -233,7 +228,6 @@ int32_t qwAddTaskToSch(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t return TSDB_CODE_SUCCESS; } - static int32_t qwAddTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int32_t status, int32_t eOpt, SQWSchStatus **sch, SQWTaskStatus **task) { SQWSchStatus *tsch = NULL; QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, sId, &tsch, QW_NOT_EXIST_ADD)); @@ -252,8 +246,6 @@ static int32_t qwAddTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_ QW_RET(code); } - - static FORCE_INLINE int32_t qwAcquireTaskResCache(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, SQWorkerResCache **res) { char id[sizeof(queryId) + sizeof(taskId)] = {0}; QW_SET_QTID(id, queryId, taskId); @@ -445,8 +437,6 @@ _return: QW_RET(code); } - - int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId) { SQWSchStatus *sch = NULL; SQWTaskStatus *task = NULL; @@ -480,7 +470,6 @@ int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t return TSDB_CODE_SUCCESS; } - int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_t taskId) { SQWSchStatus *sch = NULL; SQWTaskStatus *task = NULL; @@ -548,8 +537,6 @@ _return: QW_RET(code); } - - int32_t qwBuildAndSendQueryRsp(SRpcMsg *pMsg, int32_t code) { SQueryTableRsp *pRsp = (SQueryTableRsp *)rpcMallocCont(sizeof(SQueryTableRsp)); pRsp->code = code; @@ -648,7 +635,6 @@ int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code) { }; rpcSendResponse(&rpcRsp); - return TSDB_CODE_SUCCESS; } @@ -670,40 +656,43 @@ int32_t qwBuildAndSendDropRsp(SRpcMsg *pMsg, int32_t code) { int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) { int32_t numOfCols = 6; - SVShowTablesRsp *pRsp = (SVShowTablesRsp *)rpcMallocCont(sizeof(SVShowTablesRsp) + sizeof(SSchema) * numOfCols); + int32_t msgSize = sizeof(SVShowTablesRsp) + sizeof(SSchema) * numOfCols; + + SVShowTablesRsp *pRsp = (SVShowTablesRsp *)rpcMallocCont(msgSize); int32_t cols = 0; SSchema *pSchema = pRsp->metaInfo.pSchema; const SSchema *s = tGetTbnameColumnSchema(); - *pSchema = createSchema(s->type, htonl(s->bytes), htonl(cols++), "name"); + *pSchema = createSchema(s->type, htonl(s->bytes), htonl(++cols), "name"); pSchema++; int32_t type = TSDB_DATA_TYPE_TIMESTAMP; - *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "created"); + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(++cols), "created"); pSchema++; type = TSDB_DATA_TYPE_SMALLINT; - *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "columns"); + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(++cols), "columns"); pSchema++; - *pSchema = createSchema(s->type, htonl(s->bytes), htonl(cols++), "stable"); + *pSchema = createSchema(s->type, htonl(s->bytes), htonl(++cols), "stable"); pSchema++; type = TSDB_DATA_TYPE_BIGINT; - *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "uid"); + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(++cols), "uid"); pSchema++; type = TSDB_DATA_TYPE_INT; - *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(cols++), "vgId"); + *pSchema = createSchema(type, htonl(tDataTypes[type].bytes), htonl(++cols), "vgId"); + assert(cols == numOfCols); pRsp->metaInfo.numOfColumns = htonl(cols); SRpcMsg rpcMsg = { .handle = pMsg->handle, .ahandle = pMsg->ahandle, .pCont = pRsp, - .contLen = sizeof(*pRsp), + .contLen = msgSize, .code = code, };