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

refact vnode

上级 f8b68e92
...@@ -4,13 +4,13 @@ target_sources( ...@@ -4,13 +4,13 @@ target_sources(
vnode vnode
PRIVATE PRIVATE
# vnode # vnode
"src/vnd/vnodeOpen.c"
"src/vnd/vnodeArenaMAImpl.c" "src/vnd/vnodeArenaMAImpl.c"
"src/vnd/vnodeBufferPool.c" "src/vnd/vnodeBufferPool.c"
# "src/vnd/vnodeBufferPool2.c" # "src/vnd/vnodeBufferPool2.c"
"src/vnd/vnodeCfg.c" "src/vnd/vnodeCfg.c"
"src/vnd/vnodeCommit.c" "src/vnd/vnodeCommit.c"
"src/vnd/vnodeInt.c" "src/vnd/vnodeInt.c"
"src/vnd/vnodeOpen.c"
"src/vnd/vnodeQuery.c" "src/vnd/vnodeQuery.c"
"src/vnd/vnodeStateMgr.c" "src/vnd/vnodeStateMgr.c"
"src/vnd/vnodeWrite.c" "src/vnd/vnodeWrite.c"
......
...@@ -30,6 +30,10 @@ extern "C" { ...@@ -30,6 +30,10 @@ extern "C" {
#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0) #define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on // clang-format on
// vnodeCfg ====================
int vnodeSaveCfg(const char* dir, const SVnodeCfg* pCfg);
int vnodeCommitCfg(const char* dir);
// vnodeModule ==================== // vnodeModule ====================
int vnodeScheduleTask(int (*execute)(void*), void* arg); int vnodeScheduleTask(int (*execute)(void*), void* arg);
...@@ -75,9 +79,9 @@ void vmaFree(SVMemAllocator* pVMA, void* ptr); ...@@ -75,9 +79,9 @@ void vmaFree(SVMemAllocator* pVMA, void* ptr);
bool vmaIsFull(SVMemAllocator* pVMA); bool vmaIsFull(SVMemAllocator* pVMA);
// vnodeCfg.h // vnodeCfg.h
extern const SVnodeCfg defaultVnodeOptions; extern const SVnodeCfg vnodeCfgDefault;
int vnodeValidateOptions(const SVnodeCfg*); int vnodeCheckCfg(const SVnodeCfg*);
void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc);
// For commit // For commit
......
...@@ -15,14 +15,99 @@ ...@@ -15,14 +15,99 @@
#include "vnodeInt.h" #include "vnodeInt.h"
const SVnodeCfg defaultVnodeOptions = { #define VND_INFO_FNAME "vnode.json"
.wsize = 96 * 1024 * 1024, .ssize = 1 * 1024 * 1024, .lsize = 1024, .walCfg = {.level = TAOS_WAL_WRITE}}; /* TODO */ #define VND_INFO_FNAME_TMP "vnode_tmp.json"
int vnodeValidateOptions(const SVnodeCfg *pVnodeOptions) { static int vnodeEncodeInfo(const SVnodeCfg *pCfg, uint8_t **ppData, int *len);
static int vnodeDecodeInfo(uint8_t *pData, int len, SVnodeCfg *pCfg);
const SVnodeCfg vnodeCfgDefault = {
.wsize = 96 * 1024 * 1024, .ssize = 1 * 1024 * 1024, .lsize = 1024, .walCfg = {.level = TAOS_WAL_WRITE}};
int vnodeCheckCfg(const SVnodeCfg *pCfg) {
// TODO
return 0;
}
int vnodeSaveCfg(const char *dir, const SVnodeCfg *pCfg) {
char fname[TSDB_FILENAME_LEN];
TdFilePtr pFile;
uint8_t *data;
int len;
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP);
// encode info
data = NULL;
len = 0;
if (vnodeEncodeInfo(pCfg, &data, &len) < 0) {
return -1;
}
// save info to a vnode_tmp.json
pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (taosWriteFile(pFile, data, len) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
if (taosFsyncFile(pFile) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
goto _err;
}
taosCloseFile(&pFile);
// free info binary
taosMemoryFree(data);
vInfo("vgId: %d vnode info is saved, fname: %s", pCfg->vgId, fname);
return 0;
_err:
taosCloseFile(&pFile);
taosMemoryFree(data);
return -1;
}
int vnodeCommitCfg(const char *dir) {
char fname[TSDB_FILENAME_LEN];
char tfname[TSDB_FILENAME_LEN];
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME);
snprintf(tfname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP);
if (taosRenameFile(tfname, fname) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
return 0;
}
int vnodeLoadCfg(const char *dir) {
// TODO
return 0;
}
static int vnodeEncodeInfo(const SVnodeCfg *pCfg, uint8_t **ppData, int *len) {
// TODO // TODO
return 0; return 0;
} }
static int vnodeDecodeInfo(uint8_t *pData, int len, SVnodeCfg *pCfg) {
// TODO
return 0;
}
#if 1 //======================================================================
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) { void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg)); memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg));
} }
...@@ -46,3 +131,5 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { ...@@ -46,3 +131,5 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
#endif
\ No newline at end of file
...@@ -21,8 +21,8 @@ static int vnodeOpenImpl(SVnode *pVnode); ...@@ -21,8 +21,8 @@ static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode); static void vnodeCloseImpl(SVnode *pVnode);
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
#if 0
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];
// TODO: check if directory exists // TODO: check if directory exists
// check config // check config
...@@ -34,12 +34,11 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { ...@@ -34,12 +34,11 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
// create vnode env // create vnode env
tfsMkdir(pTfs, path); tfsMkdir(pTfs, path);
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path);
if (vnodeSaveCfg(dir, pCfg) < 0) { if (vnodeSaveCfg(dir, pCfg) < 0 || vnodeCommitCfg(dir) < 0) {
vError("vgId: %d failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno)); vError("vgId: %d failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno));
return -1; return -1;
} }
#endif
return 0; return 0;
} }
...@@ -47,7 +46,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) { ...@@ -47,7 +46,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL; SVnode *pVnode = NULL;
// Set default options // Set default options
SVnodeCfg cfg = defaultVnodeOptions; SVnodeCfg cfg = vnodeCfgDefault;
if (pVnodeCfg != NULL) { if (pVnodeCfg != NULL) {
cfg.vgId = pVnodeCfg->vgId; cfg.vgId = pVnodeCfg->vgId;
cfg.msgCb = pVnodeCfg->msgCb; cfg.msgCb = pVnodeCfg->msgCb;
...@@ -59,7 +58,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) { ...@@ -59,7 +58,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
} }
// Validate options // Validate options
if (vnodeValidateOptions(&cfg) < 0) { if (vnodeCheckCfg(&cfg) < 0) {
// TODO // TODO
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册