Merge pull request #11567 from taosdata/feature/vnode_refact1
refactor: vnode
This commit is contained in:
commit
7a795927ea
|
@ -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,27 +79,8 @@ 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 {
|
||||
|
@ -99,9 +88,6 @@ struct SMeta {
|
|||
SVnode* pVnode;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
SMetaCache* pCache;
|
||||
STbUidGenerator uidGnrt;
|
||||
SMemAllocatorFactory* pmaf;
|
||||
};
|
||||
|
||||
#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
|
||||
|
@ -85,12 +90,7 @@ bool vmaIsFull(SVMemAllocator* pVMA);
|
|||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
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
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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 "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;
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* 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 "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();
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue