提交 db2399fa 编写于 作者: H Hongze Cheng

more progress

上级 a4cb6467
...@@ -37,6 +37,11 @@ typedef struct SMetaCfg { ...@@ -37,6 +37,11 @@ typedef struct SMetaCfg {
uint64_t lruSize; uint64_t lruSize;
} SMetaCfg; } SMetaCfg;
typedef struct {
int32_t nCols;
SSchema *pSchema;
} SSchemaWrapper;
typedef SVCreateTbReq STbCfg; typedef SVCreateTbReq STbCfg;
// SMeta operations // SMeta operations
...@@ -48,7 +53,9 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid); ...@@ -48,7 +53,9 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid);
int metaCommit(SMeta *pMeta); int metaCommit(SMeta *pMeta);
// For Query // 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 // Options
void metaOptionsInit(SMetaCfg *pMetaCfg); void metaOptionsInit(SMetaCfg *pMetaCfg);
......
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
#include "vnodeCommit.h" #include "vnodeCommit.h"
#include "vnodeFS.h" #include "vnodeFS.h"
#include "vnodeMemAllocator.h" #include "vnodeMemAllocator.h"
#include "vnodeQuery.h"
#include "vnodeRequest.h" #include "vnodeRequest.h"
#include "vnodeStateMgr.h" #include "vnodeStateMgr.h"
#include "vnodeSync.h" #include "vnodeSync.h"
#include "vnodeQuery.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -62,6 +62,7 @@ typedef struct SVnodeMgr { ...@@ -62,6 +62,7 @@ typedef struct SVnodeMgr {
extern SVnodeMgr vnodeMgr; extern SVnodeMgr vnodeMgr;
struct SVnode { struct SVnode {
int32_t vgId;
char* path; char* path;
SVnodeCfg config; SVnodeCfg config;
SVState state; SVState state;
......
...@@ -45,25 +45,70 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { ...@@ -45,25 +45,70 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
} }
static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
#if 0 STableInfoMsg * pReq = (STableInfoMsg *)(pMsg->pCont);
STableInfoMsg *pReq = (STableInfoMsg *)(pMsg->pCont); STbCfg * pTbCfg = NULL;
STableMetaMsg *pRspMsg; STbCfg * pStbCfg = NULL;
int ret; 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);
return -1; 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)); pTbMetaMsg = (STableMetaMsg *)calloc(1, sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols));
if (TD_IS_NULL(*pRsp)) { if (pTbMetaMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
free(pMsg);
return -1; return -1;
} }
// TODO strcpy(pTbMetaMsg->tbFname, pTbCfg->name);
(*pRsp)->pCont = pRspMsg; 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; return 0;
} }
\ No newline at end of file
...@@ -38,11 +38,6 @@ struct SMetaDB { ...@@ -38,11 +38,6 @@ struct SMetaDB {
DB_ENV *pEvn; DB_ENV *pEvn;
}; };
typedef struct {
int32_t nCols;
SSchema *pSchema;
} SSchemaWrapper;
typedef int (*bdbIdxCbPtr)(DB *, const DBT *, const DBT *, DBT *); typedef int (*bdbIdxCbPtr)(DB *, const DBT *, const DBT *, DBT *);
static SMetaDB *metaNewDB(); static SMetaDB *metaNewDB();
...@@ -60,9 +55,6 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT * ...@@ -60,9 +55,6 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
static void metaClearTbCfg(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)) #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
...@@ -439,31 +431,7 @@ static void metaClearTbCfg(STbCfg *pTbCfg) { ...@@ -439,31 +431,7 @@ static void metaClearTbCfg(STbCfg *pTbCfg) {
} }
/* ------------------------ FOR QUERY ------------------------ */ /* ------------------------ FOR QUERY ------------------------ */
STbCfg *metaGetTableInfo(SMeta *pMeta, char *tbname) { STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
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 * pTbCfg = NULL; STbCfg * pTbCfg = NULL;
SMetaDB *pDB = pMeta->pDB; SMetaDB *pDB = pMeta->pDB;
DBT key = {0}; DBT key = {0};
...@@ -491,7 +459,7 @@ static STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { ...@@ -491,7 +459,7 @@ static STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
return pTbCfg; 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; STbCfg * pTbCfg = NULL;
SMetaDB *pDB = pMeta->pDB; SMetaDB *pDB = pMeta->pDB;
DBT key = {0}; DBT key = {0};
...@@ -521,7 +489,7 @@ static STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { ...@@ -521,7 +489,7 @@ static STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
return pTbCfg; 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; uint32_t nCols;
SSchemaWrapper *pSW = NULL; SSchemaWrapper *pSW = NULL;
SMetaDB * pDB = pMeta->pDB; SMetaDB * pDB = pMeta->pDB;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册