From b3167ae6a32755c923bb61e27dd8f62e969c2bf5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 6 Feb 2023 20:40:48 +0800 Subject: [PATCH] avoid sma and tag index name conflict --- source/dnode/mnode/impl/inc/mndIndexComm.h | 2 +- source/dnode/mnode/impl/src/mndIndex.c | 4 ++-- source/dnode/mnode/impl/src/mndIndexCom.c | 10 ++++++---- source/dnode/mnode/impl/src/mndSma.c | 10 +++++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndIndexComm.h b/source/dnode/mnode/impl/inc/mndIndexComm.h index f305aab783..2407b081a4 100644 --- a/source/dnode/mnode/impl/inc/mndIndexComm.h +++ b/source/dnode/mnode/impl/inc/mndIndexComm.h @@ -28,7 +28,7 @@ typedef struct SSIdx { void *pIdx; } SSIdx; -int32_t mndCheckIdxExist(SMnode *pMnode, char *name, int type, SSIdx *idx); +int32_t mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 0d713e2e41..3886d4a258 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -417,7 +417,7 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) { goto _OVER; } SSIdx idx = {0}; - if (mndCheckIdxExist(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) { + if (mndAcquireGlobalIdx(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) { pIdx = idx.pIdx; } if (pIdx != NULL) { @@ -884,7 +884,7 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) { } mInfo("idx:%s, start to drop", req.name); SSIdx idx = {0}; - if (mndCheckIdxExist(pMnode, req.name, SDB_IDX, &idx) == 0) { + if (mndAcquireGlobalIdx(pMnode, req.name, SDB_IDX, &idx) == 0) { pIdx = idx.pIdx; } diff --git a/source/dnode/mnode/impl/src/mndIndexCom.c b/source/dnode/mnode/impl/src/mndIndexCom.c index 12685c1833..849c220f55 100644 --- a/source/dnode/mnode/impl/src/mndIndexCom.c +++ b/source/dnode/mnode/impl/src/mndIndexCom.c @@ -26,10 +26,12 @@ static void *mndGetIdx(SMnode *pMnode, char *name, int type) { return pIdx; } -int mndCheckIdxExist(SMnode *pMnode, char *name, int type, SSIdx *idx) { +int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) { SSmaObj *pSma = mndGetIdx(pMnode, name, SDB_SMA); SIdxObj *pIdx = mndGetIdx(pMnode, name, SDB_IDX); + terrno = 0; + if (pSma == NULL && pIdx == NULL) return 0; if (pSma != NULL) { @@ -40,11 +42,11 @@ int mndCheckIdxExist(SMnode *pMnode, char *name, int type, SSIdx *idx) { mndReleaseSma(pMnode, pSma); } } else { - if (type == SDB_SMA) { - mndReleaseIdx(pMnode, pIdx); - } else { + if (type == SDB_IDX) { idx->type = SDB_IDX; idx->pIdx = pIdx; + } else { + mndReleaseIdx(pMnode, pIdx); } } return 0; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index f5635d3b9e..e87457e33f 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -737,7 +737,7 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { goto _OVER; } SSIdx idx = {0}; - if (mndCheckIdxExist(pMnode, createReq.name, SDB_SMA, &idx) == 0) { + if (mndAcquireGlobalIdx(pMnode, createReq.name, SDB_SMA, &idx) == 0) { pSma = idx.pIdx; } @@ -987,7 +987,7 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { mInfo("sma:%s, start to drop", dropReq.name); SSIdx idx = {0}; - if (mndCheckIdxExist(pMnode, dropReq.name, SDB_SMA, &idx) == 0) { + if (mndAcquireGlobalIdx(pMnode, dropReq.name, SDB_SMA, &idx) == 0) { pSma = idx.pIdx; } if (pSma == NULL) { @@ -1028,7 +1028,11 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp int32_t code = -1; SSmaObj *pSma = NULL; - pSma = mndAcquireSma(pMnode, indexReq->indexFName); + SSIdx idx = {0}; + if (0 == mndAcquireGlobalIdx(pMnode, indexReq->indexFName, SDB_SMA, &idx)) { + pSma = idx.pIdx; + } + if (pSma == NULL) { *exist = false; return 0;