diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 74a0f859321ef83ca2e5de4a569ab4237dd125de..7063ece8cd09a301a93d321f0434386cd0d0ded8 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 78214ce14da0099c832268fdc66be3fd86ed869d..fdb9837292abc0c686353bc491c8445ddfa0380e 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 a0bdfed6fb9244bd97a096868dbd023632154225..91f5fc801245f839d72d73468f4ce5c77f11208c 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) { - return -1; + 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; } - *pRsp = malloc(sizeof(SRpcMsg)); - if (TD_IS_NULL(*pRsp)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - free(pMsg); + pTbMetaMsg = (STableMetaMsg *)calloc(1, sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols)); + if (pTbMetaMsg == NULL) { return -1; } - // TODO - (*pRsp)->pCont = pRspMsg; + 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); + } + + 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 e70dcff7ad46ede37c314f315102f7dbfa8bb784..d5291340e66797847e8698c1dde8438bc2e062da 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;