diff --git a/include/common/tmsg.h b/include/common/tmsg.h index cc11254dcd..db86b6e3a4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1729,9 +1729,9 @@ int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq); #define TD_CREATE_IF_NOT_EXISTS 0x1 typedef struct SVCreateTbReq { int32_t flags; + char* name; tb_uid_t uid; int64_t ctime; - char* name; int32_t ttl; int8_t type; union { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 22ac412434..de71c0b2ab 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -3861,10 +3861,9 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) { if (tStartEncode(pCoder) < 0) return -1; if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1; + if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; if (tEncodeI64(pCoder, pReq->uid) < 0) return -1; if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1; - - if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1; if (tEncodeI8(pCoder, pReq->type) < 0) return -1; @@ -3887,10 +3886,9 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { if (tStartDecode(pCoder) < 0) return -1; if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1; + if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; if (tDecodeI64(pCoder, &pReq->uid) < 0) return -1; if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1; - - if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1; if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index d38ff716ab..ba25c5e286 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -91,6 +91,7 @@ int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); int metaGetTableEntryByName(SMetaReader* pReader, const char* name); +tb_uid_t metaGetTableEntryUidByName(SMeta* pMeta, const char* name); int metaGetTbNum(SMeta* pMeta); SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); void metaCloseCtbCursor(SMCtbCursor* pCtbCur); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index c19190e68a..184b640bdd 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -81,6 +81,19 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { return metaGetTableEntryByUid(pReader, uid); } +tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) { + void *pData = NULL; + int nData = 0; + tb_uid_t uid = 0; + + if (tdbTbGet(pMeta->pNameIdx, name, strlen(name) + 1, &pData, &nData) == 0) { + uid = *(tb_uid_t *)pData; + tdbFree(pData); + } + + return 0; +} + int metaReadNext(SMetaReader *pReader) { SMeta *pMeta = pReader->pMeta; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index ae7ec5a950..f7e66498fe 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -64,12 +64,18 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { if (pBlock == NULL) break; if (msgIter.schemaLen > 0) { - uid = tGenIdPI64(); + char *name = NULL; tDecoderInit(&dc, pBlock->data, msgIter.schemaLen); tStartDecode(&dc); tDecodeI32v(&dc, NULL); + tDecodeCStr(&dc, &name); + + uid = metaGetTableEntryUidByName(pVnode->pMeta, name); + if (uid == 0) { + uid = tGenIdPI64(); + } *(int64_t *)(dc.data + dc.pos) = uid; *(int64_t *)(dc.data + dc.pos + 8) = ctime; pBlock->uid = htobe64(uid);