diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index ee5a9e51b1a8e517a8d9e1b015ad5216dbf9cfb5..93c42376f21b01db85ef28d1acd537275323faf3 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -73,11 +73,6 @@ struct SMeta { SMetaIdx* pIdx; }; -typedef struct { - tb_uid_t uid; - int64_t ver; -} STbDbKey; - typedef struct __attribute__((__packed__)) { tb_uid_t uid; int32_t sver; diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index ac82d05eac54a881410d0e820a5ebd1e3b8044fa..e3e0784e639e0ec54a4d4aaa831d807ec42e944c 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -20,6 +20,7 @@ static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLe static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); +static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); int metaOpen(SVnode *pVnode, SMeta **ppMeta) { SMeta *pMeta = NULL; @@ -51,7 +52,7 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { } // open pTbDb - ret = tdbDbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb); + ret = tdbDbOpen("table.db", sizeof(int64_t), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb); if (ret < 0) { metaError("vgId: %d failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; @@ -64,6 +65,13 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { goto _err; } + // open pUidIdx + ret = tdbDbOpen("uid.db", sizeof(tb_uid_t), sizeof(int64_t), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx); + if (ret < 0) { + metaError("vgId: %d failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + // open pNameIdx ret = tdbDbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx); if (ret < 0) { @@ -109,6 +117,7 @@ _err: if (pMeta->pTagIdx) tdbDbClose(pMeta->pTagIdx); if (pMeta->pCtbIdx) tdbDbClose(pMeta->pCtbIdx); if (pMeta->pNameIdx) tdbDbClose(pMeta->pNameIdx); + if (pMeta->pNameIdx) tdbDbClose(pMeta->pUidIdx); if (pMeta->pSkmDb) tdbDbClose(pMeta->pSkmDb); if (pMeta->pTbDb) tdbDbClose(pMeta->pTbDb); if (pMeta->pEnv) tdbEnvClose(pMeta->pEnv); @@ -123,6 +132,7 @@ int metaClose(SMeta *pMeta) { if (pMeta->pTagIdx) tdbDbClose(pMeta->pTagIdx); if (pMeta->pCtbIdx) tdbDbClose(pMeta->pCtbIdx); if (pMeta->pNameIdx) tdbDbClose(pMeta->pNameIdx); + if (pMeta->pNameIdx) tdbDbClose(pMeta->pUidIdx); if (pMeta->pSkmDb) tdbDbClose(pMeta->pSkmDb); if (pMeta->pTbDb) tdbDbClose(pMeta->pTbDb); if (pMeta->pEnv) tdbEnvClose(pMeta->pEnv); @@ -133,18 +143,12 @@ int metaClose(SMeta *pMeta) { } static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { - STbDbKey *pTbDbKey1 = (STbDbKey *)pKey1; - STbDbKey *pTbDbKey2 = (STbDbKey *)pKey2; - - if (pTbDbKey1->uid > pTbDbKey2->uid) { - return 1; - } else if (pTbDbKey1->uid < pTbDbKey2->uid) { - return -1; - } + int64_t version1 = *(int64_t *)pKey1; + int64_t version2 = *(int64_t *)pKey2; - if (pTbDbKey1->ver > pTbDbKey2->ver) { + if (version1 > version2) { return 1; - } else if (pTbDbKey1->ver < pTbDbKey2->ver) { + } else if (version1 < version2) { return -1; } @@ -170,6 +174,19 @@ static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLe return 0; } +static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + tb_uid_t uid1 = *(tb_uid_t *)pKey1; + tb_uid_t uid2 = *(tb_uid_t *)pKey2; + + if (uid1 > uid2) { + return 1; + } else if (uid1 < uid2) { + return -1; + } + + return 0; +} + static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { SCtbIdxKey *pCtbIdxKey1 = (SCtbIdxKey *)pKey1; SCtbIdxKey *pCtbIdxKey2 = (SCtbIdxKey *)pKey2; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index e95cb53c7356f521fc2ff32c949b58989c3a2b68..3395e331b003e5dfc5f8b24fff47dd8594279484 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -16,7 +16,6 @@ #include "vnodeInt.h" int metaCreateSTable(SMeta *pMeta, SVCreateStbReq *pReq, SVCreateStbRsp *pRsp) { - STbDbKey tbDbKey = {0}; SSkmDbKey skmDbKey = {0}; SMetaEntry me = {0}; int kLen; @@ -36,15 +35,12 @@ int metaCreateSTable(SMeta *pMeta, SVCreateStbReq *pReq, SVCreateStbRsp *pRsp) { me.stbEntry.nTags = pReq->nTags; me.stbEntry.pSchemaTg = pReq->pSchemaTg; - tbDbKey.uid = pReq->suid; - tbDbKey.ver = 0; // (TODO) - skmDbKey.uid = pReq->suid; skmDbKey.sver = 0; // (TODO) // save to table.db (TODO) - pKey = &tbDbKey; - kLen = sizeof(tbDbKey); + pKey = NULL; + kLen = 0; pVal = NULL; vLen = 0; if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, NULL) < 0) {