From 9096312b41d8ce1f47fbb86ea5b8cba0ebf3d5aa Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 13 Dec 2024 09:21:43 +0800 Subject: [PATCH 1/8] Replace unsafe memory functions with safe versions in wal&sync. --- include/libs/wal/wal.h | 1 + source/libs/sync/src/syncMain.c | 2 +- source/libs/wal/src/walMeta.c | 24 ++++++++++++------------ source/libs/wal/src/walRead.c | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 999adc2eff..68f1de643d 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -36,6 +36,7 @@ extern "C" { #define WAL_FILE_LEN (WAL_PATH_LEN + 32) #define WAL_MAGIC 0xFAFBFCFDF4F3F2F1ULL #define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3) +#define WAL_JSON_BUF_SIZE 30 typedef enum { TAOS_WAL_SKIP = 0, diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index b9e2d3435f..fbde104f4e 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -692,7 +692,7 @@ int32_t syncGetArbToken(int64_t rid, char* outToken) { memset(outToken, 0, TSDB_ARB_TOKEN_SIZE); (void)taosThreadMutexLock(&pSyncNode->arbTokenMutex); - strncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE); + tstrncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE); (void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); syncNodeRelease(pSyncNode); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 78f13a58ab..3faeb53499 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -39,11 +39,11 @@ int64_t FORCE_INLINE walGetCommittedVer(SWal* pWal) { return pWal->vers.commitVe int64_t FORCE_INLINE walGetAppliedVer(SWal* pWal) { return pWal->vers.appliedVer; } static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { - return sprintf(buf, "%s/meta-ver%d", pWal->path, metaVer); + return snprintf(buf, WAL_FILE_LEN, "%s/meta-ver%d", pWal->path, metaVer); } static FORCE_INLINE int walBuildTmpMetaName(SWal* pWal, char* buf) { - return sprintf(buf, "%s/meta-ver.tmp", pWal->path); + return snprintf(buf, WAL_FILE_LEN, "%s/meta-ver.tmp", pWal->path); } static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, int64_t* lastVer) { @@ -819,7 +819,7 @@ int32_t walRollFileInfo(SWal* pWal) { } int32_t walMetaSerialize(SWal* pWal, char** serialized) { - char buf[30]; + char buf[WAL_JSON_BUF_SIZE]; int sz = taosArrayGetSize(pWal->fileInfoSet); cJSON* pRoot = cJSON_CreateObject(); cJSON* pMeta = cJSON_CreateObject(); @@ -841,19 +841,19 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) { if (!cJSON_AddItemToObject(pRoot, "meta", pMeta)) { wInfo("vgId:%d, failed to add meta to root", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pWal->vers.firstVer); + snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pWal->vers.firstVer); if (cJSON_AddStringToObject(pMeta, "firstVer", buf) == NULL) { wInfo("vgId:%d, failed to add firstVer to meta", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pWal->vers.snapshotVer); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pWal->vers.snapshotVer); if (cJSON_AddStringToObject(pMeta, "snapshotVer", buf) == NULL) { wInfo("vgId:%d, failed to add snapshotVer to meta", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pWal->vers.commitVer); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pWal->vers.commitVer); if (cJSON_AddStringToObject(pMeta, "commitVer", buf) == NULL) { wInfo("vgId:%d, failed to add commitVer to meta", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pWal->vers.lastVer); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pWal->vers.lastVer); if (cJSON_AddStringToObject(pMeta, "lastVer", buf) == NULL) { wInfo("vgId:%d, failed to add lastVer to meta", pWal->cfg.vgId); } @@ -874,23 +874,23 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) { } // cjson only support int32_t or double // string are used to prohibit the loss of precision - (void)sprintf(buf, "%" PRId64, pInfo->firstVer); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pInfo->firstVer); if (cJSON_AddStringToObject(pField, "firstVer", buf) == NULL) { wInfo("vgId:%d, failed to add firstVer to field", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pInfo->lastVer); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pInfo->lastVer); if (cJSON_AddStringToObject(pField, "lastVer", buf) == NULL) { wInfo("vgId:%d, failed to add lastVer to field", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pInfo->createTs); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pInfo->createTs); if (cJSON_AddStringToObject(pField, "createTs", buf) == NULL) { wInfo("vgId:%d, failed to add createTs to field", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pInfo->closeTs); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pInfo->closeTs); if (cJSON_AddStringToObject(pField, "closeTs", buf) == NULL) { wInfo("vgId:%d, failed to add closeTs to field", pWal->cfg.vgId); } - (void)sprintf(buf, "%" PRId64, pInfo->fileSize); + (void)snprintf(buf, WAL_JSON_BUF_SIZE, "%" PRId64, pInfo->fileSize); if (cJSON_AddStringToObject(pField, "fileSize", buf) == NULL) { wInfo("vgId:%d, failed to add fileSize to field", pWal->cfg.vgId); } diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index da5e1f47e9..f62f8e1bcf 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -539,7 +539,7 @@ int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const opts.source = pHead->head.body; opts.result = newBody; opts.unitLen = 16; - TAOS_UNUSED(strncpy((char *)opts.key, cfg->encryptKey, 16)); + tstrncpy((char *)opts.key, cfg->encryptKey, 16); int32_t count = CBC_Decrypt(&opts); From c66a834d1e3104263540741ab9209f8012b1c35b Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 13 Dec 2024 15:19:29 +0800 Subject: [PATCH 2/8] Replace unsafe memory functions with safe versions in wal&sync. --- source/dnode/mnode/impl/inc/mndStream.h | 23 +- source/dnode/mnode/impl/src/mndCluster.c | 2 +- source/dnode/mnode/impl/src/mndCompact.c | 4 +- source/dnode/mnode/impl/src/mndDb.c | 36 +-- source/dnode/mnode/impl/src/mndDnode.c | 66 ++-- source/dnode/mnode/impl/src/mndFunc.c | 2 +- source/dnode/mnode/impl/src/mndInfoSchema.c | 6 +- source/dnode/mnode/impl/src/mndMnode.c | 4 +- source/dnode/mnode/impl/src/mndPerfSchema.c | 6 +- source/dnode/mnode/impl/src/mndProfile.c | 30 +- source/dnode/mnode/impl/src/mndQnode.c | 4 +- source/dnode/mnode/impl/src/mndStb.c | 324 ++------------------ source/dnode/mnode/impl/src/mndStream.c | 92 +++--- source/dnode/mnode/impl/src/mndStreamHb.c | 28 +- source/dnode/mnode/impl/src/mndStreamUtil.c | 111 +++---- source/dnode/mnode/impl/src/mndUser.c | 31 +- source/dnode/mnode/impl/src/mndVgroup.c | 6 +- 17 files changed, 248 insertions(+), 527 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index 27d3e3c9be..ec04aa3111 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -23,8 +23,9 @@ extern "C" { #endif -#define MND_STREAM_RESERVE_SIZE 64 -#define MND_STREAM_VER_NUMBER 5 +#define MND_STREAM_RESERVE_SIZE 64 +#define MND_STREAM_VER_NUMBER 5 +#define MND_STREAM_TRIGGER_NAME_SIZE 20 #define MND_STREAM_CREATE_NAME "stream-create" #define MND_STREAM_CHECKPOINT_NAME "stream-checkpoint" @@ -60,7 +61,7 @@ typedef struct SStreamTaskResetMsg { } SStreamTaskResetMsg; typedef struct SChkptReportInfo { - SArray* pTaskList; + SArray *pTaskList; int64_t reportChkpt; int64_t streamId; } SChkptReportInfo; @@ -106,7 +107,7 @@ typedef struct STaskChkptInfo { int64_t ts; int32_t transId; int8_t dropHTask; -}STaskChkptInfo; +} STaskChkptInfo; int32_t mndInitStream(SMnode *pMnode); void mndCleanupStream(SMnode *pMnode); @@ -121,7 +122,7 @@ int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId); int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams); int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream); -int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList); +int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray **pList); void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo); void mndKillTransImpl(SMnode *pMnode, int32_t transId, const char *pDbName); int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msgType, const SEpSet *pEpset, @@ -132,7 +133,7 @@ int32_t mndPersistTransLog(SStreamObj *pStream, STrans *pTrans, int32_t status) SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans); -int32_t mndGetStreamObj(SMnode *pMnode, int64_t streamId, SStreamObj** pStream); +int32_t mndGetStreamObj(SMnode *pMnode, int64_t streamId, SStreamObj **pStream); bool mndStreamNodeIsUpdated(SMnode *pMnode); int32_t mndCheckForSnode(SMnode *pMnode, SDbObj *pSrcDb); @@ -146,8 +147,8 @@ int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray *p int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream, int64_t chkptId); int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream, int64_t chkptId); -int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts); -int32_t mndStreamSetRestartAction(SMnode* pMnode, STrans *pTrans, SStreamObj* pStream); +int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, int64_t ts); +int32_t mndStreamSetRestartAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndStreamSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, int8_t mndTrigger); int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, SArray *pChkptInfoList); @@ -174,9 +175,9 @@ void removeStreamTasksInBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode); int32_t mndGetConsensusInfo(SHashObj *pHash, int64_t streamId, int32_t numOfTasks, SCheckpointConsensusInfo **pInfo); void mndAddConsensusTasks(SCheckpointConsensusInfo *pInfo, const SRestoreCheckpointInfo *pRestoreInfo); void mndClearConsensusRspEntry(SCheckpointConsensusInfo *pInfo); -int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId); -int64_t mndClearChkptReportInfo(SHashObj* pHash, int64_t streamId); -int32_t mndResetChkptReportInfo(SHashObj* pHash, int64_t streamId); +int64_t mndClearConsensusCheckpointId(SHashObj *pHash, int64_t streamId); +int64_t mndClearChkptReportInfo(SHashObj *pHash, int64_t streamId); +int32_t mndResetChkptReportInfo(SHashObj *pHash, int64_t streamId); int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows); int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t nRows, int32_t p); diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 3779bea564..8de0df3b83 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -243,7 +243,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { int32_t code = taosGetSystemUUIDLen(clusterObj.name, TSDB_CLUSTER_ID_LEN); if (code != 0) { - (void)strcpy(clusterObj.name, "tdengine3.0"); + tstrncpy(clusterObj.name, "tdengine3.0", sizeof(clusterObj.name)); mError("failed to get name from system, set to default val %s", clusterObj.name); } diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index 4c2ff9befc..866bf4409c 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -12,8 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "mndCompact.h" #include "audit.h" +#include "mndCompact.h" #include "mndCompactDetail.h" #include "mndDb.h" #include "mndDnode.h" @@ -254,7 +254,7 @@ int32_t mndAddCompactToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompac int32_t code = 0; pCompact->compactId = tGenIdPI32(); - (void)strcpy(pCompact->dbname, pDb->name); + tstrncpy(pCompact->dbname, pDb->name, sizeof(pCompact->dbname)); pCompact->startTime = taosGetTimestampMs(); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 6705bd87c0..d4b2abac10 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -14,11 +14,11 @@ */ #define _DEFAULT_SOURCE -#include "mndDb.h" #include "audit.h" #include "command.h" #include "mndArbGroup.h" #include "mndCluster.h" +#include "mndDb.h" #include "mndDnode.h" #include "mndIndex.h" #include "mndPrivilege.h" @@ -872,22 +872,6 @@ _OVER: TAOS_RETURN(code); } -static void mndBuildAuditDetailInt32(char *detail, char *tmp, char *format, int32_t para) { - if (para > 0) { - if (strlen(detail) > 0) (void)strcat(detail, ", "); - (void)sprintf(tmp, format, para); - (void)strcat(detail, tmp); - } -} - -static void mndBuildAuditDetailInt64(char *detail, char *tmp, char *format, int64_t para) { - if (para > 0) { - if (strlen(detail) > 0) (void)strcat(detail, ", "); - (void)sprintf(tmp, format, para); - (void)strcat(detail, tmp); - } -} - static int32_t mndCheckDbEncryptKey(SMnode *pMnode, SCreateDbReq *pReq) { int32_t code = 0; SSdb *pSdb = pMnode->pSdb; @@ -1336,7 +1320,7 @@ _OVER: } static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) { - (void)strcpy(cfgRsp->db, pDb->name); + tstrncpy(cfgRsp->db, pDb->name, sizeof(cfgRsp->db)); cfgRsp->dbId = pDb->uid; cfgRsp->cfgVersion = pDb->cfgVersion; cfgRsp->numOfVgroups = pDb->cfg.numOfVgroups; @@ -2223,24 +2207,24 @@ static char *buildRetension(SArray *pRetension) { int64_t v1 = getValOfDiffPrecision(p->freqUnit, p->freq); int64_t v2 = getValOfDiffPrecision(p->keepUnit, p->keep); - len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + len += tsnprintf(p1 + len, 100 - len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); if (size > 1) { - len += sprintf(p1 + len, ","); + len += tsnprintf(p1 + len, 100 - len, ","); p = taosArrayGet(pRetension, 1); v1 = getValOfDiffPrecision(p->freqUnit, p->freq); v2 = getValOfDiffPrecision(p->keepUnit, p->keep); - len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + len += tsnprintf(p1 + len, 100 - len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); } if (size > 2) { - len += sprintf(p1 + len, ","); + len += tsnprintf(p1 + len, 100 - len, ","); p = taosArrayGet(pRetension, 2); v1 = getValOfDiffPrecision(p->freqUnit, p->freq); v2 = getValOfDiffPrecision(p->keepUnit, p->keep); - len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + len += tsnprintf(p1 + len, 100 - len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); } varDataSetLen(p1, len); @@ -2409,9 +2393,9 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, int32_t lenKeep2 = formatDurationOrKeep(keep2Str, sizeof(keep2Str), pDb->cfg.daysToKeep2); if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { - len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str); + len = tsnprintf(&keepVstr[VARSTR_HEADER_SIZE], sizeof(keepVstr), "%s,%s,%s", keep1Str, keep2Str, keep0Str); } else { - len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep0Str, keep1Str, keep2Str); + len = tsnprintf(&keepVstr[VARSTR_HEADER_SIZE], sizeof(keepVstr), "%s,%s,%s", keep0Str, keep1Str, keep2Str); } varDataSetLen(keepVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -2499,7 +2483,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)&pDb->cfg.s3ChunkSize, false), &lino, _OVER); char keeplocalVstr[128] = {0}; - len = sprintf(&keeplocalVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.s3KeepLocal); + len = tsnprintf(&keeplocalVstr[VARSTR_HEADER_SIZE], sizeof(keeplocalVstr), "%dm", pDb->cfg.s3KeepLocal); varDataSetLen(keeplocalVstr, len); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)keeplocalVstr, false), &lino, _OVER); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1cb003f02e..6ce73dfaa1 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -14,11 +14,11 @@ */ #define _DEFAULT_SOURCE -#include "mndDnode.h" #include #include "audit.h" #include "mndCluster.h" #include "mndDb.h" +#include "mndDnode.h" #include "mndMnode.h" #include "mndPrivilege.h" #include "mndQnode.h" @@ -1060,18 +1060,18 @@ _OVER: static void getSlowLogScopeString(int32_t scope, char *result) { if (scope == SLOW_LOG_TYPE_NULL) { - (void)strcat(result, "NONE"); + strncat(result, "NONE", 64); return; } while (scope > 0) { if (scope & SLOW_LOG_TYPE_QUERY) { - (void)strcat(result, "QUERY"); + strncat(result, "QUERY", 64); scope &= ~SLOW_LOG_TYPE_QUERY; } else if (scope & SLOW_LOG_TYPE_INSERT) { - (void)strcat(result, "INSERT"); + strncat(result, "INSERT", 64); scope &= ~SLOW_LOG_TYPE_INSERT; } else if (scope & SLOW_LOG_TYPE_OTHERS) { - (void)strcat(result, "OTHERS"); + strncat(result, "OTHERS", 64); scope &= ~SLOW_LOG_TYPE_OTHERS; } else { (void)printf("invalid slow log scope:%d", scope); @@ -1079,7 +1079,7 @@ static void getSlowLogScopeString(int32_t scope, char *result) { } if (scope > 0) { - (void)strcat(result, "|"); + strncat(result, "|", 64); } } } @@ -1101,66 +1101,66 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { SVariablesInfo info = {0}; - (void)strcpy(info.name, "statusInterval"); + tstrncpy(info.name, "statusInterval", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); // fill info.info if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "timezone"); + tstrncpy(info.name, "timezone", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr); - (void)strcpy(info.scope, "both"); + tstrncpy(info.scope, "both", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "locale"); + tstrncpy(info.name, "locale", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsLocale); - (void)strcpy(info.scope, "both"); + tstrncpy(info.scope, "both", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "charset"); + tstrncpy(info.name, "charset", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsCharset); - (void)strcpy(info.scope, "both"); + tstrncpy(info.scope, "both", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "monitor"); + tstrncpy(info.name, "monitor", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsEnableMonitor); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "monitorInterval"); + tstrncpy(info.name, "monitorInterval", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsMonitorInterval); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "slowLogThreshold"); + tstrncpy(info.name, "slowLogThreshold", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogThreshold); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; } - (void)strcpy(info.name, "slowLogMaxLen"); + tstrncpy(info.name, "slowLogMaxLen", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogMaxLen); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; @@ -1168,9 +1168,9 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { char scopeStr[64] = {0}; getSlowLogScopeString(tsSlowLogScope, scopeStr); - (void)strcpy(info.name, "slowLogScope"); + tstrncpy(info.name, "slowLogScope", sizeof(info.name)); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", scopeStr); - (void)strcpy(info.scope, "server"); + tstrncpy(info.scope, "server", sizeof(info.scope)); if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; @@ -1237,7 +1237,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { } char obj[200] = {0}; - (void)sprintf(obj, "%s:%d", createReq.fqdn, createReq.port); + tsnprintf(obj, sizeof(obj), "%s:%d", createReq.fqdn, createReq.port); auditRecord(pReq, pMnode->clusterId, "createDnode", "", obj, createReq.sql, createReq.sqlLen); @@ -1421,7 +1421,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj1[30] = {0}; - (void)sprintf(obj1, "%d", dropReq.dnodeId); + tsnprintf(obj1, sizeof(obj1), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropDnode", "", obj1, dropReq.sql, dropReq.sqlLen); @@ -1455,11 +1455,11 @@ static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) { if (' ' == pMCfgReq->config[optLen]) { // 'key value' if (strlen(pMCfgReq->value) != 0) goto _err; - (void)strcpy(pDCfgReq->value, p + 1); + tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value)); } else { // 'key' 'value' if (strlen(pMCfgReq->value) == 0) goto _err; - (void)strcpy(pDCfgReq->value, pMCfgReq->value); + tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value)); } TAOS_RETURN(code); @@ -1518,7 +1518,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { SDCfgDnodeReq dcfgReq = {0}; if (strcasecmp(cfgReq.config, "resetlog") == 0) { - (void)strcpy(dcfgReq.config, "resetlog"); + tstrncpy(dcfgReq.config, "resetlog", sizeof(dcfgReq.config)); #ifdef TD_ENTERPRISE } else if (strncasecmp(cfgReq.config, "s3blocksize", 11) == 0) { int32_t optLen = strlen("s3blocksize"); @@ -1534,7 +1534,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { TAOS_RETURN(code); } - strcpy(dcfgReq.config, "s3blocksize"); + tstrncpy(dcfgReq.config, "s3blocksize", sizeof(dcfgReq.config)); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); #endif } else { @@ -1553,7 +1553,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { { // audit char obj[50] = {0}; - (void)sprintf(obj, "%d", cfgReq.dnodeId); + tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen); } @@ -1669,8 +1669,8 @@ static int32_t mndProcessCreateEncryptKeyReq(SRpcMsg *pReq) { const STraceId *trace = &pReq->info.traceId; SDCfgDnodeReq dcfgReq = {0}; if (strncasecmp(cfgReq.config, "encrypt_key", 12) == 0) { - strcpy(dcfgReq.config, cfgReq.config); - strcpy(dcfgReq.value, cfgReq.value); + tstrncpy(dcfgReq.config, cfgReq.config, sizeof(dcfgReq.config)); + tstrncpy(dcfgReq.value, cfgReq.value, sizeof(dcfgReq.value)); tFreeSMCfgDnodeReq(&cfgReq); return mndProcessCreateEncryptKeyReqImpl(pReq, cfgReq.dnodeId, &dcfgReq); } else { diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index db4d842662..6e8c877126 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -723,7 +723,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } char varLang[TSDB_TYPE_STR_MAX_LEN + 1] = {0}; varDataSetLen(varLang, strlen(language)); - strcpy(varDataVal(varLang), language); + tstrncpy(varDataVal(varLang), language, strlen(varLang)); TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)varLang, false), pSdb, pFunc); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index f72f17684e..8774f75521 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -122,9 +122,9 @@ int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbN TAOS_RETURN(code); } - strcpy(pRsp->tbName, pMeta->tbName); - strcpy(pRsp->stbName, pMeta->stbName); - strcpy(pRsp->dbFName, pMeta->dbFName); + tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName)); + tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName)); + tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName)); pRsp->numOfTags = pMeta->numOfTags; pRsp->numOfColumns = pMeta->numOfColumns; pRsp->tableType = pMeta->tableType; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index c89fc26fb5..a3ffcb0300 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -14,10 +14,10 @@ */ #define _DEFAULT_SOURCE -#include "mndMnode.h" #include "audit.h" #include "mndCluster.h" #include "mndDnode.h" +#include "mndMnode.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndSync.h" @@ -880,7 +880,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[40] = {0}; - sprintf(obj, "%d", dropReq.dnodeId); + tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropMnode", "", obj, dropReq.sql, dropReq.sqlLen); diff --git a/source/dnode/mnode/impl/src/mndPerfSchema.c b/source/dnode/mnode/impl/src/mndPerfSchema.c index f36ddf7493..9bd823816a 100644 --- a/source/dnode/mnode/impl/src/mndPerfSchema.c +++ b/source/dnode/mnode/impl/src/mndPerfSchema.c @@ -107,9 +107,9 @@ int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *t TAOS_RETURN(code); } - strcpy(pRsp->tbName, pMeta->tbName); - strcpy(pRsp->stbName, pMeta->stbName); - strcpy(pRsp->dbFName, pMeta->dbFName); + tstrncpy(pRsp->tbName, pMeta->tbName, sizeof(pRsp->tbName)); + tstrncpy(pRsp->stbName, pMeta->stbName, sizeof(pRsp->stbName)); + tstrncpy(pRsp->dbFName, pMeta->dbFName, sizeof(pRsp->dbFName)); pRsp->numOfTags = pMeta->numOfTags; pRsp->numOfColumns = pMeta->numOfColumns; pRsp->tableType = pMeta->tableType; diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index e691ecb904..3d11d7be13 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -14,12 +14,12 @@ */ #define _DEFAULT_SOURCE -#include "mndProfile.h" #include "audit.h" #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" #include "mndPrivilege.h" +#include "mndProfile.h" #include "mndQnode.h" #include "mndShow.h" #include "mndSma.h" @@ -137,12 +137,12 @@ void mndCleanupProfile(SMnode *pMnode) { } } -static void setUserInfo2Conn(SConnObj* connObj, char* userApp, uint32_t userIp){ - if (connObj == NULL){ +static void setUserInfo2Conn(SConnObj *connObj, char *userApp, uint32_t userIp) { + if (connObj == NULL) { return; } tstrncpy(connObj->userApp, userApp, sizeof(connObj->userApp)); - connObj->userIp = userIp; + connObj->userIp = userIp; } static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime) { @@ -384,7 +384,7 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq) app.appId = pReq->appId; app.ip = clientIp; app.pid = pReq->pid; - (void)strcpy(app.name, pReq->name); + tstrncpy(app.name, pReq->name, sizeof(app.name)); app.startTime = pReq->startTime; (void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary)); app.lastAccessTimeMs = taosGetTimestampMs(); @@ -911,7 +911,8 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; taosInetNtoa(varDataVal(endpoint), pConn->ip); - (void)sprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), ":%d", pConn->port); + tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), + sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(varDataVal(endpoint)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false); @@ -944,7 +945,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE){ + if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE) { taosInetNtoa(varDataVal(userIp), pConn->userIp); varDataLen(userIp) = strlen(varDataVal(userIp)); } @@ -987,7 +988,8 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc cols = 0; char queryId[26 + VARSTR_HEADER_SIZE] = {0}; - (void)sprintf(&queryId[VARSTR_HEADER_SIZE], "%x:%" PRIx64, pConn->id, pQuery->reqRid); + tsnprintf(&queryId[VARSTR_HEADER_SIZE], sizeof(queryId) - VARSTR_HEADER_SIZE, "%x:%" PRIx64, pConn->id, + pQuery->reqRid); varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false); @@ -1043,7 +1045,8 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; taosInetNtoa(varDataVal(endpoint), pConn->ip); - (void)sprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), ":%d", pConn->port); + tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), + sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false); @@ -1099,11 +1102,12 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc int32_t offset = VARSTR_HEADER_SIZE; for (int32_t i = 0; i < pQuery->subPlanNum && offset + reserve < strSize; ++i) { if (i) { - offset += sprintf(subStatus + offset, ","); + offset += tsnprintf(subStatus + offset, sizeof(subStatus) - offset, ","); } if (offset + reserve < strSize) { SQuerySubDesc *pDesc = taosArrayGet(pQuery->subDesc, i); - offset += sprintf(subStatus + offset, "%" PRIu64 ":%s", pDesc->tid, pDesc->status); + offset += + tsnprintf(subStatus + offset, sizeof(subStatus) - offset, "%" PRIu64 ":%s", pDesc->tid, pDesc->status); } else { break; } @@ -1138,7 +1142,7 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc } char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE){ + if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE) { taosInetNtoa(varDataVal(userIp), pConn->userIp); varDataLen(userIp) = strlen(varDataVal(userIp)); } @@ -1242,7 +1246,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo } char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - (void)sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name); + tsnprintf(&name[VARSTR_HEADER_SIZE], sizeof(name) - VARSTR_HEADER_SIZE, "%s", pApp->name); varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, numOfRows, (const char *)name, false); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index ba1a88aab3..30bf40c0d8 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -333,7 +333,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - (void)sprintf(obj, "%d", createReq.dnodeId); + tsnprintf(obj, sizeof(obj), "%d", createReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "createQnode", "", obj, createReq.sql, createReq.sqlLen); _OVER: @@ -465,7 +465,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - (void)sprintf(obj, "%d", dropReq.dnodeId); + tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropQnode", "", obj, dropReq.sql, dropReq.sqlLen); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index eb6c326d1e..4304ef3eb8 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "mndStb.h" #include "audit.h" #include "mndDb.h" #include "mndDnode.h" @@ -27,6 +26,7 @@ #include "mndScheduler.h" #include "mndShow.h" #include "mndSma.h" +#include "mndStb.h" #include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" @@ -1365,7 +1365,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { if (createReq.sql == NULL && createReq.sqlLen == 0) { char detail[1000] = {0}; - sprintf(detail, "dbname:%s, stable name:%s", name.dbname, name.tname); + tsnprintf(detail, sizeof(detail), "dbname:%s, stable name:%s", name.dbname, name.tname); auditRecord(pReq, pMnode->clusterId, "createStb", name.dbname, name.tname, detail, strlen(detail)); } else { @@ -3145,7 +3145,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t TAOS_RETURN(code); } - sprintf(tbFName, "%s.%s", pStbVersion->dbFName, pStbVersion->stbName); + tsnprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVersion->dbFName, pStbVersion->stbName); int32_t code = mndGetTableSma(pMnode, tbFName, &indexRsp, &exist); if (code || !exist) { indexRsp.suid = pStbVersion->suid; @@ -3153,8 +3153,8 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t indexRsp.pIndex = NULL; } - strcpy(indexRsp.dbFName, pStbVersion->dbFName); - strcpy(indexRsp.tbName, pStbVersion->stbName); + tstrncpy(indexRsp.dbFName, pStbVersion->dbFName, sizeof(indexRsp.dbFName)); + tstrncpy(indexRsp.tbName, pStbVersion->stbName, sizeof(indexRsp.tbName)); if (taosArrayPush(hbRsp.pIndexRsp, &indexRsp) == NULL) { code = terrno; @@ -3253,282 +3253,6 @@ void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t } } -// static int32_t mndProcessRetrieveStbReq(SRpcMsg *pReq) { -// SMnode *pMnode = pReq->info.node; -// SShowMgmt *pMgmt = &pMnode->showMgmt; -// SShowObj *pShow = NULL; -// int32_t rowsToRead = SHOW_STEP_SIZE; -// int32_t rowsRead = 0; -// -// SRetrieveTableReq retrieveReq = {0}; -// if (tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq) != 0) { -// terrno = TSDB_CODE_INVALID_MSG; -// return -1; -// } -// -// SMnode *pMnode = pReq->info.node; -// SSdb *pSdb = pMnode->pSdb; -// int32_t numOfRows = 0; -// SDbObj *pDb = NULL; -// ESdbStatus objStatus = 0; -// -// SUserObj *pUser = mndAcquireUser(pMnode, pReq->info.conn.user); -// if (pUser == NULL) return 0; -// bool sysinfo = pUser->sysInfo; -// -// // Append the information_schema database into the result. -//// if (!pShow->sysDbRsp) { -//// SDbObj infoschemaDb = {0}; -//// setInformationSchemaDbCfg(pMnode, &infoschemaDb); -//// size_t numOfTables = 0; -//// getVisibleInfosTablesNum(sysinfo, &numOfTables); -//// mndDumpDbInfoData(pMnode, pBlock, &infoschemaDb, pShow, numOfRows, numOfTables, true, 0, 1); -//// -//// numOfRows += 1; -//// -//// SDbObj perfschemaDb = {0}; -//// setPerfSchemaDbCfg(pMnode, &perfschemaDb); -//// numOfTables = 0; -//// getPerfDbMeta(NULL, &numOfTables); -//// mndDumpDbInfoData(pMnode, pBlock, &perfschemaDb, pShow, numOfRows, numOfTables, true, 0, 1); -//// -//// numOfRows += 1; -//// pShow->sysDbRsp = true; -//// } -// -// SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_COLS); -// blockDataEnsureCapacity(p, rowsToRead); -// -// size_t size = 0; -// const SSysTableMeta* pSysDbTableMeta = NULL; -// -// getInfosDbMeta(&pSysDbTableMeta, &size); -// p->info.rows = buildDbColsInfoBlock(sysinfo, p, pSysDbTableMeta, size, TSDB_INFORMATION_SCHEMA_DB); -// -// getPerfDbMeta(&pSysDbTableMeta, &size); -// p->info.rows = buildDbColsInfoBlock(sysinfo, p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB); -// -// blockDataDestroy(p); -// -// -// while (numOfRows < rowsToRead) { -// pShow->pIter = sdbFetchAll(pSdb, SDB_DB, pShow->pIter, (void **)&pDb, &objStatus, true); -// if (pShow->pIter == NULL) break; -// if (strncmp(retrieveReq.db, pDb->name, strlen(retrieveReq.db)) != 0){ -// continue; -// } -// if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) != 0) { -// continue; -// } -// -// while (numOfRows < rowsToRead) { -// pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); -// if (pShow->pIter == NULL) break; -// -// if (pDb != NULL && pStb->dbUid != pDb->uid) { -// sdbRelease(pSdb, pStb); -// continue; -// } -// -// cols = 0; -// -// SName name = {0}; -// char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; -// mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN); -// varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); -// -// SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); -// -// char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; -// tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); -// tNameGetDbName(&name, varDataVal(db)); -// varDataSetLen(db, strlen(varDataVal(db))); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)db, false); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->createdTime, false); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfColumns, false); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfTags, false); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// if (pStb->commentLen > 0) { -// char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; -// STR_TO_VARSTR(comment, pStb->comment); -// colDataSetVal(pColInfo, numOfRows, comment, false); -// } else if (pStb->commentLen == 0) { -// char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; -// STR_TO_VARSTR(comment, ""); -// colDataSetVal(pColInfo, numOfRows, comment, false); -// } else { -// colDataSetNULL(pColInfo, numOfRows); -// } -// -// char watermark[64 + VARSTR_HEADER_SIZE] = {0}; -// sprintf(varDataVal(watermark), "%" PRId64 "a,%" PRId64 "a", pStb->watermark[0], pStb->watermark[1]); -// varDataSetLen(watermark, strlen(varDataVal(watermark))); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false); -// -// char maxDelay[64 + VARSTR_HEADER_SIZE] = {0}; -// sprintf(varDataVal(maxDelay), "%" PRId64 "a,%" PRId64 "a", pStb->maxdelay[0], pStb->maxdelay[1]); -// varDataSetLen(maxDelay, strlen(varDataVal(maxDelay))); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)maxDelay, false); -// -// char rollup[160 + VARSTR_HEADER_SIZE] = {0}; -// int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs); -// char *sep = ", "; -// int32_t sepLen = strlen(sep); -// int32_t rollupLen = sizeof(rollup) - VARSTR_HEADER_SIZE - 2; -// for (int32_t i = 0; i < rollupNum; ++i) { -// char *funcName = taosArrayGet(pStb->pFuncs, i); -// if (i) { -// strncat(varDataVal(rollup), sep, rollupLen); -// rollupLen -= sepLen; -// } -// strncat(varDataVal(rollup), funcName, rollupLen); -// rollupLen -= strlen(funcName); -// } -// varDataSetLen(rollup, strlen(varDataVal(rollup))); -// -// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); -// colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false); -// -// numOfRows++; -// sdbRelease(pSdb, pStb); -// } -// -// if (pDb != NULL) { -// mndReleaseDb(pMnode, pDb); -// } -// -// sdbRelease(pSdb, pDb); -// } -// -// pShow->numOfRows += numOfRows; -// mndReleaseUser(pMnode, pUser); -// -// -// -// -// -// -// -// -// ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; -// if (retrieveFp == NULL) { -// mndReleaseShowObj(pShow, false); -// terrno = TSDB_CODE_MSG_NOT_PROCESSED; -// mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); -// return -1; -// } -// -// mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type); -// if (retrieveReq.user[0] != 0) { -// memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN); -// } else { -// memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1); -// } -// if (retrieveReq.db[0] && mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db) != 0) { -// return -1; -// } -// -// int32_t numOfCols = pShow->pMeta->numOfColumns; -// -// SSDataBlock *pBlock = createDataBlock(); -// for (int32_t i = 0; i < numOfCols; ++i) { -// SColumnInfoData idata = {0}; -// -// SSchema *p = &pShow->pMeta->pSchemas[i]; -// -// idata.info.bytes = p->bytes; -// idata.info.type = p->type; -// idata.info.colId = p->colId; -// blockDataAppendColInfo(pBlock, &idata); -// } -// -// blockDataEnsureCapacity(pBlock, rowsToRead); -// -// if (mndCheckRetrieveFinished(pShow)) { -// mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); -// rowsRead = 0; -// } else { -// rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead); -// if (rowsRead < 0) { -// terrno = rowsRead; -// mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); -// mndReleaseShowObj(pShow, true); -// blockDataDestroy(pBlock); -// return -1; -// } -// -// pBlock->info.rows = rowsRead; -// mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows); -// } -// -// size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + -// blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)); -// -// SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); -// if (pRsp == NULL) { -// mndReleaseShowObj(pShow, false); -// terrno = TSDB_CODE_OUT_OF_MEMORY; -// mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); -// blockDataDestroy(pBlock); -// return -1; -// } -// -// pRsp->handle = htobe64(pShow->id); -// -// if (rowsRead > 0) { -// char *pStart = pRsp->data; -// SSchema *ps = pShow->pMeta->pSchemas; -// -// *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns); -// pStart += sizeof(int32_t); // number of columns -// -// for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { -// SSysTableSchema *pSchema = (SSysTableSchema *)pStart; -// pSchema->bytes = htonl(ps[i].bytes); -// pSchema->colId = htons(ps[i].colId); -// pSchema->type = ps[i].type; -// -// pStart += sizeof(SSysTableSchema); -// } -// -// int32_t len = blockEncode(pBlock, pStart, pShow->pMeta->numOfColumns); -// } -// -// pRsp->numOfRows = htonl(rowsRead); -// pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision -// pReq->info.rsp = pRsp; -// pReq->info.rspLen = size; -// -// if (rowsRead == 0 || rowsRead < rowsToRead) { -// pRsp->completed = 1; -// mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); -// mndReleaseShowObj(pShow, true); -// } else { -// mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); -// mndReleaseShowObj(pShow, false); -// } -// -// blockDataDestroy(pBlock); -// return TSDB_CODE_SUCCESS; -//} - static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -3604,14 +3328,16 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc } char watermark[64 + VARSTR_HEADER_SIZE] = {0}; - sprintf(varDataVal(watermark), "%" PRId64 "a,%" PRId64 "a", pStb->watermark[0], pStb->watermark[1]); + tsnprintf(varDataVal(watermark), sizeof(watermark) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", + pStb->watermark[0], pStb->watermark[1]); varDataSetLen(watermark, strlen(varDataVal(watermark))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false), pStb, &lino, _ERROR); char maxDelay[64 + VARSTR_HEADER_SIZE] = {0}; - sprintf(varDataVal(maxDelay), "%" PRId64 "a,%" PRId64 "a", pStb->maxdelay[0], pStb->maxdelay[1]); + tsnprintf(varDataVal(maxDelay), sizeof(maxDelay) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", + pStb->maxdelay[0], pStb->maxdelay[1]); varDataSetLen(maxDelay, strlen(varDataVal(maxDelay))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -3705,13 +3431,16 @@ static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *p int8_t colType = pm->schema[j].type; pColInfoData = taosArrayGet(p->pDataBlock, 4); char colTypeStr[VARSTR_HEADER_SIZE + 32]; - int colTypeLen = sprintf(varDataVal(colTypeStr), "%s", tDataTypes[colType].name); + int colTypeLen = + tsnprintf(varDataVal(colTypeStr), sizeof(colTypeStr) - VARSTR_HEADER_SIZE, "%s", tDataTypes[colType].name); if (colType == TSDB_DATA_TYPE_VARCHAR) { colTypeLen += - sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", (int32_t)(pm->schema[j].bytes - VARSTR_HEADER_SIZE)); + tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, "(%d)", + (int32_t)(pm->schema[j].bytes - VARSTR_HEADER_SIZE)); } else if (colType == TSDB_DATA_TYPE_NCHAR) { - colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", - (int32_t)((pm->schema[j].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); + colTypeLen += + tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, "(%d)", + (int32_t)((pm->schema[j].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } varDataSetLen(colTypeStr, colTypeLen); TAOS_CHECK_GOTO(colDataSetVal(pColInfoData, numOfRows, (char *)colTypeStr, false), &lino, _OVER); @@ -3861,13 +3590,16 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB int8_t colType = pStb->pColumns[i].type; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); char colTypeStr[VARSTR_HEADER_SIZE + 32]; - int colTypeLen = sprintf(varDataVal(colTypeStr), "%s", tDataTypes[colType].name); + int colTypeLen = + tsnprintf(varDataVal(colTypeStr), sizeof(colTypeStr) - VARSTR_HEADER_SIZE, "%s", tDataTypes[colType].name); if (colType == TSDB_DATA_TYPE_VARCHAR) { - colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", - (int32_t)(pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE)); + colTypeLen += + tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, + "(%d)", (int32_t)(pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE)); } else if (colType == TSDB_DATA_TYPE_NCHAR) { - colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", - (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); + colTypeLen += + tsnprintf(varDataVal(colTypeStr) + colTypeLen, sizeof(colTypeStr) - colTypeLen - VARSTR_HEADER_SIZE, + "(%d)", (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } varDataSetLen(colTypeStr, colTypeLen); RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false), pStb, &lino, _OVER); @@ -4086,11 +3818,10 @@ typedef struct SMDropTbTsmaInfos { } SMDropTbTsmaInfos; typedef struct SMndDropTbsWithTsmaCtx { - SHashObj *pVgMap; // + SHashObj *pVgMap; // } SMndDropTbsWithTsmaCtx; -static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, - int32_t vgId); +static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, int32_t vgId); static void destroySVDropTbBatchReqs(void *p); static void mndDestroyDropTbsWithTsmaCtx(SMndDropTbsWithTsmaCtx *p) { @@ -4297,8 +4028,7 @@ static int32_t mndDropTbAdd(SMnode *pMnode, SHashObj *pVgHashMap, const SVgroupI return 0; } -static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, - int32_t vgId) { +static int32_t mndDropTbForSingleVg(SMnode *pMnode, SMndDropTbsWithTsmaCtx *pCtx, SArray *pTbs, int32_t vgId) { int32_t code = 0; SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId); diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 0a107518df..127c474c1f 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -13,13 +13,13 @@ * along with this program. If not, see . */ -#include "mndStream.h" #include "audit.h" #include "mndDb.h" #include "mndPrivilege.h" #include "mndScheduler.h" #include "mndShow.h" #include "mndStb.h" +#include "mndStream.h" #include "mndTrans.h" #include "osMemory.h" #include "parser.h" @@ -159,16 +159,16 @@ void mndCleanupStream(SMnode *pMnode) { taosHashCleanup(execInfo.pTransferStateStreams); taosHashCleanup(execInfo.pChkptStreams); taosHashCleanup(execInfo.pStreamConsensus); - (void) taosThreadMutexDestroy(&execInfo.lock); + (void)taosThreadMutexDestroy(&execInfo.lock); mDebug("mnd stream exec info cleanup"); } SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { int32_t code = 0; int32_t lino = 0; - SSdbRow * pRow = NULL; + SSdbRow *pRow = NULL; SStreamObj *pStream = NULL; - void * buf = NULL; + void *buf = NULL; int8_t sver = 0; int32_t tlen; int32_t dataPos = 0; @@ -237,7 +237,7 @@ static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream) { static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pOldStream, SStreamObj *pNewStream) { mTrace("stream:%s, perform update action", pOldStream->name); - (void) atomic_exchange_32(&pOldStream->version, pNewStream->version); + (void)atomic_exchange_32(&pOldStream->version, pNewStream->version); taosWLockLatch(&pOldStream->lock); @@ -252,7 +252,7 @@ static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pOldStream, SStream int32_t mndAcquireStream(SMnode *pMnode, char *streamName, SStreamObj **pStream) { int32_t code = 0; - SSdb *pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; (*pStream) = sdbAcquire(pSdb, SDB_STREAM, streamName); if ((*pStream) == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { code = TSDB_CODE_MND_STREAM_NOT_EXIST; @@ -301,7 +301,7 @@ static int32_t createSchemaByFields(const SArray *pFields, SSchemaWrapper *pWrap pWrapper->pSchema[index].bytes = pField->bytes; } pWrapper->pSchema[index].colId = index + 1; - strcpy(pWrapper->pSchema[index].name, pField->name); + tstrncpy(pWrapper->pSchema[index].name, pField->name, sizeof(pWrapper->pSchema[index].name)); pWrapper->pSchema[index].flags = pField->flags; index += 1; } @@ -359,7 +359,8 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB); if (pSourceDb == NULL) { code = terrno; - mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, tstrerror(code)); + mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, + tstrerror(code)); goto FAIL; } @@ -371,7 +372,8 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SDbObj *pTargetDb = mndAcquireDbByStb(pMnode, pObj->targetSTbName); if (pTargetDb == NULL) { code = terrno; - mError("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, tstrerror(code)); + mError("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, + tstrerror(code)); goto FAIL; } @@ -417,7 +419,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, pFullSchema[i].bytes = pObj->outputSchema.pSchema[dataIndex].bytes; pFullSchema[i].colId = i + 1; // pObj->outputSchema.pSchema[dataIndex].colId; pFullSchema[i].flags = pObj->outputSchema.pSchema[dataIndex].flags; - strcpy(pFullSchema[i].name, pObj->outputSchema.pSchema[dataIndex].name); + tstrncpy(pFullSchema[i].name, pObj->outputSchema.pSchema[dataIndex].name, sizeof(pFullSchema[i].name)); pFullSchema[i].type = pObj->outputSchema.pSchema[dataIndex].type; dataIndex++; } else { @@ -435,7 +437,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, pFullSchema[i].bytes = pObj->outputSchema.pSchema[dataIndex].bytes; pFullSchema[i].colId = i + 1; // pObj->outputSchema.pSchema[dataIndex].colId; pFullSchema[i].flags = pObj->outputSchema.pSchema[dataIndex].flags; - strcpy(pFullSchema[i].name, pObj->outputSchema.pSchema[dataIndex].name); + tstrncpy(pFullSchema[i].name, pObj->outputSchema.pSchema[dataIndex].name, sizeof(pFullSchema[i].name)); pFullSchema[i].type = pObj->outputSchema.pSchema[dataIndex].type; dataIndex++; } else { @@ -457,7 +459,8 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, .pAstRoot = pAst, .topicQuery = false, .streamQuery = true, - .triggerType = (pObj->conf.trigger == STREAM_TRIGGER_MAX_DELAY)? STREAM_TRIGGER_WINDOW_CLOSE : pObj->conf.trigger, + .triggerType = + (pObj->conf.trigger == STREAM_TRIGGER_MAX_DELAY) ? STREAM_TRIGGER_WINDOW_CLOSE : pObj->conf.trigger, .watermark = pObj->conf.watermark, .igExpired = pObj->conf.igExpired, .deleteMark = pObj->deleteMark, @@ -540,7 +543,8 @@ int32_t mndPersistTaskDeployReq(STrans *pTrans, SStreamTask *pTask) { return code; } - code = setTransAction(pTrans, buf, tlen, TDMT_STREAM_TASK_DEPLOY, &pTask->info.epSet, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + code = setTransAction(pTrans, buf, tlen, TDMT_STREAM_TASK_DEPLOY, &pTask->info.epSet, 0, + TSDB_CODE_VND_INVALID_VGROUP_ID); if (code) { taosMemoryFree(buf); } @@ -550,7 +554,7 @@ int32_t mndPersistTaskDeployReq(STrans *pTrans, SStreamTask *pTask) { int32_t mndPersistStreamTasks(STrans *pTrans, SStreamObj *pStream) { SStreamTaskIter *pIter = NULL; - int32_t code = createStreamTaskIter(pStream, &pIter); + int32_t code = createStreamTaskIter(pStream, &pIter); if (code) { mError("failed to create task iter for stream:%s", pStream->name); return code; @@ -637,7 +641,7 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre SField *pField = taosArrayGet(createReq.pTags, 0); TSDB_CHECK_NULL(pField, code, lino, _OVER, terrno); - strcpy(pField->name, "group_id"); + tstrncpy(pField->name, "group_id", sizeof(pField->name)); pField->type = TSDB_DATA_TYPE_UBIGINT; pField->flags = 0; pField->bytes = 8; @@ -963,7 +967,8 @@ static int32_t mndProcessRestartStreamReq(SRpcMsg *pReq) { } STrans *pTrans = NULL; - code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESTART_NAME, "restart the stream", &pTrans); + code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESTART_NAME, "restart the stream", + &pTrans); if (pTrans == NULL || code) { mError("stream:%s failed to pause stream since %s", pauseReq.name, tstrerror(code)); sdbRelease(pMnode->pSdb, pStream); @@ -1289,7 +1294,7 @@ static int32_t mndProcessStreamCheckpoint(SRpcMsg *pReq) { streamMutexUnlock(&execInfo.lock); SCheckpointInterval in = {.streamId = pStream->uid, .duration = duration}; - void* p = taosArrayPush(pList, &in); + void *p = taosArrayPush(pList, &in); if (p) { int32_t currentSize = taosArrayGetSize(pList); mDebug("stream:%s (uid:0x%" PRIx64 ") total %d stream(s) beyond chpt interval threshold: %ds(%" PRId64 @@ -1366,7 +1371,7 @@ static int32_t mndProcessStreamCheckpoint(SRpcMsg *pReq) { } static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { - SMnode * pMnode = pReq->info.node; + SMnode *pMnode = pReq->info.node; SStreamObj *pStream = NULL; int32_t code = 0; @@ -1396,7 +1401,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { if (pStream->smaId != 0) { mDebug("stream:%s, uid:0x%" PRIx64 " try to drop sma related stream", dropReq.name, pStream->uid); - void * pIter = NULL; + void *pIter = NULL; SSmaObj *pSma = NULL; pIter = sdbFetch(pMnode->pSdb, SDB_SMA, pIter, (void **)&pSma); while (pIter) { @@ -1925,7 +1930,8 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange // here create only one trans if (pTrans == NULL) { - code = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_TASK_UPDATE_NAME, "update task epsets", &pTrans); + code = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_TASK_UPDATE_NAME, + "update task epsets", &pTrans); if (pTrans == NULL || code) { sdbRelease(pSdb, pStream); sdbCancelFetch(pSdb, pIter); @@ -2056,9 +2062,9 @@ static int32_t refreshNodeListFromExistedStreams(SMnode *pMnode, SArray *pNodeLi continue; } - char buf[256] = {0}; + char buf[256] = {0}; int32_t ret = epsetToStr(&pEntry->epset, buf, tListLen(buf)); // ignore this error since it is only for log file - if (ret != 0) { // print error and continue + if (ret != 0) { // print error and continue mError("failed to convert epset to str, code:%s", tstrerror(ret)); } @@ -2178,7 +2184,7 @@ static int32_t mndProcessNodeCheckReq(SRpcMsg *pMsg) { mndDestroyVgroupChangeInfo(&changeInfo); - _end: +_end: streamMutexUnlock(&execInfo.lock); taosArrayDestroy(pNodeSnapshot); @@ -2227,7 +2233,7 @@ void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode) code = taosHashPut(pExecNode->pTaskMap, &id, sizeof(id), &entry, sizeof(entry)); if (code == 0) { - void * px = taosArrayPush(pExecNode->pTaskList, &id); + void *px = taosArrayPush(pExecNode->pTaskList, &id); int32_t num = (int32_t)taosArrayGetSize(pExecNode->pTaskList); if (px) { mInfo("s-task:0x%x add into task buffer, total:%d", (int32_t)entry.id.taskId, num); @@ -2235,7 +2241,7 @@ void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode) mError("s-task:0x%x failed to add into task buffer, total:%d", (int32_t)entry.id.taskId, num); } } else { - mError("s-task:0x%x failed to add into task map, since out of memory", (int32_t) entry.id.taskId); + mError("s-task:0x%x failed to add into task map, since out of memory", (int32_t)entry.id.taskId); } // add the new vgroups if not added yet @@ -2252,11 +2258,12 @@ void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode) SNodeEntry nodeEntry = {.hbTimestamp = -1, .nodeId = pTask->info.nodeId, .lastHbMsgId = -1}; epsetAssign(&nodeEntry.epset, &pTask->info.epSet); - void* px = taosArrayPush(pExecNode->pNodeList, &nodeEntry); + void *px = taosArrayPush(pExecNode->pNodeList, &nodeEntry); if (px) { mInfo("vgId:%d added into nodeList, total:%d", nodeEntry.nodeId, (int)taosArrayGetSize(pExecNode->pNodeList)); } else { - mError("vgId:%d failed to add into nodeList, total:%d", nodeEntry.nodeId, (int)taosArrayGetSize(pExecNode->pNodeList)) + mError("vgId:%d failed to add into nodeList, total:%d", nodeEntry.nodeId, + (int)taosArrayGetSize(pExecNode->pNodeList)) } } } @@ -2308,7 +2315,7 @@ int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq) { streamMutexLock(&execInfo.lock); SStreamObj *pStream = NULL; - int32_t code = mndGetStreamObj(pMnode, req.streamId, &pStream); + int32_t code = mndGetStreamObj(pMnode, req.streamId, &pStream); if (pStream == NULL || code != 0) { mWarn("failed to find the stream:0x%" PRIx64 ", not handle the checkpoint req, try to acquire in buf", req.streamId); @@ -2359,7 +2366,7 @@ int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq) { } // remove this entry - (void) taosHashRemove(execInfo.pTransferStateStreams, &req.streamId, sizeof(int64_t)); + (void)taosHashRemove(execInfo.pTransferStateStreams, &req.streamId, sizeof(int64_t)); int32_t numOfStreams = taosHashGetSize(execInfo.pTransferStateStreams); mDebug("stream:0x%" PRIx64 " removed, remain streams:%d fill-history not completed", req.streamId, numOfStreams); @@ -2470,7 +2477,7 @@ static void doAddReportStreamTask(SArray *pList, int64_t reportChkptId, const SC mError("failed to put into task list, taskId:0x%x", pReport->taskId); } else { int32_t size = taosArrayGetSize(pList); - mDebug("stream:0x%"PRIx64" %d tasks has send checkpoint-report", pReport->streamId, size); + mDebug("stream:0x%" PRIx64 " %d tasks has send checkpoint-report", pReport->streamId, size); } } @@ -2500,7 +2507,7 @@ int32_t mndProcessCheckpointReport(SRpcMsg *pReq) { streamMutexLock(&execInfo.lock); SStreamObj *pStream = NULL; - int32_t code = mndGetStreamObj(pMnode, req.streamId, &pStream); + int32_t code = mndGetStreamObj(pMnode, req.streamId, &pStream); if (pStream == NULL || code != 0) { mWarn("failed to find the stream:0x%" PRIx64 ", not handle checkpoint-report, try to acquire in buf", req.streamId); @@ -2520,7 +2527,8 @@ int32_t mndProcessCheckpointReport(SRpcMsg *pReq) { int32_t numOfTasks = (pStream == NULL) ? 0 : mndGetNumOfStreamTasks(pStream); - SChkptReportInfo *pInfo = (SChkptReportInfo*)taosHashGet(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId)); + SChkptReportInfo *pInfo = + (SChkptReportInfo *)taosHashGet(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId)); if (pInfo == NULL) { SChkptReportInfo info = {.pTaskList = taosArrayInit(4, sizeof(STaskChkptInfo)), .streamId = req.streamId}; if (info.pTaskList != NULL) { @@ -2553,14 +2561,14 @@ int32_t mndProcessCheckpointReport(SRpcMsg *pReq) { return code; } -static int64_t getConsensusId(int64_t streamId, int32_t numOfTasks, int32_t* pExistedTasks, bool *pAllSame) { +static int64_t getConsensusId(int64_t streamId, int32_t numOfTasks, int32_t *pExistedTasks, bool *pAllSame) { int32_t num = 0; int64_t chkId = INT64_MAX; *pExistedTasks = 0; *pAllSame = true; - for(int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { - STaskId* p = taosArrayGet(execInfo.pTaskList, i); + for (int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { + STaskId *p = taosArrayGet(execInfo.pTaskList, i); if (p == NULL) { continue; } @@ -2570,7 +2578,7 @@ static int64_t getConsensusId(int64_t streamId, int32_t numOfTasks, int32_t* pEx } num += 1; - STaskStatusEntry* pe = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); + STaskStatusEntry *pe = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); if (chkId > pe->checkpointInfo.latestId) { if (chkId != INT64_MAX) { *pAllSame = false; @@ -2580,7 +2588,7 @@ static int64_t getConsensusId(int64_t streamId, int32_t numOfTasks, int32_t* pEx } *pExistedTasks = num; - if (num < numOfTasks) { // not all task send info to mnode through hbMsg, no valid checkpoint Id + if (num < numOfTasks) { // not all task send info to mnode through hbMsg, no valid checkpoint Id return -1; } @@ -2677,7 +2685,7 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { mError("failed to create consensus-checkpoint trans, stream:0x%" PRIx64, pStream->uid); } - void* p = taosArrayPush(pList, &pe->req.taskId); + void *p = taosArrayPush(pList, &pe->req.taskId); if (p == NULL) { mError("failed to put into task list, taskId:0x%x", pe->req.taskId); } @@ -2717,7 +2725,7 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { mError("streamId is -1, streamId:%" PRIx64, pInfo->streamId); return TSDB_CODE_FAILED; } - void* p = taosArrayPush(pStreamList, &streamId); + void *p = taosArrayPush(pStreamList, &streamId); if (p == NULL) { mError("failed to put into stream list, stream:0x%" PRIx64, streamId); } @@ -2784,7 +2792,7 @@ void mndStreamResetInitTaskListLoadFlag() { execInfo.initTaskList = false; } -void mndUpdateStreamExecInfoRole(SMnode* pMnode, int32_t role) { +void mndUpdateStreamExecInfoRole(SMnode *pMnode, int32_t role) { execInfo.switchFromFollower = false; if (execInfo.role == NODE_ROLE_UNINIT) { @@ -2833,14 +2841,14 @@ void addAllStreamTasksIntoBuf(SMnode *pMnode, SStreamExecInfo *pExecInfo) { int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, SArray *pChkptInfoList) { STrans *pTrans = NULL; int32_t code = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_CHKPT_UPDATE_NAME, - "update checkpoint-info", &pTrans); + "update checkpoint-info", &pTrans); if (pTrans == NULL || code) { sdbRelease(pMnode->pSdb, pStream); return code; } code = mndStreamRegisterTrans(pTrans, MND_STREAM_CHKPT_UPDATE_NAME, pStream->uid); - if (code){ + if (code) { sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); return code; diff --git a/source/dnode/mnode/impl/src/mndStreamHb.c b/source/dnode/mnode/impl/src/mndStreamHb.c index 4b3db28aa1..302f1217d9 100644 --- a/source/dnode/mnode/impl/src/mndStreamHb.c +++ b/source/dnode/mnode/impl/src/mndStreamHb.c @@ -32,7 +32,7 @@ static int32_t suspendAllStreams(SMnode *pMnode, SRpcHandleInfo *info); static bool validateHbMsg(const SArray *pNodeList, int32_t vgId); static void cleanupAfterProcessHbMsg(SStreamHbMsg *pReq, SArray *pFailedChkptList, SArray *pOrphanTasks); static void doSendHbMsgRsp(int32_t code, SRpcHandleInfo *pRpcInfo, int32_t vgId, int32_t msgId); -static void checkforOrphanTask(SMnode* pMnode, STaskStatusEntry* p, SArray* pOrphanTasks); +static void checkforOrphanTask(SMnode *pMnode, STaskStatusEntry *p, SArray *pOrphanTasks); void updateStageInfo(STaskStatusEntry *pTaskEntry, int64_t stage) { int32_t numOfNodes = taosArrayGetSize(execInfo.pNodeList); @@ -62,7 +62,7 @@ void addIntoFailedChkptList(SArray *pList, const SFailedCheckpointInfo *pInfo) { } } - void* p = taosArrayPush(pList, pInfo); + void *p = taosArrayPush(pList, pInfo); if (p == NULL) { mError("failed to push failed checkpoint info checkpointId:%" PRId64 " in list", pInfo->checkpointId); } @@ -119,8 +119,8 @@ int32_t mndSendResetFromCheckpointMsg(SMnode *pMnode, int64_t streamId, int32_t int32_t size = sizeof(SStreamTaskResetMsg); int32_t num = taosArrayGetSize(execInfo.pKilledChkptTrans); - for(int32_t i = 0; i < num; ++i) { - SStreamTaskResetMsg* p = taosArrayGet(execInfo.pKilledChkptTrans, i); + for (int32_t i = 0; i < num; ++i) { + SStreamTaskResetMsg *p = taosArrayGet(execInfo.pKilledChkptTrans, i); if (p == NULL) { continue; } @@ -217,11 +217,11 @@ int32_t mndProcessResetStatusReq(SRpcMsg *pReq) { int32_t code = TSDB_CODE_SUCCESS; SStreamObj *pStream = NULL; - SStreamTaskResetMsg* pMsg = pReq->pCont; + SStreamTaskResetMsg *pMsg = pReq->pCont; mndKillTransImpl(pMnode, pMsg->transId, ""); streamMutexLock(&execInfo.lock); - code = mndResetChkptReportInfo(execInfo.pChkptStreams, pMsg->streamId); // do thing if failed + code = mndResetChkptReportInfo(execInfo.pChkptStreams, pMsg->streamId); // do thing if failed streamMutexUnlock(&execInfo.lock); code = mndGetStreamObj(pMnode, pMsg->streamId, &pStream); @@ -289,7 +289,7 @@ int32_t suspendAllStreams(SMnode *pMnode, SRpcHandleInfo *info) { if (pStream->status != STREAM_STATUS__PAUSE) { SMPauseStreamReq reqPause = {0}; - strcpy(reqPause.name, pStream->name); + tstrncpy(reqPause.name, pStream->name, sizeof(reqPause.name)); reqPause.igNotExists = 1; int32_t contLen = tSerializeSMPauseStreamReq(NULL, 0, &reqPause); @@ -370,8 +370,8 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { TAOS_RETURN(TSDB_CODE_INVALID_MSG); } - for(int32_t i = 0; i < taosArrayGetSize(execInfo.pNodeList); ++i) { - SNodeEntry* pEntry = taosArrayGet(execInfo.pNodeList, i); + for (int32_t i = 0; i < taosArrayGetSize(execInfo.pNodeList); ++i) { + SNodeEntry *pEntry = taosArrayGet(execInfo.pNodeList, i); if (pEntry == NULL) { continue; } @@ -464,7 +464,7 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { // remove failed trans from pChkptStreams code = mndResetChkptReportInfo(execInfo.pChkptStreams, p->id.streamId); if (code) { - mError("failed to remove stream:0x%"PRIx64" in checkpoint stream list", p->id.streamId); + mError("failed to remove stream:0x%" PRIx64 " in checkpoint stream list", p->id.streamId); } } } @@ -570,8 +570,8 @@ void doSendHbMsgRsp(int32_t code, SRpcHandleInfo *pRpcInfo, int32_t vgId, int32_ return; } - ((SMStreamHbRspMsg*)buf)->head.vgId = htonl(vgId); - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + ((SMStreamHbRspMsg *)buf)->head.vgId = htonl(vgId); + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); SEncoder encoder; tEncoderInit(&encoder, abuf, tlen); @@ -589,7 +589,7 @@ void doSendHbMsgRsp(int32_t code, SRpcHandleInfo *pRpcInfo, int32_t vgId, int32_ pRpcInfo->handle = NULL; // disable auto rsp } -void checkforOrphanTask(SMnode* pMnode, STaskStatusEntry* p, SArray* pOrphanTasks) { +void checkforOrphanTask(SMnode *pMnode, STaskStatusEntry *p, SArray *pOrphanTasks) { SStreamObj *pStream = NULL; int32_t code = mndGetStreamObj(pMnode, p->id.streamId, &pStream); @@ -600,7 +600,7 @@ void checkforOrphanTask(SMnode* pMnode, STaskStatusEntry* p, SArray* pOrphanTask SOrphanTask oTask = {.streamId = p->id.streamId, .taskId = p->id.taskId, .nodeId = p->nodeId}; void *px = taosArrayPush(pOrphanTasks, &oTask); if (px == NULL) { - mError("failed to put task into orphan list, taskId:0x%" PRIx64", code:%s", p->id.taskId, tstrerror(terrno)); + mError("failed to put task into orphan list, taskId:0x%" PRIx64 ", code:%s", p->id.taskId, tstrerror(terrno)); } } else { if (pStream != NULL) { diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index 9720dc6b8a..8654fd64e4 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -31,7 +31,7 @@ struct SStreamTaskIter { int32_t doRemoveTasks(SStreamExecInfo *pExecNode, STaskId *pRemovedId); -int32_t createStreamTaskIter(SStreamObj* pStream, SStreamTaskIter** pIter) { +int32_t createStreamTaskIter(SStreamObj *pStream, SStreamTaskIter **pIter) { *pIter = taosMemoryCalloc(1, sizeof(SStreamTaskIter)); if (*pIter == NULL) { return terrno; @@ -46,7 +46,7 @@ int32_t createStreamTaskIter(SStreamObj* pStream, SStreamTaskIter** pIter) { return 0; } -bool streamTaskIterNextTask(SStreamTaskIter* pIter) { +bool streamTaskIterNextTask(SStreamTaskIter *pIter) { if (pIter->level >= pIter->totalLevel) { pIter->pTask = NULL; return false; @@ -56,7 +56,7 @@ bool streamTaskIterNextTask(SStreamTaskIter* pIter) { pIter->level += 1; } - while(pIter->level < pIter->totalLevel) { + while (pIter->level < pIter->totalLevel) { SArray *pList = taosArrayGetP(pIter->pStream->tasks, pIter->level); if (pIter->ordinalIndex >= taosArrayGetSize(pList)) { pIter->level += 1; @@ -74,7 +74,7 @@ bool streamTaskIterNextTask(SStreamTaskIter* pIter) { return false; } -int32_t streamTaskIterGetCurrent(SStreamTaskIter* pIter, SStreamTask** pTask) { +int32_t streamTaskIterGetCurrent(SStreamTaskIter *pIter, SStreamTask **pTask) { if (pTask) { *pTask = pIter->pTask; if (*pTask != NULL) { @@ -85,9 +85,7 @@ int32_t streamTaskIterGetCurrent(SStreamTaskIter* pIter, SStreamTask** pTask) { return TSDB_CODE_INVALID_PARA; } -void destroyStreamTaskIter(SStreamTaskIter* pIter) { - taosMemoryFree(pIter); -} +void destroyStreamTaskIter(SStreamTaskIter *pIter) { taosMemoryFree(pIter); } static bool checkStatusForEachReplica(SVgObj *pVgroup) { for (int32_t i = 0; i < pVgroup->replica; ++i) { @@ -334,8 +332,8 @@ int32_t mndGetStreamTask(STaskId *pId, SStreamObj *pStream, SStreamTask **pTask) int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream) { int32_t num = 0; - for(int32_t i = 0; i < taosArrayGetSize(pStream->tasks); ++i) { - SArray* pLevel = taosArrayGetP(pStream->tasks, i); + for (int32_t i = 0; i < taosArrayGetSize(pStream->tasks); ++i) { + SArray *pLevel = taosArrayGetP(pStream->tasks, i); num += taosArrayGetSize(pLevel); } @@ -368,8 +366,8 @@ int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) return 0; } -static void freeTaskList(void* param) { - SArray** pList = (SArray **)param; +static void freeTaskList(void *param) { + SArray **pList = (SArray **)param; taosArrayDestroy(*pList); } @@ -430,7 +428,7 @@ void removeExpiredNodeInfo(const SArray *pNodeSnapshot) { if (pEntry->nodeId == p->nodeId) { p->hbTimestamp = pEntry->hbTimestamp; - void* px = taosArrayPush(pValidList, p); + void *px = taosArrayPush(pValidList, p); if (px == NULL) { mError("failed to put node into list, nodeId:%d", p->nodeId); } else { @@ -477,7 +475,7 @@ int32_t doRemoveTasks(SStreamExecInfo *pExecNode, STaskId *pRemovedId) { return TSDB_CODE_SUCCESS; } -void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo* pExecInfo) { +void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo *pExecInfo) { for (int32_t i = 0; i < taosArrayGetSize(pTaskIds); ++i) { STaskId *pId = taosArrayGet(pTaskIds, i); if (pId == NULL) { @@ -486,7 +484,7 @@ void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo* pExecInfo) { int32_t code = doRemoveTasks(pExecInfo, pId); if (code) { - mError("failed to remove task in buffer list, 0x%"PRIx64, pId->taskId); + mError("failed to remove task in buffer list, 0x%" PRIx64, pId->taskId); } } } @@ -513,7 +511,7 @@ void removeStreamTasksInBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode) { STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId}; code = doRemoveTasks(pExecNode, &id); if (code) { - mError("failed to remove task in buffer list, 0x%"PRIx64, id.taskId); + mError("failed to remove task in buffer list, 0x%" PRIx64, id.taskId); } } @@ -580,7 +578,7 @@ int32_t removeExpiredNodeEntryAndTaskInBuf(SArray *pNodeSnapshot) { bool existed = taskNodeExists(pNodeSnapshot, pEntry->nodeId); if (!existed) { - void* p = taosArrayPush(pRemovedTasks, pId); + void *p = taosArrayPush(pRemovedTasks, pId); if (p == NULL) { mError("failed to put task entry into remove list, taskId:0x%" PRIx64, pId->taskId); } @@ -611,7 +609,7 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { streamMutexLock(&execInfo.lock); while ((pIter = taosHashIterate(execInfo.pChkptStreams, pIter)) != NULL) { - SChkptReportInfo* px = (SChkptReportInfo *)pIter; + SChkptReportInfo *px = (SChkptReportInfo *)pIter; if (taosArrayGetSize(px->pTaskList) == 0) { continue; } @@ -665,14 +663,14 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { int32_t size = taosArrayGetSize(pDropped); if (size > 0) { for (int32_t i = 0; i < size; ++i) { - int64_t* pStreamId = (int64_t *)taosArrayGet(pDropped, i); + int64_t *pStreamId = (int64_t *)taosArrayGet(pDropped, i); if (pStreamId == NULL) { continue; } code = taosHashRemove(execInfo.pChkptStreams, pStreamId, sizeof(*pStreamId)); if (code) { - mError("failed to remove stream in buf:0x%"PRIx64, *pStreamId); + mError("failed to remove stream in buf:0x%" PRIx64, *pStreamId); } } @@ -740,10 +738,10 @@ int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, i return TSDB_CODE_ACTION_IN_PROGRESS; } -int32_t mndGetConsensusInfo(SHashObj* pHash, int64_t streamId, int32_t numOfTasks, SCheckpointConsensusInfo **pInfo) { +int32_t mndGetConsensusInfo(SHashObj *pHash, int64_t streamId, int32_t numOfTasks, SCheckpointConsensusInfo **pInfo) { *pInfo = NULL; - void* px = taosHashGet(pHash, &streamId, sizeof(streamId)); + void *px = taosHashGet(pHash, &streamId, sizeof(streamId)); if (px != NULL) { *pInfo = px; return 0; @@ -803,12 +801,12 @@ void mndAddConsensusTasks(SCheckpointConsensusInfo *pInfo, const SRestoreCheckpo } } -void mndClearConsensusRspEntry(SCheckpointConsensusInfo* pInfo) { +void mndClearConsensusRspEntry(SCheckpointConsensusInfo *pInfo) { taosArrayDestroy(pInfo->pTaskList); pInfo->pTaskList = NULL; } -int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId) { +int64_t mndClearConsensusCheckpointId(SHashObj *pHash, int64_t streamId) { int32_t code = 0; int32_t numOfStreams = taosHashGetSize(pHash); if (numOfStreams == 0) { @@ -819,13 +817,13 @@ int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId) { if (code == 0) { mDebug("drop stream:0x%" PRIx64 " in consensus-checkpointId list, remain:%d", streamId, numOfStreams); } else { - mError("failed to remove stream:0x%"PRIx64" in consensus-checkpointId list, remain:%d", streamId, numOfStreams); + mError("failed to remove stream:0x%" PRIx64 " in consensus-checkpointId list, remain:%d", streamId, numOfStreams); } return code; } -int64_t mndClearChkptReportInfo(SHashObj* pHash, int64_t streamId) { +int64_t mndClearChkptReportInfo(SHashObj *pHash, int64_t streamId) { int32_t code = 0; int32_t numOfStreams = taosHashGetSize(pHash); if (numOfStreams == 0) { @@ -836,14 +834,14 @@ int64_t mndClearChkptReportInfo(SHashObj* pHash, int64_t streamId) { if (code == 0) { mDebug("drop stream:0x%" PRIx64 " in chkpt-report list, remain:%d", streamId, numOfStreams); } else { - mError("failed to remove stream:0x%"PRIx64" in chkpt-report list, remain:%d", streamId, numOfStreams); + mError("failed to remove stream:0x%" PRIx64 " in chkpt-report list, remain:%d", streamId, numOfStreams); } return code; } -int32_t mndResetChkptReportInfo(SHashObj* pHash, int64_t streamId) { - SChkptReportInfo* pInfo = taosHashGet(pHash, &streamId, sizeof(streamId)); +int32_t mndResetChkptReportInfo(SHashObj *pHash, int64_t streamId) { + SChkptReportInfo *pInfo = taosHashGet(pHash, &streamId, sizeof(streamId)); if (pInfo != NULL) { taosArrayClear(pInfo->pTaskList); mDebug("stream:0x%" PRIx64 " checkpoint-report list cleared, prev report checkpointId:%" PRId64, streamId, @@ -857,28 +855,28 @@ int32_t mndResetChkptReportInfo(SHashObj* pHash, int64_t streamId) { static void mndShowStreamStatus(char *dst, SStreamObj *pStream) { int8_t status = atomic_load_8(&pStream->status); if (status == STREAM_STATUS__NORMAL) { - strcpy(dst, "ready"); + tstrncpy(dst, "ready", MND_STREAM_TRIGGER_NAME_SIZE); } else if (status == STREAM_STATUS__STOP) { - strcpy(dst, "stop"); + tstrncpy(dst, "stop", MND_STREAM_TRIGGER_NAME_SIZE); } else if (status == STREAM_STATUS__FAILED) { - strcpy(dst, "failed"); + tstrncpy(dst, "failed", MND_STREAM_TRIGGER_NAME_SIZE); } else if (status == STREAM_STATUS__RECOVER) { - strcpy(dst, "recover"); + tstrncpy(dst, "recover", MND_STREAM_TRIGGER_NAME_SIZE); } else if (status == STREAM_STATUS__PAUSE) { - strcpy(dst, "paused"); + tstrncpy(dst, "paused", MND_STREAM_TRIGGER_NAME_SIZE); } } static void mndShowStreamTrigger(char *dst, SStreamObj *pStream) { int8_t trigger = pStream->conf.trigger; if (trigger == STREAM_TRIGGER_AT_ONCE) { - strcpy(dst, "at once"); + tstrncpy(dst, "at once", MND_STREAM_TRIGGER_NAME_SIZE); } else if (trigger == STREAM_TRIGGER_WINDOW_CLOSE) { - strcpy(dst, "window close"); + tstrncpy(dst, "window close", MND_STREAM_TRIGGER_NAME_SIZE); } else if (trigger == STREAM_TRIGGER_MAX_DELAY) { - strcpy(dst, "max delay"); + tstrncpy(dst, "max delay", MND_STREAM_TRIGGER_NAME_SIZE); } else if (trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) { - strcpy(dst, "force window close"); + tstrncpy(dst, "force window close", MND_STREAM_TRIGGER_NAME_SIZE); } } @@ -938,7 +936,7 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_ TSDB_CHECK_CODE(code, lino, _end); char status[20 + VARSTR_HEADER_SIZE] = {0}; - char status2[20] = {0}; + char status2[MND_STREAM_TRIGGER_NAME_SIZE] = {0}; mndShowStreamStatus(status2, pStream); STR_WITH_MAXSIZE_TO_VARSTR(status, status2, sizeof(status)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -985,7 +983,7 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_ TSDB_CHECK_CODE(code, lino, _end); char trigger[20 + VARSTR_HEADER_SIZE] = {0}; - char trigger2[20] = {0}; + char trigger2[MND_STREAM_TRIGGER_NAME_SIZE] = {0}; mndShowStreamTrigger(trigger2, pStream); STR_WITH_MAXSIZE_TO_VARSTR(trigger, trigger2, sizeof(trigger)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1007,7 +1005,7 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_ // checkpoint interval char tmp[20 + VARSTR_HEADER_SIZE] = {0}; - sprintf(varDataVal(tmp), "%d sec", tsStreamCheckpointInterval); + tsnprintf(varDataVal(tmp), sizeof(tmp) - VARSTR_HEADER_SIZE, "%d sec", tsStreamCheckpointInterval); varDataSetLen(tmp, strlen(varDataVal(tmp))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1027,7 +1025,7 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_ // history scan idle char scanHistoryIdle[20 + VARSTR_HEADER_SIZE] = {0}; - strcpy(scanHistoryIdle, "100a"); + tstrncpy(scanHistoryIdle, "100a", sizeof(scanHistoryIdle)); memset(dstStr, 0, tListLen(dstStr)); STR_TO_VARSTR(dstStr, scanHistoryIdle) @@ -1043,7 +1041,8 @@ _end: return code; } -int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t numOfRows, int32_t precision) { +int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t numOfRows, + int32_t precision) { SColumnInfoData *pColInfo = NULL; int32_t cols = 0; int32_t code = 0; @@ -1054,7 +1053,7 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo STaskStatusEntry *pe = taosHashGet(execInfo.pTaskMap, &id, sizeof(id)); if (pe == NULL) { mError("task:0x%" PRIx64 " not exists in any vnodes, streamName:%s, streamId:0x%" PRIx64 " createTs:%" PRId64 - " no valid status/stage info", + " no valid status/stage info", id.taskId, pStream->name, pStream->uid, pStream->createTime); return TSDB_CODE_STREAM_TASK_NOT_EXIST; } @@ -1192,7 +1191,7 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo if (pTask->info.taskLevel == TASK_LEVEL__SINK) { colDataSetNULL(pColInfo, numOfRows); } else { - sprintf(buf, formatTotalMb, pe->outputTotal); + tsnprintf(buf, sizeof(buf), formatTotalMb, pe->outputTotal); memset(vbuf, 0, tListLen(vbuf)); STR_TO_VARSTR(vbuf, buf); @@ -1219,19 +1218,11 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); TSDB_CHECK_CODE(code, lino, _end); } - - // output queue - // sprintf(buf, queueInfoStr, pe->outputQUsed, pe->outputRate); - // STR_TO_VARSTR(vbuf, buf); - - // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - // colDataSetVal(pColInfo, numOfRows, (const char*)vbuf, false); - // info if (pTask->info.taskLevel == TASK_LEVEL__SINK) { const char *sinkStr = "%.2f MiB"; snprintf(buf, tListLen(buf), sinkStr, pe->sinkDataSize); - } else if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { // offset info + } else if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { // offset info if (pTask->info.trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) { int32_t ret = taosFormatUtcTime(buf, tListLen(buf), pe->processedVer, precision); if (ret != 0) { @@ -1339,7 +1330,7 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo code = colDataSetVal(pColInfo, numOfRows, 0, true); TSDB_CHECK_CODE(code, lino, _end); - _end: +_end: if (code) { mError("error happens during build task attr result blocks, lino:%d, code:%s", lino, tstrerror(code)); } @@ -1356,7 +1347,7 @@ static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent) return true; } -void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) { +void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo) { if (pInfo != NULL) { taosArrayDestroy(pInfo->pUpdateNodeList); taosHashCleanup(pInfo->pDBMap); @@ -1378,7 +1369,7 @@ int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, cons } pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), - pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { mndDestroyVgroupChangeInfo(pInfo); @@ -1395,7 +1386,7 @@ int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, cons int32_t num = taosArrayGetSize(pNodeList); for (int32_t j = 0; j < num; ++j) { SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); - if(pCurrent == NULL) { + if (pCurrent == NULL) { continue; } @@ -1417,7 +1408,7 @@ int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, cons epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); epsetAssign(&updateInfo.newEp, &pCurrent->epset); - void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); + void *p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); TSDB_CHECK_NULL(p, code, lino, _err, terrno); } @@ -1436,11 +1427,11 @@ int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, cons return code; - _err: +_err: mError("failed to find node change info, code:%s at %s line:%d", tstrerror(code), __func__, lino); mndDestroyVgroupChangeInfo(pInfo); return code; - } +} static int32_t doCheckForUpdated(SMnode *pMnode, SArray **ppNodeSnapshot) { bool allReady = false; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 6a9d67fc83..7f011d234f 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -691,7 +691,7 @@ static void ipRangeToStr(SIpV4Range *range, char *buf) { (void)uv_inet_ntop(AF_INET, &addr, buf, 32); if (range->mask != 32) { - (void)sprintf(buf + strlen(buf), "/%d", range->mask); + tsnprintf(buf + strlen(buf), 36 - strlen(buf), "/%d", range->mask); } return; } @@ -699,14 +699,14 @@ static bool isDefaultRange(SIpV4Range *pRange) { static SIpV4Range val = {.ip = 16777343, .mask = 32}; return pRange->ip == val.ip && pRange->mask == val.mask; } -static int32_t ipRangeListToStr(SIpV4Range *range, int32_t num, char *buf) { +static int32_t ipRangeListToStr(SIpV4Range *range, int32_t num, char *buf, int64_t bufLen) { int32_t len = 0; for (int i = 0; i < num; i++) { char tbuf[36] = {0}; SIpV4Range *pRange = &range[i]; ipRangeToStr(&range[i], tbuf); - len += sprintf(buf + len, "%s,", tbuf); + len += tsnprintf(buf + len, bufLen - len, "%s,", tbuf); } if (len > 0) buf[len - 1] = 0; return len; @@ -738,11 +738,13 @@ int32_t convertIpWhiteListToStr(SIpWhiteList *pList, char **buf) { *buf = NULL; return 0; } - *buf = taosMemoryCalloc(1, pList->num * 36); + int64_t bufLen = pList->num * 36; + *buf = taosMemoryCalloc(1, bufLen); if (*buf == NULL) { return 0; } - int32_t len = ipRangeListToStr(pList->pIpRange, pList->num, *buf); + + int32_t len = ipRangeListToStr(pList->pIpRange, pList->num, *buf, bufLen); if (len == 0) { taosMemoryFreeClear(*buf); return 0; @@ -1899,13 +1901,13 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char detail[1000] = {0}; - (void)sprintf(detail, "enable:%d, superUser:%d, sysInfo:%d, password:xxx", createReq.enable, createReq.superUser, - createReq.sysInfo); + tsnprintf(detail, sizeof(detail), "enable:%d, superUser:%d, sysInfo:%d, password:xxx", createReq.enable, + createReq.superUser, createReq.sysInfo); char operation[15] = {0}; if (createReq.isImport == 1) { - (void)strcpy(operation, "importUser"); + tstrncpy(operation, "importUser", sizeof(operation)); } else { - (void)strcpy(operation, "createUser"); + tstrncpy(operation, "createUser", sizeof(operation)); } auditRecord(pReq, pMnode->clusterId, operation, "", createReq.user, detail, strlen(detail)); @@ -2502,9 +2504,10 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) { if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) { char detail[1000] = {0}; - (void)sprintf(detail, "alterType:%s, enable:%d, superUser:%d, sysInfo:%d, createdb:%d, tabName:%s, password:xxx", - mndUserAuditTypeStr(alterReq.alterType), alterReq.enable, alterReq.superUser, alterReq.sysInfo, - alterReq.createdb ? 1 : 0, alterReq.tabName); + tsnprintf(detail, sizeof(detail), + "alterType:%s, enable:%d, superUser:%d, sysInfo:%d, createdb:%d, tabName:%s, password:xxx", + mndUserAuditTypeStr(alterReq.alterType), alterReq.enable, alterReq.superUser, alterReq.sysInfo, + alterReq.createdb ? 1 : 0, alterReq.tabName); auditRecord(pReq, pMnode->clusterId, "alterUser", "", alterReq.user, detail, strlen(detail)); } else if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER || alterReq.alterType == TSDB_ALTER_USER_ENABLE || alterReq.alterType == TSDB_ALTER_USER_SYSINFO || alterReq.alterType == TSDB_ALTER_USER_CREATEDB) { @@ -2892,12 +2895,12 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i if (nodesStringToNode(value, &pAst) == 0) { if (nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen) != 0) { sqlLen = 5; - (void)sprintf(*sql, "error"); + tsnprintf(*sql, bufSz + 1, "error"); } nodesDestroyNode(pAst); } else { sqlLen = 5; - (void)sprintf(*sql, "error"); + tsnprintf(*sql, bufSz + 1, "error"); } STR_WITH_MAXSIZE_TO_VARSTR((*condition), (*sql), pShow->pMeta->pSchemas[cols].bytes); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 389b04b1d6..29bc1756f5 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "mndVgroup.h" #include "audit.h" #include "mndArbGroup.h" #include "mndDb.h" @@ -27,6 +26,7 @@ #include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" +#include "mndVgroup.h" #include "tmisce.h" #define VGROUP_VER_NUMBER 1 @@ -1077,7 +1077,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p char buf1[20] = {0}; char role[20] = "offline"; if (!exist) { - strcpy(role, "dropping"); + tstrncpy(role, "dropping", sizeof(role)); } else if (online) { char *star = ""; if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER || @@ -2561,7 +2561,7 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - sprintf(obj, "%d", req.vgId); + tsnprintf(obj, sizeof(obj), "%d", req.vgId); auditRecord(pReq, pMnode->clusterId, "RedistributeVgroup", "", obj, req.sql, req.sqlLen); From d191caca98818d865545ae58c1d0032fd77e31d7 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 13 Dec 2024 17:10:47 +0800 Subject: [PATCH 3/8] Fix merge errors. --- source/dnode/mnode/impl/src/mndUser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index bd1aecc32b..03519a7fdb 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -2895,12 +2895,12 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i if (nodesStringToNode(value, &pAst) == 0) { if (nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen) != 0) { sqlLen = 5; - tsnprintf(*sql, bufSz + 1, "error"); + tsnprintf(*sql, bufSz, "error"); } nodesDestroyNode(pAst); } else { sqlLen = 5; - tsnprintf(*sql, bufSz + 1, "error"); + tsnprintf(*sql, bufSz, "error"); } STR_WITH_MAXSIZE_TO_VARSTR((*condition), (*sql), pShow->pMeta->pSchemas[cols].bytes); From da8dd39bd8f010e4e31917b0bd17cf349bee6b0f Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 13 Dec 2024 17:21:30 +0800 Subject: [PATCH 4/8] Fix ci problems. --- source/dnode/mnode/impl/src/mndStream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 127c474c1f..7cc0b6c30b 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -2366,7 +2366,7 @@ int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq) { } // remove this entry - (void)taosHashRemove(execInfo.pTransferStateStreams, &req.streamId, sizeof(int64_t)); + (void) taosHashRemove(execInfo.pTransferStateStreams, &req.streamId, sizeof(int64_t)); int32_t numOfStreams = taosHashGetSize(execInfo.pTransferStateStreams); mDebug("stream:0x%" PRIx64 " removed, remain streams:%d fill-history not completed", req.streamId, numOfStreams); From 7b921b81d2eccaa6681e5fc0f0b2e6eb772152cf Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 13 Dec 2024 17:48:51 +0800 Subject: [PATCH 5/8] Fix ci. --- source/dnode/mnode/impl/src/mndDnode.c | 16 ++++++++-------- source/dnode/mnode/impl/src/mndMnode.c | 2 +- source/dnode/mnode/impl/src/mndProfile.c | 8 ++++---- source/dnode/mnode/impl/src/mndQnode.c | 4 ++-- source/dnode/mnode/impl/src/mndStb.c | 8 ++++---- source/dnode/mnode/impl/src/mndStreamUtil.c | 4 ++-- source/dnode/mnode/impl/src/mndUser.c | 10 +++++----- source/dnode/mnode/impl/src/mndVgroup.c | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 6ce73dfaa1..ee009d2ad5 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1060,18 +1060,18 @@ _OVER: static void getSlowLogScopeString(int32_t scope, char *result) { if (scope == SLOW_LOG_TYPE_NULL) { - strncat(result, "NONE", 64); + (void)strncat(result, "NONE", 64); return; } while (scope > 0) { if (scope & SLOW_LOG_TYPE_QUERY) { - strncat(result, "QUERY", 64); + (void)strncat(result, "QUERY", 64); scope &= ~SLOW_LOG_TYPE_QUERY; } else if (scope & SLOW_LOG_TYPE_INSERT) { - strncat(result, "INSERT", 64); + (void)strncat(result, "INSERT", 64); scope &= ~SLOW_LOG_TYPE_INSERT; } else if (scope & SLOW_LOG_TYPE_OTHERS) { - strncat(result, "OTHERS", 64); + (void)strncat(result, "OTHERS", 64); scope &= ~SLOW_LOG_TYPE_OTHERS; } else { (void)printf("invalid slow log scope:%d", scope); @@ -1079,7 +1079,7 @@ static void getSlowLogScopeString(int32_t scope, char *result) { } if (scope > 0) { - strncat(result, "|", 64); + (void)strncat(result, "|", 64); } } } @@ -1237,7 +1237,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { } char obj[200] = {0}; - tsnprintf(obj, sizeof(obj), "%s:%d", createReq.fqdn, createReq.port); + (void)tsnprintf(obj, sizeof(obj), "%s:%d", createReq.fqdn, createReq.port); auditRecord(pReq, pMnode->clusterId, "createDnode", "", obj, createReq.sql, createReq.sqlLen); @@ -1421,7 +1421,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj1[30] = {0}; - tsnprintf(obj1, sizeof(obj1), "%d", dropReq.dnodeId); + (void)tsnprintf(obj1, sizeof(obj1), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropDnode", "", obj1, dropReq.sql, dropReq.sqlLen); @@ -1553,7 +1553,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { { // audit char obj[50] = {0}; - tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId); + (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen); } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index a3ffcb0300..1f81e422c8 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -880,7 +880,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[40] = {0}; - tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); + (void)tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropMnode", "", obj, dropReq.sql, dropReq.sqlLen); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 3d11d7be13..8fe36ca0c4 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -911,7 +911,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; taosInetNtoa(varDataVal(endpoint), pConn->ip); - tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), + (void)tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(varDataVal(endpoint)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -988,7 +988,7 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc cols = 0; char queryId[26 + VARSTR_HEADER_SIZE] = {0}; - tsnprintf(&queryId[VARSTR_HEADER_SIZE], sizeof(queryId) - VARSTR_HEADER_SIZE, "%x:%" PRIx64, pConn->id, + (void)tsnprintf(&queryId[VARSTR_HEADER_SIZE], sizeof(queryId) - VARSTR_HEADER_SIZE, "%x:%" PRIx64, pConn->id, pQuery->reqRid); varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1045,7 +1045,7 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; taosInetNtoa(varDataVal(endpoint), pConn->ip); - tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), + (void)tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1246,7 +1246,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo } char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - tsnprintf(&name[VARSTR_HEADER_SIZE], sizeof(name) - VARSTR_HEADER_SIZE, "%s", pApp->name); + (void)tsnprintf(&name[VARSTR_HEADER_SIZE], sizeof(name) - VARSTR_HEADER_SIZE, "%s", pApp->name); varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, numOfRows, (const char *)name, false); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 30bf40c0d8..ea42551fa5 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -333,7 +333,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - tsnprintf(obj, sizeof(obj), "%d", createReq.dnodeId); + (void)tsnprintf(obj, sizeof(obj), "%d", createReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "createQnode", "", obj, createReq.sql, createReq.sqlLen); _OVER: @@ -465,7 +465,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); + (void)tsnprintf(obj, sizeof(obj), "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropQnode", "", obj, dropReq.sql, dropReq.sqlLen); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 60a7fc0b6d..2db76f6312 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1368,7 +1368,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { if (createReq.sql == NULL && createReq.sqlLen == 0) { char detail[1000] = {0}; - tsnprintf(detail, sizeof(detail), "dbname:%s, stable name:%s", name.dbname, name.tname); + (void)tsnprintf(detail, sizeof(detail), "dbname:%s, stable name:%s", name.dbname, name.tname); auditRecord(pReq, pMnode->clusterId, "createStb", name.dbname, name.tname, detail, strlen(detail)); } else { @@ -3148,7 +3148,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t TAOS_RETURN(code); } - tsnprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVersion->dbFName, pStbVersion->stbName); + (void)tsnprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVersion->dbFName, pStbVersion->stbName); int32_t code = mndGetTableSma(pMnode, tbFName, &indexRsp, &exist); if (code || !exist) { indexRsp.suid = pStbVersion->suid; @@ -3331,7 +3331,7 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc } char watermark[64 + VARSTR_HEADER_SIZE] = {0}; - tsnprintf(varDataVal(watermark), sizeof(watermark) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", + (void)tsnprintf(varDataVal(watermark), sizeof(watermark) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", pStb->watermark[0], pStb->watermark[1]); varDataSetLen(watermark, strlen(varDataVal(watermark))); @@ -3339,7 +3339,7 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false), pStb, &lino, _ERROR); char maxDelay[64 + VARSTR_HEADER_SIZE] = {0}; - tsnprintf(varDataVal(maxDelay), sizeof(maxDelay) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", + (void)tsnprintf(varDataVal(maxDelay), sizeof(maxDelay) - VARSTR_HEADER_SIZE, "%" PRId64 "a,%" PRId64 "a", pStb->maxdelay[0], pStb->maxdelay[1]); varDataSetLen(maxDelay, strlen(varDataVal(maxDelay))); diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index 8654fd64e4..537a22bb7c 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -1005,7 +1005,7 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_ // checkpoint interval char tmp[20 + VARSTR_HEADER_SIZE] = {0}; - tsnprintf(varDataVal(tmp), sizeof(tmp) - VARSTR_HEADER_SIZE, "%d sec", tsStreamCheckpointInterval); + (void)tsnprintf(varDataVal(tmp), sizeof(tmp) - VARSTR_HEADER_SIZE, "%d sec", tsStreamCheckpointInterval); varDataSetLen(tmp, strlen(varDataVal(tmp))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1191,7 +1191,7 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo if (pTask->info.taskLevel == TASK_LEVEL__SINK) { colDataSetNULL(pColInfo, numOfRows); } else { - tsnprintf(buf, sizeof(buf), formatTotalMb, pe->outputTotal); + (void)tsnprintf(buf, sizeof(buf), formatTotalMb, pe->outputTotal); memset(vbuf, 0, tListLen(vbuf)); STR_TO_VARSTR(vbuf, buf); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 03519a7fdb..e1518d3752 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -691,7 +691,7 @@ static void ipRangeToStr(SIpV4Range *range, char *buf) { (void)uv_inet_ntop(AF_INET, &addr, buf, 32); if (range->mask != 32) { - tsnprintf(buf + strlen(buf), 36 - strlen(buf), "/%d", range->mask); + (void)tsnprintf(buf + strlen(buf), 36 - strlen(buf), "/%d", range->mask); } return; } @@ -1901,7 +1901,7 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char detail[1000] = {0}; - tsnprintf(detail, sizeof(detail), "enable:%d, superUser:%d, sysInfo:%d, password:xxx", createReq.enable, + (void)tsnprintf(detail, sizeof(detail), "enable:%d, superUser:%d, sysInfo:%d, password:xxx", createReq.enable, createReq.superUser, createReq.sysInfo); char operation[15] = {0}; if (createReq.isImport == 1) { @@ -2504,7 +2504,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) { if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) { char detail[1000] = {0}; - tsnprintf(detail, sizeof(detail), + (void)tsnprintf(detail, sizeof(detail), "alterType:%s, enable:%d, superUser:%d, sysInfo:%d, createdb:%d, tabName:%s, password:xxx", mndUserAuditTypeStr(alterReq.alterType), alterReq.enable, alterReq.superUser, alterReq.sysInfo, alterReq.createdb ? 1 : 0, alterReq.tabName); @@ -2895,12 +2895,12 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i if (nodesStringToNode(value, &pAst) == 0) { if (nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen) != 0) { sqlLen = 5; - tsnprintf(*sql, bufSz, "error"); + (void)tsnprintf(*sql, bufSz, "error"); } nodesDestroyNode(pAst); } else { sqlLen = 5; - tsnprintf(*sql, bufSz, "error"); + (void)tsnprintf(*sql, bufSz, "error"); } STR_WITH_MAXSIZE_TO_VARSTR((*condition), (*sql), pShow->pMeta->pSchemas[cols].bytes); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 29bc1756f5..0bce21290b 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -2561,7 +2561,7 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - tsnprintf(obj, sizeof(obj), "%d", req.vgId); + (void)tsnprintf(obj, sizeof(obj), "%d", req.vgId); auditRecord(pReq, pMnode->clusterId, "RedistributeVgroup", "", obj, req.sql, req.sqlLen); From b4afa6ff90097eb14ef182e9e73de1e84ee5f5a1 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Mon, 16 Dec 2024 13:44:58 +0800 Subject: [PATCH 6/8] Fix merge errors. --- source/dnode/mnode/impl/src/mndConfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index f34b6bd583..3fa2bd2941 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -418,7 +418,7 @@ static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) { } size_t optLen = p - pMCfgReq->config; - tstrncpy(pDCfgReq->config, pMCfgReq->config, optLen); + tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config)); pDCfgReq->config[optLen] = 0; if (' ' == pMCfgReq->config[optLen]) { From 9d733c03b4193a1f8b1f696a5c8b32c85743b7e9 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Mon, 16 Dec 2024 14:13:23 +0800 Subject: [PATCH 7/8] Fix merge errors. --- source/dnode/mnode/impl/src/mndConfig.c | 84 ++----------------------- 1 file changed, 4 insertions(+), 80 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 3fa2bd2941..0247a1c88c 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -854,94 +854,17 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { SShowVariablesRsp rsp = {0}; int32_t code = -1; - if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES) != 0) { - goto _OVER; - } - - rsp.variables = taosArrayInit(16, sizeof(SVariablesInfo)); - if (NULL == rsp.variables) { - mError("failed to alloc SVariablesInfo array while process show variables req"); - code = terrno; + if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) { goto _OVER; } SVariablesInfo info = {0}; - tstrncpy(info.name, "statusInterval", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval); - tstrncpy(info.scope, "server", sizeof(info.scope)); - // fill info.info - if (taosArrayPush(rsp.variables, &info) == NULL) { + rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg)); + if (rsp.variables == NULL) { code = terrno; goto _OVER; } - - tstrncpy(info.name, "timezone", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr); - tstrncpy(info.scope, "both", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "locale", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsLocale); - tstrncpy(info.scope, "both", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "charset", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", tsCharset); - tstrncpy(info.scope, "both", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "monitor", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsEnableMonitor); - tstrncpy(info.scope, "server", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "monitorInterval", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsMonitorInterval); - tstrncpy(info.scope, "server", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "slowLogThreshold", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogThreshold); - tstrncpy(info.scope, "server", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - tstrncpy(info.name, "slowLogMaxLen", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogMaxLen); - tstrncpy(info.scope, "server", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - - char scopeStr[64] = {0}; - getSlowLogScopeString(tsSlowLogScope, scopeStr); - tstrncpy(info.name, "slowLogScope", sizeof(info.name)); - (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%s", scopeStr); - tstrncpy(info.scope, "server", sizeof(info.scope)); - if (taosArrayPush(rsp.variables, &info) == NULL) { - code = terrno; - goto _OVER; - } - int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp); void *pRsp = rpcMallocCont(rspLen); if (pRsp == NULL) { @@ -950,6 +873,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { } if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) { + rpcFreeCont(pRsp); code = rspLen; goto _OVER; } From 8a2ae888cc1e58845c4e2e985ca936917ec70d41 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Mon, 16 Dec 2024 15:41:19 +0800 Subject: [PATCH 8/8] fix ci errors. --- source/dnode/mnode/impl/src/mndFunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 6e8c877126..1b0132ce9c 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -723,7 +723,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } char varLang[TSDB_TYPE_STR_MAX_LEN + 1] = {0}; varDataSetLen(varLang, strlen(language)); - tstrncpy(varDataVal(varLang), language, strlen(varLang)); + tstrncpy(varDataVal(varLang), language, sizeof(varLang) - VARSTR_HEADER_SIZE); TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)varLang, false), pSdb, pFunc); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);