未验证 提交 7a795927 编写于 作者: H Hongze Cheng 提交者: GitHub

Merge pull request #11567 from taosdata/feature/vnode_refact1

refactor: vnode
...@@ -18,12 +18,11 @@ target_sources( ...@@ -18,12 +18,11 @@ target_sources(
"src/vnd/vnodeSvr.c" "src/vnd/vnodeSvr.c"
# meta # meta
# "src/meta/metaBDBImpl.c" "src/meta/metaOpen.c"
"src/meta/metaIdx.c" "src/meta/metaIdx.c"
"src/meta/metaMain.c"
"src/meta/metaTable.c" "src/meta/metaTable.c"
"src/meta/metaTbUid.c"
"src/meta/metaTDBImpl.c" "src/meta/metaTDBImpl.c"
# "src/meta/metaBDBImpl.c"
# tsdb # tsdb
"src/tsdb/tsdbTDBImpl.c" "src/tsdb/tsdbTDBImpl.c"
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
extern "C" { extern "C" {
#endif #endif
typedef struct SMetaCache SMetaCache;
typedef struct SMetaIdx SMetaIdx; typedef struct SMetaIdx SMetaIdx;
typedef struct SMetaDB SMetaDB; typedef struct SMetaDB SMetaDB;
typedef struct SMCtbCursor SMCtbCursor; typedef struct SMCtbCursor SMCtbCursor;
...@@ -36,13 +35,22 @@ typedef struct SMSmaCursor SMSmaCursor; ...@@ -36,13 +35,22 @@ typedef struct SMSmaCursor SMSmaCursor;
#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0) #define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on // 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_SUPER_TABLE TD_SUPER_TABLE
#define META_CHILD_TABLE TD_CHILD_TABLE #define META_CHILD_TABLE TD_CHILD_TABLE
#define META_NORMAL_TABLE TD_NORMAL_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 metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
int metaDropTable(SMeta* pMeta, tb_uid_t uid); int metaDropTable(SMeta* pMeta, tb_uid_t uid);
int metaCommit(SMeta* pMeta); int metaCommit(SMeta* pMeta);
...@@ -71,27 +79,8 @@ int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); ...@@ -71,27 +79,8 @@ int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
// SMetaCache
int metaOpenCache(SMeta* pMeta);
void metaCloseCache(SMeta* pMeta);
// SMetaIdx // 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); tb_uid_t metaGenerateUid(SMeta* pMeta);
struct SMeta { struct SMeta {
...@@ -99,9 +88,6 @@ struct SMeta { ...@@ -99,9 +88,6 @@ struct SMeta {
SVnode* pVnode; SVnode* pVnode;
SMetaDB* pDB; SMetaDB* pDB;
SMetaIdx* pIdx; SMetaIdx* pIdx;
SMetaCache* pCache;
STbUidGenerator uidGnrt;
SMemAllocatorFactory* pmaf;
}; };
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -44,6 +44,11 @@ int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); ...@@ -44,6 +44,11 @@ int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg);
int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg); int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo); int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
int vnodeLoadInfo(const char* dir, 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 #if 1
// SVBufPool // SVBufPool
...@@ -85,12 +90,7 @@ bool vmaIsFull(SVMemAllocator* pVMA); ...@@ -85,12 +90,7 @@ bool vmaIsFull(SVMemAllocator* pVMA);
extern const SVnodeCfg vnodeCfgDefault; extern const SVnodeCfg vnodeCfgDefault;
int vnodeCheckCfg(const SVnodeCfg*); int vnodeCheckCfg(const SVnodeCfg*);
void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc);
// For commit
#define vnodeShouldCommit vnodeBufPoolIsFull
int vnodeSyncCommit(SVnode* pVnode);
int vnodeAsyncCommit(SVnode* pVnode);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
...@@ -15,16 +15,52 @@ ...@@ -15,16 +15,52 @@
#include "vnodeInt.h" #include "vnodeInt.h"
int metaOpenUidGnrt(SMeta *pMeta) { int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
// Init a generator SMeta *pMeta = NULL;
pMeta->uidGnrt.nextUid = IVLD_TB_UID; 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; return 0;
}
void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ _err:
if (pMeta->pIdx) metaCloseIdx(pMeta);
if (pMeta->pDB) metaCloseDB(pMeta);
taosMemoryFree(pMeta);
return -1;
} }
tb_uid_t metaGenerateUid(SMeta *pMeta) { int metaClose(SMeta *pMeta) {
// Generate a new table UID if (pMeta) {
return tGenIdPI64(); metaCloseIdx(pMeta);
metaCloseDB(pMeta);
taosMemoryFree(pMeta);
}
return 0;
} }
\ No newline at end of file
...@@ -23,11 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) { ...@@ -23,11 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) {
return 0; return 0;
} }
#if 1 //======================================================================
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg));
}
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
uint32_t hashValue = 0; uint32_t hashValue = 0;
...@@ -47,5 +42,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { ...@@ -47,5 +42,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
#endif
\ No newline at end of file
...@@ -65,14 +65,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { ...@@ -65,14 +65,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
} }
// create handle // create handle
pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode)); pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1);
if (pVnode == NULL) { if (pVnode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
return NULL; return NULL;
} }
pVnode->path = strdup(dir); pVnode->path = (char *)&pVnode[1];
strcpy(pVnode->path, path);
pVnode->config = info.config; pVnode->config = info.config;
pVnode->state.committed = info.state.committed; pVnode->state.committed = info.state.committed;
pVnode->state.processed = pVnode->state.applied = pVnode->state.committed; pVnode->state.processed = pVnode->state.applied = pVnode->state.committed;
...@@ -88,9 +89,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { ...@@ -88,9 +89,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
} }
// open meta // open meta
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_META_DIR); if (metaOpen(pVnode, &pVnode->pMeta) < 0) {
pVnode->pMeta = metaOpen(tdir, vBufPoolGetMAF(pVnode));
if (pVnode->pMeta == NULL) {
vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err; goto _err;
} }
...@@ -141,7 +140,6 @@ _err: ...@@ -141,7 +140,6 @@ _err:
if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb); if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb);
if (pVnode->pMeta) metaClose(pVnode->pMeta); if (pVnode->pMeta) metaClose(pVnode->pMeta);
tsem_destroy(&(pVnode->canCommit)); tsem_destroy(&(pVnode->canCommit));
taosMemoryFreeClear(pVnode->path);
taosMemoryFree(pVnode); taosMemoryFree(pVnode);
return NULL; return NULL;
} }
...@@ -159,7 +157,6 @@ void vnodeClose(SVnode *pVnode) { ...@@ -159,7 +157,6 @@ void vnodeClose(SVnode *pVnode) {
vnodeCloseBufPool(pVnode); vnodeCloseBufPool(pVnode);
// destroy handle // destroy handle
tsem_destroy(&(pVnode->canCommit)); tsem_destroy(&(pVnode->canCommit));
taosMemoryFreeClear(pVnode->path);
taosMemoryFree(pVnode); taosMemoryFree(pVnode);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册