提交 e861bdeb 编写于 作者: H Hongze Cheng

more

上级 018661e1
......@@ -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 ------------------------ */
......
......@@ -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
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册