diff --git a/include/util/tdef.h b/include/util/tdef.h index 64a169b4f16616e6521c8cc99d4c54dcc659528e..5edd0549f08b755b8e818a0d5b283716edbcbe98 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -204,7 +204,7 @@ do { \ #define TSDB_CLUSTER_ID_LEN 40 #define TSDB_FQDN_LEN 128 -#define TSDB_EP_LEN (TSDB_FQDN_LEN+6) +#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6) #define TSDB_IPv4ADDR_LEN 16 #define TSDB_FILENAME_LEN 128 #define TSDB_SHOW_SQL_LEN 512 diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 0ee99f77aa9219a8ea135058f35f63702abedd9c..e584a6685afed40be396b56559fc005e59bc94fc 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -420,7 +420,15 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); } - SDataBuf buf = {.pData = pMsg->pCont, .len = pMsg->contLen}; + SDataBuf buf = {.len = pMsg->contLen}; + buf.pData = calloc(1, pMsg->contLen); + if (buf.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pMsg->code = TSDB_CODE_OUT_OF_MEMORY; + } else { + memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + } + pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); rpcFreeCont(pMsg->pCont); } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index bdf54eb21c198657b683bc10b8e69b16e84ec875..b46304e62285ecadd16a45cc2da21039ed1e5a95 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -99,10 +99,10 @@ SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { } else { assert(pRequest != NULL); pMsgSendInfo->requestObjRefId = pRequest->self; - pMsgSendInfo->msgInfo = pRequest->body.requestMsg; - pMsgSendInfo->msgType = pRequest->type; + pMsgSendInfo->msgInfo = pRequest->body.requestMsg; + pMsgSendInfo->msgType = pRequest->type; pMsgSendInfo->requestId = pRequest->requestId; - pMsgSendInfo->param = pRequest; + pMsgSendInfo->param = pRequest; pMsgSendInfo->fp = (handleRequestRspFp[pRequest->type] == NULL)? genericRspCallback:handleRequestRspFp[pRequest->type]; } @@ -165,8 +165,11 @@ int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) pRetrieve->precision = htons(pRetrieve->precision); SReqResultInfo* pResInfo = &pRequest->body.resInfo; + + tfree(pResInfo->pRspMsg); + pResInfo->pRspMsg = pMsg->pData; pResInfo->numOfRows = pRetrieve->numOfRows; - pResInfo->pData = pRetrieve->data; // todo fix this in async model + pResInfo->pData = pRetrieve->data; // todo fix this in async model pResInfo->current = 0; setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index d14719fffbaa1c4d2b90ef8c859b2caff60a3465..f5943fd01ad701ef395319ae10858114eb703f13 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -169,6 +169,44 @@ TEST(testCase, create_db_Test) { taos_close(pConn); } +TEST(testCase, create_dnode_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create dnode abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create 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, drop_dnode_Test) { + TAOS* pConn = taos_connect("ubuntu", "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("ubuntu", "root", "taosdata", NULL, 0); assert(pConn != NULL); @@ -273,7 +311,6 @@ TEST(testCase, show_stable_Test) { } TAOS_ROW pRow = NULL; - TAOS_FIELD* pFields = taos_fetch_fields(pRes); int32_t numOfFields = taos_num_fields(pRes); @@ -284,7 +321,6 @@ TEST(testCase, show_stable_Test) { } taos_free_result(pRes); - taos_close(pConn); } diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 848bbc346e195950ee9f4ad55b7e821cf6f121a2..a2843b587152205a8740f6677d603093087aca60 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -13,5 +13,7 @@ SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* ms SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); +SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); #endif // TDENGINE_ASTTOMSG_H diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 6b92357748595e57103453f83c8445e9e684bfa6..bafa9b25d409252729c2f6d3c7c16461d4fa66c9 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -376,3 +376,43 @@ SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* return pDropTableMsg; } +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"; + + if (taosArrayGetSize(pInfo->pMiscInfo->a) > 1) { + buildInvalidOperationMsg(pMsgBuf, msg1); + return NULL; + } + + SToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0); + if (id->type != TK_ID) { + buildInvalidOperationMsg(pMsgBuf, msg2); + return NULL; + } + + SCreateDnodeMsg *pCreate = (SCreateDnodeMsg *) calloc(1, sizeof(SCreateDnodeMsg)); + strncpy(pCreate->ep, id->z, id->n); + *len = sizeof(SCreateDnodeMsg); + + return pCreate; +} + +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); + *len = sizeof(SDropDnodeMsg); + + if (end - pzName->z != pzName->n) { + buildInvalidOperationMsg(pMsgBuf, "invalid dnode id"); + tfree(pDrop); + return NULL; + } + + return pDrop; +} + diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index ddbd6eb58cdc6469e0d2ca0cab9a150f977cb252..abf78f4f85c41e5792128a6561f86dc4ee7b9655 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -712,11 +712,30 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_DROP_TABLE: { pDcl->pMsg = (char*)buildDropTableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); if (pDcl->pMsg == NULL) { - return terrno; + code = terrno; } pDcl->msgType = TDMT_MND_DROP_STB; - return TSDB_CODE_SUCCESS; + break; + } + + case TSDB_SQL_CREATE_DNODE: { + pDcl->pMsg = (char*) buildCreateDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); + if (pDcl->pMsg == NULL) { + code = terrno; + } + + pDcl->msgType = TDMT_MND_CREATE_DNODE; + break; + } + + case TSDB_SQL_DROP_DNODE: { + pDcl->pMsg = (char*) buildDropDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); + if (pDcl->pMsg == NULL) { + code = terrno; + } + + pDcl->msgType = TDMT_MND_DROP_DNODE; break; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 0f77135ec1a38dea1ee2214fa44383a502195106..5c9a48e52f2b7ed945275bd4c25b7bfb03974f8a 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -44,11 +44,12 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (!isDqlSqlStatement(&info)) { - SDclStmtInfo* pDcl = calloc(1, sizeof(SQueryStmtInfo)); + SDclStmtInfo* pDcl = calloc(1, sizeof(SDclStmtInfo)); if (NULL == pDcl) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code. return terrno; } + pDcl->nodeType = info.type; int32_t code = qParserValidateDclSqlNode(&info, &pCxt->ctx, pDcl, pCxt->pMsg, pCxt->msgLen); if (code == TSDB_CODE_SUCCESS) {