From 1d7b85d93006ceb561154aebcb726abfe9e63722 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 9 Nov 2021 11:22:25 +0800 Subject: [PATCH] refact --- source/dnode/vnode/impl/inc/vnodeCommit.h | 5 ++-- source/dnode/vnode/impl/inc/vnodeDef.h | 4 ++- source/dnode/vnode/impl/src/vnodeCommit.c | 6 ++-- source/dnode/vnode/impl/src/vnodeWrite.c | 36 +++++++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/source/dnode/vnode/impl/inc/vnodeCommit.h b/source/dnode/vnode/impl/inc/vnodeCommit.h index 544a42f0e8..c8ff4947aa 100644 --- a/source/dnode/vnode/impl/inc/vnodeCommit.h +++ b/source/dnode/vnode/impl/inc/vnodeCommit.h @@ -16,13 +16,14 @@ #ifndef _TD_VNODE_COMMIT_H_ #define _TD_VNODE_COMMIT_H_ -#include "vnodeInt.h" +#include "vnode.h" #ifdef __cplusplus extern "C" { #endif -int vnodeAsyncCommit(SVnode *pVnode); +bool vnodeShouldCommit(SVnode *pVnode); +int vnodeAsyncCommit(SVnode *pVnode); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 012e6fc5d1..62b8ea0b3a 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -16,10 +16,12 @@ #ifndef _TD_VNODE_DEF_H_ #define _TD_VNODE_DEF_H_ +#include "mallocator.h" #include "vnode.h" #include "vnodeAllocatorPool.h" #include "vnodeOptions.h" #include "vnodeStateMgr.h" +#include "vnodeCommit.h" #ifdef __cplusplus extern "C" { @@ -30,7 +32,7 @@ struct SVnode { SVnodeOptions options; SVState state; SVAllocatorPool pool; - SVMemAllocator* inuse; + SMemAllocator* inuse; SMeta* pMeta; STsdb* pTsdb; STQ* pTq; diff --git a/source/dnode/vnode/impl/src/vnodeCommit.c b/source/dnode/vnode/impl/src/vnodeCommit.c index 826589e8c9..18a0c6d91d 100644 --- a/source/dnode/vnode/impl/src/vnodeCommit.c +++ b/source/dnode/vnode/impl/src/vnodeCommit.c @@ -13,13 +13,15 @@ * along with this program. If not, see . */ -#include "vnodeInt.h" +#include "vnodeDef.h" static int vnodeStartCommit(SVnode *pVnode); static int vnodeEndCommit(SVnode *pVnode); +bool vnodeShouldCommit(SVnode *pVnode) { return false; } + int vnodeAsyncCommit(SVnode *pVnode) { - #if 0 +#if 0 if (vnodeStartCommit(pVnode) < 0) { // TODO } diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 401c2add9c..3126633411 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -21,9 +21,39 @@ int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch) { } int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest) { - int type; - /* TODO */ - return 0; + int reqType; /* TODO */ + size_t reqSize; /* TODO */ + int code = 0; + + // Copy the request to vnode buffer + SRequest *pReq = mMalloc(pVnode->inuse, reqSize); + if (pReq == NULL) { + // TODO: handle error + } + + // Push the request to TQ so consumers can consume + tqPushMsg(pVnode->pTq, pReq, 0); + + // Process the request + switch (reqType) { + case TSDB_MSG_TYPE_CREATE_TABLE: + code = metaCreateTable(pVnode->pMeta, NULL /* TODO */); + break; + case TSDB_MSG_TYPE_DROP_TABLE: + code = metaDropTable(pVnode->pMeta, 0 /* TODO */); + break; + /* TODO */ + default: + break; + } + + if (vnodeShouldCommit(pVnode)) { + if (vnodeAsyncCommit(pVnode) < 0) { + // TODO: handle error + } + } + + return code; } /* ------------------------ STATIC METHODS ------------------------ */ \ No newline at end of file -- GitLab