From 55a93c96490f83905bab471ced7e0d63a07f85a3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 6 Feb 2023 16:00:59 +0800 Subject: [PATCH] opt sma and ndex name conflict --- source/dnode/mnode/impl/inc/mndIndexComm.h | 37 ++++++++++++++++ source/dnode/mnode/impl/src/mndIndex.c | 11 ++++- source/dnode/mnode/impl/src/mndIndexCom.c | 51 ++++++++++++++++++++++ source/dnode/mnode/impl/src/mndSma.c | 11 ++++- 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 source/dnode/mnode/impl/inc/mndIndexComm.h create mode 100644 source/dnode/mnode/impl/src/mndIndexCom.c diff --git a/source/dnode/mnode/impl/inc/mndIndexComm.h b/source/dnode/mnode/impl/inc/mndIndexComm.h new file mode 100644 index 0000000000..f305aab783 --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndIndexComm.h @@ -0,0 +1,37 @@ + +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_MND_IDX_COMM_H_ +#define _TD_MND_IDX_COMM_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SSIdx { + int type; // sma or idx + void *pIdx; +} SSIdx; + +int32_t mndCheckIdxExist(SMnode *pMnode, char *name, int type, SSIdx *idx); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_IDX_COMM_H_*/ \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 61f4183a58..0d713e2e41 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -17,6 +17,7 @@ #include "mndIndex.h" #include "mndDb.h" #include "mndDnode.h" +#include "mndIndexComm.h" #include "mndInfoSchema.h" #include "mndMnode.h" #include "mndPrivilege.h" @@ -415,8 +416,10 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) { mError("idx:%s, failed to create since stb:%s not exist", createReq.idxName, createReq.stbName); goto _OVER; } - - pIdx = mndAcquireIdx(pMnode, createReq.idxName); + SSIdx idx = {0}; + if (mndCheckIdxExist(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) { + pIdx = idx.pIdx; + } if (pIdx != NULL) { terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; goto _OVER; @@ -880,6 +883,10 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) { goto _OVER; } mInfo("idx:%s, start to drop", req.name); + SSIdx idx = {0}; + if (mndCheckIdxExist(pMnode, req.name, SDB_IDX, &idx) == 0) { + pIdx = idx.pIdx; + } pIdx = mndAcquireIdx(pMnode, req.name); if (pIdx == NULL) { diff --git a/source/dnode/mnode/impl/src/mndIndexCom.c b/source/dnode/mnode/impl/src/mndIndexCom.c new file mode 100644 index 0000000000..12685c1833 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndIndexCom.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "mndIndex.h" +#include "mndIndexComm.h" +#include "mndSma.h" + +static void *mndGetIdx(SMnode *pMnode, char *name, int type) { + SSdb *pSdb = pMnode->pSdb; + void *pIdx = sdbAcquire(pSdb, type, name); + if (pIdx == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { + terrno = 0; + } + return pIdx; +} + +int mndCheckIdxExist(SMnode *pMnode, char *name, int type, SSIdx *idx) { + SSmaObj *pSma = mndGetIdx(pMnode, name, SDB_SMA); + SIdxObj *pIdx = mndGetIdx(pMnode, name, SDB_IDX); + + if (pSma == NULL && pIdx == NULL) return 0; + + if (pSma != NULL) { + if (type == SDB_SMA) { + idx->type = SDB_SMA; + idx->pIdx = pSma; + } else { // type == SDB_IDX + mndReleaseSma(pMnode, pSma); + } + } else { + if (type == SDB_SMA) { + mndReleaseIdx(pMnode, pIdx); + } else { + idx->type = SDB_IDX; + idx->pIdx = pIdx; + } + } + return 0; +} diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index b7b779f71e..f5635d3b9e 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -18,6 +18,7 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndIndex.h" +#include "mndIndexComm.h" #include "mndInfoSchema.h" #include "mndMnode.h" #include "mndPrivilege.h" @@ -735,8 +736,11 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST; goto _OVER; } + SSIdx idx = {0}; + if (mndCheckIdxExist(pMnode, createReq.name, SDB_SMA, &idx) == 0) { + pSma = idx.pIdx; + } - pSma = mndAcquireSma(pMnode, createReq.name); if (pSma != NULL) { if (createReq.igExists) { mInfo("sma:%s, already exist in sma:%s, ignore exist is set", createReq.name, pSma->name); @@ -982,7 +986,10 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { mInfo("sma:%s, start to drop", dropReq.name); - pSma = mndAcquireSma(pMnode, dropReq.name); + SSIdx idx = {0}; + if (mndCheckIdxExist(pMnode, dropReq.name, SDB_SMA, &idx) == 0) { + pSma = idx.pIdx; + } if (pSma == NULL) { if (dropReq.igNotExists) { mInfo("sma:%s, not exist, ignore not exist is set", dropReq.name); -- GitLab