diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index af288456731f003f9090f289241a4a556bc882a9..050e7639196095f67cbee9cab79d668ee54bad84 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -502,8 +502,31 @@ void* doFetchRow(SRequestObj* pRequest) { pRequest->type = TDMT_MND_SHOW_RETRIEVE; } else if (pRequest->type == TDMT_VND_SHOW_TABLES) { pRequest->type = TDMT_VND_SHOW_TABLES_FETCH; - } else { - // do nothing + } else if (pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { + pRequest->type = TDMT_VND_SHOW_TABLES; + SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; + pShowReqInfo->currentIndex += 1; + if (pShowReqInfo->currentIndex >= taosArrayGetSize(pShowReqInfo->pArray)) { + return NULL; + } + + SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex); + SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); + pShowReq->head.vgId = htonl(pVgroupInfo->vgId); + + pRequest->body.requestMsg.len = sizeof(SVShowTablesReq); + pRequest->body.requestMsg.pData = pShowReq; + + SMsgSendInfo* body = buildMsgInfoImpl(pRequest); + + int64_t transporterId = 0; + STscObj *pTscObj = pRequest->pTscObj; + asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); + + tsem_wait(&pRequest->body.rspSem); + destroySendMsgInfo(body); + + pRequest->type = TDMT_VND_SHOW_TABLES_FETCH; } SMsgSendInfo* body = buildMsgInfoImpl(pRequest); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index d6d71d5fc3e583ebb512e36c2579431e26b9e69f..013cf794e3b79fb624065ee1de676fa846cd7302 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -96,24 +96,24 @@ TEST(testCase, connect_Test) { // taos_close(pConn); //} -TEST(testCase, show_user_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "show users"); - 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_close(pConn); -} +//TEST(testCase, show_user_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "show users"); +// 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_close(pConn); +//} //TEST(testCase, drop_user_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -128,24 +128,24 @@ TEST(testCase, show_user_Test) { // taos_close(pConn); //} -TEST(testCase, show_db_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "show databases"); - 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_close(pConn); -} +//TEST(testCase, show_db_Test) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +//// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "show databases"); +// 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_close(pConn); +//} //TEST(testCase, create_db_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index 2dde9e03e8346f377eced92876cb60fa32e5cf9b..a80828b6f799246819378e6fbb22b4d1ce8aa15a 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -16,6 +16,8 @@ #include "vnodeQuery.h" #include "vnodeDef.h" +static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); + int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); } int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { @@ -39,7 +41,8 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { case TDMT_VND_SHOW_TABLES: return qWorkerProcessShowMsg(pVnode, pVnode->pQuery, pMsg); case TDMT_VND_SHOW_TABLES_FETCH: - return qWorkerProcessShowFetchMsg(pVnode, pVnode->pQuery, pMsg); + return vnodeGetTableList(pVnode, pMsg); +// return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg); default: vError("unknown msg type:%d in fetch queue", pMsg->msgType); return TSDB_CODE_VND_APP_ERROR; @@ -112,5 +115,55 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pSch->bytes = htonl(pSch->bytes); } + return 0; +} + +/** + * @param pVnode + * @param pMsg + * @param pRsp + */ +static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { + SMTbCursor* pCur = metaOpenTbCursor(pVnode->pMeta); + SArray* pArray = taosArrayInit(10, POINTER_BYTES); + + char* name = NULL; + int32_t totalLen = 0; + while ((name = metaTbCursorNext(pCur)) != NULL) { + taosArrayPush(pArray, &name); + totalLen += strlen(name); + } + + metaCloseTbCursor(pCur); + + int32_t rowLen = (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; + int32_t numOfTables = (int32_t) taosArrayGetSize(pArray); + + int32_t payloadLen = rowLen * numOfTables; +// SVShowTablesFetchReq *pFetchReq = pMsg->pCont; + + SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp) + payloadLen); + memset(pFetchRsp, 0, sizeof(struct SVShowTablesFetchRsp) + payloadLen); + + char* p = pFetchRsp->data; + for(int32_t i = 0; i < numOfTables; ++i) { + char* n = taosArrayGetP(pArray, i); + STR_TO_VARSTR(p, n); + + p += rowLen; + } + + pFetchRsp->numOfRows = htonl(numOfTables); + pFetchRsp->precision = 0; + + SRpcMsg rpcMsg = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pFetchRsp, + .contLen = sizeof(SVShowTablesFetchRsp) + payloadLen, + .code = 0, + }; + + rpcSendResponse(&rpcMsg); return 0; } \ No newline at end of file