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

Merge pull request #11567 from taosdata/feature/vnode_refact1

refactor: vnode
......@@ -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"
......
......@@ -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
......
......@@ -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
......
/*
* 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 @@
#include "vnodeInt.h"
int metaOpenUidGnrt(SMeta *pMeta) {
// Init a generator
pMeta->uidGnrt.nextUid = IVLD_TB_UID;
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;
}
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) {
// Generate a new table UID
return tGenIdPI64();
}
int metaClose(SMeta *pMeta) {
if (pMeta) {
metaCloseIdx(pMeta);
metaCloseDB(pMeta);
taosMemoryFree(pMeta);
}
return 0;
}
\ No newline at end of file
......@@ -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
......@@ -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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册