From 37c2fd5b08eabfbab3e58b1273c9f35decfa9ec8 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 10 Oct 2022 10:16:00 +0800 Subject: [PATCH] fix: coverity scan for sma and tfs --- source/dnode/vnode/src/sma/smaCommit.c | 2 ++ source/dnode/vnode/src/sma/smaRollup.c | 3 ++- source/dnode/vnode/src/sma/smaSnapshot.c | 6 +++++- source/libs/tfs/inc/tfsInt.h | 2 +- source/libs/tfs/src/tfs.c | 10 +++++----- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c index fb5caad269..db5f4c55b9 100644 --- a/source/dnode/vnode/src/sma/smaCommit.c +++ b/source/dnode/vnode/src/sma/smaCommit.c @@ -161,10 +161,12 @@ static int32_t tdProcessRSmaSyncPreCommitImpl(SSma *pSma) { * @return int32_t */ static int32_t tdProcessRSmaSyncCommitImpl(SSma *pSma) { +#if 0 SSmaEnv *pSmaEnv = SMA_RSMA_ENV(pSma); if (!pSmaEnv) { return TSDB_CODE_SUCCESS; } +#endif return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 27da9da02c..1ecb27c5d3 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -1935,7 +1935,8 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { int8_t oldStat = atomic_val_compare_exchange_8(RSMA_COMMIT_STAT(pRSmaStat), 0, 2); if (oldStat == 0 || ((oldStat == 2) && atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat)) < TASK_TRIGGER_STAT_PAUSED)) { - atomic_fetch_add_32(&pRSmaStat->nFetchAll, 1); + int32_t oldVal = atomic_fetch_add_32(&pRSmaStat->nFetchAll, 1); + ASSERT(oldVal >= 0); tdRSmaFetchAllResult(pSma, pInfo); if (0 == atomic_sub_fetch_32(&pRSmaStat->nFetchAll, 1)) { atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0); diff --git a/source/dnode/vnode/src/sma/smaSnapshot.c b/source/dnode/vnode/src/sma/smaSnapshot.c index 4939fce20c..db9fcde85a 100644 --- a/source/dnode/vnode/src/sma/smaSnapshot.c +++ b/source/dnode/vnode/src/sma/smaSnapshot.c @@ -373,7 +373,11 @@ int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) { // TODO: rsma1/rsma2 // qtaskinfo if (pWriter->pQTaskFWriter) { - taosRemoveFile(pWriter->pQTaskFWriter->fname); + if (taosRemoveFile(pWriter->pQTaskFWriter->fname) != 0) { + smaWarn("vgId:%d, vnode snapshot rsma writer failed to remove %s since %s", SMA_VID(pWriter->pSma), + pWriter->pQTaskFWriter->fname ? pWriter->pQTaskFWriter->fname : "NULL", + terrstr(TAOS_SYSTEM_ERROR(errno))); + } } } else { // rsma1/rsma2 diff --git a/source/libs/tfs/inc/tfsInt.h b/source/libs/tfs/inc/tfsInt.h index 2a508cf676..8e77dc8c0c 100644 --- a/source/libs/tfs/inc/tfsInt.h +++ b/source/libs/tfs/inc/tfsInt.h @@ -57,7 +57,7 @@ typedef struct { typedef struct STfsDir { SDiskIter iter; SDiskID did; - char dirname[TSDB_FILENAME_LEN]; + char dirName[TSDB_FILENAME_LEN]; STfsFile tfile; TdDirPtr pDir; STfs *pTfs; diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 4600e5e568..a78d324622 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -332,7 +332,7 @@ STfsDir *tfsOpendir(STfs *pTfs, const char *rname) { SDiskID diskId = {.id = 0, .level = 0}; pDir->iter.pDisk = TFS_DISK_AT(pTfs, diskId); pDir->pTfs = pTfs; - tstrncpy(pDir->dirname, rname, TSDB_FILENAME_LEN); + tstrncpy(pDir->dirName, rname, TSDB_FILENAME_LEN); if (tfsOpendirImpl(pTfs, pDir) < 0) { taosMemoryFree(pDir); @@ -354,10 +354,10 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) { char *name = taosGetDirEntryName(pDirEntry); if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue; - if (pTfsDir->dirname == NULL || pTfsDir->dirname[0] == 0) { + if (pTfsDir->dirName == NULL || pTfsDir->dirName[0] == 0) { snprintf(bname, TMPNAME_LEN * 2, "%s", name); } else { - snprintf(bname, TMPNAME_LEN * 2, "%s%s%s", pTfsDir->dirname, TD_DIRSEP, name); + snprintf(bname, TMPNAME_LEN * 2, "%s%s%s", pTfsDir->dirName, TD_DIRSEP, name); } tfsInitFile(pTfsDir->pTfs, &pTfsDir->tfile, pTfsDir->did, bname); @@ -523,9 +523,9 @@ static int32_t tfsOpendirImpl(STfs *pTfs, STfsDir *pTfsDir) { pTfsDir->did.id = pDisk->id; if (pDisk->path == NULL || pDisk->path[0] == 0) { - snprintf(adir, TMPNAME_LEN * 2, "%s", pTfsDir->dirname); + snprintf(adir, TMPNAME_LEN * 2, "%s", pTfsDir->dirName); } else { - snprintf(adir, TMPNAME_LEN * 2, "%s%s%s", pDisk->path, TD_DIRSEP, pTfsDir->dirname); + snprintf(adir, TMPNAME_LEN * 2, "%s%s%s", pDisk->path, TD_DIRSEP, pTfsDir->dirName); } pTfsDir->pDir = taosOpenDir(adir); if (pTfsDir->pDir != NULL) break; -- GitLab