提交 a9a1ad4c 编写于 作者: H Hongze Cheng

refactor: vnode

上级 973b9383
...@@ -21,6 +21,7 @@ target_sources( ...@@ -21,6 +21,7 @@ target_sources(
"src/meta/metaIdx.c" "src/meta/metaIdx.c"
"src/meta/metaTable.c" "src/meta/metaTable.c"
"src/meta/metaTDBImpl.c" "src/meta/metaTDBImpl.c"
"src/meta/metaQuery.c"
# tsdb # tsdb
"src/tsdb/tsdbTDBImpl.c" "src/tsdb/tsdbTDBImpl.c"
...@@ -69,6 +70,7 @@ target_link_libraries( ...@@ -69,6 +70,7 @@ target_link_libraries(
PUBLIC transport PUBLIC transport
PUBLIC stream PUBLIC stream
) )
# target_compile_definitions(vnode PUBLIC -DMETA_REFACT)
if(${BUILD_TEST}) if(${BUILD_TEST})
add_subdirectory(test) add_subdirectory(test)
......
...@@ -47,6 +47,22 @@ int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); ...@@ -47,6 +47,22 @@ int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);
static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); } 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_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
...@@ -71,6 +87,7 @@ SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); ...@@ -71,6 +87,7 @@ SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
void metaCloseCtbCurosr(SMCtbCursor* pCtbCur); void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
#ifndef META_REFACT
// SMetaDB // SMetaDB
int metaOpenDB(SMeta* pMeta); int metaOpenDB(SMeta* pMeta);
void metaCloseDB(SMeta* pMeta); void metaCloseDB(SMeta* pMeta);
...@@ -78,17 +95,9 @@ int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg); ...@@ -78,17 +95,9 @@ int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); 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);
#endif
// SMetaIdx #endif
tb_uid_t metaGenerateUid(SMeta* pMeta);
struct SMeta {
char* path;
SVnode* pVnode;
SMetaDB* pDB;
SMetaIdx* pIdx;
};
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -51,7 +51,9 @@ int metaOpenIdx(SMeta *pMeta) { ...@@ -51,7 +51,9 @@ int metaOpenIdx(SMeta *pMeta) {
#ifdef USE_INVERTED_INDEX #ifdef USE_INVERTED_INDEX
SIndexOpts opts; 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 #endif
return 0; return 0;
...@@ -67,7 +69,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ ...@@ -67,7 +69,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
#ifdef USE_INVERTED_INDEX #ifdef USE_INVERTED_INDEX
SIndexOpts opts; SIndexOpts opts;
if (indexClose(pMeta->pIdx->pIdx) != 0) { return -1; } if (indexClose(pMeta->pIdx->pIdx) != 0) {
return -1;
}
#endif #endif
} }
...@@ -84,7 +88,7 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) { ...@@ -84,7 +88,7 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
tb_uid_t tuid = 0; // child table uid tb_uid_t tuid = 0; // child table uid
SIndexMultiTerm *terms = indexMultiTermCreate(); SIndexMultiTerm *terms = indexMultiTermCreate();
SIndexTerm * term = SIndexTerm *term =
indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid); indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
indexMultiTermAdd(terms, term); indexMultiTermAdd(terms, term);
...@@ -114,10 +118,13 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) { ...@@ -114,10 +118,13 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) {
// TODO: add atomicity // TODO: add atomicity
#ifdef META_REFACT
#else
if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) { if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
#endif
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -125,9 +132,12 @@ int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) { ...@@ -125,9 +132,12 @@ int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
// TODO: Validate the cfg // TODO: Validate the cfg
// TODO: add atomicity // TODO: add atomicity
#ifdef META_REFACT
#else
if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) { if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
#endif
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
\ No newline at end of file
...@@ -21,6 +21,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { ...@@ -21,6 +21,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
*ppMeta = NULL; *ppMeta = NULL;
#ifdef META_REFACT
#else
// create handle // create handle
slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3; slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3;
if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) { if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) {
...@@ -44,22 +46,29 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { ...@@ -44,22 +46,29 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
if (metaOpenIdx(pMeta) < 0) { if (metaOpenIdx(pMeta) < 0) {
goto _err; goto _err;
} }
#endif
*ppMeta = pMeta; *ppMeta = pMeta;
return 0; return 0;
_err: _err:
#ifdef META_REFACT
#else
if (pMeta->pIdx) metaCloseIdx(pMeta); if (pMeta->pIdx) metaCloseIdx(pMeta);
if (pMeta->pDB) metaCloseDB(pMeta); if (pMeta->pDB) metaCloseDB(pMeta);
taosMemoryFree(pMeta); taosMemoryFree(pMeta);
#endif
return -1; return -1;
} }
int metaClose(SMeta *pMeta) { int metaClose(SMeta *pMeta) {
if (pMeta) { if (pMeta) {
#ifdef META_REFACT
#else
metaCloseIdx(pMeta); metaCloseIdx(pMeta);
metaCloseDB(pMeta); metaCloseDB(pMeta);
taosMemoryFree(pMeta); taosMemoryFree(pMeta);
#endif
} }
return 0; return 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"
\ No newline at end of file
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "vnodeInt.h" #include "vnodeInt.h"
#ifndef META_REFACT
typedef struct SPoolMem { typedef struct SPoolMem {
int64_t size; int64_t size;
struct SPoolMem *prev; struct SPoolMem *prev;
...@@ -1134,3 +1136,5 @@ static void poolFree(void *arg, void *ptr) { ...@@ -1134,3 +1136,5 @@ static void poolFree(void *arg, void *ptr) {
tdbOsFree(pMem); tdbOsFree(pMem);
} }
#endif
\ No newline at end of file
...@@ -16,18 +16,13 @@ ...@@ -16,18 +16,13 @@
#include "vnodeInt.h" #include "vnodeInt.h"
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
// Validate the tbOptions #ifdef META_REFACT
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) { #else
// // TODO: handle error
// return -1;
// }
// TODO: add atomicity
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) { if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
#endif
if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) { if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) {
// TODO: handle error // TODO: handle error
...@@ -50,4 +45,3 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) { ...@@ -50,4 +45,3 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
return 0; return 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册