From 9fc55aa7f4d6967bfe8a60f7bba18d00b65e40ea Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 19 Apr 2022 06:23:54 +0000 Subject: [PATCH] refactor: vnode --- include/common/tmsg.h | 14 ++-- source/common/src/tmsg.c | 104 ++++++++++++++++++------- source/dnode/mnode/impl/src/mndStb.c | 1 - source/dnode/vnode/src/vnd/vnodeSvr.c | 4 - source/libs/parser/src/parTranslater.c | 2 + 5 files changed, 83 insertions(+), 42 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 32d59c6929..64cdbc0d5c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1444,10 +1444,9 @@ typedef struct SVCreateTbReq { union { struct { tb_uid_t suid; - col_id_t nCols; - col_id_t nBSmaCols; + int16_t nCols; SSchema* pSchema; - col_id_t nTagCols; + int16_t nTagCols; SSchema* pTagSchema; SRSmaParam* pRSmaParam; } stbCfg; @@ -1456,14 +1455,15 @@ typedef struct SVCreateTbReq { SKVRow pTag; } ctbCfg; struct { - col_id_t nCols; - col_id_t nBSmaCols; - SSchema* pSchema; - SRSmaParam* pRSmaParam; + int16_t nCols; + SSchema* pSchema; } ntbCfg; }; } SVCreateTbReq, SVUpdateTbReq; +int tEncodeSVCreateTbReq(SCoder* pCoder, const SVCreateTbReq* pReq); +int tDecodeSVCreateTbReq(SCoder* pCoder, SVCreateTbReq* pReq); + typedef struct { int32_t code; } SVCreateTbRsp, SVUpdateTbRsp; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 30524471a9..bd8d54c437 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -394,6 +394,80 @@ int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchR return 0; } +int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) { +#if 0 + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; + if (tEncodeU32v(pCoder, pReq->ttl) < 0) return -1; + if (tEncodeU32v(pCoder, pReq->keep) < 0) return -1; + if (tEncodeI8(pCoder, pReq->type) < 0) return -1; + + if (pReq->type == TSDB_SUPER_TABLE) { + if (tEncodeI64(pCoder, pReq->stbCfg.suid) < 0) return -1; + if (tEncodeI16v(pCoder, pReq->stbCfg.nCols) < 0) return -1; + for (int i = 0; i < pReq->stbCfg.nCols; i++) { + if (tEncodeSSchema(pCoder, pReq->stbCfg.pSchema + i) < 0) return -1; + } + if (tEncodeI16v(pCoder, pReq->stbCfg.nTagCols) < 0) return -1; + for (int i = 0; i < pReq->stbCfg.nTagCols; i++) { + if (tEncodeSSchema(pCoder, pReq->stbCfg.pTagSchema + i) < 0) return -1; + } + + } else if (pReq->type == TSDB_CHILD_TABLE) { + if (tEncodeI64(pCoder, pReq->ctbCfg.suid) < 0) return -1; + // TODO: encode SKVRow + } else if (pReq->type == TSDB_NORMAL_TABLE) { + if (tEncodeI16v(pCoder, pReq->ntbCfg.nCols) < 0) return -1; + for (int i = 0; i < pReq->ntbCfg.nCols; i++) { + if (tEncodeSSchema(pCoder, pReq->stbCfg.pSchema + i) < 0) return -1; + } + } else { + ASSERT(0); + } + + tEndEncode(pCoder); +#endif + return 0; +} + +int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) { +#if 0 + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; + if (tDecodeU32v(pCoder, &pReq->ttl) < 0) return -1; + if (tDecodeU32v(pCoder, &pReq->keep) < 0) return -1; + if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; + + if (pReq->type == TSDB_SUPER_TABLE) { + if (tDecodeI64(pCoder, &pReq->stbCfg.suid) < 0) return -1; + if (tDecodeI16v(pCoder, &pReq->stbCfg.nCols) < 0) return -1; + for (int i = 0; i < pReq->stbCfg.nCols; i++) { + if (tDecodeSSchema(pCoder, &pReq->stbCfg.pSchema + i) < 0) return -1; + } + if (tDecodeI16v(pCoder, pReq->stbCfg.nTagCols) < 0) return -1; + for (int i = 0; i < pReq->stbCfg.nTagCols; i++) { + if (tDecodeSSchema(pCoder, pReq->stbCfg.pTagSchema + i) < 0) return -1; + } + + } else if (pReq->type == TSDB_CHILD_TABLE) { + if (tDecodeI64(pCoder, pReq->ctbCfg.suid) < 0) return -1; + // TODO: decode SKVRow + } else if (pReq->type == TSDB_NORMAL_TABLE) { + if (tDecodeI16v(pCoder, pReq->ntbCfg.nCols) < 0) return -1; + for (int i = 0; i < pReq->ntbCfg.nCols; i++) { + if (tDecodeSSchema(pCoder, pReq->stbCfg.pSchema + i) < 0) return -1; + } + } else { + ASSERT(0); + } + + tEndDecode(pCoder); +#endif + return 0; +} + int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int32_t tlen = 0; @@ -406,7 +480,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { case TD_SUPER_TABLE: tlen += taosEncodeFixedI64(buf, pReq->stbCfg.suid); tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nCols); - tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); for (col_id_t i = 0; i < pReq->stbCfg.nCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type); tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].flags); @@ -438,7 +511,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { break; case TD_NORMAL_TABLE: tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nCols); - tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nBSmaCols); for (col_id_t i = 0; i < pReq->ntbCfg.nCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type); tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].flags); @@ -446,15 +518,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); } - if (pReq->rollup && pReq->ntbCfg.pRSmaParam) { - SRSmaParam *param = pReq->ntbCfg.pRSmaParam; - tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); - tlen += taosEncodeFixedI32(buf, param->delay); - tlen += taosEncodeFixedI8(buf, param->nFuncIds); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); - } - } break; default: ASSERT(0); @@ -473,7 +536,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { case TD_SUPER_TABLE: buf = taosDecodeFixedI64(buf, &(pReq->stbCfg.suid)); buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nCols)); - buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); pReq->stbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchema)); for (col_id_t i = 0; i < pReq->stbCfg.nCols; ++i) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type)); @@ -515,7 +577,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { break; case TD_NORMAL_TABLE: buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.nCols); - buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols)); pReq->ntbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchema)); for (col_id_t i = 0; i < pReq->ntbCfg.nCols; ++i) { buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type); @@ -524,23 +585,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } - if (pReq->rollup) { - pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam)); - SRSmaParam *param = pReq->ntbCfg.pRSmaParam; - buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); - buf = taosDecodeFixedI32(buf, ¶m->delay); - buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); - if (param->nFuncIds > 0) { - param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t)); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - buf = taosDecodeFixedI32(buf, param->pFuncIds + i); - } - } else { - param->pFuncIds = NULL; - } - } else { - pReq->ntbCfg.pRSmaParam = NULL; - } break; default: ASSERT(0); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3ead2f26a3..71b9fc2a77 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -357,7 +357,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt req.stbCfg.nCols = pStb->numOfColumns; req.stbCfg.nTagCols = pStb->numOfTags; req.stbCfg.pTagSchema = pStb->pTags; - req.stbCfg.nBSmaCols = pStb->numOfSmas; req.stbCfg.pSchema = (SSchema *)taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema)); if (req.stbCfg.pSchema == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index fface9d6c5..01241ec686 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -253,10 +253,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR taosMemoryFree(pCreateTbReq->ctbCfg.pTag); } else { taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); - if (pCreateTbReq->ntbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); - } } } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 5eb9815dd7..ded9b5dbd1 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2756,6 +2756,7 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { return TSDB_CODE_SUCCESS; } +#if 0 pReq->ntbCfg.pRSmaParam = taosMemoryCalloc(1, sizeof(SRSmaParam)); if (NULL == pReq->ntbCfg.pRSmaParam) { return TSDB_CODE_OUT_OF_MEMORY; @@ -2770,6 +2771,7 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { int32_t index = 0; SNode* pFunc = NULL; FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; } +#endif return TSDB_CODE_SUCCESS; }