more
This commit is contained in:
parent
757dea6170
commit
018661e177
|
@ -156,6 +156,10 @@ typedef struct {
|
|||
|
||||
/// Create table request
|
||||
typedef STbCfg SVCreateTableReq;
|
||||
|
||||
int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq);
|
||||
void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq);
|
||||
|
||||
/// Drop table request
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "sync.h"
|
||||
#include "tlockfree.h"
|
||||
#include "wal.h"
|
||||
#include "tcoding.h"
|
||||
|
||||
#include "vnode.h"
|
||||
#include "vnodeBufferPool.h"
|
||||
|
|
|
@ -22,12 +22,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// SVCreateTableReq
|
||||
int vnodeBuildCreateTableReq(const SVCreateTableReq *pReq, char *msg, int len);
|
||||
int vnodeParseCreateTableReq(const char *msg, int len, SVCreateTableReq *pReq);
|
||||
// SVDropTableReq
|
||||
int vnodeBuildDropTableReq(const SVDropTableReq *pReq, char *msg, int len);
|
||||
int vnodeParseDropTableReq(const char *msg, int len, SVDropTableReq *pReq);
|
||||
int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq);
|
||||
void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -12,3 +12,68 @@
|
|||
* 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/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
}
|
|
@ -56,9 +56,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
|||
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_CREATE_TABLE:
|
||||
if (vnodeParseCreateTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(ctReq)) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq));
|
||||
|
||||
if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) {
|
||||
// TODO: handle error
|
||||
|
@ -67,7 +65,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
|||
// TODO: maybe need to clear the requst struct
|
||||
break;
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,66 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
|
|||
SVnode *pVnode = vnodeOpen("vnode1", NULL);
|
||||
ASSERT_NE(pVnode, nullptr);
|
||||
|
||||
// Create table
|
||||
// SArray *pArray = taosArrayInit()
|
||||
// vnodeProcessWMsgs(pVnode, );
|
||||
tb_uid_t suid = 1638166374163;
|
||||
{
|
||||
// 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
|
||||
vnodeClose(pVnode);
|
||||
|
|
|
@ -51,3 +51,8 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) {
|
|||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue