From 6454a205a855c8e6f3fc62ceab5805bcb383e63c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 16 May 2022 12:13:59 +0000 Subject: [PATCH] more alter table --- source/dnode/vnode/inc/vnode.h | 2 ++ source/dnode/vnode/src/meta/metaTable.c | 40 ++++++++++++++++--------- source/dnode/vnode/src/vnd/vnodeSvr.c | 24 +++++++++++---- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 4431a2c48b..f7eac3a9d9 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -196,6 +196,8 @@ struct SMetaEntry { STSma *tsma; } smaEntry; }; + + uint8_t *pBuf; }; struct SMetaReader { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 2c260531da..d218f49e14 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -523,7 +523,8 @@ _err: } static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - SMetaEntry entry = {0}; + SMetaEntry ctbEntry = {0}; + SMetaEntry stbEntry = {0}; void *pVal = NULL; int nVal = 0; int ret; @@ -555,35 +556,46 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA oversion = *(int64_t *)pData; // search table.db - TDBC *pTbDbc = NULL; + TDBC *pTbDbc = NULL; + SDecoder dc = {0}; + /* get ctbEntry */ tdbDbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn); tdbDbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); ASSERT(c == 0); tdbDbcGet(pTbDbc, NULL, NULL, &pData, &nData); - // get table entry - SDecoder dc = {0}; - tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &entry); + ctbEntry.pBuf = taosMemoryMalloc(nData); + memcpy(ctbEntry.pBuf, pData, nData); + tDecoderInit(&dc, ctbEntry.pBuf, nData); + metaDecodeEntry(&dc, &ctbEntry); + tDecoderClear(&dc); - if (entry.type != TSDB_CHILD_TABLE) { - terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; - goto _err; - } + /* get stbEntry*/ - // do actual job { - // TODO + // get table entry + // SDecoder dc = {0}; + // tDecoderInit(&dc, pData, nData); + // metaDecodeEntry(&dc, &ctbEntry); + + // if (ctbEntry.type != TSDB_CHILD_TABLE) { + // terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; + // goto _err; + // } + + // // do actual job + // { + // // TODO + // } } - tDecoderClear(&dc); + // tDecoderClear(&dc); tdbDbcClose(pTbDbc); tdbDbcClose(pUidIdxc); return 0; _err: - tDecoderClear(&dc); tdbDbcClose(pTbDbc); tdbDbcClose(pUidIdxc); return -1; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 43d68fc9fd..43ff04a287 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -199,7 +199,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { int32_t ret = TAOS_SYNC_PROPOSE_OTHER_ERROR; - + if (syncEnvIsStart()) { SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); assert(pSyncNode != NULL); @@ -462,7 +462,11 @@ _exit: static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { SVAlterTbReq vAlterTbReq = {0}; + SVAlterTbRsp vAlterTbRsp = {0}; SDecoder dc = {0}; + int rcode = 0; + int ret; + SEncoder ec = {0}; pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP; pRsp->pCont = NULL; @@ -473,19 +477,27 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, i // decode if (tDecodeSVAlterTbReq(&dc, &vAlterTbReq) < 0) { - pRsp->code = TSDB_CODE_INVALID_MSG; + vAlterTbRsp.code = TSDB_CODE_INVALID_MSG; tDecoderClear(&dc); - return -1; + rcode = -1; + goto _exit; } // process if (metaAlterTable(pVnode->pMeta, version, &vAlterTbReq) < 0) { - pRsp->code = terrno; + vAlterTbRsp.code = TSDB_CODE_INVALID_MSG; tDecoderClear(&dc); - return -1; + rcode = -1; + goto _exit; } - tDecoderClear(&dc); + +_exit: + tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret); + pRsp->pCont = rpcMallocCont(pRsp->contLen); + tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); + tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp); + tEncoderClear(&ec); return 0; } -- GitLab