From 66c86a60d50772fd34c6141e905df19419a5da8a Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Thu, 6 Apr 2023 15:58:53 +0800 Subject: [PATCH] fix: add func_version to systable --- source/common/src/systable.c | 1 + source/common/src/tmsg.c | 16 +++++++++++----- source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/src/mndFunc.c | 11 +++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 2c15980167..228aa40fa9 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -116,6 +116,7 @@ static const SSysDbTableSchema userFuncSchema[] = { {.name = "bufsize", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false}, {.name = "func_language", .bytes = TSDB_TYPE_STR_MAX_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false}, {.name = "func_body", .bytes = TSDB_MAX_BINARY_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false}, + {.name = "func_version", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false}, }; static const SSysDbTableSchema userIdxSchema[] = { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 2d2c6f5523..f103b33138 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1921,11 +1921,17 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp pRsp->pFuncVersions = taosArrayInit(pRsp->numOfFuncs, sizeof(int32_t)); if (pRsp->pFuncVersions == NULL) return -1; - - for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) { - int32_t version = 0; - if (tDecodeI32(&decoder, &version) < 0) return -1; - taosArrayPush(pRsp->pFuncVersions, &version); + if (tDecodeIsEnd(&decoder)) { + for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) { + int32_t version = 0; + taosArrayPush(pRsp->pFuncVersions, &version); + } + } else { + for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) { + int32_t version = 0; + if (tDecodeI32(&decoder, &version) < 0) return -1; + taosArrayPush(pRsp->pFuncVersions, &version); + } } tEndDecode(&decoder); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index c22e5422b6..1ff1165e21 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -447,7 +447,7 @@ typedef struct { int32_t codeSize; char* pComment; char* pCode; - int32_t funcVersions; + int32_t funcVersion; } SFuncObj; typedef struct { diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index e707af2694..08336ef70a 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -83,7 +83,7 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER) } SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER) - SDB_SET_INT32(pRaw, dataPos, pFunc->funcVersions, _OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->funcVersion, _OVER) SDB_SET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER) SDB_SET_DATALEN(pRaw, dataPos, _OVER); @@ -147,7 +147,7 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER) if(sver >= 2){ - SDB_GET_INT32(pRaw, dataPos, &pFunc->funcVersions, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->funcVersion, _OVER) } SDB_GET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER) @@ -234,7 +234,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SRpcMsg *pReq, SCreateFuncReq *pCre if(oldFunc == NULL){ goto _OVER; } - func.funcVersions = oldFunc->funcVersions + 1; + func.funcVersion = oldFunc->funcVersion + 1; mndReleaseFunc(pMnode, oldFunc); } @@ -473,7 +473,7 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { } taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo); - taosArrayPush(retrieveRsp.pFuncVersions, &pFunc->funcVersions); + taosArrayPush(retrieveRsp.pFuncVersions, &pFunc->funcVersion); mndReleaseFunc(pMnode, pFunc); } @@ -590,6 +590,9 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl colDataSetVal(pColInfo, numOfRows, (const char*)b4, false); taosMemoryFree(b4); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetVal(pColInfo, numOfRows, (const char*)&pFunc->funcVersion, false); + numOfRows++; sdbRelease(pSdb, pFunc); }