serialize show req

This commit is contained in:
Shengliang Guan 2022-02-14 18:42:42 +08:00
parent 54584fd1e1
commit a72fe7750b
9 changed files with 182 additions and 80 deletions

View File

@ -275,6 +275,7 @@ typedef struct {
int32_t tSerializeSMCreateStbReq(void** buf, SMCreateStbReq* pReq); int32_t tSerializeSMCreateStbReq(void** buf, SMCreateStbReq* pReq);
void* tDeserializeSMCreateStbReq(void* buf, SMCreateStbReq* pReq); void* tDeserializeSMCreateStbReq(void* buf, SMCreateStbReq* pReq);
void tFreeSMCreateStbReq(SMCreateStbReq* pReq);
typedef struct { typedef struct {
char name[TSDB_TABLE_FNAME_LEN]; char name[TSDB_TABLE_FNAME_LEN];
@ -888,12 +889,16 @@ typedef struct {
* payloadLen is the length of payload * payloadLen is the length of payload
*/ */
typedef struct { typedef struct {
int8_t type; int32_t type;
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int16_t payloadLen; int32_t payloadLen;
char payload[]; char* payload;
} SShowReq; } SShowReq;
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
void tFreeSShowReq(SShowReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int32_t numOfVgroup; int32_t numOfVgroup;

View File

@ -440,6 +440,11 @@ void *tDeserializeSMCreateStbReq(void *buf, SMCreateStbReq *pReq) {
return buf; return buf;
} }
void tFreeSMCreateStbReq(SMCreateStbReq *pReq) {
taosArrayDestroy(pReq->pColumns);
taosArrayDestroy(pReq->pTags);
}
int32_t tSerializeSMDropStbReq(void **buf, SMDropStbReq *pReq) { int32_t tSerializeSMDropStbReq(void **buf, SMDropStbReq *pReq) {
int32_t tlen = 0; int32_t tlen = 0;
@ -1469,4 +1474,43 @@ void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) {
} }
taosArrayDestroy(pRsp->pArray); taosArrayDestroy(pRsp->pArray);
} }
int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI32(&encoder, pReq->type) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
if (tEncodeI32(&encoder, pReq->payloadLen) < 0) return -1;
if (pReq->payloadLen > 0) {
if (tEncodeCStr(&encoder, pReq->payload) < 0) return -1;
}
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->type) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->payloadLen) < 0) return -1;
if (pReq->payloadLen > 0) {
pReq->payload = malloc(pReq->payloadLen);
if (pReq->payload == NULL) return -1;
if (tDecodeCStrTo(&decoder, pReq->payload) < 0) return -1;
}
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
void tFreeSShowReq(SShowReq *pReq) { free(pReq->payload); }

View File

@ -80,12 +80,16 @@ SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) {
} }
void Testbase::SendShowMetaReq(int8_t showType, const char* db) { void Testbase::SendShowMetaReq(int8_t showType, const char* db) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen); showReq.type = showType;
pShow->type = showType; //strcpy(showReq.db, db);
strcpy(pShow->db, db);
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
char* pReq = (char*)rpcMallocCont(contLen);
tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pReq, contLen);
SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont; SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont;
ASSERT(pShowRsp != nullptr); ASSERT(pShowRsp != nullptr);

View File

@ -118,27 +118,28 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
static int32_t mndProcessShowReq(SMnodeMsg *pReq) { static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SShowMgmt *pMgmt = &pMnode->showMgmt; SShowMgmt *pMgmt = &pMnode->showMgmt;
SShowReq *pShowReq = pReq->rpcMsg.pCont; int32_t code = -1;
int8_t type = pShowReq->type; SShowReq showReq = {0};
int16_t payloadLen = htonl(pShowReq->payloadLen);
if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) { if (tDeserializeSShowReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &showReq) != 0) {
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; terrno = TSDB_CODE_INVALID_MSG;
mError("failed to process show-meta req since %s", terrstr()); goto SHOW_OVER;
return -1;
} }
ShowMetaFp metaFp = pMgmt->metaFps[type]; if (showReq.type <= TSDB_MGMT_TABLE_START || showReq.type >= TSDB_MGMT_TABLE_MAX) {
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
goto SHOW_OVER;
}
ShowMetaFp metaFp = pMgmt->metaFps[showReq.type];
if (metaFp == NULL) { if (metaFp == NULL) {
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr()); goto SHOW_OVER;
return -1;
} }
SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq); SShowObj *pShow = mndCreateShowObj(pMnode, &showReq);
if (pShow == NULL) { if (pShow == NULL) {
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr()); goto SHOW_OVER;
return -1;
} }
int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
@ -146,26 +147,30 @@ static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
if (pRsp == NULL) { if (pRsp == NULL) {
mndReleaseShowObj(pShow, true); mndReleaseShowObj(pShow, true);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("show:0x%" PRIx64 ", failed to process show-meta req:%s since malloc rsp error", pShow->id, goto SHOW_OVER;
mndShowStr(type));
return -1;
} }
int32_t code = (*metaFp)(pReq, pShow, &pRsp->tableMeta); code = (*metaFp)(pReq, pShow, &pRsp->tableMeta);
mDebug("show:0x%" PRIx64 ", 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 showReq.type:%s, result:%s", pShow->id,
pShow->numOfColumns, mndShowStr(type), tstrerror(code)); pShow->numOfRows, pShow->numOfColumns, mndShowStr(showReq.type), tstrerror(code));
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
pReq->pCont = pRsp; pReq->pCont = pRsp;
pRsp->showId = htobe64(pShow->id); pRsp->showId = htobe64(pShow->id);
mndReleaseShowObj(pShow, false); mndReleaseShowObj(pShow, false);
return TSDB_CODE_SUCCESS;
} else { } else {
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
mndReleaseShowObj(pShow, true); mndReleaseShowObj(pShow, true);
return code;
} }
SHOW_OVER:
if (code != 0) {
mError("failed to process show-meta req since %s", terrstr());
}
tFreeSShowReq(&showReq);
return code;
} }
static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {

View File

@ -56,10 +56,13 @@ TEST_F(MndTestAcct, 03_Drop_Acct) {
} }
TEST_F(MndTestAcct, 04_Show_Acct) { TEST_F(MndTestAcct, 04_Show_Acct) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_ACCT;
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_ACCT; void* pReq = rpcMallocCont(contLen);
tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);

