提交 018661e1 编写于 作者: H Hongze Cheng

more

上级 757dea61
...@@ -65,14 +65,14 @@ typedef struct SVnodeCfg { ...@@ -65,14 +65,14 @@ typedef struct SVnodeCfg {
/* ------------------------ SVnode ------------------------ */ /* ------------------------ SVnode ------------------------ */
/** /**
* @brief Initialize the vnode module * @brief Initialize the vnode module
* *
* @return int 0 for success and -1 for failure * @return int 0 for success and -1 for failure
*/ */
int vnodeInit(); int vnodeInit();
/** /**
* @brief clear a vnode * @brief clear a vnode
* *
*/ */
void vnodeClear(); void vnodeClear();
...@@ -156,6 +156,10 @@ typedef struct { ...@@ -156,6 +156,10 @@ typedef struct {
/// Create table request /// Create table request
typedef STbCfg SVCreateTableReq; typedef STbCfg SVCreateTableReq;
int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq);
void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq);
/// Drop table request /// Drop table request
typedef struct { typedef struct {
tb_uid_t uid; tb_uid_t uid;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "sync.h" #include "sync.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "wal.h" #include "wal.h"
#include "tcoding.h"
#include "vnode.h" #include "vnode.h"
#include "vnodeBufferPool.h" #include "vnodeBufferPool.h"
......
...@@ -22,12 +22,9 @@ ...@@ -22,12 +22,9 @@
extern "C" { extern "C" {
#endif #endif
// SVCreateTableReq
int vnodeBuildCreateTableReq(const SVCreateTableReq *pReq, char *msg, int len);
int vnodeParseCreateTableReq(const char *msg, int len, SVCreateTableReq *pReq);
// SVDropTableReq // SVDropTableReq
int vnodeBuildDropTableReq(const SVDropTableReq *pReq, char *msg, int len); int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq);
int vnodeParseDropTableReq(const char *msg, int len, SVDropTableReq *pReq); void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -11,4 +11,69 @@ ...@@ -11,4 +11,69 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
\ No newline at end of file
#include "vnodeDef.h"
int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) {
int tsize = 0;
tsize += taosEncodeString(buf, pReq->name);
tsize += taosEncodeFixedU32(buf, pReq->ttl);
tsize += taosEncodeFixedU32(buf, pReq->keep);
tsize += taosEncodeFixedU8(buf, pReq->type);
switch (pReq->type) {
case META_SUPER_TABLE:
tsize += taosEncodeFixedU64(buf, pReq->stbCfg.suid);
tsize += tdEncodeSchema(buf, pReq->stbCfg.pSchema);
tsize += tdEncodeSchema(buf, pReq->stbCfg.pTagSchema);
break;
case META_CHILD_TABLE:
tsize += taosEncodeFixedU64(buf, pReq->ctbCfg.suid);
tsize += tdEncodeKVRow(buf, pReq->ctbCfg.pTag);
break;
case META_NORMAL_TABLE:
tsize += tdEncodeSchema(buf, pReq->ntbCfg.pSchema);
break;
default:
break;
}
return tsize;
}
void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) {
buf = taosDecodeString(buf, &(pReq->name));
buf = taosDecodeFixedU32(buf, &(pReq->ttl));
buf = taosDecodeFixedU32(buf, &(pReq->keep));
buf = taosDecodeFixedU8(buf, &(pReq->type));
switch (pReq->type) {
case META_SUPER_TABLE:
buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid));
buf = tdDecodeSchema(buf, &(pReq->stbCfg.pSchema));
buf = tdDecodeSchema(buf, &(pReq->stbCfg.pTagSchema));
break;
case META_CHILD_TABLE:
buf = taosDecodeFixedU64(buf, &(pReq->ctbCfg.suid));
buf = tdDecodeKVRow(buf, pReq->ctbCfg.pTag);
break;
case META_NORMAL_TABLE:
buf = tdDecodeSchema(buf, &(pReq->ntbCfg.pSchema));
break;
default:
break;
}
return buf;
}
int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) {
// TODO
return 0;
}
void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) {
// TODO
}
\ No newline at end of file
...@@ -56,9 +56,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { ...@@ -56,9 +56,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
switch (pMsg->msgType) { switch (pMsg->msgType) {
case TSDB_MSG_TYPE_CREATE_TABLE: case TSDB_MSG_TYPE_CREATE_TABLE:
if (vnodeParseCreateTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(ctReq)) < 0) { vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq));
// TODO: handle error
}
if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) { if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) {
// TODO: handle error // TODO: handle error
...@@ -67,7 +65,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { ...@@ -67,7 +65,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
// TODO: maybe need to clear the requst struct // TODO: maybe need to clear the requst struct
break; break;
case TSDB_MSG_TYPE_DROP_TABLE: case TSDB_MSG_TYPE_DROP_TABLE:
if (vnodeParseDropTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(dtReq)) < 0) { if (vnodeParseDropTableReq(pVnodeReq->req, &(dtReq)) < 0) {
// TODO: handle error // TODO: handle error
} }
......
...@@ -10,9 +10,66 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { ...@@ -10,9 +10,66 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
SVnode *pVnode = vnodeOpen("vnode1", NULL); SVnode *pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr); ASSERT_NE(pVnode, nullptr);
// Create table tb_uid_t suid = 1638166374163;
// SArray *pArray = taosArrayInit() {
// vnodeProcessWMsgs(pVnode, ); // Create a super table
STSchema *pSchema = NULL;
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);
int zs = vnodeBuildCreateTableReq(NULL, &stbCfg);
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);
taosArrayPush(pMsgs, &(pMsg));
vnodeProcessWMsgs(pVnode, pMsgs);
free(pMsg);
taosArrayClear(pMsgs);
}
{
// Create some child tables
int ntables = 1000000;
int batch = 10;
for (int i = 0; i < ntables / batch; i++) {
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));
for (int j = 0; j < batch; j++) {
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);
int tz = vnodeBuildCreateTableReq(NULL, &ctbCfg);
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);
}
vnodeProcessWMsgs(pVnode, pMsgs);
for (int j = 0; j < batch; j++) {
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs);
free(pMsg);
}
taosArrayClear(pMsgs);
}
}
// Close the vnode // Close the vnode
vnodeClose(pVnode); vnodeClose(pVnode);
......
...@@ -50,4 +50,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ ...@@ -50,4 +50,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) { int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) {
// TODO // TODO
return 0; return 0;
}
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
// TODO
return 0;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册