提交 55a93c96 编写于 作者: dengyihao's avatar dengyihao

opt sma and ndex name conflict

上级 0dd4433e
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "mndIndex.h" #include "mndIndex.h"
#include "mndDb.h" #include "mndDb.h"
#include "mndDnode.h" #include "mndDnode.h"
#include "mndIndexComm.h"
#include "mndInfoSchema.h" #include "mndInfoSchema.h"
#include "mndMnode.h" #include "mndMnode.h"
#include "mndPrivilege.h" #include "mndPrivilege.h"
...@@ -415,8 +416,10 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) { ...@@ -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); mError("idx:%s, failed to create since stb:%s not exist", createReq.idxName, createReq.stbName);
goto _OVER; goto _OVER;
} }
SSIdx idx = {0};
pIdx = mndAcquireIdx(pMnode, createReq.idxName); if (mndCheckIdxExist(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) {
pIdx = idx.pIdx;
}
if (pIdx != NULL) { if (pIdx != NULL) {
terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST;
goto _OVER; goto _OVER;
...@@ -880,6 +883,10 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) { ...@@ -880,6 +883,10 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) {
goto _OVER; goto _OVER;
} }
mInfo("idx:%s, start to drop", req.name); 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); pIdx = mndAcquireIdx(pMnode, req.name);
if (pIdx == NULL) { if (pIdx == NULL) {
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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;
}
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "mndDb.h" #include "mndDb.h"
#include "mndDnode.h" #include "mndDnode.h"
#include "mndIndex.h" #include "mndIndex.h"
#include "mndIndexComm.h"
#include "mndInfoSchema.h" #include "mndInfoSchema.h"
#include "mndMnode.h" #include "mndMnode.h"
#include "mndPrivilege.h" #include "mndPrivilege.h"
...@@ -735,8 +736,11 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { ...@@ -735,8 +736,11 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST; terrno = TSDB_CODE_MND_STREAM_ALREADY_EXIST;
goto _OVER; 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 (pSma != NULL) {
if (createReq.igExists) { if (createReq.igExists) {
mInfo("sma:%s, already exist in sma:%s, ignore exist is set", createReq.name, pSma->name); 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) { ...@@ -982,7 +986,10 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) {
mInfo("sma:%s, start to drop", dropReq.name); 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 (pSma == NULL) {
if (dropReq.igNotExists) { if (dropReq.igNotExists) {
mInfo("sma:%s, not exist, ignore not exist is set", dropReq.name); mInfo("sma:%s, not exist, ignore not exist is set", dropReq.name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册