diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 11cdc1614dfb0e18f1546628ee25a1998ae17b8d..b4074e3a502e0bf7e4212e252117ed2497d2399a 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1479,7 +1479,7 @@ typedef struct SVCreateStbReq { SSchema* pSchema; int16_t nTags; SSchema* pSchemaTg; - SRSmaParam* pRSmaParam; + SRSmaParam pRSmaParam; } SVCreateStbReq; int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 6839618c0c344cc7bbd8b94f6685409b4b849c74..51dcb5fd27a7aed3cba9888065dc41cdf8fe31cf 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -3076,7 +3076,6 @@ int32_t tDeserializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq return 0; } - int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -3096,7 +3095,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq SReplica *pReplica = &pReq->replicas[i]; if (tEncodeSReplica(&encoder, pReplica) < 0) return -1; } - + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3129,7 +3128,6 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR return 0; } - int32_t tSerializeSKillQueryReq(void *buf, int32_t bufLen, SKillQueryReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -3723,16 +3721,17 @@ int tDecodeSVCreateStbReq(SCoder *pCoder, SVCreateStbReq *pReq) { if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1; if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1; if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1; - if (tDecodeI16v(pCoder, &pReq->nCols) < 0) return -1; - // TCODER_MALLOC(pReq->pSchema, SSchema, sizeof(SSchema) * pReq->nCols, pCoder); - pReq->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pReq->nCols); + if (tDecodeI16v(pCoder, &pReq->nCols) < 0) return -1; + pReq->pSchema = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pReq->nCols); + if (pReq->pSchema == NULL) return -1; for (int iCol = 0; iCol < pReq->nCols; iCol++) { if (tDecodeSSchema(pCoder, pReq->pSchema + iCol) < 0) return -1; } if (tDecodeI16v(pCoder, &pReq->nTags) < 0) return -1; - // TCODER_MALLOC(pReq->pSchemaTg, SSchema, sizeof(SSchema) * pReq->nTags, pCoder); + pReq->pSchemaTg = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pReq->nTags); + if (pReq->pSchemaTg == NULL) return -1; pReq->pSchemaTg = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pReq->nTags); for (int iTag = 0; iTag < pReq->nTags; iTag++) { if (tDecodeSSchema(pCoder, pReq->pSchemaTg + iTag) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 1afb91b92c195c572f4ca62dc94bae82e51d7954..1f2c18cb94e3acf1e1fc2f1e0a893e98127d8f7e 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -394,66 +394,55 @@ static FORCE_INLINE int schemaExColIdCompare(const void *colId, const void *pSch } static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) { -#if 0 - SName name = {0}; + SCoder coder; + int32_t contLen; + SName name = {0}; + tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); char dbFName[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(&name, dbFName); - SVCreateTbReq req = {0}; + SVCreateStbReq req = {0}; req.name = (char *)tNameGetTableName(&name); - req.ttl = 0; - req.keep = 0; + req.suid = pStb->uid; req.rollup = pStb->aggregationMethod > -1 ? 1 : 0; - req.type = TD_SUPER_TABLE; - req.stbCfg.suid = pStb->uid; - req.stbCfg.nCols = pStb->numOfColumns; - req.stbCfg.nTagCols = pStb->numOfTags; - req.stbCfg.pTagSchema = pStb->pTags; - req.stbCfg.pSchema = (SSchema *)taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema)); - if (req.stbCfg.pSchema == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + req.ttl = 0; + req.nCols = pStb->numOfColumns; + req.pSchema = pStb->pColumns; + req.nTags = pStb->numOfTags; + req.pSchemaTg = pStb->pTags; - memcpy(req.stbCfg.pSchema, pStb->pColumns, sizeof(SSchema) * pStb->numOfColumns); - for (int i = 0; i < pStb->numOfColumns; i++) { - req.stbCfg.pSchema[i].flags = SCHEMA_SMA_ON; + // TODO: remove here + for (int iCol = 0; iCol < req.nCols; iCol++) { + req.pSchema[iCol].flags = SCHEMA_SMA_ON; } - SRSmaParam *pRSmaParam = NULL; if (req.rollup) { - pRSmaParam = (SRSmaParam *)taosMemoryCalloc(1, sizeof(SRSmaParam)); - if (pRSmaParam == NULL) { - taosMemoryFreeClear(req.stbCfg.pSchema); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - - pRSmaParam->xFilesFactor = pStb->xFilesFactor; - pRSmaParam->delay = pStb->delay; - pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently - pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t)); - if (pRSmaParam->pFuncIds == NULL) { - taosMemoryFreeClear(req.stbCfg.pRSmaParam); - taosMemoryFreeClear(req.stbCfg.pSchema); + req.pRSmaParam.xFilesFactor = pStb->xFilesFactor; + req.pRSmaParam.delay = pStb->delay; + req.pRSmaParam.nFuncIds = 1; // only 1 aggregation method supported currently + req.pRSmaParam.pFuncIds = (func_id_t *)taosMemoryCalloc(req.pRSmaParam.nFuncIds, sizeof(func_id_t)); + if (req.pRSmaParam.pFuncIds == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) { - *(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod; + for (int32_t f = 0; f < req.pRSmaParam.nFuncIds; ++f) { + req.pRSmaParam.pFuncIds[f] = pStb->aggregationMethod; } - req.stbCfg.pRSmaParam = pRSmaParam; } - int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead); + // get length + tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); + if (tEncodeSVCreateStbReq(&coder, &req) < 0) { + taosMemoryFree(req.pRSmaParam.pFuncIds); + return NULL; + } + tCoderClear(&coder); + + contLen = sizeof(SMsgHead) + coder.pos; SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { - if (pRSmaParam) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); - taosMemoryFreeClear(pRSmaParam); - } - // taosMemoryFreeClear(req.stbCfg.pSchema); + taosMemoryFree(req.pRSmaParam.pFuncIds); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -462,17 +451,16 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt pHead->vgId = htonl(pVgroup->vgId); void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); - tSerializeSVCreateTbReq(&pBuf, &req); + tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER); + if (tEncodeSVCreateStbReq(&coder, &req) < 0) { + taosMemoryFree(req.pRSmaParam.pFuncIds); + return NULL; + } + tCoderClear(&coder); *pContLen = contLen; - if (pRSmaParam) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); - taosMemoryFreeClear(pRSmaParam); - } - // taosMemoryFreeClear(req.stbCfg.pSchema); + taosMemoryFree(req.pRSmaParam.pFuncIds); return pHead; -#endif - return NULL; } static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) { diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index a4b540edc71ef77d6127772873d1c468073f27db..749dcb22b4d0c07dc10965d9d9ba6bb9fdd61f95 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -45,6 +45,9 @@ void metaCloseIdx(SMeta* pMeta); int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions); int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); +// metaTable ================== +int metaCreateSTable(SMeta* pMeta, SVCreateStbReq* pReq, SVCreateStbRsp* pRsp); + // metaCommit ================== int metaBegin(SMeta* pMeta); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 1aa3fbb582d1f180348b7a11d6646f5a47d62a1b..07a4f36496e7bdbd318fa042e6a95ad6941655f8 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -15,6 +15,11 @@ #include "vnodeInt.h" +int metaCreateSTable(SMeta *pMeta, SVCreateStbReq *pReq, SVCreateStbRsp *pRsp) { + // TODO + return 0; +} + int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { #ifdef META_REFACT #else diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index c8c7a210538607798e9feab1548d68f182fc5df3..9c5207102d055772f3fc785de4aa53843ca9e4f3 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -196,20 +196,22 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq, int len) { - SVCreateTbReq vCreateTbReq = {0}; - tDeserializeSVCreateTbReq(pReq, &vCreateTbReq); - if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { - // TODO + SVCreateStbReq req = {0}; + SCoder coder; + + tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER); + + if (tDecodeSVCreateStbReq(&coder, &req) < 0) { + tCoderClear(&coder); return -1; } - // taosMemoryFree(vCreateTbReq.stbCfg.pSchema); - // taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - // if (vCreateTbReq.stbCfg.pRSmaParam) { - // taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); - // taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); - // } - // taosMemoryFree(vCreateTbReq.name); + if (metaCreateSTable(pVnode->pMeta, pReq, NULL) < 0) { + tCoderClear(&coder); + return -1; + } + + tCoderClear(&coder); return 0; }