View File

@ -26,11 +26,13 @@ class MndTestShow : public ::testing::Test {
Testbase MndTestShow::test; Testbase MndTestShow::test;
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_MAX;
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_MAX; void* pReq = rpcMallocCont(contLen);
strcpy(pReq->db, ""); tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
@ -38,11 +40,13 @@ TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
} }
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_START;
SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq)); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_START; void* pReq = rpcMallocCont(contLen);
strcpy(pReq->db, ""); tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);

View File

@ -1,18 +1,32 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_ASTTOMSG_H #ifndef TDENGINE_ASTTOMSG_H
#define TDENGINE_ASTTOMSG_H #define TDENGINE_ASTTOMSG_H
#include "parserInt.h" #include "parserInt.h"
#include "tmsg.h" #include "tmsg.h"
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t *len, SParseContext *pCtx, SMsgBuf* pMsgBuf); char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf);
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
#endif // TDENGINE_ASTTOMSG_H #endif // TDENGINE_ASTTOMSG_H

View File

@ -1,3 +1,18 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "astGenerator.h" #include "astGenerator.h"
#include "parserInt.h" #include "parserInt.h"
#include "parserUtil.h" #include "parserUtil.h"
@ -11,7 +26,7 @@ char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id,
createReq.superUser = (int8_t)pUser->type; createReq.superUser = (int8_t)pUser->type;
if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
// pMsg->privilege = (char)pCmd->count; // pMsg->privilege = (char)pCmd->count;
} else { } else {
strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n); strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n);
} }
@ -71,7 +86,7 @@ char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id,
return pReq; return pReq;
} }
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgBufLen) {
SDropUserReq dropReq = {0}; SDropUserReq dropReq = {0};
SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0);
@ -89,30 +104,26 @@ char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBu
} }
tSerializeSDropUserReq(pReq, tlen, &dropReq); tSerializeSDropUserReq(pReq, tlen, &dropReq);
*msgLen = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pCtx, SMsgBuf* pMsgBuf) { char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
SShowReq* pShowMsg = calloc(1, sizeof(SShowReq)); SShowReq showReq = {.type = pShowInfo->showType};
if (pShowMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return pShowMsg;
}
pShowMsg->type = pShowInfo->showType;
if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
SToken* pPattern = &pShowInfo->pattern; SToken* pPattern = &pShowInfo->pattern;
if (pPattern->type > 0) { // only show tables support wildcard query if (pPattern->type > 0) { // only show tables support wildcard query
strncpy(pShowMsg->payload, pPattern->z, pPattern->n); showReq.payloadLen = pPattern->n;
pShowMsg->payloadLen = htons(pPattern->n); showReq.payload = malloc(showReq.payloadLen);
strncpy(showReq.payload, pPattern->z, pPattern->n);
} }
} else { } else {
SToken* pEpAddr = &pShowInfo->prefix; SToken* pEpAddr = &pShowInfo->prefix;
assert(pEpAddr->n > 0 && pEpAddr->type > 0); assert(pEpAddr->n > 0 && pEpAddr->type > 0);
showReq.payloadLen = pEpAddr->n;
strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); showReq.payload = malloc(showReq.payloadLen);
pShowMsg->payloadLen = htons(pEpAddr->n); strncpy(showReq.payload, pEpAddr->z, pEpAddr->n);
} }
if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) { if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) {
@ -121,22 +132,32 @@ SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pCtx, SMsgBuf* pMsgB
if (pShowInfo->prefix.n > 0) { if (pShowInfo->prefix.n > 0) {
if (pShowInfo->prefix.n >= TSDB_DB_FNAME_LEN) { if (pShowInfo->prefix.n >= TSDB_DB_FNAME_LEN) {
terrno = buildInvalidOperationMsg(pMsgBuf, "prefix name is too long"); terrno = buildInvalidOperationMsg(pMsgBuf, "prefix name is too long");
tfree(pShowMsg); tFreeSShowReq(&showReq);
return NULL; return NULL;
} }
tNameSetDbName(&n, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n); tNameSetDbName(&n, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n);
} else if (pCtx->db == NULL || strlen(pCtx->db) == 0) { } else if (pCtx->db == NULL || strlen(pCtx->db) == 0) {
terrno = buildInvalidOperationMsg(pMsgBuf, "database is not specified"); terrno = buildInvalidOperationMsg(pMsgBuf, "database is not specified");
tfree(pShowMsg); tFreeSShowReq(&showReq);
return NULL; return NULL;
} else { } else {
tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db)); tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db));
} }
tNameGetFullDbName(&n, pShowMsg->db); tNameGetFullDbName(&n, showReq.db);
} }
return pShowMsg; int32_t tlen = tSerializeSShowReq(NULL, 0, &showReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
tSerializeSShowReq(pReq, tlen, &showReq);
tFreeSShowReq(&showReq);
*outputLen = tlen;
return pReq;
} }
static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) { static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) {
@ -330,7 +351,7 @@ static int32_t doCheckDbOptions(SCreateDbReq* pCreate, SMsgBuf* pMsgBuf) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* len, SParseContext* pCtx, SMsgBuf* pMsgBuf) { char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
SCreateDbReq createReq = {0}; SCreateDbReq createReq = {0};
if (setDbOptions(&createReq, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) { if (setDbOptions(&createReq, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) {
@ -360,11 +381,12 @@ char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* len, SParseContext
} }
tSerializeSCreateDbReq(pReq, tlen, &createReq); tSerializeSCreateDbReq(pReq, tlen, &createReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx,
SMsgBuf* pMsgBuf) {
SMCreateStbReq createReq = {0}; SMCreateStbReq createReq = {0};
createReq.igExists = pCreateTableSql->existCheck ? 1 : 0; createReq.igExists = pCreateTableSql->existCheck ? 1 : 0;
createReq.pColumns = pCreateTableSql->colInfo.pColumns; createReq.pColumns = pCreateTableSql->colInfo.pColumns;
@ -374,11 +396,13 @@ char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseCo
SName n = {0}; SName n = {0};
if (createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf) != 0) { if (createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf) != 0) {
tFreeSMCreateStbReq(&createReq);
return NULL; return NULL;
} }
if (tNameExtractFullName(&n, createReq.name) != 0) { if (tNameExtractFullName(&n, createReq.name) != 0) {
buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified"); buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified");
tFreeSMCreateStbReq(&createReq);
return NULL; return NULL;
} }
@ -391,11 +415,12 @@ char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseCo
void* pBuf = pReq; void* pBuf = pReq;
tSerializeSMCreateStbReq(&pBuf, &createReq); tSerializeSMCreateStbReq(&pBuf, &createReq);
*len = tlen; tFreeSMCreateStbReq(&createReq);
*outputLen = tlen;
return pReq; return pReq;
} }
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) {
SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0);
SName name = {0}; SName name = {0};
@ -420,11 +445,11 @@ char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx
void* pBuf = pReq; void* pBuf = pReq;
tSerializeSMDropStbReq(&pBuf, &dropReq); tSerializeSMDropStbReq(&pBuf, &dropReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
const char* msg1 = "invalid host name (name too long, maximum length 128)"; const char* msg1 = "invalid host name (name too long, maximum length 128)";
const char* msg2 = "dnode name can not be string"; const char* msg2 = "dnode name can not be string";
const char* msg3 = "port should be an integer that is less than 65535 and greater than 0"; const char* msg3 = "port should be an integer that is less than 65535 and greater than 0";
@ -469,11 +494,11 @@ char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) {
} }
tSerializeSCreateDnodeReq(pReq, tlen, &createReq); tSerializeSCreateDnodeReq(pReq, tlen, &createReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
SDropDnodeReq dropReq = {0}; SDropDnodeReq dropReq = {0};
SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0);
@ -494,6 +519,6 @@ char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) {
} }
tSerializeSDropDnodeReq(pReq, tlen, &dropReq); tSerializeSDropDnodeReq(pReq, tlen, &dropReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }

View File

@ -114,12 +114,10 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseContext* pCtx, void** out
} }
*pEpSet = pCtx->mgmtEpSet; *pEpSet = pCtx->mgmtEpSet;
*output = buildShowMsg(pShowInfo, pCtx, pMsgBuf); *output = buildShowMsg(pShowInfo, outputLen, pCtx, pMsgBuf);
if (*output == NULL) { if (*output == NULL) {
return terrno; return terrno;
} }
*outputLen = sizeof(SShowReq) /* + htons(pShowMsg->payloadLen)*/;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;