From 588ff5e9688185fb9324c909bcb9150e79d01ce3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 21 Apr 2022 13:22:34 +0000 Subject: [PATCH] more refact --- source/dnode/vnode/src/inc/meta.h | 5 ---- source/dnode/vnode/src/meta/metaOpen.c | 39 ++++++++++++++++++------- source/dnode/vnode/src/meta/metaTable.c | 8 ++--- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index ee5a9e51b1..93c42376f2 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 ac82d05eac..e3e0784e63 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 e95cb53c73..3395e331b0 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) { -- GitLab