From a9a1ad4ce87d7c34aabe01f505ef7ed3c948c908 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 19 Apr 2022 07:09:58 +0000 Subject: [PATCH] refactor: vnode --- source/dnode/vnode/CMakeLists.txt | 2 ++ source/dnode/vnode/src/inc/meta.h | 29 +++++++++++++++-------- source/dnode/vnode/src/meta/metaIdx.c | 16 ++++++++++--- source/dnode/vnode/src/meta/metaOpen.c | 9 +++++++ source/dnode/vnode/src/meta/metaQuery.c | 16 +++++++++++++ source/dnode/vnode/src/meta/metaTDBImpl.c | 4 ++++ source/dnode/vnode/src/meta/metaTable.c | 12 +++------- 7 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 source/dnode/vnode/src/meta/metaQuery.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index f7f55a7b28..6175792c7e 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -21,6 +21,7 @@ target_sources( "src/meta/metaIdx.c" "src/meta/metaTable.c" "src/meta/metaTDBImpl.c" + "src/meta/metaQuery.c" # tsdb "src/tsdb/tsdbTDBImpl.c" @@ -69,6 +70,7 @@ target_link_libraries( PUBLIC transport PUBLIC stream ) +# target_compile_definitions(vnode PUBLIC -DMETA_REFACT) if(${BUILD_TEST}) add_subdirectory(test) diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index fb875a46e0..71fdae92a0 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -47,6 +47,22 @@ int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); } +struct SMeta { + char* path; + SVnode* pVnode; +#ifdef META_REFACT + TENV* pEnv; + TDB* pTbDb; + TDB* pSchemaDb; + TDB* pNameIdx; + TDB* pCtbIdx; +#else + SMetaDB* pDB; +#endif + SMetaIdx* pIdx; +}; + +#if 1 #define META_SUPER_TABLE TD_SUPER_TABLE #define META_CHILD_TABLE TD_CHILD_TABLE #define META_NORMAL_TABLE TD_NORMAL_TABLE @@ -71,6 +87,7 @@ SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); void metaCloseCtbCurosr(SMCtbCursor* pCtbCur); tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); +#ifndef META_REFACT // SMetaDB int metaOpenDB(SMeta* pMeta); void metaCloseDB(SMeta* pMeta); @@ -78,17 +95,9 @@ int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg); int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); +#endif -// SMetaIdx - -tb_uid_t metaGenerateUid(SMeta* pMeta); - -struct SMeta { - char* path; - SVnode* pVnode; - SMetaDB* pDB; - SMetaIdx* pIdx; -}; +#endif #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/meta/metaIdx.c b/source/dnode/vnode/src/meta/metaIdx.c index 9a566f788c..ad50d36c9d 100644 --- a/source/dnode/vnode/src/meta/metaIdx.c +++ b/source/dnode/vnode/src/meta/metaIdx.c @@ -51,7 +51,9 @@ int metaOpenIdx(SMeta *pMeta) { #ifdef USE_INVERTED_INDEX SIndexOpts opts; - if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) { return -1; } + if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) { + return -1; + } #endif return 0; @@ -67,7 +69,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ #ifdef USE_INVERTED_INDEX SIndexOpts opts; - if (indexClose(pMeta->pIdx->pIdx) != 0) { return -1; } + if (indexClose(pMeta->pIdx->pIdx) != 0) { + return -1; + } #endif } @@ -84,7 +88,7 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) { tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id tb_uid_t tuid = 0; // child table uid SIndexMultiTerm *terms = indexMultiTermCreate(); - SIndexTerm * term = + SIndexTerm *term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid); indexMultiTermAdd(terms, term); @@ -114,10 +118,13 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) { // TODO: add atomicity +#ifdef META_REFACT +#else if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) { // TODO: handle error return -1; } +#endif return TSDB_CODE_SUCCESS; } @@ -125,9 +132,12 @@ int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) { // TODO: Validate the cfg // TODO: add atomicity +#ifdef META_REFACT +#else if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) { // TODO: handle error return -1; } +#endif return TSDB_CODE_SUCCESS; } \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 4419420e59..5047a61279 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -21,6 +21,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { *ppMeta = NULL; +#ifdef META_REFACT +#else // create handle slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3; if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) { @@ -44,22 +46,29 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { if (metaOpenIdx(pMeta) < 0) { goto _err; } +#endif *ppMeta = pMeta; return 0; _err: +#ifdef META_REFACT +#else if (pMeta->pIdx) metaCloseIdx(pMeta); if (pMeta->pDB) metaCloseDB(pMeta); taosMemoryFree(pMeta); +#endif return -1; } int metaClose(SMeta *pMeta) { if (pMeta) { +#ifdef META_REFACT +#else metaCloseIdx(pMeta); metaCloseDB(pMeta); taosMemoryFree(pMeta); +#endif } return 0; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c new file mode 100644 index 0000000000..5022d0e050 --- /dev/null +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -0,0 +1,16 @@ +/* + * 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 . + */ + +#include "vnodeInt.h" \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index 9fd11222bf..0be6cd1531 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -15,6 +15,8 @@ #include "vnodeInt.h" +#ifndef META_REFACT + typedef struct SPoolMem { int64_t size; struct SPoolMem *prev; @@ -1134,3 +1136,5 @@ static void poolFree(void *arg, void *ptr) { tdbOsFree(pMem); } + +#endif \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 7f06ba8855..1aa3fbb582 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -16,18 +16,13 @@ #include "vnodeInt.h" int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { - // Validate the tbOptions - // if (metaValidateTbCfg(pMeta, pTbCfg) < 0) { - // // TODO: handle error - // return -1; - // } - - // TODO: add atomicity - +#ifdef META_REFACT +#else if (metaSaveTableToDB(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } +#endif if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) { // TODO: handle error @@ -50,4 +45,3 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) { return 0; } -