From 9586f86ceb8c02aa516270955d540c5b4b9451e3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Jan 2023 22:26:52 +0800 Subject: [PATCH] update add/drop index msg --- include/common/tmsg.h | 2 +- source/dnode/mnode/impl/src/mndStb.c | 26 ++++++++++++++++++++++++- source/dnode/vnode/src/meta/metaTable.c | 6 +++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index fc9445e4c2..bfbb7cbef9 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -346,7 +346,7 @@ void tFreeSSubmitRsp(SSubmitRsp* pRsp); #define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL))) #define IS_BSMA_ON(s) (((s)->flags & 0x01) == COL_SMA_ON) -#define IS_INDX_ON(s) (((s)->flags & 0x2) == COL_IDX_ON) +#define IS_IDX_ON(s) (((s)->flags & 0x2) == COL_IDX_ON) #define SSCHMEA_TYPE(s) ((s)->type) #define SSCHMEA_FLAGS(s) ((s)->flags) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index c21c4c2a6d..26a8ebb425 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -2631,7 +2631,9 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *ta int32_t code = -1; SField *pField0 = NULL; - SStbObj stbObj = {0}; + SStbObj stbObj = {0}; + SStbObj *pNew = &stbObj; + taosRLockLatch(&pOld->lock); memcpy(&stbObj, pOld, sizeof(SStbObj)); taosRUnLockLatch(&pOld->lock); @@ -2641,6 +2643,28 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *ta stbObj.updateTime = taosGetTimestampMs(); stbObj.lock = 0; + int32_t tag = mndFindSuperTableTagIndex(pOld, tagIdxReq->colName); + if (tag < 0) { + terrno = TSDB_CODE_MND_TAG_NOT_EXIST; + return -1; + } + col_id_t colId = pOld->pTags[tag].colId; + if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { + return -1; + } + if (mndAllocStbSchemas(pOld, pNew) != 0) { + return -1; + } + + SSchema *pTag = pNew->pTags + tag; + if (IS_IDX_ON(pTag)) { + terrno = TSDB_CODE_MND_TAG_NOT_EXIST; + return -1; + } else { + pTag->flags |= COL_IDX_ON; + } + pNew->tagVer++; + return TSDB_CODE_SUCCESS; } static int32_t mndProcessCreateIndexReq(SRpcMsg *pReq) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 790a6b4aff..d72aef89d7 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -653,7 +653,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { } else { for (int i = 0; i < pTagSchema->nCols; i++) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[i]; - if (!IS_INDX_ON(pTagColumn)) continue; + if (!IS_IDX_ON(pTagColumn)) continue; STagIdxKey *pTagIdxKey = NULL; int32_t nTagIdxKey; @@ -1436,7 +1436,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT goto _err; } - if (IS_INDX_ON(pCol)) { + if (IS_IDX_ON(pCol)) { terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS; goto _err; } @@ -1664,7 +1664,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { } else { for (int i = 0; i < pTagSchema->nCols; i++) { pTagColumn = &pTagSchema->pSchema[i]; - if (!IS_INDX_ON(pTagColumn)) continue; + if (!IS_IDX_ON(pTagColumn)) continue; STagVal tagVal = {.cid = pTagColumn->colId}; tTagGet((const STag *)pCtbEntry->ctbEntry.pTags, &tagVal);