From eafc9db1c18ab19cab33f407e565794911fbeb7c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 18 Feb 2023 18:24:10 +0800 Subject: [PATCH] fix iter and case --- source/dnode/mnode/impl/inc/mndIndexComm.h | 6 ++ source/dnode/mnode/impl/src/mndIndex.c | 22 +++---- source/dnode/mnode/impl/src/mndIndexCom.c | 2 +- source/dnode/mnode/impl/src/mndSma.c | 59 +++++++++++-------- .../tsim/tagindex/sma_and_tag_index.sim | 35 ++++++++++- 5 files changed, 86 insertions(+), 38 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndIndexComm.h b/source/dnode/mnode/impl/inc/mndIndexComm.h index 2407b081a4..68112f0a2d 100644 --- a/source/dnode/mnode/impl/inc/mndIndexComm.h +++ b/source/dnode/mnode/impl/inc/mndIndexComm.h @@ -28,6 +28,12 @@ typedef struct SSIdx { void *pIdx; } SSIdx; +// retrieve sma index and tag index +typedef struct { + void *pSmaIter; + void *pIdxIter; +} SSmaAndTagIter; + 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 983ea28515..2f4672ee0e 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -43,9 +43,9 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq); // static int32_t mndProcessDropIdxReq(SRpcMsg *pReq); static int32_t mndProcessGetIdxReq(SRpcMsg *pReq); static int32_t mndProcessGetTbIdxReq(SRpcMsg *pReq); -static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); -static void mndCancelGetNextIdx(SMnode *pMnode, void *pIter); -static void mndDestroyIdxObj(SIdxObj *pIdxObj); +// static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); +// static void mndCancelGetNextIdx(SMnode *pMnode, void *pIter); +static void mndDestroyIdxObj(SIdxObj *pIdxObj); static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *req, SDbObj *pDb, SStbObj *pStb); @@ -496,10 +496,11 @@ int32_t mndRetrieveTagIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, i pDb = mndAcquireDb(pMnode, pShow->db); if (pDb == NULL) return 0; } - int invalid = -1; + SSmaAndTagIter *pIter = pShow->pIter; + int invalid = -1; while (numOfRows < rows) { - pShow->pIter = sdbFetch(pSdb, SDB_IDX, pShow->pIter, (void **)&pIdx); - if (pShow->pIter == NULL) break; + pIter->pIdxIter = sdbFetch(pSdb, SDB_IDX, pIter->pIdxIter, (void **)&pIdx); + if (pIter->pIdxIter == NULL) break; if (NULL != pDb && pIdx->dbUid != pDb->uid) { sdbRelease(pSdb, pIdx); @@ -559,10 +560,11 @@ int32_t mndRetrieveTagIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, i return numOfRows; } -static void mndCancelGetNextIdx(SMnode *pMnode, void *pIter) { - SSdb *pSdb = pMnode->pSdb; - sdbCancelFetch(pSdb, pIter); -} +// static void mndCancelGetNextIdx(SMnode *pMnode, void *pIter) { +// SSdb *pSdb = pMnode->pSdb; +// +// sdbCancelFetch(pSdb, pIter); +//} static int32_t mndCheckIndexReq(SCreateTagIndexReq *pReq) { // impl return TSDB_CODE_SUCCESS; diff --git a/source/dnode/mnode/impl/src/mndIndexCom.c b/source/dnode/mnode/impl/src/mndIndexCom.c index 454c92e40b..2858d7548e 100644 --- a/source/dnode/mnode/impl/src/mndIndexCom.c +++ b/source/dnode/mnode/impl/src/mndIndexCom.c @@ -38,7 +38,7 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) { if (type == SDB_SMA) { idx->type = SDB_SMA; idx->pIdx = pSma; - } else { // type == SDB_IDX + } else { mndReleaseSma(pMnode, pSma); terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; return -1; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index a9a0560205..c10851cfad 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -45,27 +45,13 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq); static int32_t mndProcessGetSmaReq(SRpcMsg *pReq); static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq); static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); -static void mndCancelGetNextSma(SMnode *pMnode, void *pIter); static void mndDestroySmaObj(SSmaObj *pSmaObj); -// retrieve sma index and tag index -static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { - int32_t read = mndRetrieveSma(pReq, pShow, pBlock, rows); - read += mndRetrieveTagIdx(pReq, pShow, pBlock, rows - read); - return read; -} +// sma and tag index comm func +static int32_t mndProcessDropIdxReq(SRpcMsg *pReq); +static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); +static void mndCancelRetrieveIdx(SMnode *pMnode, void *pIter); -static int32_t mndProcessDropIdxReq(SRpcMsg *pReq) { - int ret = mndProcessDropSmaReq(pReq); - if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST) { - terrno = 0; - ret = mndProcessDropTagIdxReq(pReq); - } - return ret; -} -static void mndCancelGetNextIdx(SMnode *pMnode, void *pIter) { - // TODO -} int32_t mndInitSma(SMnode *pMnode) { SSdbTable table = { .sdbType = SDB_SMA, @@ -85,7 +71,7 @@ int32_t mndInitSma(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_GET_TABLE_INDEX, mndProcessGetTbSmaReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveIdx); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextIdx); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelRetrieveIdx); return sdbSetTable(pMnode->pSdb, table); } @@ -1244,10 +1230,10 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pDb = mndAcquireDb(pMnode, pShow->db); if (pDb == NULL) return 0; } - + SSmaAndTagIter *pIter = pShow->pIter; while (numOfRows < rows) { - pShow->pIter = sdbFetch(pSdb, SDB_SMA, pShow->pIter, (void **)&pSma); - if (pShow->pIter == NULL) break; + pIter->pSmaIter = sdbFetch(pSdb, SDB_SMA, pIter->pSmaIter, (void **)&pSma); + if (pIter->pSmaIter == NULL) break; if (NULL != pDb && pSma->dbUid != pDb->uid) { sdbRelease(pSdb, pSma); @@ -1305,7 +1291,30 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc return numOfRows; } -static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) { - SSdb *pSdb = pMnode->pSdb; - sdbCancelFetch(pSdb, pIter); +// sma and tag index comm func +static int32_t mndProcessDropIdxReq(SRpcMsg *pReq) { + int ret = mndProcessDropSmaReq(pReq); + if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST) { + terrno = 0; + ret = mndProcessDropTagIdxReq(pReq); + } + return ret; +} + +static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { + if (pShow->pIter == NULL) { + pShow->pIter = taosMemoryCalloc(1, sizeof(SSmaAndTagIter)); + } + int32_t read = mndRetrieveSma(pReq, pShow, pBlock, rows); + if (read < rows) read += mndRetrieveTagIdx(pReq, pShow, pBlock, rows - read); + return read; +} +static void mndCancelRetrieveIdx(SMnode *pMnode, void *pIter) { + SSmaAndTagIter *p = pIter; + if (p != NULL) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, p->pSmaIter); + sdbCancelFetch(pSdb, p->pIdxIter); + } + taosMemoryFree(p); } diff --git a/tests/script/tsim/tagindex/sma_and_tag_index.sim b/tests/script/tsim/tagindex/sma_and_tag_index.sim index 76de7b4c34..13c7d16c01 100644 --- a/tests/script/tsim/tagindex/sma_and_tag_index.sim +++ b/tests/script/tsim/tagindex/sma_and_tag_index.sim @@ -48,19 +48,50 @@ while $i < $tbNum endw -print --> create sma and tag index, global name conflict +print ==== create sma and tag index, global name conflict sql create sma index t2i on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); sql_error create index t2i on $mtPrefix (t2) sql drop index t2i -#print --> create tagindex and sma index, global name conflict +print ==== create tagindex and sma index, global name conflict sql create index t2i on $mtPrefix (t2) sql_error create sma index t2i on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); sql drop index t2i +print ===== iter sma and tag index + +sql create index tagt2i on $mtPrefix (t2) +sql create sma index smat2i on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); + + +sql select * from information_schema.ins_indexes +if $rows != 2 then + return -1 +endi + +sql drop index smat2i + +$i = 0 +$smaPre = sma3 +while $i < 5000 + $sma = $smaPre . $i + $i = $i + 1 + sql create sma index $sma on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); +endw + +sql select * from information_schema.ins_indexes +if $rows != 5001 then + return -1 +endi + + + + + + print ==== test name conflict sql_error create index ti3 on $mtPrefix(t2)