diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 44ae1bb79fc56d85f6b37ac31e374dd510839a10..b5994a50e1dd86b512c1f28168ad573d388b8010 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -71,7 +71,7 @@ typedef struct STbCfg { } STbCfg; // SMeta operations -SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); +SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg); void metaClose(SMeta *pMeta); void metaRemove(const char *path); int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); @@ -79,8 +79,8 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); // Options -void metaOptionsInit(SMetaCfg *pOptions); -void metaOptionsClear(SMetaCfg *pOptions); +void metaOptionsInit(SMetaCfg *pMetaCfg); +void metaOptionsClear(SMetaCfg *pMetaCfg); // STbCfg #define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ diff --git a/include/dnode/vnode/tq/tq.h b/include/dnode/vnode/tq/tq.h index 747d97b7a08992389092f2b9a7b6d69a4e00a208..074678f248dc84f9c09a1b699ed6c8eee28a27b4 100644 --- a/include/dnode/vnode/tq/tq.h +++ b/include/dnode/vnode/tq/tq.h @@ -264,7 +264,7 @@ typedef struct STQ { // open in each vnode STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac); -void tqDestroy(STQ*); +void tqClose(STQ*); // void* will be replace by a msg type int tqPushMsg(STQ*, void* msg, int64_t version); diff --git a/include/dnode/vnode/tsdb/tsdb.h b/include/dnode/vnode/tsdb/tsdb.h index f8eac9768fc8ad98d9d7f80095b265fcca5f7e0c..b85c6b64f67993effcacd2915ced28157e10e909 100644 --- a/include/dnode/vnode/tsdb/tsdb.h +++ b/include/dnode/vnode/tsdb/tsdb.h @@ -16,6 +16,8 @@ #ifndef _TD_TSDB_H_ #define _TD_TSDB_H_ +#include "mallocator.h" + #ifdef __cplusplus extern "C" { #endif @@ -25,7 +27,7 @@ typedef struct STsdb STsdb; typedef struct STsdbCfg STsdbCfg; // STsdb -STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg); +STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF); void tsdbClose(STsdb *); void tsdbRemove(const char *path); int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg); diff --git a/source/dnode/vnode/impl/inc/vnodeBufferPool.h b/source/dnode/vnode/impl/inc/vnodeBufferPool.h index d96671d2bda84d6b092016c2086954602a2d3eba..b4535597ee29e47ec6ca0683bd2caf4e304f9c86 100644 --- a/source/dnode/vnode/impl/inc/vnodeBufferPool.h +++ b/source/dnode/vnode/impl/inc/vnodeBufferPool.h @@ -32,6 +32,8 @@ int vnodeBufPoolRecycle(SVnode *pVnode); void *vnodeMalloc(SVnode *pVnode, uint64_t size); bool vnodeBufPoolIsFull(SVnode *pVnode); +SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode); + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/impl/inc/vnodeMAF.h b/source/dnode/vnode/impl/inc/vnodeMAF.h new file mode 100644 index 0000000000000000000000000000000000000000..7aa405103c2eb1576ce70ab8e014916f183a3d2e --- /dev/null +++ b/source/dnode/vnode/impl/inc/vnodeMAF.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_VNODE_MAF_H_ +#define _TD_VNODE_MAF_H_ + +#include "vnode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int vnodeOpenMAF(SVnode *pVnode); +void vnodeCloseMAF(SVnode *pVnode); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_MAF_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index 152a346f0a61961418795482be89808b782eaa4d..49e7889517ab290a2393f1f2bb467a491598c024 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -24,8 +24,8 @@ struct SVBufPool { TD_DLIST(SVMemAllocator) free; TD_DLIST(SVMemAllocator) incycle; SVMemAllocator *inuse; - // MAF for submodules - // SMemAllocatorFactory maf; + // MAF for submodules to use + SMemAllocatorFactory *pMAF; }; int vnodeOpenBufPool(SVnode *pVnode) { @@ -125,6 +125,8 @@ bool vnodeBufPoolIsFull(SVnode *pVnode) { return vmaIsFull(pVnode->pBufPool->inuse); } +SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode) { return pVnode->pBufPool->pMAF; } + #if 0 typedef enum { diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 59e3bae5d7581986caa4b71dbb11b9178b9eede5..c1539659aed662e2d48ff566f1177145768b3845 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open tsdb sprintf(dir, "%s/tsdb", pVnode->path); - pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg)); + pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode)); if (pVnode->pTsdb == NULL) { // TODO: handle error return -1; @@ -110,7 +110,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // TODO: Open TQ sprintf(dir, "%s/tq", pVnode->path); - pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL); + pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, vBufPoolGetMAF(pVnode)); if (pVnode->pTq == NULL) { // TODO: handle error return -1; @@ -131,7 +131,9 @@ static int vnodeOpenImpl(SVnode *pVnode) { static void vnodeCloseImpl(SVnode *pVnode) { if (pVnode) { vnodeCloseBufPool(pVnode); - tsdbClose(pVnode->pTsdb); metaClose(pVnode->pMeta); + tsdbClose(pVnode->pTsdb); + tqClose(pVnode->pTq); + walClose(pVnode->pWal); } } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaMain.c b/source/dnode/vnode/meta/src/metaMain.c index 53055dcea301eeac7ed3dd653de0b76d2d4a58d8..f2602fbad7b16fedac972d8e65603556a3ac9ede 100644 --- a/source/dnode/vnode/meta/src/metaMain.c +++ b/source/dnode/vnode/meta/src/metaMain.c @@ -17,27 +17,27 @@ #include "metaDef.h" -static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions); +static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg); static void metaFree(SMeta *pMeta); static int metaOpenImpl(SMeta *pMeta); static void metaCloseImpl(SMeta *pMeta); -SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) { +SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg) { SMeta *pMeta = NULL; // Set default options - if (pMetaOptions == NULL) { - pMetaOptions = &defaultMetaOptions; + if (pMetaCfg == NULL) { + pMetaCfg = &defaultMetaOptions; } // Validate the options - if (metaValidateOptions(pMetaOptions) < 0) { + if (metaValidateOptions(pMetaCfg) < 0) { // TODO: deal with error return NULL; } // Allocate handle - pMeta = metaNew(path, pMetaOptions); + pMeta = metaNew(path, pMetaCfg); if (pMeta == NULL) { // TODO: handle error return NULL; @@ -65,7 +65,7 @@ void metaClose(SMeta *pMeta) { void metaRemove(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) { +static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg) { SMeta *pMeta; size_t psize = strlen(path); @@ -80,7 +80,7 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) { return NULL; } - metaOptionsCopy(&(pMeta->options), pMetaOptions); + metaOptionsCopy(&(pMeta->options), pMetaCfg); return pMeta; }; diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index 249ffd7ae3eeb4f13d22dae952772edbac7ea76d..4aabf07c2dd88cfa18e48eeaa6f36161b3d73978 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -66,6 +66,10 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAl return pTq; } +void tqClose(STQ*pTq) { + // TODO +} + static int tqProtoCheck(TmqMsgHead *pMsg) { return pMsg->protoVer == 0; } diff --git a/source/dnode/vnode/tsdb/src/tsdbMain.c b/source/dnode/vnode/tsdb/src/tsdbMain.c index 2fe7a61930cff4342568bb2da7cb1f6701f44f61..20b75aa78fe37b02fef37ee1ac24b9f9d87e97e4 100644 --- a/source/dnode/vnode/tsdb/src/tsdbMain.c +++ b/source/dnode/vnode/tsdb/src/tsdbMain.c @@ -15,27 +15,27 @@ #include "tsdbDef.h" -static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions); +static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg); static void tsdbFree(STsdb *pTsdb); static int tsdbOpenImpl(STsdb *pTsdb); static void tsdbCloseImpl(STsdb *pTsdb); -STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) { +STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) { STsdb *pTsdb = NULL; // Set default TSDB Options - if (pTsdbOptions == NULL) { - pTsdbOptions = &defautlTsdbOptions; + if (pTsdbCfg == NULL) { + pTsdbCfg = &defautlTsdbOptions; } // Validate the options - if (tsdbValidateOptions(pTsdbOptions) < 0) { + if (tsdbValidateOptions(pTsdbCfg) < 0) { // TODO: handle error return NULL; } // Create the handle - pTsdb = tsdbNew(path, pTsdbOptions); + pTsdb = tsdbNew(path, pTsdbCfg); if (pTsdb == NULL) { // TODO: handle error return NULL; @@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) { void tsdbRemove(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) { +static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg) { STsdb *pTsdb = NULL; pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); @@ -72,7 +72,7 @@ static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) { } pTsdb->path = strdup(path); - tsdbOptionsCopy(&(pTsdb->options), pTsdbOptions); + tsdbOptionsCopy(&(pTsdb->options), pTsdbCfg); return pTsdb; }