From d78480998f278b7445769bcbbabdf9146dee9790 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 8 Nov 2021 10:04:24 +0800 Subject: [PATCH] more --- source/dnode/mgmt/src/dnodeVnodes.c | 2 +- source/dnode/vnode/impl/inc/vnodeDef.h | 6 ++++ source/dnode/vnode/impl/inc/vnodeOptions.h | 33 ++++++++++++++++++ source/dnode/vnode/impl/src/vnodeInt.c | 1 - source/dnode/vnode/impl/src/vnodeMain.c | 40 ++++++++++++++++++++-- source/dnode/vnode/impl/src/vnodeOptions.c | 13 +++++-- 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 source/dnode/vnode/impl/inc/vnodeOptions.h diff --git a/source/dnode/mgmt/src/dnodeVnodes.c b/source/dnode/mgmt/src/dnodeVnodes.c index c23773f92f..4ec9e1dc60 100644 --- a/source/dnode/mgmt/src/dnodeVnodes.c +++ b/source/dnode/mgmt/src/dnodeVnodes.c @@ -376,7 +376,7 @@ static void *dnodeOpenVnodeFunc(void *param) { char path[PATH_MAX + 20] = {0}; snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, pVnode->vgId); - SVnode *pImpl = vnodeOpen(pVnode->vgId, path); + SVnode *pImpl = vnodeOpen(path, NULL); if (pImpl == NULL) { dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex); pThread->failed++; diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 6a327ceefa..a42cd93b01 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -17,12 +17,18 @@ #define _TD_VNODE_DEF_H_ #include "vnode.h" +#include "vnodeOptions.h" #ifdef __cplusplus extern "C" { #endif struct SVnode { + char* path; + SVnodeOptions options; + SMeta* pMeta; + STsdb* pTsdb; + STQ* pTq; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/impl/inc/vnodeOptions.h b/source/dnode/vnode/impl/inc/vnodeOptions.h new file mode 100644 index 0000000000..4b31de1966 --- /dev/null +++ b/source/dnode/vnode/impl/inc/vnodeOptions.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_OPTIONS_H_ +#define _TD_VNODE_OPTIONS_H_ + +#include "vnode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const SVnodeOptions defaultVnodeOptions; + +int vnodeValidateOptions(const SVnodeOptions*); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_OPTIONS_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeInt.c b/source/dnode/vnode/impl/src/vnodeInt.c index 5f40fa5f73..2cbdf318a2 100644 --- a/source/dnode/vnode/impl/src/vnodeInt.c +++ b/source/dnode/vnode/impl/src/vnodeInt.c @@ -20,7 +20,6 @@ int32_t vnodeInit(SVnodePara para) { return 0; } void vnodeCleanup() {} -void vnodeClose(SVnode *pVnode) {} int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg) { return NULL; } void vnodeDrop(SVnode *pVnode) {} diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index f074dd9876..d531b44f15 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -15,13 +15,47 @@ #include "vnodeDef.h" +static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions); +static void vnodeFree(SVnode *pVnode); + SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) { SVnode *pVnode = NULL; - /* TODO */ + + // Set default options + if (pVnodeOptions == NULL) { + pVnodeOptions = &defaultVnodeOptions; + } + + // Validate options + if (vnodeValidateOptions(pVnodeOptions) < 0) { + // TODO + return NULL; + } + + pVnode = vnodeNew(path, pVnodeOptions); + if (pVnode == NULL) { + // TODO: handle error + return NULL; + } + + taosMkDir(path); + return pVnode; } -void vnodeCloee(SVnode *pVnode) { /* TODO */ +void vnodeClose(SVnode *pVnode) { /* TODO */ +} + +void vnodeDestroy(const char *path) { taosRemoveDir(path); } + +/* ------------------------ STATIC METHODS ------------------------ */ +static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) { + // TODO + return NULL; } -void vnodeDestroy(const char *path) { taosRemoveDir(path); } \ No newline at end of file +static void vnodeFree(SVnode *pVnode) { + if (pVnode) { + // TODO + } +} \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeOptions.c b/source/dnode/vnode/impl/src/vnodeOptions.c index a384eb9e53..ebf1dc35ba 100644 --- a/source/dnode/vnode/impl/src/vnodeOptions.c +++ b/source/dnode/vnode/impl/src/vnodeOptions.c @@ -15,6 +15,15 @@ #include "vnodeDef.h" -void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */ } +const SVnodeOptions defaultVnodeOptions = {0}; /* TODO */ -void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */ } \ No newline at end of file +void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */ +} + +void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */ +} + +int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) { + // TODO + return 0; +} \ No newline at end of file -- GitLab