diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 560490569ac00a6476d838641e9b2b33a70678fa..583496a4c673b5364f462d65d644d7a5524c9b1d 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1363,28 +1363,48 @@ typedef struct { int64_t tuid; } SDDropTopicReq; +typedef struct { + float xFilesFactor; + int8_t delayUnit; + int8_t nFuncIds; + int32_t* pFuncIds; + int64_t delay; +} SRSmaParam; + typedef struct SVCreateTbReq { int64_t ver; // use a general definition char* dbFName; char* name; uint32_t ttl; uint32_t keep; - uint8_t type; union { + uint8_t info; struct { - tb_uid_t suid; - uint32_t nCols; - SSchema* pSchema; - uint32_t nTagCols; - SSchema* pTagSchema; + uint8_t rollup : 1; // 1 means rollup sma + uint8_t type : 7; + }; + }; + union { + struct { + tb_uid_t suid; + uint32_t nCols; + SSchema* pSchema; + uint32_t nTagCols; + SSchema* pTagSchema; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + SRSmaParam* pRSmaParam; } stbCfg; struct { tb_uid_t suid; SKVRow pTag; } ctbCfg; struct { - uint32_t nCols; - SSchema* pSchema; + uint32_t nCols; + SSchema* pSchema; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + SRSmaParam* pRSmaParam; } ntbCfg; }; } SVCreateTbReq, SVUpdateTbReq; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 47872b89d57ea56e5fe8f96b267bdc3be2b4342a..1ea00566f483e87340d8ff2a9816af1b4901e2fb 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -290,7 +290,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeString(buf, pReq->name); tlen += taosEncodeFixedU32(buf, pReq->ttl); tlen += taosEncodeFixedU32(buf, pReq->keep); - tlen += taosEncodeFixedU8(buf, pReq->type); + tlen += taosEncodeFixedU8(buf, pReq->info); switch (pReq->type) { case TD_SUPER_TABLE: @@ -309,6 +309,20 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); } + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); + } + if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); + tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeFixedI8(buf, param->nFuncIds); + for(int8_t i=0; i< param->nFuncIds; ++i) { + tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); + } + tlen += taosEncodeFixedI64(buf, param->delay); + } break; case TD_CHILD_TABLE: tlen += taosEncodeFixedI64(buf, pReq->ctbCfg.suid); @@ -322,6 +336,20 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); } + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); + } + if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); + tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeFixedI8(buf, param->nFuncIds); + for(int8_t i=0; i< param->nFuncIds; ++i) { + tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); + } + tlen += taosEncodeFixedI64(buf, param->delay); + } break; default: ASSERT(0); @@ -335,7 +363,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeString(buf, &(pReq->name)); buf = taosDecodeFixedU32(buf, &(pReq->ttl)); buf = taosDecodeFixedU32(buf, &(pReq->keep)); - buf = taosDecodeFixedU8(buf, &(pReq->type)); + buf = taosDecodeFixedU8(buf, &(pReq->info)); switch (pReq->type) { case TD_SUPER_TABLE: @@ -356,6 +384,32 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); } + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); + if(pReq->stbCfg.nBSmaCols > 0) { + pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); + } + } else { + pReq->stbCfg.pBSmaCols = NULL; + } + if(pReq->rollup) { + pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); + if(param->nFuncIds > 0) { + for (int8_t i = 0; i< param->nFuncIds; ++i) { + buf = taosDecodeFixedI32(buf, param->pFuncIds + i); + } + } else { + param->pFuncIds = NULL; + } + buf = taosDecodeFixedI64(buf, ¶m->delay); + } else { + pReq->stbCfg.pRSmaParam = NULL; + } break; case TD_CHILD_TABLE: buf = taosDecodeFixedI64(buf, &pReq->ctbCfg.suid); @@ -370,6 +424,32 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); + if(pReq->stbCfg.nBSmaCols > 0) { + pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); + } + } else { + pReq->stbCfg.pBSmaCols = NULL; + } + if(pReq->rollup) { + pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); + if(param->nFuncIds > 0) { + for (int8_t i = 0; i< param->nFuncIds; ++i) { + buf = taosDecodeFixedI32(buf, param->pFuncIds + i); + } + } else { + param->pFuncIds = NULL; + } + buf = taosDecodeFixedI64(buf, ¶m->delay); + } else { + pReq->stbCfg.pRSmaParam = NULL; + } break; default: ASSERT(0); diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index 3eb9a480acff7f926b19f6796f0a326583fdbc4e..0a93ea67b340b1e8dcafd65bdf8d3c54cd52138d 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -527,7 +527,7 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { buf = taosDecodeString(buf, &(pTbCfg->name)); buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl)); buf = taosDecodeFixedU32(buf, &(pTbCfg->keep)); - buf = taosDecodeFixedU8(buf, &(pTbCfg->type)); + buf = taosDecodeFixedU8(buf, &(pTbCfg->info)); if (pTbCfg->type == META_SUPER_TABLE) { SSchemaWrapper sw; diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index b9bf432a72d46b26a988640b6bc5d6f684801ec6..3c51ad5d71284fa635349a565cc971383bbb0a69 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -33,6 +33,61 @@ int main(int argc, char **argv) { return RUN_ALL_TESTS(); } +TEST(testCase, unionEncodeDecodeTest) { + typedef struct { + union { + uint8_t info; + struct { + uint8_t rollup : 1; // 1 means rollup sma + uint8_t type : 7; + }; + }; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + } SUnionTest; + + SUnionTest sut = {0}; + sut.rollup = 1; + sut.type = 1; + + sut.nBSmaCols = 2; + sut.pBSmaCols = (col_id_t*)malloc(sut.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { + sut.pBSmaCols[i] = i + 100; + } + + void* buf = malloc(1024); + void * pBuf = buf; + int32_t tlen = 0; + tlen += taosEncodeFixedU8(&buf, sut.info); + tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols); + for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(&buf, sut.pBSmaCols[i]); + } + + SUnionTest dut = {0}; + pBuf = taosDecodeFixedU8(pBuf, &dut.info); + pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols); + if(dut.nBSmaCols > 0) { + dut.pBSmaCols = (col_id_t*)malloc(dut.nBSmaCols * sizeof(col_id_t)); + for(col_id_t i=0; i < dut.nBSmaCols; ++i) { + pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i); + } + } else { + dut.pBSmaCols = NULL; + } + + printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info); + printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info); + + ASSERT_EQ(sut.rollup, dut.rollup); + ASSERT_EQ(sut.type, dut.type); + ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols); + for (col_id_t i = 0; i< sut.nBSmaCols; ++i) { + ASSERT_EQ(*(col_id_t*)(sut.pBSmaCols + i), sut.pBSmaCols[i]); + ASSERT_EQ(*(col_id_t*)(sut.pBSmaCols + i), dut.pBSmaCols[i]); + } +} #if 1 TEST(testCase, tSma_Meta_Encode_Decode_Test) { // encode