From c3abd9d554c9d9dc72feef05d5548e7c29c9be7a Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Jun 2024 09:38:55 +0800 Subject: [PATCH 1/4] enh: support display unlimited for expiration time --- include/common/tgrant.h | 1 + source/common/src/systable.c | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/dnode/mnode/impl/src/mndCluster.c | 20 +++++++++++++++++--- source/dnode/mnode/impl/src/mndMain.c | 6 ++++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index b707045bd1..fc1e45fb2a 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -29,6 +29,7 @@ extern "C" { #endif #define GRANT_HEART_BEAT_MIN 2 +#define GRANT_UNIQ_UNLIMITED (-1) #define GRANT_ACTIVE_CODE "activeCode" #define GRANT_FLAG_ALL (0x01) #define GRANT_FLAG_AUDIT (0x02) diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 6558df1fc1..35f2908968 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -85,7 +85,7 @@ static const SSysDbTableSchema clusterSchema[] = { {.name = "uptime", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true}, {.name = "version", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, - {.name = "expire_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true}, + {.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, }; static const SSysDbTableSchema userDBSchema[] = { diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 2da14c65d2..0c446182a6 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -100,7 +100,7 @@ typedef struct { } SSyncMgmt; typedef struct { - int64_t expireTimeMS; + int64_t expireTimeSec; int64_t timeseriesAllowed; } SGrantInfo; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f2b279276e..ca7544877c 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -310,11 +310,25 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock * pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataSetVal(pColInfo, numOfRows, (const char *)ver, false); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + char expireTime[25] = {0}; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); if (tsExpireTime <= 0) { - colDataSetNULL(pColInfo, numOfRows); + if (tsExpireTime == GRANT_UNIQ_UNLIMITED) { + STR_WITH_MAXSIZE_TO_VARSTR(expireTime, "unlimited", pShow->pMeta->pSchemas[cols].bytes); + colDataSetVal(pColInfo, numOfRows, expireTime, false); + } else { + colDataSetNULL(pColInfo, numOfRows); + } } else { - colDataSetVal(pColInfo, numOfRows, (const char *)&tsExpireTime, false); + char ts[20] = {0}; + struct tm ptm; + if (taosLocalTime(&tsExpireTime, &ptm, ts) != NULL) { + strftime(ts, 20, "%Y-%m-%d %H:%M:%S", &ptm); + } else { + ts[0] = 0; + } + STR_WITH_MAXSIZE_TO_VARSTR(expireTime, ts, pShow->pMeta->pSchemas[cols].bytes); + colDataSetVal(pColInfo, numOfRows, expireTime, false); } sdbRelease(pSdb, pCluster); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index cad8c6d745..7c8ef2f0b7 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -1028,9 +1028,11 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } // grant info - pGrantInfo->expire_time = (pMnode->grant.expireTimeMS - ms) / 1000; + pGrantInfo->expire_time = pMnode->grant.expireTimeSec == GRANT_UNIQ_UNLIMITED + ? GRANT_UNIQ_UNLIMITED + : (pMnode->grant.expireTimeSec - ms / 1000); pGrantInfo->timeseries_total = pMnode->grant.timeseriesAllowed; - if (pMnode->grant.expireTimeMS == 0) { + if (pMnode->grant.expireTimeSec == 0) { pGrantInfo->expire_time = 0; pGrantInfo->timeseries_total = 0; } From 7c429e5799fe1a0dad51106e9ae40b7d6fc881d0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Jun 2024 14:25:17 +0800 Subject: [PATCH 2/4] enh: support display unlimited for expiration time --- include/common/tgrant.h | 13 +++++++------ source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/dnode/mnode/impl/src/mndCluster.c | 15 +++++++-------- source/dnode/mnode/impl/src/mndMain.c | 6 ++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index fc1e45fb2a..ae58ba88ad 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -28,12 +28,13 @@ extern "C" { #define GRANTS_COL_MAX_LEN 196 #endif -#define GRANT_HEART_BEAT_MIN 2 -#define GRANT_UNIQ_UNLIMITED (-1) -#define GRANT_ACTIVE_CODE "activeCode" -#define GRANT_FLAG_ALL (0x01) -#define GRANT_FLAG_AUDIT (0x02) -#define GRANT_FLAG_VIEW (0x04) +#define GRANT_HEART_BEAT_MIN 2 +#define GRANT_MAX_EXPIRE_SEC (31556995201) +#define GRANT_EXPIRE_UNLIMITED(v) ((v) == GRANT_MAX_EXPIRE_SEC) +#define GRANT_ACTIVE_CODE "activeCode" +#define GRANT_FLAG_ALL (0x01) +#define GRANT_FLAG_AUDIT (0x02) +#define GRANT_FLAG_VIEW (0x04) typedef enum { TSDB_GRANT_ALL, diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 0c446182a6..2da14c65d2 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -100,7 +100,7 @@ typedef struct { } SSyncMgmt; typedef struct { - int64_t expireTimeSec; + int64_t expireTimeMS; int64_t timeseriesAllowed; } SGrantInfo; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index ca7544877c..a811a1ada0 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -312,17 +312,16 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock * char expireTime[25] = {0}; pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - if (tsExpireTime <= 0) { - if (tsExpireTime == GRANT_UNIQ_UNLIMITED) { - STR_WITH_MAXSIZE_TO_VARSTR(expireTime, "unlimited", pShow->pMeta->pSchemas[cols].bytes); - colDataSetVal(pColInfo, numOfRows, expireTime, false); - } else { - colDataSetNULL(pColInfo, numOfRows); - } + if (GRANT_EXPIRE_UNLIMITED(tsExpireTime / 1000)) { + STR_WITH_MAXSIZE_TO_VARSTR(expireTime, "unlimited", pShow->pMeta->pSchemas[cols].bytes); + colDataSetVal(pColInfo, numOfRows, expireTime, false); + } else if (tsExpireTime <= 0) { + colDataSetNULL(pColInfo, numOfRows); } else { char ts[20] = {0}; + time_t expireSec = tsExpireTime / 1000; struct tm ptm; - if (taosLocalTime(&tsExpireTime, &ptm, ts) != NULL) { + if (taosLocalTime(&expireSec, &ptm, ts) != NULL) { strftime(ts, 20, "%Y-%m-%d %H:%M:%S", &ptm); } else { ts[0] = 0; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 7c8ef2f0b7..cad8c6d745 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -1028,11 +1028,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } // grant info - pGrantInfo->expire_time = pMnode->grant.expireTimeSec == GRANT_UNIQ_UNLIMITED - ? GRANT_UNIQ_UNLIMITED - : (pMnode->grant.expireTimeSec - ms / 1000); + pGrantInfo->expire_time = (pMnode->grant.expireTimeMS - ms) / 1000; pGrantInfo->timeseries_total = pMnode->grant.timeseriesAllowed; - if (pMnode->grant.expireTimeSec == 0) { + if (pMnode->grant.expireTimeMS == 0) { pGrantInfo->expire_time = 0; pGrantInfo->timeseries_total = 0; } From 780ce7aa95233e125bfc92b59a463946505ca27f Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 19 Jun 2024 14:33:17 +0800 Subject: [PATCH 3/4] enh: support display unlimited for expiration time --- include/common/tgrant.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index ae58ba88ad..42adabd6f7 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -29,8 +29,8 @@ extern "C" { #endif #define GRANT_HEART_BEAT_MIN 2 -#define GRANT_MAX_EXPIRE_SEC (31556995201) -#define GRANT_EXPIRE_UNLIMITED(v) ((v) == GRANT_MAX_EXPIRE_SEC) +#define GRANT_EXPIRE_VALUE (31556995201) +#define GRANT_EXPIRE_UNLIMITED(v) ((v) == GRANT_EXPIRE_VALUE) #define GRANT_ACTIVE_CODE "activeCode" #define GRANT_FLAG_ALL (0x01) #define GRANT_FLAG_AUDIT (0x02) From 606b9cfcb0af5d46ffaa9dbe7cea0e2cf475e1da Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 20 Jun 2024 15:38:22 +0800 Subject: [PATCH 4/4] fix: error process for oom --- source/dnode/mnode/impl/inc/mndShow.h | 8 ++++++++ source/dnode/mnode/impl/src/mndCluster.c | 15 ++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index 5a3e487e3d..de7068e9ad 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -23,6 +23,14 @@ extern "C" { #endif +#define COL_DATA_SET_VAL_RET(pData, isNull, pObj) \ + do { \ + if ((code = colDataSetVal(pColInfo, numOfRows, (pData), (isNull))) != 0) { \ + if (pObj) sdbRelease(pSdb, (pObj)); \ + return code; \ + } \ + } while (0) + int32_t mndInitShow(SMnode *pMnode); void mndCleanupShow(SMnode *pMnode); void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp); diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index a811a1ada0..31ebc6609d 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -280,6 +280,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pMsg->info.node; SSdb *pSdb = pMnode->pSdb; + int32_t code = 0; int32_t numOfRows = 0; int32_t cols = 0; SClusterObj *pCluster = NULL; @@ -290,31 +291,31 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock * cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pCluster->id, false); + COL_DATA_SET_VAL_RET((const char *)&pCluster->id, false, pCluster); char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, buf, false); + COL_DATA_SET_VAL_RET(buf, false, pCluster); int32_t upTime = mndGetClusterUpTimeImp(pCluster); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&upTime, false); + COL_DATA_SET_VAL_RET((const char *)&upTime, false, pCluster); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pCluster->createdTime, false); + COL_DATA_SET_VAL_RET((const char *)&pCluster->createdTime, false, pCluster); char ver[12] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)ver, false); + COL_DATA_SET_VAL_RET((const char *)ver, false, pCluster); char expireTime[25] = {0}; pColInfo = taosArrayGet(pBlock->pDataBlock, cols); if (GRANT_EXPIRE_UNLIMITED(tsExpireTime / 1000)) { STR_WITH_MAXSIZE_TO_VARSTR(expireTime, "unlimited", pShow->pMeta->pSchemas[cols].bytes); - colDataSetVal(pColInfo, numOfRows, expireTime, false); + COL_DATA_SET_VAL_RET(expireTime, false, pCluster); } else if (tsExpireTime <= 0) { colDataSetNULL(pColInfo, numOfRows); } else { @@ -327,7 +328,7 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock * ts[0] = 0; } STR_WITH_MAXSIZE_TO_VARSTR(expireTime, ts, pShow->pMeta->pSchemas[cols].bytes); - colDataSetVal(pColInfo, numOfRows, expireTime, false); + COL_DATA_SET_VAL_RET(expireTime, false, pCluster); } sdbRelease(pSdb, pCluster);