refactor: vnode
This commit is contained in:
parent
973b93830d
commit
a9a1ad4ce8
|
@ -21,6 +21,7 @@ target_sources(
|
|||
"src/meta/metaIdx.c"
|
||||
"src/meta/metaTable.c"
|
||||
"src/meta/metaTDBImpl.c"
|
||||
"src/meta/metaQuery.c"
|
||||
|
||||
# tsdb
|
||||
"src/tsdb/tsdbTDBImpl.c"
|
||||
|
@ -69,6 +70,7 @@ target_link_libraries(
|
|||
PUBLIC transport
|
||||
PUBLIC stream
|
||||
)
|
||||
# target_compile_definitions(vnode PUBLIC -DMETA_REFACT)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
|
|
|
@ -47,6 +47,22 @@ int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);
|
|||
|
||||
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_CHILD_TABLE TD_CHILD_TABLE
|
||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||
|
@ -71,6 +87,7 @@ SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
|
|||
void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
|
||||
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
||||
|
||||
#ifndef META_REFACT
|
||||
// SMetaDB
|
||||
int metaOpenDB(SMeta* pMeta);
|
||||
void metaCloseDB(SMeta* pMeta);
|
||||
|
@ -78,17 +95,9 @@ int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
|
|||
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||
#endif
|
||||
|
||||
// SMetaIdx
|
||||
|
||||
tb_uid_t metaGenerateUid(SMeta* pMeta);
|
||||
|
||||
struct SMeta {
|
||||
char* path;
|
||||
SVnode* pVnode;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -51,7 +51,9 @@ int metaOpenIdx(SMeta *pMeta) {
|
|||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
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
|
||||
return 0;
|
||||
|
@ -67,7 +69,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
|
|||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) { return -1; }
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -84,7 +88,7 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
|
|||
tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
|
||||
tb_uid_t tuid = 0; // child table uid
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
SIndexTerm * term =
|
||||
SIndexTerm *term =
|
||||
indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
||||
|
@ -114,10 +118,13 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) {
|
|||
|
||||
// TODO: add atomicity
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -125,9 +132,12 @@ int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
|
|||
// TODO: Validate the cfg
|
||||
// TODO: add atomicity
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -21,6 +21,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
|||
|
||||
*ppMeta = NULL;
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
// create handle
|
||||
slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3;
|
||||
if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) {
|
||||
|
@ -44,22 +46,29 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
|||
if (metaOpenIdx(pMeta) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
#endif
|
||||
|
||||
*ppMeta = pMeta;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pDB) metaCloseDB(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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"
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifndef META_REFACT
|
||||
|
||||
typedef struct SPoolMem {
|
||||
int64_t size;
|
||||
struct SPoolMem *prev;
|
||||
|
@ -1134,3 +1136,5 @@ static void poolFree(void *arg, void *ptr) {
|
|||
|
||||
tdbOsFree(pMem);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,18 +16,13 @@
|
|||
#include "vnodeInt.h"
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||
// Validate the tbOptions
|
||||
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
||||
// // TODO: handle error
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// TODO: add atomicity
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) {
|
||||
// TODO: handle error
|
||||
|
@ -50,4 +45,3 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue