refact vnode

This commit is contained in:
Hongze Cheng 2022-04-16 08:19:21 +00:00
parent fe368d0ffe
commit 6e7ab6ca4d
3 changed files with 19 additions and 41 deletions

View File

@ -135,7 +135,6 @@ struct STsdbCfg {
struct SVnodeCfg { struct SVnodeCfg {
int32_t vgId; int32_t vgId;
uint64_t dbId; uint64_t dbId;
STfs *pTfs;
uint64_t wsize; uint64_t wsize;
uint64_t ssize; uint64_t ssize;
uint64_t lsize; uint64_t lsize;
@ -146,7 +145,6 @@ struct SVnodeCfg {
bool isWeak; bool isWeak;
STsdbCfg tsdbCfg; STsdbCfg tsdbCfg;
SWalCfg walCfg; SWalCfg walCfg;
SMsgCb msgCb;
uint32_t hashBegin; uint32_t hashBegin;
uint32_t hashEnd; uint32_t hashEnd;
int8_t hashMethod; int8_t hashMethod;

View File

@ -83,6 +83,8 @@ struct SVnode {
char* path; char* path;
SVnodeCfg config; SVnodeCfg config;
SVState state; SVState state;
STfs* pTfs;
SMsgCb msgCb;
SVBufPool* pBufPool; SVBufPool* pBufPool;
SMeta* pMeta; SMeta* pMeta;
STsdb* pTsdb; STsdb* pTsdb;
@ -91,8 +93,6 @@ struct SVnode {
SSink* pSink; SSink* pSink;
tsem_t canCommit; tsem_t canCommit;
SQHandle* pQuery; SQHandle* pQuery;
SMsgCb msgCb;
STfs* pTfs;
}; };
#define TD_VID(PVNODE) (PVNODE)->config.vgId #define TD_VID(PVNODE) (PVNODE)->config.vgId

View File

@ -15,8 +15,6 @@
#include "vnodeInt.h" #include "vnodeInt.h"
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
static void vnodeFree(SVnode *pVnode);
static int vnodeOpenImpl(SVnode *pVnode); static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode); static void vnodeCloseImpl(SVnode *pVnode);
@ -68,17 +66,24 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
return NULL; return NULL;
} }
info.config.pTfs = pTfs; // create handle
info.config.msgCb = msgCb; pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode));
// crate handle
pVnode = vnodeNew(dir, &info.config);
if (pVnode == NULL) { if (pVnode == NULL) {
// TODO: handle error terrno = TSDB_CODE_OUT_OF_MEMORY;
vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
return NULL; return NULL;
} }
// Open the vnode pVnode->path = strdup(dir);
pVnode->config = info.config;
pVnode->state.committed = info.state.committed;
pVnode->state.processed = pVnode->state.applied = pVnode->state.committed;
pVnode->pTfs = pTfs;
pVnode->msgCb = msgCb;
tsem_init(&(pVnode->canCommit), 0, 1);
// open the vnode
if (vnodeOpenImpl(pVnode) < 0) { if (vnodeOpenImpl(pVnode) < 0) {
// TODO: handle error // TODO: handle error
return NULL; return NULL;
@ -90,38 +95,13 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
void vnodeClose(SVnode *pVnode) { void vnodeClose(SVnode *pVnode) {
if (pVnode) { if (pVnode) {
vnodeCloseImpl(pVnode); vnodeCloseImpl(pVnode);
vnodeFree(pVnode);
}
}
/* ------------------------ STATIC METHODS ------------------------ */
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL;
pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode));
if (pVnode == NULL) {
// TODO
return NULL;
}
pVnode->msgCb = pVnodeCfg->msgCb;
pVnode->pTfs = pVnodeCfg->pTfs;
pVnode->path = strdup(path);
vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
tsem_init(&(pVnode->canCommit), 0, 1);
return pVnode;
}
static void vnodeFree(SVnode *pVnode) {
if (pVnode) {
tsem_destroy(&(pVnode->canCommit)); tsem_destroy(&(pVnode->canCommit));
taosMemoryFreeClear(pVnode->path); taosMemoryFreeClear(pVnode->path);
taosMemoryFree(pVnode); taosMemoryFree(pVnode);
} }
} }
/* ------------------------ STATIC METHODS ------------------------ */
static int vnodeOpenImpl(SVnode *pVnode) { static int vnodeOpenImpl(SVnode *pVnode) {
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];