From 5703d2921c7954f7842e644d5b952d96ef3b6a70 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 9 Feb 2022 19:41:14 +0800 Subject: [PATCH] drop stb --- include/common/tmsg.h | 3 +++ source/common/src/tmsg.c | 16 ++++++++++++++ source/dnode/mnode/impl/src/mndStb.c | 22 ++++++++++--------- source/dnode/mnode/impl/test/stb/stb.cpp | 11 ++++++---- source/libs/parser/inc/astToMsg.h | 4 ++-- source/libs/parser/src/astToMsg.c | 28 +++++++++++++++--------- source/libs/parser/src/dCDAstProcess.c | 4 ++-- 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 611902e8d9..fd00ba6a82 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -272,6 +272,9 @@ typedef struct { int8_t igNotExists; } SMDropStbReq; +int32_t tSerializeSMDropStbReq(void** buf, SMDropStbReq* pReq); +void* tDeserializeSMDropStbReq(void* buf, SMDropStbReq* pReq); + typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t alterType; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0711981436..6e3bd5fb66 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -399,3 +399,19 @@ void *tDeserializeSMCreateStbReq(void *buf, SMCreateStbReq *pReq) { return buf; } + +int32_t tSerializeSMDropStbReq(void **buf, SMDropStbReq *pReq) { + int32_t tlen = 0; + + tlen += taosEncodeString(buf, pReq->name); + tlen += taosEncodeFixedI8(buf, pReq->igNotExists); + + return tlen; +} + +void *tDeserializeSMDropStbReq(void *buf, SMDropStbReq *pReq) { + buf = taosDecodeStringTo(buf, pReq->name); + buf = taosDecodeFixedI8(buf, &pReq->igNotExists); + + return buf; +} diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 845f911787..30f3f550fb 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1118,28 +1118,30 @@ DROP_STB_OVER: } static int32_t mndProcessMDropStbReq(SMnodeMsg *pReq) { - SMnode *pMnode = pReq->pMnode; - SMDropStbReq *pDrop = pReq->rpcMsg.pCont; + SMnode *pMnode = pReq->pMnode; + + SMDropStbReq dropReq = {0}; + tDeserializeSMDropStbReq(pReq->rpcMsg.pCont, &dropReq); - mDebug("stb:%s, start to drop", pDrop->name); + mDebug("stb:%s, start to drop", dropReq.name); - SStbObj *pStb = mndAcquireStb(pMnode, pDrop->name); + SStbObj *pStb = mndAcquireStb(pMnode, dropReq.name); if (pStb == NULL) { - if (pDrop->igNotExists) { - mDebug("stb:%s, not exist, ignore not exist is set", pDrop->name); + if (dropReq.igNotExists) { + mDebug("stb:%s, not exist, ignore not exist is set", dropReq.name); return 0; } else { terrno = TSDB_CODE_MND_STB_NOT_EXIST; - mError("stb:%s, failed to drop since %s", pDrop->name, terrstr()); + mError("stb:%s, failed to drop since %s", dropReq.name, terrstr()); return -1; } } - SDbObj *pDb = mndAcquireDbByStb(pMnode, pDrop->name); + SDbObj *pDb = mndAcquireDbByStb(pMnode, dropReq.name); if (pDb == NULL) { mndReleaseStb(pMnode, pStb); terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - mError("stb:%s, failed to drop since %s", pDrop->name, terrstr()); + mError("stb:%s, failed to drop since %s", dropReq.name, terrstr()); return -1; } @@ -1148,7 +1150,7 @@ static int32_t mndProcessMDropStbReq(SMnodeMsg *pReq) { mndReleaseStb(pMnode, pStb); if (code != 0) { - mError("stb:%s, failed to drop since %s", pDrop->name, terrstr()); + mError("stb:%s, failed to drop since %s", dropReq.name, terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/test/stb/stb.cpp b/source/dnode/mnode/impl/test/stb/stb.cpp index b870bc8fe8..951964a8e1 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -388,12 +388,15 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { } { - int32_t contLen = sizeof(SMDropStbReq); + SMDropStbReq dropReq = {0}; + strcpy(dropReq.name, stbname); - SMDropStbReq* pReq = (SMDropStbReq*)rpcMallocCont(contLen); - strcpy(pReq->name, stbname); + int32_t contLen = tSerializeSMDropStbReq(NULL, &dropReq); + void* pHead = rpcMallocCont(contLen); + void* pBuf = pHead; + tSerializeSMDropStbReq(&pBuf, &dropReq); - SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pHead, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); } diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 8f2c2ad4b3..82648e0bfa 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -10,8 +10,8 @@ SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext *pCtx, SMsgBuf* pMsgBuf); -SMCreateStbReq* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); -SMDropStbReq* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); +char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); +char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); SCreateDnodeReq *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); SDropDnodeReq *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index dbbfc8be2e..e1828b6a26 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -249,8 +249,7 @@ SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext *pCtx return pCreateMsg; } -SMCreateStbReq* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, - SMsgBuf* pMsgBuf) { +char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { SMCreateStbReq createReq = {0}; createReq.igExists = pCreateTableSql->existCheck ? 1 : 0; createReq.pColumns = pCreateTableSql->colInfo.pColumns; @@ -275,30 +274,39 @@ SMCreateStbReq* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len return NULL; } - void *buf = req; + void* buf = req; tSerializeSMCreateStbReq(&buf, &createReq); *len = tlen; return req; } -SMDropStbReq* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { +char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0); - SName name = {0}; + SName name = {0}; int32_t code = createSName(&name, tableName, pParseCtx, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { terrno = buildInvalidOperationMsg(pMsgBuf, "invalid table name"); return NULL; } - SMDropStbReq *pDropTableMsg = (SMDropStbReq*) calloc(1, sizeof(SMDropStbReq)); + SMDropStbReq dropReq = {0}; + code = tNameExtractFullName(&name, dropReq.name); - code = tNameExtractFullName(&name, pDropTableMsg->name); assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T); + dropReq.igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - *len = sizeof(SMDropStbReq); - return pDropTableMsg; + int32_t tlen = tSerializeSMDropStbReq(NULL, &dropReq); + void* req = malloc(tlen); + if (req == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + void* buf = req; + tSerializeSMDropStbReq(&buf, &dropReq); + *len = tlen; + return req; } SCreateDnodeReq *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 50ae3bfd26..4b70d2c6c3 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -924,13 +924,13 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch goto _error; } - pDcl->pMsg = (char*)buildCreateStbMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->pMsg = buildCreateStbReq(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); pDcl->msgType = TDMT_MND_CREATE_STB; break; } case TSDB_SQL_DROP_TABLE: { - pDcl->pMsg = (char*)buildDropStableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->pMsg = buildDropStableReq(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); if (pDcl->pMsg == NULL) { goto _error; } -- GitLab