From 212376551d3fb88bc6a92475ba47ab380165164e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Dec 2021 05:43:44 +0000 Subject: [PATCH 1/5] more --- source/dnode/vnode/meta/src/metaBDBImpl.c | 52 ++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 4ef7dc01a4..d76ee369bf 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -38,6 +38,11 @@ struct SMetaDB { DB_ENV *pEvn; }; +typedef struct { + int32_t nCols; + SSchema *pSchema; +} SSchemaWrapper; + typedef int (*bdbIdxCbPtr)(DB *, const DBT *, const DBT *, DBT *); static SMetaDB *metaNewDB(); @@ -55,6 +60,7 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT * static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void metaClearTbCfg(STbCfg *pTbCfg); +static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code)) @@ -432,6 +438,7 @@ static void metaClearTbCfg(STbCfg *pTbCfg) { /* ------------------------ FOR QUERY ------------------------ */ int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) { +#if 0 DBT key = {0}; DBT value = {0}; SMetaDB * pMetaDB = pMeta->pDB; @@ -490,7 +497,7 @@ int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) { pMsg->tuid = tbCfg.stbCfg.suid; memcpy(pMsg->pSchema, tbCfg.stbCfg.pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols); memcpy(POINTER_SHIFT(pMsg->pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols), tbCfg.stbCfg.pTagSchema, - sizeof(SSchema) * tbCfg.stbCfg.nTagCols); + sizeof(SSchema) * tbCfg.stbCfg.nTagCols); break; case META_CHILD_TABLE: ASSERT(0); @@ -505,5 +512,48 @@ int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) { *ppMsg = pMsg; +#endif return 0; +} + +static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { + uint32_t nCols; + SSchemaWrapper *pSW = NULL; + SMetaDB * pDB = pMeta->pDB; + int ret; + void * pBuf; + SSchema * pSchema; + SSchemaKey schemaKey = {uid, sver}; + DBT key = {0}; + DBT value = {0}; + + // Set key/value properties + key.data = &schemaKey; + key.size = sizeof(schemaKey); + + // Query + ret = pDB->pSchemaDB->get(pDB->pSchemaDB, NULL, &key, &value, 0); + if (ret != 0) { + return NULL; + } + + // Decode the schema + pBuf = value.data; + taosDecodeFixedI32(&pBuf, &nCols); + pSW = (SSchemaWrapper *)malloc(sizeof(*pSW) + sizeof(SSchema) * nCols); + if (pSW == NULL) { + return NULL; + } + + pSW->pSchema = POINTER_SHIFT(pSW, sizeof(*pSW)); + + for (int i = 0; i < nCols; i++) { + pSchema = pSW->pSchema + i; + taosDecodeFixedI8(&pBuf, &(pSchema->type)); + taosDecodeFixedI32(&pBuf, &(pSchema->colId)); + taosDecodeFixedI32(&pBuf, &(pSchema->bytes)); + taosDecodeStringTo(&pBuf, pSchema->name); + } + + return pSW; } \ No newline at end of file From a4cb6467c2e4ea5c00ce7f61cae30ef7ca0fa77a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Dec 2021 06:28:58 +0000 Subject: [PATCH 2/5] more progress --- include/dnode/vnode/meta/meta.h | 2 +- source/dnode/vnode/impl/src/vnodeQuery.c | 2 + source/dnode/vnode/meta/src/metaBDBImpl.c | 173 ++++++++++++---------- 3 files changed, 98 insertions(+), 79 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index cc5eabf3bf..74a0f85932 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -48,7 +48,7 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); // For Query -int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg); +STbCfg *metaGetTableInfo(SMeta *pMeta, char *tbname); // Options void metaOptionsInit(SMetaCfg *pMetaCfg); diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index 1c6924040c..a0bdfed6fb 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -45,6 +45,7 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { +#if 0 STableInfoMsg *pReq = (STableInfoMsg *)(pMsg->pCont); STableMetaMsg *pRspMsg; int ret; @@ -63,5 +64,6 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO (*pRsp)->pCont = pRspMsg; +#endif return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index d76ee369bf..e70dcff7ad 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -60,7 +60,9 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT * static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void metaClearTbCfg(STbCfg *pTbCfg); -static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); +static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); +static STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); +static STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code)) @@ -437,86 +439,89 @@ static void metaClearTbCfg(STbCfg *pTbCfg) { } /* ------------------------ FOR QUERY ------------------------ */ -int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) { -#if 0 - DBT key = {0}; - DBT value = {0}; - SMetaDB * pMetaDB = pMeta->pDB; - int ret; - STbCfg tbCfg; - SSchemaKey schemaKey; - DBT key1 = {0}; - DBT value1 = {0}; - uint32_t ncols; - void * pBuf; - int tlen; - STableMetaMsg *pMsg; - SSchema * pSchema; +STbCfg *metaGetTableInfo(SMeta *pMeta, char *tbname) { + STbCfg * pTbCfg = NULL; + STbCfg * pStbCfg = NULL; + tb_uid_t uid; + int32_t sver = 0; + SSchemaWrapper *pSW; - key.data = tbname; - key.size = strlen(tbname) + 1; - - ret = pMetaDB->pNameIdx->get(pMetaDB->pNameIdx, NULL, &key, &value, 0); - if (ret != 0) { - // TODO - return -1; + pTbCfg = metaGetTbInfoByName(pMeta, tbname, &uid); + if (pTbCfg == NULL) { + return NULL; } - metaDecodeTbInfo(value.data, &tbCfg); - - switch (tbCfg.type) { - case META_SUPER_TABLE: - schemaKey.uid = tbCfg.stbCfg.suid; - schemaKey.sver = 0; - - key1.data = &schemaKey; - key1.size = sizeof(schemaKey); - - ret = pMetaDB->pSchemaDB->get(pMetaDB->pSchemaDB, &key1, &value1, NULL, 0); - if (ret != 0) { - // TODO - return -1; - } - pBuf = value1.data; - pBuf = taosDecodeFixedU32(pBuf, &ncols); - - tlen = sizeof(STableMetaMsg) + (tbCfg.stbCfg.nTagCols + ncols) * sizeof(SSchema); - pMsg = calloc(1, tlen); - if (pMsg == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - strcpy(pMsg->tbFname, tbCfg.name); - pMsg->numOfTags = tbCfg.stbCfg.nTagCols; - pMsg->numOfColumns = ncols; - pMsg->tableType = tbCfg.type; - pMsg->sversion = 0; - pMsg->tversion = 0; - pMsg->suid = tbCfg.stbCfg.suid; - pMsg->tuid = tbCfg.stbCfg.suid; - memcpy(pMsg->pSchema, tbCfg.stbCfg.pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols); - memcpy(POINTER_SHIFT(pMsg->pSchema, sizeof(SSchema) * tbCfg.stbCfg.nCols), tbCfg.stbCfg.pTagSchema, - sizeof(SSchema) * tbCfg.stbCfg.nTagCols); - break; - case META_CHILD_TABLE: - ASSERT(0); - break; - case META_NORMAL_TABLE: - ASSERT(0); - break; - default: - ASSERT(0); - break; + if (pTbCfg->type == META_CHILD_TABLE) { + uid = pTbCfg->ctbCfg.suid; } - *ppMsg = pMsg; + pSW = metaGetTableSchema(pMeta, uid, 0, false); + if (pSW == NULL) { + return NULL; + } -#endif - return 0; + return pTbCfg; } -static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { +static STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { + STbCfg * pTbCfg = NULL; + SMetaDB *pDB = pMeta->pDB; + DBT key = {0}; + DBT value = {0}; + int ret; + + // Set key/value + key.data = &uid; + key.size = sizeof(uid); + + // Query + ret = pDB->pTbDB->get(pDB->pTbDB, NULL, &key, &value, 0); + if (ret != 0) { + return NULL; + } + + // Decode + pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg)); + if (pTbCfg == NULL) { + return NULL; + } + + metaDecodeTbInfo(value.data, pTbCfg); + + return pTbCfg; +} + +static STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { + STbCfg * pTbCfg = NULL; + SMetaDB *pDB = pMeta->pDB; + DBT key = {0}; + DBT pkey = {0}; + DBT pvalue = {0}; + int ret; + + // Set key/value + key.data = tbname; + key.size = strlen(tbname); + + // Query + ret = pDB->pNameIdx->pget(pDB->pNameIdx, NULL, &key, &pkey, &pvalue, 0); + if (ret != 0) { + return NULL; + } + + // Decode + *uid = *(tb_uid_t *)(pkey.data); + pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg)); + if (pTbCfg == NULL) { + return NULL; + } + + metaDecodeTbInfo(pvalue.data, pTbCfg); + + return pTbCfg; +} + +static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { uint32_t nCols; SSchemaWrapper *pSW = NULL; SMetaDB * pDB = pMeta->pDB; @@ -540,12 +545,24 @@ static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sv // Decode the schema pBuf = value.data; taosDecodeFixedI32(&pBuf, &nCols); - pSW = (SSchemaWrapper *)malloc(sizeof(*pSW) + sizeof(SSchema) * nCols); - if (pSW == NULL) { - return NULL; - } + if (isinline) { + pSW = (SSchemaWrapper *)malloc(sizeof(*pSW) + sizeof(SSchema) * nCols); + if (pSW == NULL) { + return NULL; + } + pSW->pSchema = POINTER_SHIFT(pSW, sizeof(*pSW)); + } else { + pSW = (SSchemaWrapper *)malloc(sizeof(*pSW)); + if (pSW == NULL) { + return NULL; + } - pSW->pSchema = POINTER_SHIFT(pSW, sizeof(*pSW)); + pSW->pSchema = (SSchema *)malloc(sizeof(SSchema) * nCols); + if (pSW->pSchema == NULL) { + free(pSW); + return NULL; + } + } for (int i = 0; i < nCols; i++) { pSchema = pSW->pSchema + i; From db2399fa3c2322aca40eccd96cffa4f637ef6feb Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Dec 2021 07:05:49 +0000 Subject: [PATCH 3/5] more progress --- include/dnode/vnode/meta/meta.h | 9 ++- source/dnode/vnode/impl/inc/vnodeDef.h | 3 +- source/dnode/vnode/impl/src/vnodeQuery.c | 71 ++++++++++++++++++----- source/dnode/vnode/meta/src/metaBDBImpl.c | 38 +----------- 4 files changed, 71 insertions(+), 50 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 74a0f85932..7063ece8cd 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -37,6 +37,11 @@ typedef struct SMetaCfg { uint64_t lruSize; } SMetaCfg; +typedef struct { + int32_t nCols; + SSchema *pSchema; +} SSchemaWrapper; + typedef SVCreateTbReq STbCfg; // SMeta operations @@ -48,7 +53,9 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); // For Query -STbCfg *metaGetTableInfo(SMeta *pMeta, char *tbname); +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); // Options void metaOptionsInit(SMetaCfg *pMetaCfg); diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 78214ce14d..fdb9837292 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -31,10 +31,10 @@ #include "vnodeCommit.h" #include "vnodeFS.h" #include "vnodeMemAllocator.h" +#include "vnodeQuery.h" #include "vnodeRequest.h" #include "vnodeStateMgr.h" #include "vnodeSync.h" -#include "vnodeQuery.h" #ifdef __cplusplus extern "C" { @@ -62,6 +62,7 @@ typedef struct SVnodeMgr { extern SVnodeMgr vnodeMgr; struct SVnode { + int32_t vgId; char* path; SVnodeCfg config; SVState state; diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index a0bdfed6fb..91f5fc8012 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -45,25 +45,70 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { -#if 0 - STableInfoMsg *pReq = (STableInfoMsg *)(pMsg->pCont); - STableMetaMsg *pRspMsg; - int ret; + STableInfoMsg * pReq = (STableInfoMsg *)(pMsg->pCont); + STbCfg * pTbCfg = NULL; + STbCfg * pStbCfg = NULL; + tb_uid_t uid; + int32_t nCols; + int32_t nTagCols; + SSchemaWrapper *pSW; + STableMetaMsg * pTbMetaMsg; + SSchema * pTagSchema; - if (metaGetTableInfo(pVnode->pMeta, pReq->tableFname, &pRspMsg) < 0) { + pTbCfg = metaGetTbInfoByName(pVnode->pMeta, pReq->tableFname, &uid); + if (pTbCfg == NULL) { + return NULL; + } + + if (pTbCfg->type == META_CHILD_TABLE) { + pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid); + if (pStbCfg == NULL) { + return NULL; + } + + pSW = metaGetTableSchema(pVnode->pMeta, pTbCfg->ctbCfg.suid, 0, true); + } else { + pSW = metaGetTableSchema(pVnode->pMeta, uid, 0, true); + } + + nCols = pSW->nCols; + if (pTbCfg->type == META_SUPER_TABLE) { + nTagCols = pTbCfg->stbCfg.nTagCols; + pTagSchema = pTbCfg->stbCfg.pTagSchema; + } else if (pTbCfg->type == META_SUPER_TABLE) { + nTagCols = pStbCfg->stbCfg.nTagCols; + pTagSchema = pStbCfg->stbCfg.pTagSchema; + } else { + nTagCols = 0; + pTagSchema = NULL; + } + + pTbMetaMsg = (STableMetaMsg *)calloc(1, sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols)); + if (pTbMetaMsg == NULL) { return -1; } - *pRsp = malloc(sizeof(SRpcMsg)); - if (TD_IS_NULL(*pRsp)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - free(pMsg); - return -1; + strcpy(pTbMetaMsg->tbFname, pTbCfg->name); + if (pTbCfg->type == META_CHILD_TABLE) { + strcpy(pTbMetaMsg->stbFname, pStbCfg->name); + pTbMetaMsg->suid = htobe64(pTbCfg->ctbCfg.suid); + } + pTbMetaMsg->numOfTags = htonl(nTagCols); + pTbMetaMsg->numOfColumns = htonl(nCols); + pTbMetaMsg->tableType = pTbCfg->type; + pTbMetaMsg->tuid = htobe64(uid); + pTbMetaMsg->vgId = htonl(pVnode->vgId); + + memcpy(pTbMetaMsg->pSchema, pSW->pSchema, sizeof(SSchema) * pSW->nCols); + if (nTagCols) { + memcpy(POINTER_SHIFT(pTbMetaMsg->pSchema, sizeof(SSchema) * pSW->nCols), pTagSchema, sizeof(SSchema) * nTagCols); } - // TODO - (*pRsp)->pCont = pRspMsg; + for (int i = 0; i < nCols + nTagCols; i++) { + SSchema *pSch = pTbMetaMsg->pSchema + i; + pSch->colId = htonl(pSch->colId); + pSch->bytes = htonl(pSch->bytes); + } -#endif return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index e70dcff7ad..d5291340e6 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -38,11 +38,6 @@ struct SMetaDB { DB_ENV *pEvn; }; -typedef struct { - int32_t nCols; - SSchema *pSchema; -} SSchemaWrapper; - typedef int (*bdbIdxCbPtr)(DB *, const DBT *, const DBT *, DBT *); static SMetaDB *metaNewDB(); @@ -60,9 +55,6 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT * static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void metaClearTbCfg(STbCfg *pTbCfg); -static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); -static STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); -static STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code)) @@ -439,31 +431,7 @@ static void metaClearTbCfg(STbCfg *pTbCfg) { } /* ------------------------ FOR QUERY ------------------------ */ -STbCfg *metaGetTableInfo(SMeta *pMeta, char *tbname) { - STbCfg * pTbCfg = NULL; - STbCfg * pStbCfg = NULL; - tb_uid_t uid; - int32_t sver = 0; - SSchemaWrapper *pSW; - - pTbCfg = metaGetTbInfoByName(pMeta, tbname, &uid); - if (pTbCfg == NULL) { - return NULL; - } - - if (pTbCfg->type == META_CHILD_TABLE) { - uid = pTbCfg->ctbCfg.suid; - } - - pSW = metaGetTableSchema(pMeta, uid, 0, false); - if (pSW == NULL) { - return NULL; - } - - return pTbCfg; -} - -static STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { +STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { STbCfg * pTbCfg = NULL; SMetaDB *pDB = pMeta->pDB; DBT key = {0}; @@ -491,7 +459,7 @@ static STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { return pTbCfg; } -static STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { +STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { STbCfg * pTbCfg = NULL; SMetaDB *pDB = pMeta->pDB; DBT key = {0}; @@ -521,7 +489,7 @@ static STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { return pTbCfg; } -static SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { +SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { uint32_t nCols; SSchemaWrapper *pSW = NULL; SMetaDB * pDB = pMeta->pDB; From bbf1c53b6d97f230097e266ea3b115c412dc1ca3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Dec 2021 07:07:16 +0000 Subject: [PATCH 4/5] more --- source/dnode/vnode/impl/src/vnodeQuery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index 91f5fc8012..170319681a 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -57,13 +57,13 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pTbCfg = metaGetTbInfoByName(pVnode->pMeta, pReq->tableFname, &uid); if (pTbCfg == NULL) { - return NULL; + return -1; } if (pTbCfg->type == META_CHILD_TABLE) { pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid); if (pStbCfg == NULL) { - return NULL; + return -1; } pSW = metaGetTableSchema(pVnode->pMeta, pTbCfg->ctbCfg.suid, 0, true); From 2c5311abbd65290b2ef3b15a65fc3ffa5808f8f9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Dec 2021 07:40:04 +0000 Subject: [PATCH 5/5] more --- include/dnode/vnode/meta/meta.h | 6 ++++ source/dnode/vnode/meta/src/metaBDBImpl.c | 40 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 7063ece8cd..b75e478add 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -42,6 +42,8 @@ typedef struct { SSchema *pSchema; } SSchemaWrapper; +typedef struct SMTbCursor SMTbCursor; + typedef SVCreateTbReq STbCfg; // SMeta operations @@ -57,6 +59,10 @@ 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); +SMTbCursor * metaOpenTbCursor(SMeta *pMeta); +void metaCloseTbCursor(SMTbCursor *pTbCur); +char *metaTbCursorNext(SMTbCursor *pTbCur); + // Options void metaOptionsInit(SMetaCfg *pMetaCfg); void metaOptionsClear(SMetaCfg *pMetaCfg); diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index d5291340e6..1f693346cc 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -541,4 +541,44 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo } return pSW; +} + +struct SMTbCursor { + DBC *pCur; +}; + +SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { + SMTbCursor *pTbCur = NULL; + SMetaDB * pDB = pMeta->pDB; + + pTbCur = (SMTbCursor *)calloc(1, sizeof(*pTbCur)); + if (pTbCur == NULL) { + return NULL; + } + + pDB->pTbDB->cursor(pDB->pTbDB, NULL, &(pTbCur->pCur), 0); + + return pTbCur; +} + +void metaCloseTbCursor(SMTbCursor *pTbCur) { + if (pTbCur) { + if (pTbCur->pCur) { + pTbCur->pCur->close(pTbCur->pCur); + } + free(pTbCur); + } +} + +char *metaTbCursorNext(SMTbCursor *pTbCur) { + DBT key = {0}; + DBT value = {0}; + STbCfg tbCfg; + + if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) { + metaDecodeTbInfo(&(value.data), &tbCfg); + return tbCfg.name; + } else { + return NULL; + } } \ No newline at end of file