提交 0c605acf 编写于 作者: H Hongze Cheng

refact meta

上级 c704496f
......@@ -51,13 +51,13 @@ int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
// metaQuery ==================
typedef struct SMetaEntryReader SMetaEntryReader;
typedef struct SMetaReader SMetaReader;
void metaEntryReaderInit(SMetaEntryReader* pReader);
void metaEntryReaderClear(SMetaEntryReader* pReader);
int metaGetTableEntryByVersion(SMeta* pMeta, SMetaEntryReader* pReader, int64_t version, tb_uid_t uid);
int metaGetTableEntryByUid(SMeta* pMeta, SMetaEntryReader* pReader, tb_uid_t uid);
int metaGetTableEntryByName(SMeta* pMeta, SMetaEntryReader* pReader, const char* name);
void metaEntryReaderInit(SMetaReader* pReader, SMeta* pMeta, int32_t flags);
void metaEntryReaderClear(SMetaReader* pReader);
int metaGetTableEntryByVersion(SMetaReader* pReader, int64_t version, tb_uid_t uid);
int metaGetTableEntryByUid(SMetaReader* pReader, tb_uid_t uid);
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
// metaIdx ==================
int metaOpenIdx(SMeta* pMeta);
......@@ -158,7 +158,9 @@ struct SMetaEntry {
};
};
struct SMetaEntryReader {
struct SMetaReader {
int32_t flags;
SMeta* pMeta;
SCoder coder;
SMetaEntry me;
void* pBuf;
......
......@@ -15,14 +15,19 @@
#include "vnodeInt.h"
void metaEntryReaderInit(SMetaEntryReader *pReader) { memset(pReader, 0, sizeof(*pReader)); }
void metaEntryReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) {
memset(pReader, 0, sizeof(*pReader));
pReader->flags = flags;
pReader->pMeta = pMeta;
}
void metaEntryReaderClear(SMetaEntryReader *pReader) {
void metaEntryReaderClear(SMetaReader *pReader) {
tCoderClear(&pReader->coder);
TDB_FREE(pReader->pBuf);
}
int metaGetTableEntryByVersion(SMeta *pMeta, SMetaEntryReader *pReader, int64_t version, tb_uid_t uid) {
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
SMeta *pMeta = pReader->pMeta;
STbDbKey tbDbKey = {.version = version, .uid = uid};
// query table.db
......@@ -43,7 +48,8 @@ _err:
return -1;
}
int metaGetTableEntryByUid(SMeta *pMeta, SMetaEntryReader *pReader, tb_uid_t uid) {
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
SMeta *pMeta = pReader->pMeta;
int64_t version;
// query uid.idx
......@@ -52,10 +58,11 @@ int metaGetTableEntryByUid(SMeta *pMeta, SMetaEntryReader *pReader, tb_uid_t uid
}
version = *(int64_t *)pReader->pBuf;
return metaGetTableEntryByVersion(pMeta, pReader, version, uid);
return metaGetTableEntryByVersion(pReader, version, uid);
}
int metaGetTableEntryByName(SMeta *pMeta, SMetaEntryReader *pReader, const char *name) {
int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
SMeta *pMeta = pReader->pMeta;
tb_uid_t uid;
// query name.idx
......@@ -64,7 +71,7 @@ int metaGetTableEntryByName(SMeta *pMeta, SMetaEntryReader *pReader, const char
}
uid = *(tb_uid_t *)pReader->pBuf;
return metaGetTableEntryByUid(pMeta, pReader, uid);
return metaGetTableEntryByUid(pReader, uid);
}
#if 1
......
......@@ -22,17 +22,17 @@ int vnodeQueryOpen(SVnode *pVnode) {
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
STableInfoReq infoReq = {0};
STableMetaRsp metaRsp = {0};
SMetaEntryReader mer1 = {0};
SMetaEntryReader mer2 = {0};
char tableFName[TSDB_TABLE_FNAME_LEN];
SRpcMsg rpcMsg;
int32_t code = 0;
int32_t rspLen = 0;
void *pRsp = NULL;
SSchemaWrapper schema = {0};
SSchemaWrapper schemaTag = {0};
STableInfoReq infoReq = {0};
STableMetaRsp metaRsp = {0};
SMetaReader mer1 = {0};
SMetaReader mer2 = {0};
char tableFName[TSDB_TABLE_FNAME_LEN];
SRpcMsg rpcMsg;
int32_t code = 0;
int32_t rspLen = 0;
void *pRsp = NULL;
SSchemaWrapper schema = {0};
SSchemaWrapper schemaTag = {0};
// decode req
if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
......@@ -51,9 +51,9 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
}
// query meta
metaEntryReaderInit(&mer1);
metaEntryReaderInit(&mer1, pVnode->pMeta, 0);
if (metaGetTableEntryByName(pVnode->pMeta, &mer1, infoReq.tbName) < 0) {
if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
goto _exit;
}
......@@ -66,8 +66,8 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
schemaTag = mer1.me.stbEntry.schemaTag;
metaRsp.suid = mer1.me.uid;
} else if (mer1.me.type == TSDB_CHILD_TABLE) {
metaEntryReaderInit(&mer2);
if (metaGetTableEntryByUid(pVnode->pMeta, &mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
metaEntryReaderInit(&mer2, pVnode->pMeta, 0);
if (metaGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
metaRsp.suid = mer2.me.uid;
schema = mer2.me.stbEntry.schema;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册