diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index c0e458219c9f76dc8d1fb9be837348704851a7a5..5a6fdd1b40b14b539c66a4a3f8769ad4cd73f052 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -18,12 +18,11 @@ target_sources( "src/vnd/vnodeSvr.c" # meta - # "src/meta/metaBDBImpl.c" + "src/meta/metaOpen.c" "src/meta/metaIdx.c" - "src/meta/metaMain.c" "src/meta/metaTable.c" - "src/meta/metaTbUid.c" "src/meta/metaTDBImpl.c" + # "src/meta/metaBDBImpl.c" # tsdb "src/tsdb/tsdbTDBImpl.c" diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index f30696c9ac2e31723a28014cb64491eb9747d293..fb875a46e0a0d0f785b5b2df0977398e59573604 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -20,7 +20,6 @@ extern "C" { #endif -typedef struct SMetaCache SMetaCache; typedef struct SMetaIdx SMetaIdx; typedef struct SMetaDB SMetaDB; typedef struct SMCtbCursor SMCtbCursor; @@ -36,13 +35,22 @@ typedef struct SMSmaCursor SMSmaCursor; #define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0) // clang-format on +// metaOpen ================== +int metaOpen(SVnode* pVnode, SMeta** ppMeta); +int metaClose(SMeta* pMeta); + +// metaIdx ================== +int metaOpenIdx(SMeta* pMeta); +void metaCloseIdx(SMeta* pMeta); +int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions); +int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); + +static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); } + #define META_SUPER_TABLE TD_SUPER_TABLE #define META_CHILD_TABLE TD_CHILD_TABLE #define META_NORMAL_TABLE TD_NORMAL_TABLE -SMeta* metaOpen(const char* path, SMemAllocatorFactory* pMAF); -void metaClose(SMeta* pMeta); -void metaRemove(const char* path); int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg); int metaDropTable(SMeta* pMeta, tb_uid_t uid); int metaCommit(SMeta* pMeta); @@ -71,37 +79,15 @@ int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); -// SMetaCache -int metaOpenCache(SMeta* pMeta); -void metaCloseCache(SMeta* pMeta); - // SMetaIdx -int metaOpenIdx(SMeta* pMeta); -void metaCloseIdx(SMeta* pMeta); -int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions); -int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); - -// STbUidGnrt -typedef struct STbUidGenerator { - tb_uid_t nextUid; -} STbUidGenerator; - -// STableUidGenerator -int metaOpenUidGnrt(SMeta* pMeta); -void metaCloseUidGnrt(SMeta* pMeta); -// tb_uid_t -#define IVLD_TB_UID 0 tb_uid_t metaGenerateUid(SMeta* pMeta); struct SMeta { - char* path; - SVnode* pVnode; - SMetaDB* pDB; - SMetaIdx* pIdx; - SMetaCache* pCache; - STbUidGenerator uidGnrt; - SMemAllocatorFactory* pmaf; + char* path; + SVnode* pVnode; + SMetaDB* pDB; + SMetaIdx* pIdx; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index cb40900e81c5e8b695d95232c794de26ab09b98f..6be6c07e3012a6f2eb6870606b387ee5bf9d5561 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -44,6 +44,11 @@ int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg); int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo); int vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo); +int vnodeBegin(SVnode* pVnode, int option); +int vnodeSyncCommit(SVnode* pVnode); +int vnodeAsyncCommit(SVnode* pVnode); + +#define vnodeShouldCommit vnodeBufPoolIsFull #if 1 // SVBufPool @@ -84,13 +89,8 @@ bool vmaIsFull(SVMemAllocator* pVMA); // vnodeCfg.h extern const SVnodeCfg vnodeCfgDefault; -int vnodeCheckCfg(const SVnodeCfg*); -void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); +int vnodeCheckCfg(const SVnodeCfg*); -// For commit -#define vnodeShouldCommit vnodeBufPoolIsFull -int vnodeSyncCommit(SVnode* pVnode); -int vnodeAsyncCommit(SVnode* pVnode); #endif #ifdef __cplusplus diff --git a/source/dnode/vnode/src/meta/metaMain.c b/source/dnode/vnode/src/meta/metaMain.c deleted file mode 100644 index 879a7e8a6fc46b9c5ea9336a9aee3d8798d2cf32..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaMain.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 "tcoding.h" - -#include "vnodeInt.h" - -static SMeta *metaNew(const char *path, SMemAllocatorFactory *pMAF); -static void metaFree(SMeta *pMeta); -static int metaOpenImpl(SMeta *pMeta); -static void metaCloseImpl(SMeta *pMeta); - -SMeta *metaOpen(const char *path, SMemAllocatorFactory *pMAF) { - SMeta *pMeta = NULL; - - // Allocate handle - pMeta = metaNew(path, pMAF); - if (pMeta == NULL) { - // TODO: handle error - return NULL; - } - - // Create META path (TODO) - taosMkDir(path); - - // Open meta - if (metaOpenImpl(pMeta) < 0) { - metaFree(pMeta); - return NULL; - } - - return pMeta; -} - -void metaClose(SMeta *pMeta) { - if (pMeta) { - metaCloseImpl(pMeta); - metaFree(pMeta); - } -} - -void metaRemove(const char *path) { taosRemoveDir(path); } - -/* ------------------------ STATIC METHODS ------------------------ */ -static SMeta *metaNew(const char *path, SMemAllocatorFactory *pMAF) { - SMeta *pMeta; - size_t psize = strlen(path); - - pMeta = (SMeta *)taosMemoryCalloc(1, sizeof(*pMeta)); - if (pMeta == NULL) { - return NULL; - } - - pMeta->path = strdup(path); - if (pMeta->path == NULL) { - metaFree(pMeta); - return NULL; - } - - return pMeta; -}; - -static void metaFree(SMeta *pMeta) { - if (pMeta) { - taosMemoryFreeClear(pMeta->path); - taosMemoryFree(pMeta); - } -} - -static int metaOpenImpl(SMeta *pMeta) { - // Open meta db - if (metaOpenDB(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - // Open meta index - if (metaOpenIdx(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - // Open meta table uid generator - if (metaOpenUidGnrt(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - return 0; -} - -static void metaCloseImpl(SMeta *pMeta) { - metaCloseUidGnrt(pMeta); - metaCloseIdx(pMeta); - metaCloseDB(pMeta); -} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c new file mode 100644 index 0000000000000000000000000000000000000000..4419420e5965b22442d69b28c9e8248ba4e05326 --- /dev/null +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -0,0 +1,66 @@ +/* + * 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" + +int metaOpen(SVnode *pVnode, SMeta **ppMeta) { + SMeta *pMeta = NULL; + int slen; + + *ppMeta = NULL; + + // create handle + slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3; + if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pMeta->path = (char *)&pMeta[1]; + sprintf(pMeta->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, + VNODE_META_DIR); + pMeta->pVnode = pVnode; + + // create path if not created yet + taosMkDir(pMeta->path); + + // open meta + if (metaOpenDB(pMeta) < 0) { + goto _err; + } + + if (metaOpenIdx(pMeta) < 0) { + goto _err; + } + + *ppMeta = pMeta; + return 0; + +_err: + if (pMeta->pIdx) metaCloseIdx(pMeta); + if (pMeta->pDB) metaCloseDB(pMeta); + taosMemoryFree(pMeta); + return -1; +} + +int metaClose(SMeta *pMeta) { + if (pMeta) { + metaCloseIdx(pMeta); + metaCloseDB(pMeta); + taosMemoryFree(pMeta); + } + + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c deleted file mode 100644 index 27a2ecfb195c300998246f52c145bb08d0bf311e..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaTbUid.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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" - -int metaOpenUidGnrt(SMeta *pMeta) { - // Init a generator - pMeta->uidGnrt.nextUid = IVLD_TB_UID; - return 0; -} - -void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ -} - -tb_uid_t metaGenerateUid(SMeta *pMeta) { - // Generate a new table UID - return tGenIdPI64(); -} diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 34b983c20c7f344288bd4f7dad7fb6ad624882fd..a5596dc998eb429ae3000c02372096b992c67b09 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -23,11 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) { return 0; } -#if 1 //====================================================================== -void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) { - memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg)); -} - int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { uint32_t hashValue = 0; @@ -47,5 +42,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { return TSDB_CODE_SUCCESS; } - -#endif \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index d0433b7764e7c12af442d95996030a0192cb3634..5d4b07ec185d813ef0e984879f08240a11569856 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -65,14 +65,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // create handle - pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode)); + pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); return NULL; } - pVnode->path = strdup(dir); + pVnode->path = (char *)&pVnode[1]; + strcpy(pVnode->path, path); pVnode->config = info.config; pVnode->state.committed = info.state.committed; pVnode->state.processed = pVnode->state.applied = pVnode->state.committed; @@ -88,9 +89,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // open meta - sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_META_DIR); - pVnode->pMeta = metaOpen(tdir, vBufPoolGetMAF(pVnode)); - if (pVnode->pMeta == NULL) { + if (metaOpen(pVnode, &pVnode->pMeta) < 0) { vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } @@ -141,7 +140,6 @@ _err: if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb); if (pVnode->pMeta) metaClose(pVnode->pMeta); tsem_destroy(&(pVnode->canCommit)); - taosMemoryFreeClear(pVnode->path); taosMemoryFree(pVnode); return NULL; } @@ -159,7 +157,6 @@ void vnodeClose(SVnode *pVnode) { vnodeCloseBufPool(pVnode); // destroy handle tsem_destroy(&(pVnode->canCommit)); - taosMemoryFreeClear(pVnode->path); taosMemoryFree(pVnode); } }