From 8f14f8e8b3513e2d35d18e7804a304823182239a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 25 Apr 2022 11:40:56 +0800 Subject: [PATCH] fix(query): enable mnd support show topics processing. --- include/util/taoserror.h | 2 +- source/dnode/mnode/impl/src/mndInfoSchema.c | 6 +++--- source/dnode/mnode/impl/src/mndPerfSchema.c | 2 +- source/dnode/mnode/impl/src/mndShow.c | 13 +++++++++---- source/dnode/mnode/impl/src/mndTopic.c | 9 ++++++--- source/util/src/terror.c | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 3ac440346c..2545b33574 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -252,7 +252,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE) // mnode-infoSchema -#define TSDB_CODE_MND_INVALID_INFOS_TBL TAOS_DEF_ERROR_CODE(0, 0x03B0) +#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03B0) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index 5dbbd27930..2b46fc9274 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -325,7 +325,7 @@ static int32_t mndInsInitMeta(SHashObj *hash) { return -1; } - if (taosHashPut(hash, meta.tbName, strlen(meta.tbName) + 1, &meta, sizeof(meta))) { + if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -340,10 +340,10 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * return -1; } - STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName) + 1); + STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName)); if (NULL == pMeta) { mError("invalid information schema table name:%s", tbName); - terrno = TSDB_CODE_MND_INVALID_INFOS_TBL; + terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME; return -1; } diff --git a/source/dnode/mnode/impl/src/mndPerfSchema.c b/source/dnode/mnode/impl/src/mndPerfSchema.c index 737068a2dd..a0ecbe9ae4 100644 --- a/source/dnode/mnode/impl/src/mndPerfSchema.c +++ b/source/dnode/mnode/impl/src/mndPerfSchema.c @@ -128,7 +128,7 @@ int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName)); if (NULL == meta) { mError("invalid performance schema table name:%s", tbName); - terrno = TSDB_CODE_MND_INVALID_INFOS_TBL; + terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME; return -1; } diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 1ab25f795f..94366a241d 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -100,6 +100,8 @@ static int32_t convertToRetrieveType(char* name, int32_t len) { type = TSDB_MGMT_TABLE_QUERIES; } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) { type = TSDB_MGMT_TABLE_VNODES; + } else if (strncasecmp(name, TSDB_PERFS_TABLE_TOPICS, len) == 0) { + type = TSDB_MGMT_TABLE_TOPICS; } else { // ASSERT(0); } @@ -187,11 +189,14 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { } if (retrieveReq.showId == 0) { - STableMetaRsp *pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb) + 1); + STableMetaRsp *pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb)); if (pMeta == NULL) { - terrno = TSDB_CODE_MND_INVALID_INFOS_TBL; - mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); - return -1; + pMeta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb)); + if (pMeta == NULL) { + terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME; + mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); + return -1; + } } pShow = mndCreateShowObj(pMnode, &retrieveReq); diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index faddc3a1c5..2516c43860 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -520,8 +520,11 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB int32_t cols = 0; char topicName[TSDB_TOPIC_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tstrncpy(&topicName[VARSTR_HEADER_SIZE], pTopic->name, TSDB_TOPIC_NAME_LEN); - varDataSetLen(topicName, strlen(&topicName[VARSTR_HEADER_SIZE])); + + SName n; + tNameFromString(&n, pTopic->name, T_NAME_ACCT|T_NAME_DB); + tNameGetDbName(&n, varDataVal(topicName)); + varDataSetLen(topicName, strlen(varDataVal(topicName))); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)topicName, false); @@ -535,7 +538,7 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB varDataSetLen(sql, strlen(&sql[VARSTR_HEADER_SIZE])); colDataAppend(pColInfo, numOfRows, (const char *)sql, false); - taosMemoryFree(sql); +// taosMemoryFree(sql); numOfRows++; sdbRelease(pSdb, pTopic); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9332cb481e..50c924bbb9 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -258,7 +258,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREADY_EXIST, "Column already exists TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST, "Column does not exist") // mnode-infoSchema -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_INFOS_TBL, "Invalid information schema table name") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") // mnode-func -- GitLab