diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 86ebb643a4f392b3c7d165f989422aa23be7b10c..031ed178f0e92349c3b07cf9087575beb03e4e58 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -58,6 +58,7 @@ int metaCommit(SMeta *pMeta); STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); +STSchema * metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); SMTbCursor *metaOpenTbCursor(SMeta *pMeta); void metaCloseTbCursor(SMTbCursor *pTbCur); diff --git a/include/dnode/vnode/tsdb/tsdb.h b/include/dnode/vnode/tsdb/tsdb.h index 53c10f09faff2f66dd53dae78ddf72839f797ea3..33528db11242b3e9ab79220c306b30f343143610 100644 --- a/include/dnode/vnode/tsdb/tsdb.h +++ b/include/dnode/vnode/tsdb/tsdb.h @@ -17,6 +17,7 @@ #define _TD_TSDB_H_ #include "mallocator.h" +#include "meta.h" #ifdef __cplusplus extern "C" { @@ -58,7 +59,7 @@ typedef struct STsdbCfg { } STsdbCfg; // STsdb -STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF); +STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta); void tsdbClose(STsdb *); void tsdbRemove(const char *path); int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg, SSubmitRsp *pRsp); diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 615773180e9f8deca655ca897cf52ec1541a3cde..55742d5cad5ac00a0ada018d55f6d1be5c9b2911 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -106,7 +106,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open tsdb sprintf(dir, "%s/tsdb", pVnode->path); - pVnode->pTsdb = tsdbOpen(dir, pVnode->vgId, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode)); + pVnode->pTsdb = tsdbOpen(dir, pVnode->vgId, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode), pVnode->pMeta); if (pVnode->pTsdb == NULL) { // TODO: handle error return -1; diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 4220a604b4326c93e017691db80b1a9c30f51aa5..31e8f84be630c5ea143c4da792c4de05d80a03d5 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -589,4 +589,27 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { return NULL; } } +} + +STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { + STSchemaBuilder sb; + STSchema * pTSchema = NULL; + SSchema * pSchema; + SSchemaWrapper *pSW; + + pSW = metaGetTableSchema(pMeta, uid, sver, true); + if (pSW == NULL) { + return NULL; + } + + // Rebuild a schema + tdInitTSchemaBuilder(&sb, 0); + for (int32_t i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes); + } + pTSchema = tdGetSchemaFromBuilder(&sb); + tdDestroyTSchemaBuilder(&sb); + + return pTSchema; } \ No newline at end of file diff --git a/source/dnode/vnode/tsdb/CMakeLists.txt b/source/dnode/vnode/tsdb/CMakeLists.txt index 2d3f6d6e4283a63131145f501bd0845741d9494a..0d77518100ad4f133fcfb35c51959d2528bfba7f 100644 --- a/source/dnode/vnode/tsdb/CMakeLists.txt +++ b/source/dnode/vnode/tsdb/CMakeLists.txt @@ -29,4 +29,5 @@ target_link_libraries( PUBLIC common PUBLIC tkv PUBLIC tfs + PUBLIC meta ) \ No newline at end of file diff --git a/source/dnode/vnode/tsdb/inc/tsdbDef.h b/source/dnode/vnode/tsdb/inc/tsdbDef.h index 1c000d2d905d54ab58a0df78abacf766915e7b39..51ddbe80aaca8e71894f7046b4ed536e4dd6cd57 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbDef.h +++ b/source/dnode/vnode/tsdb/inc/tsdbDef.h @@ -17,6 +17,7 @@ #define _TD_TSDB_DEF_H_ #include "mallocator.h" +#include "meta.h" #include "tcompression.h" #include "tglobal.h" #include "thash.h" @@ -48,6 +49,7 @@ struct STsdb { SRtn rtn; SMemAllocatorFactory *pmaf; STsdbFS * fs; + SMeta * pMeta; }; #define REPO_ID(r) ((r)->vgId) diff --git a/source/dnode/vnode/tsdb/inc/tsdbFS.h b/source/dnode/vnode/tsdb/inc/tsdbFS.h index dfd34deb84813bb60107a4519064cf76fb950044..af432aa9d9f836ada62d6ff59c7cd9566b145336 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbFS.h +++ b/source/dnode/vnode/tsdb/inc/tsdbFS.h @@ -70,7 +70,7 @@ typedef struct { #define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC #define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC -STsdbFS *tsdbNewFS(STsdbCfg *pCfg); +STsdbFS *tsdbNewFS(const STsdbCfg *pCfg); void * tsdbFreeFS(STsdbFS *pfs); int tsdbOpenFS(STsdb *pRepo); void tsdbCloseFS(STsdb *pRepo); @@ -79,7 +79,7 @@ int tsdbEndFSTxn(STsdb *pRepo); int tsdbEndFSTxnWithError(STsdbFS *pfs); void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta); // void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile); -int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet); +int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet); void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction); void tsdbFSIterSeek(SFSIter *pIter, int fid); diff --git a/source/dnode/vnode/tsdb/src/tsdbCommit.c b/source/dnode/vnode/tsdb/src/tsdbCommit.c index c97554f39b495112ea539193da745949ef4fd3ae..f4162d065243dfc4fff6ae94597ecfd0f85e3615 100644 --- a/source/dnode/vnode/tsdb/src/tsdbCommit.c +++ b/source/dnode/vnode/tsdb/src/tsdbCommit.c @@ -420,6 +420,13 @@ static int tsdbCreateCommitIters(SCommitH *pCommith) { pCommitIter = pCommith->iters + i; pCommitIter->pIter = tSkipListCreateIter(pTbData->pData); tSkipListIterNext(pCommitIter->pIter); + +#if 0 + // TODO + pCommitIter->pTable = (STable *)malloc(sizeof(STable)); + pCommitIter->pTable->uid = pTbData->uid; + pCommitIter->pTable->pSchema = metaGetTableSchema(); +#endif } return 0; diff --git a/source/dnode/vnode/tsdb/src/tsdbFS.c b/source/dnode/vnode/tsdb/src/tsdbFS.c index e56a78a4ef779150024740ad3b948811d1be1336..b874da03f4a4bc1e8b13ede415254bb0a1860093 100644 --- a/source/dnode/vnode/tsdb/src/tsdbFS.c +++ b/source/dnode/vnode/tsdb/src/tsdbFS.c @@ -191,7 +191,7 @@ static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) { } // ================== STsdbFS -STsdbFS *tsdbNewFS(STsdbCfg *pCfg) { +STsdbFS *tsdbNewFS(const STsdbCfg *pCfg) { int keep = pCfg->keep; int days = pCfg->daysPerFile; int maxFSet = TSDB_MAX_FSETS(keep, days); diff --git a/source/dnode/vnode/tsdb/src/tsdbMain.c b/source/dnode/vnode/tsdb/src/tsdbMain.c index 5b43038bc9dfb126d99a1410bccc889920ce3d61..ab1f0294bfd43ef2e475a5f995be2adcf55ca640 100644 --- a/source/dnode/vnode/tsdb/src/tsdbMain.c +++ b/source/dnode/vnode/tsdb/src/tsdbMain.c @@ -15,12 +15,13 @@ #include "tsdbDef.h" -static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF); +static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, + SMeta *pMeta); static void tsdbFree(STsdb *pTsdb); static int tsdbOpenImpl(STsdb *pTsdb); static void tsdbCloseImpl(STsdb *pTsdb); -STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) { +STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta) { STsdb *pTsdb = NULL; // Set default TSDB Options @@ -35,7 +36,7 @@ STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAl } // Create the handle - pTsdb = tsdbNew(path, vgId, pTsdbCfg, pMAF); + pTsdb = tsdbNew(path, vgId, pTsdbCfg, pMAF, pMeta); if (pTsdb == NULL) { // TODO: handle error return NULL; @@ -62,7 +63,8 @@ void tsdbClose(STsdb *pTsdb) { void tsdbRemove(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) { +static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, + SMeta *pMeta) { STsdb *pTsdb = NULL; pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); @@ -75,6 +77,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, pTsdb->vgId = vgId; tsdbOptionsCopy(&(pTsdb->config), pTsdbCfg); pTsdb->pmaf = pMAF; + pTsdb->pMeta = pMeta; pTsdb->fs = tsdbNewFS(pTsdbCfg);