diff --git a/include/util/tchecksum.h b/include/util/tchecksum.h index 28fb784c46..9113861d4c 100644 --- a/include/util/tchecksum.h +++ b/include/util/tchecksum.h @@ -29,7 +29,7 @@ static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, } static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) { - if (ssize < sizeof(TSCKSUM)) return -1; + if (ssize < sizeof(TSCKSUM)) return TSDB_CODE_INVALID_PARA; *((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM))); diff --git a/source/common/src/tname.c b/source/common/src/tname.c index e495547cc5..491c203a58 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -169,7 +169,7 @@ void tNameAssign(SName* dst, const SName* src) { memcpy(dst, src, sizeof(SName)) int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t nameLen) { // too long account id or too long db name if (nameLen <= 0 || nameLen >= tListLen(dst->dbname)) { - return -1; + return TSDB_CODE_INVALID_PARA; } dst->type = TSDB_DB_NAME_T; diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 3d4067ba99..98f5615f5e 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -271,7 +271,7 @@ int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo) { if (*ppEntry) { // update if (pInfo->suid != (*ppEntry)->info.suid) { metaError("meta/cache: suid should be same as the one in cache."); - return TSDB_CODE_FAILED; + return TSDB_CODE_INVALID_PARA; } if (pInfo->version > (*ppEntry)->info.version) { (*ppEntry)->info.version = pInfo->version; @@ -543,7 +543,7 @@ int32_t metaGetCachedTableUidList(void* pVnode, tb_uid_t suid, const uint8_t* pK STagFilterResEntry** pEntry = taosHashGet(pTableMap, &suid, sizeof(uint64_t)); if (NULL == pEntry) { metaError("meta/cache: pEntry should not be NULL."); - return TSDB_CODE_FAILED; + return TSDB_CODE_NOT_FOUND; } *acquireRes = 1; @@ -750,7 +750,7 @@ int32_t metaGetCachedTbGroup(void* pVnode, tb_uid_t suid, const uint8_t* pKey, i STagFilterResEntry** pEntry = taosHashGet(pTableMap, &suid, sizeof(uint64_t)); if (NULL == pEntry) { metaDebug("suid %" PRIu64 " not in tb group cache", suid); - return TSDB_CODE_FAILED; + return TSDB_CODE_NOT_FOUND; } *pList = taosArrayDup(taosLRUCacheValue(pCache, pHandle), NULL); diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c index 1fba59c9b2..7db66cf47c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c @@ -139,7 +139,7 @@ int32_t getPosInBlockInfoBuf(SBlockInfoBuf* pBuf, int32_t index, STableBlockScan int32_t bucketIndex = index / pBuf->numPerBucket; char** pBucket = taosArrayGet(pBuf->pData, bucketIndex); if (pBucket == NULL) { - return TSDB_CODE_FAILED; + return TSDB_CODE_NOT_FOUND; } *pInfo = (STableBlockScanInfo*)((*pBucket) + (index % pBuf->numPerBucket) * sizeof(STableBlockScanInfo)); diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index e2db87173d..1f2cf707f3 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -301,8 +301,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { #if defined(TD_ENTERPRISE) if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) { if (tsEncryptKey[0] == 0) { - terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; - return -1; + return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; } else { strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index cfaf155276..8fcbe49f9a 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -413,9 +413,9 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { pInfo->info.state.commitID, pInfo->info.state.committed, pInfo->info.state.commitTerm); // persist wal before starting - if (walPersist(pVnode->pWal) < 0) { - vError("vgId:%d, failed to persist wal since %s", TD_VID(pVnode), terrstr()); - return -1; + if ((code = walPersist(pVnode->pWal)) < 0) { + vError("vgId:%d, failed to persist wal since %s", TD_VID(pVnode), tstrerror(code)); + return code; } (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); @@ -556,7 +556,6 @@ int vnodeDecodeInfo(uint8_t *pData, SVnodeInfo *pInfo) { pJson = tjsonParse(pData); if (pJson == NULL) { TSDB_CHECK_CODE(code = TSDB_CODE_INVALID_DATA_FMT, lino, _exit); - return -1; } code = tjsonToObject(pJson, "config", vnodeDecodeConfig, (void *)&pInfo->config); diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 4f5d7c24e1..ed008d4f88 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -39,13 +39,14 @@ static int32_t vnodeMkDir(STfs *pTfs, const char *path) { } int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs *pTfs) { + int32_t code = 0; SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; // check config - if (vnodeCheckCfg(pCfg) < 0) { - vError("vgId:%d, failed to create vnode since:%s", pCfg->vgId, tstrerror(terrno)); - return -1; + if ((code = vnodeCheckCfg(pCfg)) < 0) { + vError("vgId:%d, failed to create vnode since:%s", pCfg->vgId, tstrerror(code)); + return code; } // create vnode env @@ -72,9 +73,9 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs } vInfo("vgId:%d, save config while create", info.config.vgId); - if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir) < 0) { - vError("vgId:%d, failed to save vnode config since %s", pCfg ? pCfg->vgId : 0, tstrerror(terrno)); - return -1; + if ((code = vnodeSaveInfo(dir, &info)) < 0 || (code = vnodeCommitInfo(dir)) < 0) { + vError("vgId:%d, failed to save vnode config since %s", pCfg ? pCfg->vgId : 0, tstrerror(code)); + return code; } vInfo("vgId:%d, vnode is created", info.config.vgId); @@ -93,7 +94,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t ret = vnodeLoadInfo(dir, &info); if (ret < 0) { vError("vgId:%d, failed to read vnode config from %s since %s", pReq->vgId, path, tstrerror(terrno)); - return -1; + return ret; } SSyncCfg *pCfg = &info.config.syncCfg; @@ -144,13 +145,13 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t ret = vnodeSaveInfo(dir, &info); if (ret < 0) { vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno)); - return -1; + return ret; } ret = vnodeCommitInfo(dir); if (ret < 0) { vError("vgId:%d, failed to commit vnode config since %s", pReq->vgId, tstrerror(terrno)); - return -1; + return ret; } vInfo("vgId:%d, vnode config is saved", info.config.vgId); @@ -226,7 +227,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod ret = vnodeLoadInfo(dir, &info); if (ret < 0) { vError("vgId:%d, failed to read vnode config from %s since %s", pReq->srcVgId, srcPath, tstrerror(terrno)); - return -1; + return ret; } vInfo("vgId:%d, alter hashrange from [%u, %u] to [%u, %u]", pReq->srcVgId, info.config.hashBegin, info.config.hashEnd, @@ -256,13 +257,13 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod ret = vnodeSaveInfo(dir, &info); if (ret < 0) { vError("vgId:%d, failed to save vnode config since %s", pReq->dstVgId, tstrerror(terrno)); - return -1; + return ret; } ret = vnodeCommitInfo(dir); if (ret < 0) { vError("vgId:%d, failed to commit vnode config since %s", pReq->dstVgId, tstrerror(terrno)); - return -1; + return ret; } vInfo("vgId:%d, rename %s to %s", pReq->dstVgId, srcPath, dstPath); @@ -270,7 +271,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod if (ret < 0) { vError("vgId:%d, failed to rename vnode from %s to %s since %s", pReq->dstVgId, srcPath, dstPath, tstrerror(terrno)); - return -1; + return ret; } vInfo("vgId:%d, vnode hashrange is altered", info.config.vgId); @@ -293,9 +294,9 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s } (void)vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); - if (vnodeLoadInfo(dir, &info) < 0) { + if ((code = vnodeLoadInfo(dir, &info)) < 0) { vError("vgId:%d, failed to read vnode config from %s since %s", srcVgId, srcPath, tstrerror(terrno)); - return -1; + return code; } if (info.config.vgId == srcVgId) { diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 36d473fe56..904b29bf43 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -545,7 +545,7 @@ int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) { SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, uid, 1); if (NULL == pCur) { qError("vnode get all table list failed"); - return TSDB_CODE_FAILED; + return terrno; } while (1) { @@ -576,7 +576,7 @@ int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) { SMCtbCursor *pCur = metaOpenCtbCursor(pVnodeObj, suid, 1); if (NULL == pCur) { qError("vnode get all table list failed"); - return TSDB_CODE_FAILED; + return terrno; } while (1) { @@ -627,7 +627,7 @@ int32_t vnodeGetStbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bo int32_t code = TSDB_CODE_SUCCESS; SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid); if (!pCur) { - return TSDB_CODE_FAILED; + return terrno; } while (1) { @@ -655,7 +655,7 @@ _exit: int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) { SMCtbCursor *pCur = metaOpenCtbCursor(pVnode, suid, 0); if (!pCur) { - return TSDB_CODE_FAILED; + return terrno; } *num = 0; @@ -757,8 +757,7 @@ int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) { SArray *suidList = NULL; if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_FAILED; + return terrno = TSDB_CODE_OUT_OF_MEMORY; } int32_t tbFilterSize = 0; @@ -774,7 +773,7 @@ int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) { (tbFilterSize && vnodeGetStbIdListByFilter(pVnode, 0, suidList, vnodeTimeSeriesFilter, pVnode) < 0)) { qError("vgId:%d, failed to get stb id list error: %s", TD_VID(pVnode), terrstr()); taosArrayDestroy(suidList); - return TSDB_CODE_FAILED; + return terrno; } *num = 0; @@ -799,7 +798,7 @@ _exit: int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) { SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0); if (!pCur) { - return TSDB_CODE_FAILED; + return terrno; } *num = 0; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 3f6ca053cd..dc84b73c10 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -1980,7 +1980,7 @@ _err: tDecoderClear(&coder); vError("vgId:%d, failed to create tsma %s:%" PRIi64 " version %" PRIi64 "for table %" PRIi64 " since %s", TD_VID(pVnode), req.indexName, req.indexUid, ver, req.tableUid, terrstr()); - return -1; + return terrno; } /** diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index d9630b56fd..31e44f5912 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -381,7 +381,7 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { if (pMsg == NULL || pMsg->pCont == NULL) { - return -1; + return TSDB_CODE_INVALID_PARA; } if (msgcb == NULL || msgcb->putToQueueFp == NULL) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index f953f50aa7..db1d61a023 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -818,7 +818,10 @@ int32_t walMetaDeserialize(SWal* pWal, const char* bytes) { int sz = cJSON_GetArraySize(pFiles); // deserialize SArray* pArray = pWal->fileInfoSet; - (void)taosArrayEnsureCap(pArray, sz); + if (taosArrayEnsureCap(pArray, sz)) { + cJSON_Delete(pRoot); + return terrno; + } for (int i = 0; i < sz; i++) { pInfoJson = cJSON_GetArrayItem(pFiles, i); @@ -841,7 +844,10 @@ int32_t walMetaDeserialize(SWal* pWal, const char* bytes) { pField = cJSON_GetObjectItem(pInfoJson, "fileSize"); if (!pField) goto _err; info.fileSize = atoll(cJSON_GetStringValue(pField)); - (void)taosArrayPush(pArray, &info); + if (!taosArrayPush(pArray, &info)) { + cJSON_Delete(pRoot); + return terrno; + } } pWal->fileInfoSet = pArray; pWal->writeCur = sz - 1; @@ -860,8 +866,8 @@ static int walFindCurMetaVer(SWal* pWal) { TdDirPtr pDir = taosOpenDir(pWal->path); if (pDir == NULL) { - wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - return -1; + wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, tstrerror(terrno)); + return terrno; } TdDirEntryPtr pDirEntry; diff --git a/source/util/src/tbloomfilter.c b/source/util/src/tbloomfilter.c index cf9d5cd79c..b20fb4bf39 100644 --- a/source/util/src/tbloomfilter.c +++ b/source/util/src/tbloomfilter.c @@ -131,16 +131,16 @@ void tBloomFilterDestroy(SBloomFilter* pBF) { } int32_t tBloomFilterEncode(const SBloomFilter* pBF, SEncoder* pEncoder) { - if (tEncodeU32(pEncoder, pBF->hashFunctions) < 0) return -1; - if (tEncodeU64(pEncoder, pBF->expectedEntries) < 0) return -1; - if (tEncodeU64(pEncoder, pBF->numUnits) < 0) return -1; - if (tEncodeU64(pEncoder, pBF->numBits) < 0) return -1; - if (tEncodeU64(pEncoder, pBF->size) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pBF->hashFunctions)); + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pBF->expectedEntries)); + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pBF->numUnits)); + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pBF->numBits)); + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pBF->size)); for (uint64_t i = 0; i < pBF->numUnits; i++) { uint64_t* pUnits = (uint64_t*)pBF->buffer; - if (tEncodeU64(pEncoder, pUnits[i]) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pUnits[i])); } - if (tEncodeDouble(pEncoder, pBF->errorRate) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeDouble(pEncoder, pBF->errorRate)); return 0; } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 9ba88b4451..780a6c94f1 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -372,7 +372,7 @@ void taosQsetThreadResume(STaosQset *qset) { } int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) { - if (queue->qset) return -1; + if (queue->qset) return TSDB_CODE_INVALID_PARA; (void)taosThreadMutexLock(&qset->mutex); diff --git a/source/util/src/tscalablebf.c b/source/util/src/tscalablebf.c index 80b633f5e8..c48cd38886 100644 --- a/source/util/src/tscalablebf.c +++ b/source/util/src/tscalablebf.c @@ -188,19 +188,19 @@ void tScalableBfDestroy(SScalableBf* pSBf) { int32_t tScalableBfEncode(const SScalableBf* pSBf, SEncoder* pEncoder) { if (!pSBf) { - if (tEncodeI32(pEncoder, 0) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, 0)); return 0; } int32_t size = taosArrayGetSize(pSBf->bfArray); - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; i++) { SBloomFilter* pBF = taosArrayGetP(pSBf->bfArray, i); - if (tBloomFilterEncode(pBF, pEncoder) < 0) return -1; + TAOS_CHECK_RETURN(tBloomFilterEncode(pBF, pEncoder)); } - if (tEncodeU32(pEncoder, pSBf->growth) < 0) return -1; - if (tEncodeU64(pEncoder, pSBf->numBits) < 0) return -1; - if (tEncodeU32(pEncoder, pSBf->maxBloomFilters) < 0) return -1; - if (tEncodeI8(pEncoder, pSBf->status) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSBf->growth)); + TAOS_CHECK_RETURN(tEncodeU64(pEncoder, pSBf->numBits)); + TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSBf->maxBloomFilters)); + TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSBf->status)); return 0; } diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index 04d903491b..6779e8dee5 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -189,12 +189,12 @@ int taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) { if (pSched == NULL) { uError("sched is not ready, msg:%p is dropped", pMsg); - return -1; + return TSDB_CODE_INVALID_PARA; } if (atomic_load_8(&pSched->stop)) { uError("sched is already stopped, msg:%p is dropped", pMsg); - return -1; + return TSDB_CODE_INVALID_PARA; } if ((ret = tsem_wait(&pSched->emptySem)) != 0) { diff --git a/source/util/src/tsimplehash.c b/source/util/src/tsimplehash.c index fddb3f354d..e39c7364b7 100644 --- a/source/util/src/tsimplehash.c +++ b/source/util/src/tsimplehash.c @@ -209,7 +209,7 @@ static int32_t tSimpleHashTableResize(SSHashObj *pHashObj) { int32_t tSimpleHashPut(SSHashObj *pHashObj, const void *key, size_t keyLen, const void *data, size_t dataLen) { if (!pHashObj || !key) { - return TSDB_CODE_FAILED; + return TSDB_CODE_INVALID_PARA; } uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);