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

feat: get latest schema

上级 b350d002
...@@ -155,44 +155,52 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { ...@@ -155,44 +155,52 @@ int metaTbCursorNext(SMTbCursor *pTbCur) {
} }
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) {
void *pKey = NULL; void *pData = NULL;
void *pVal = NULL; int nData = 0;
int kLen = 0; int64_t version;
int vLen = 0; SSchemaWrapper schema = {0};
int ret; SSchemaWrapper *pSchema = NULL;
SSkmDbKey skmDbKey; SDecoder dc = {0};
SSchemaWrapper *pSW = NULL;
SSchema *pSchema = NULL;
void *pBuf;
SDecoder coder = {0};
// fetch
skmDbKey.uid = uid;
skmDbKey.sver = sver;
pKey = &skmDbKey;
kLen = sizeof(skmDbKey);
metaRLock(pMeta); metaRLock(pMeta);
ret = tdbTbGet(pMeta->pSkmDb, pKey, kLen, &pVal, &vLen); if (sver < 0) {
metaULock(pMeta); if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData) < 0) {
if (ret < 0) { goto _err;
return NULL; }
}
// decode version = *(int64_t *)pData;
pBuf = pVal;
pSW = taosMemoryMalloc(sizeof(SSchemaWrapper));
tDecoderInit(&coder, pVal, vLen); tdbTbGet(pMeta->pTbDb, &(STbDbKey){.uid = uid, .version = version}, sizeof(STbDbKey), &pData, &nData);
tDecodeSSchemaWrapper(&coder, pSW);
pSchema = taosMemoryMalloc(sizeof(SSchema) * pSW->nCols); SMetaEntry me = {0};
memcpy(pSchema, pSW->pSchema, sizeof(SSchema) * pSW->nCols); tDecoderInit(&dc, pData, nData);
tDecoderClear(&coder); metaDecodeEntry(&dc, &me);
if (me.type == TSDB_SUPER_TABLE) {
pSchema = tCloneSSchemaWrapper(&me.stbEntry.schemaRow);
} else if (me.type == TSDB_NORMAL_TABLE) {
} else {
ASSERT(0);
}
tDecoderClear(&dc);
} else {
if (tdbTbGet(pMeta->pSkmDb, &(SSkmDbKey){.uid = uid, .sver = sver}, sizeof(SSkmDbKey), &pData, &nData) < 0) {
goto _err;
}
pSW->pSchema = pSchema; tDecoderInit(&dc, pData, nData);
tDecodeSSchemaWrapper(&dc, &schema);
pSchema = tCloneSSchemaWrapper(&schema);
tDecoderClear(&dc);
}
tdbFree(pVal); metaULock(pMeta);
tdbFree(pData);
return pSchema;
return pSW; _err:
metaULock(pMeta);
tdbFree(pData);
return NULL;
} }
struct SMCtbCursor { struct SMCtbCursor {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册