diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 58ad9334611b419a5e40d4f3882725f5c056feb0..393028651af11269d5bc7ad1936044a292e6f45e 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -144,9 +144,17 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ REQUESTS ------------------------ */ +typedef STbCfg SVCreateTableReq; +typedef struct { + tb_uid_t uid; +} SVDropTableReq; + typedef struct { uint64_t ver; - char req[]; + union { + SVCreateTableReq ctReq; + SVDropTableReq dtReq; + }; } SVnodeReq; typedef struct { @@ -154,24 +162,21 @@ typedef struct { char info[]; } SVnodeRsp; -/// Create table request -typedef STbCfg SVCreateTableReq; +#define VNODE_INIT_CREATE_STB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ + { .ver = (VER), .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) } -int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); -void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); +#define VNODE_INIT_CREATE_CTB_REQ(VER, NAME, TTL, KEEP, SUID, PTAG) \ + { .ver = (VER), .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) } -/// Drop table request -typedef struct { - tb_uid_t uid; -} SVDropTableReq; -/// Alter table request -typedef struct { - // TODO -} SVAlterTableReq; +#define VNODE_INIT_CREATE_NTB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA) \ + { .ver = (VER), .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) } + +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); +void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); -int vnodeCreateTable(SVnode *pVnode, SVCreateTableReq *pReq, SVnodeRsp *pRsp); -int vnodeDropTable(SVnode *pVnode, SVDropTableReq *pReq, SVnodeRsp *pRsp); -int vnodeAlterTable(SVnode *pVnode, SVAlterTableReq *pReq, SVnodeRsp *pRsp); +// TODO +int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); +void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); /* ------------------------ FOR COMPILE ------------------------ */ diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index d89f34e7e594d797cdce289d22822638687ab7be..59031fd530cb0fd815f384b7fb9ac5c9d3bea9a6 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -15,6 +15,39 @@ #include "vnodeDef.h" +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { + int tsize = 0; + + tsize += taosEncodeFixedU64(buf, pReq->ver); + switch (type) { + case TSDB_MSG_TYPE_CREATE_TABLE: + tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq)); + /* code */ + break; + + default: + break; + } + /* TODO */ + return tsize; +} + +void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { + buf = taosDecodeFixedU64(buf, &(pReq->ver)); + + switch (type) { + case TSDB_MSG_TYPE_CREATE_TABLE: + buf = vnodeParseCreateTableReq(buf, &(pReq->ctReq)); + break; + + default: + break; + } + + // TODO + return buf; +} + int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { int tsize = 0; @@ -69,11 +102,11 @@ void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { return buf; } -int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { - // TODO - return 0; +int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { + // TODO + return 0; } void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) { - // TODO + // TODO } \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 074453aded21aca89f91ddbfc5b03445c5a64bb1..08c2bd3542809892caf4bcf0c62df6a73bb23c25 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -23,10 +23,10 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); // ser request version - pVnodeReq = (SVnodeReq *)(pMsg->pCont); - pVnodeReq->ver = pVnode->state.processed++; + void **pBuf = &(pMsg->pCont); + taosEncodeFixedU64(pBuf, pVnode->state.processed++); - if (walWrite(pVnode->pWal, pVnodeReq->ver, pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver)) < 0) { + if (walWrite(pVnode->pWal, pVnodeReq->ver, pMsg->pCont, pMsg->contLen) < 0) { // TODO: handle error } } @@ -36,9 +36,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // Apply each request now for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); - pVnodeReq = (SVnodeReq *)(pMsg->pCont); - SVCreateTableReq ctReq; - SVDropTableReq dtReq; + SVnodeReq vReq; // Apply the request { @@ -47,29 +45,28 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // TODO: handle error } - memcpy(ptr, pVnodeReq, pMsg->contLen); + // TODO: copy here need to be extended + memcpy(ptr, pMsg->pCont, pMsg->contLen); - // todo: change the interface here - if (tqPushMsg(pVnode->pTq, ptr, pVnodeReq->ver) < 0) { + // // todo: change the interface here + uint64_t ver; + taosDecodeFixedU64(pMsg->pCont, &ver); + if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) { // TODO: handle error } + vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType); + switch (pMsg->msgType) { case TSDB_MSG_TYPE_CREATE_TABLE: - vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq)); - - if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) { + if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) { // TODO: handle error } // TODO: maybe need to clear the requst struct break; case TSDB_MSG_TYPE_DROP_TABLE: - if (vnodeParseDropTableReq(pVnodeReq->req, &(dtReq)) < 0) { - // TODO: handle error - } - - if (metaDropTable(pVnode->pMeta, dtReq.uid) < 0) { + if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { // TODO: handle error } break; diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 940c09e7c322db3397d11e329d9348a8a8a410a0..5679fc06f2acb1235de8ae9005a5deecc7135d02 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -17,18 +17,18 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { STSchema *pTagSchema = NULL; char tbname[128] = "st"; - SArray *pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); - STbCfg stbCfg = META_INIT_STB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); + SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); + SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); - int zs = vnodeBuildCreateTableReq(NULL, &stbCfg); + int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); pMsg->contLen = zs; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); void **pBuf = &(pMsg->pCont); - vnodeBuildCreateTableReq(pBuf, &stbCfg); - META_CLEAR_TB_CFG(&stbCfg); + vnodeBuildReq(pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + META_CLEAR_TB_CFG(&vCreateSTbReq); taosArrayPush(pMsgs, &(pMsg)); @@ -48,16 +48,16 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { SRow *pTag = NULL; char tbname[128]; sprintf(tbname, "tb%d", i * batch + j); - STbCfg ctbCfg = META_INIT_CTB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pTag); + SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pTag); - int tz = vnodeBuildCreateTableReq(NULL, &ctbCfg); + int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); void **pBuf = &(pMsg->pCont); - vnodeBuildCreateTableReq(pBuf, &ctbCfg); - META_CLEAR_TB_CFG(&ctbCfg); + vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + META_CLEAR_TB_CFG(&vCreateCTbReq); } vnodeProcessWMsgs(pVnode, pMsgs);