fix: refactor return code

This commit is contained in:
kailixu 2024-07-29 11:11:51 +08:00
parent 1cf7744c74
commit 4b6bd5b43d
9 changed files with 35 additions and 32 deletions

View File

@ -33,7 +33,7 @@ void executeSQL(TAOS *taos, const char *sql) {
void checkErrorCode(TAOS_STMT *stmt, int code, const char *msg) { void checkErrorCode(TAOS_STMT *stmt, int code, const char *msg) {
if (code != 0) { if (code != 0) {
printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt)); printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt));
taos_stmt_close(stmt); (void)taos_stmt_close(stmt);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -123,7 +123,7 @@ void insertData(TAOS *taos) {
int affectedRows = taos_stmt_affected_rows(stmt); int affectedRows = taos_stmt_affected_rows(stmt);
printf("successfully inserted %d rows\n", affectedRows); printf("successfully inserted %d rows\n", affectedRows);
// close // close
taos_stmt_close(stmt); (void)taos_stmt_close(stmt);
} }
int main() { int main() {

View File

@ -33,7 +33,7 @@ void executeSQL(TAOS *taos, const char *sql) {
void checkErrorCode(TAOS_STMT *stmt, int code, const char* msg) { void checkErrorCode(TAOS_STMT *stmt, int code, const char* msg) {
if (code != 0) { if (code != 0) {
printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt)); printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt));
taos_stmt_close(stmt); (void)taos_stmt_close(stmt);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -119,7 +119,7 @@ void insertData(TAOS *taos) {
int affectedRows = taos_stmt_affected_rows(stmt); int affectedRows = taos_stmt_affected_rows(stmt);
printf("successfully inserted %d rows\n", affectedRows); printf("successfully inserted %d rows\n", affectedRows);
// close // close
taos_stmt_close(stmt); (void)taos_stmt_close(stmt);
} }
int main() { int main() {

View File

@ -59,7 +59,7 @@ int main() {
printf("total rows consumed: %d\n", nTotalRows); printf("total rows consumed: %d\n", nTotalRows);
int keep = 0; // whether to keep subscribe process int keep = 0; // whether to keep subscribe process
taos_unsubscribe(tsub, keep); (void)taos_unsubscribe(tsub, keep);
taos_close(taos); taos_close(taos);
taos_cleanup(); taos_cleanup();

View File

@ -682,7 +682,7 @@ static void ipRangeToStr(SIpV4Range *range, char *buf) {
struct in_addr addr; struct in_addr addr;
addr.s_addr = range->ip; addr.s_addr = range->ip;
uv_inet_ntop(AF_INET, &addr, buf, 32); (void)uv_inet_ntop(AF_INET, &addr, buf, 32);
if (range->mask != 32) { if (range->mask != 32) {
(void)sprintf(buf + strlen(buf), "/%d", range->mask); (void)sprintf(buf + strlen(buf), "/%d", range->mask);
} }
@ -2188,7 +2188,7 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
} }
taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len); (void)taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len);
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
} else { } else {
taosHashClear(pNewUser->readDbs); taosHashClear(pNewUser->readDbs);
@ -2204,7 +2204,7 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
} }
taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len); (void)taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len);
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
} else { } else {
taosHashClear(pNewUser->writeDbs); taosHashClear(pNewUser->writeDbs);
@ -2311,7 +2311,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
TAOS_CHECK_GOTO(mndAcquireUser(pMnode, alterReq.user, &pUser), &lino, _OVER); TAOS_CHECK_GOTO(mndAcquireUser(pMnode, alterReq.user, &pUser), &lino, _OVER);
mndAcquireUser(pMnode, pReq->info.conn.user, &pOperUser); (void)mndAcquireUser(pMnode, pReq->info.conn.user, &pOperUser);
if (pOperUser == NULL) { if (pOperUser == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_MND_NO_USER_FROM_CONN, &lino, _OVER); TAOS_CHECK_GOTO(TSDB_CODE_MND_NO_USER_FROM_CONN, &lino, _OVER);
} }
@ -2517,7 +2517,7 @@ static int32_t mndDropUser(SMnode *pMnode, SRpcMsg *pReq, SUserObj *pUser) {
mndTransDrop(pTrans); mndTransDrop(pTrans);
TAOS_RETURN(terrno); TAOS_RETURN(terrno);
} }
ipWhiteMgtRemove(pUser->user); (void)ipWhiteMgtRemove(pUser->user);
mndTransDrop(pTrans); mndTransDrop(pTrans);
TAOS_RETURN(0); TAOS_RETURN(0);
@ -2830,7 +2830,10 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i
} }
if (nodesStringToNode(value, &pAst) == 0) { if (nodesStringToNode(value, &pAst) == 0) {
nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen); if (nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen) != 0) {
sqlLen = 5;
(void)sprintf(*sql, "error");
}
nodesDestroyNode(pAst); nodesDestroyNode(pAst);
} else { } else {
sqlLen = 5; sqlLen = 5;

View File

@ -194,7 +194,7 @@ typedef enum {
#define TD_SMA_LOOPS_CHECK(n, limit) \ #define TD_SMA_LOOPS_CHECK(n, limit) \
if (++(n) > limit) { \ if (++(n) > limit) { \
sched_yield(); \ (void)sched_yield(); \
(n) = 0; \ (n) = 0; \
} }

View File

@ -257,7 +257,7 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
if (RSMA_INFO_IS_DEL(pRSmaInfo)) { if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
int32_t refVal = T_REF_VAL_GET(pRSmaInfo); int32_t refVal = T_REF_VAL_GET(pRSmaInfo);
if (refVal == 0) { if (refVal == 0) {
taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid)); (void)taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid));
} else { } else {
smaDebug( smaDebug(
"vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for " "vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for "

View File

@ -46,7 +46,7 @@ int32_t smaInit() {
old = atomic_val_compare_exchange_8(&smaMgmt.inited, 0, 2); old = atomic_val_compare_exchange_8(&smaMgmt.inited, 0, 2);
if (old != 2) break; if (old != 2) break;
if (++nLoops > 1000) { if (++nLoops > 1000) {
sched_yield(); (void)sched_yield();
nLoops = 0; nLoops = 0;
} }
} }
@ -69,7 +69,7 @@ int32_t smaInit() {
if (!smaMgmt.refHash || !smaMgmt.tmrHandle) { if (!smaMgmt.refHash || !smaMgmt.tmrHandle) {
code = terrno; code = terrno;
taosCloseRef(smaMgmt.rsetId); (void)taosCloseRef(smaMgmt.rsetId);
if (smaMgmt.refHash) { if (smaMgmt.refHash) {
taosHashCleanup(smaMgmt.refHash); taosHashCleanup(smaMgmt.refHash);
smaMgmt.refHash = NULL; smaMgmt.refHash = NULL;
@ -97,7 +97,7 @@ void smaCleanUp() {
old = atomic_val_compare_exchange_8(&smaMgmt.inited, 1, 2); old = atomic_val_compare_exchange_8(&smaMgmt.inited, 1, 2);
if (old != 2) break; if (old != 2) break;
if (++nLoops > 1000) { if (++nLoops > 1000) {
sched_yield(); (void)sched_yield();
nLoops = 0; nLoops = 0;
} }
} }
@ -130,7 +130,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
: atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv); : atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv);
if ((code = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) { if ((code = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) {
tdFreeSmaEnv(pEnv); (void)tdFreeSmaEnv(pEnv);
*ppEnv = NULL; *ppEnv = NULL;
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL) (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL)
: atomic_store_ptr(&SMA_RSMA_ENV(pSma), NULL); : atomic_store_ptr(&SMA_RSMA_ENV(pSma), NULL);
@ -179,7 +179,7 @@ static void tRSmaInfoHashFreeNode(void *data) {
if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 1)) && pItem->level) { if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 1)) && pItem->level) {
(void)taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES); (void)taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES);
} }
tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo); (void)tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo);
} }
} }
@ -207,7 +207,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
SRSmaStat *pRSmaStat = (SRSmaStat *)(*pSmaStat); SRSmaStat *pRSmaStat = (SRSmaStat *)(*pSmaStat);
pRSmaStat->pSma = (SSma *)pSma; pRSmaStat->pSma = (SSma *)pSma;
atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_INIT); atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_INIT);
tsem_init(&pRSmaStat->notEmpty, 0, 0); (void)tsem_init(&pRSmaStat->notEmpty, 0, 0);
if (!(pRSmaStat->blocks = taosArrayInit(1, sizeof(SSDataBlock)))) { if (!(pRSmaStat->blocks = taosArrayInit(1, sizeof(SSDataBlock)))) {
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
TAOS_CHECK_GOTO(code, &lino, _exit); TAOS_CHECK_GOTO(code, &lino, _exit);
@ -216,7 +216,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
(void)taosArrayPush(pRSmaStat->blocks, &datablock); (void)taosArrayPush(pRSmaStat->blocks, &datablock);
// init smaMgmt // init smaMgmt
smaInit(); TAOS_CHECK_GOTO(smaInit(), &lino, _exit);
int64_t refId = taosAddRef(smaMgmt.rsetId, pRSmaStat); int64_t refId = taosAddRef(smaMgmt.rsetId, pRSmaStat);
if (refId < 0) { if (refId < 0) {
@ -285,20 +285,20 @@ static void tdDestroyRSmaStat(void *pRSmaStat) {
} }
// step 3: // step 3:
tdRsmaStopExecutor(pSma); (void)tdRsmaStopExecutor(pSma);
// step 4: destroy the rsma info and associated fetch tasks // step 4: destroy the rsma info and associated fetch tasks
taosHashCleanup(RSMA_INFO_HASH(pStat)); taosHashCleanup(RSMA_INFO_HASH(pStat));
// step 5: free pStat // step 5: free pStat
tsem_destroy(&(pStat->notEmpty)); (void)tsem_destroy(&(pStat->notEmpty));
taosArrayDestroy(pStat->blocks); taosArrayDestroy(pStat->blocks);
taosMemoryFreeClear(pStat); taosMemoryFreeClear(pStat);
} }
} }
static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) {
tdDestroySmaState(pSmaStat, smaType); (void)tdDestroySmaState(pSmaStat, smaType);
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
taosMemoryFreeClear(pSmaStat); taosMemoryFreeClear(pSmaStat);
} }
@ -438,7 +438,7 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) {
pthread = (TdThread *)&pStat->data; pthread = (TdThread *)&pStat->data;
for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) { for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) {
tsem_post(&(pRSmaStat->notEmpty)); (void)tsem_post(&(pRSmaStat->notEmpty));
} }
for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) { for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) {

View File

@ -412,7 +412,7 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
_exit: _exit:
if (code != 0) { if (code != 0) {
tdFreeRSmaInfo(pSma, pRSmaInfo); (void)tdFreeRSmaInfo(pSma, pRSmaInfo);
} else { } else {
smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid); smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid);
} }
@ -1264,7 +1264,7 @@ _checkpoint:
if (pItem && pItem->pStreamTask) { if (pItem && pItem->pStreamTask) {
SStreamTask *pTask = pItem->pStreamTask; SStreamTask *pTask = pItem->pStreamTask;
// atomic_store_32(&pTask->pMeta->chkptNotReadyTasks, 1); // atomic_store_32(&pTask->pMeta->chkptNotReadyTasks, 1);
streamTaskSetActiveCheckpointInfo(pTask, checkpointId); (void)streamTaskSetActiveCheckpointInfo(pTask, checkpointId);
pTask->chkInfo.checkpointId = checkpointId; // 1pTask->checkpointingId; pTask->chkInfo.checkpointId = checkpointId; // 1pTask->checkpointingId;
pTask->chkInfo.checkpointVer = pItem->submitReqVer; pTask->chkInfo.checkpointVer = pItem->submitReqVer;
@ -1373,7 +1373,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
", rsetId:%d refId:%" PRIi64, ", rsetId:%d refId:%" PRIi64,
SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaRef->refId); SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaRef->refId);
if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) { if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) {
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); (void)taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
} }
tdReleaseRSmaInfo(pSma, pRSmaInfo); tdReleaseRSmaInfo(pSma, pRSmaInfo);
(void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId);
@ -1629,7 +1629,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
batchMax = TMAX(batchMax, 4); batchMax = TMAX(batchMax, 4);
} }
while (occupied || (++batchCnt < batchMax)) { // greedy mode while (occupied || (++batchCnt < batchMax)) { // greedy mode
taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock (void)taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock
int32_t qallItemSize = taosQallItemSize(pInfo->qall); int32_t qallItemSize = taosQallItemSize(pInfo->qall);
if (qallItemSize > 0) { if (qallItemSize > 0) {
if ((code = tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type)) != 0) { if ((code = tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type)) != 0) {
@ -1663,7 +1663,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
} }
if (qallItemSize > 0) { if (qallItemSize > 0) {
atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize); (void)atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize);
continue; continue;
} }
if (RSMA_NEED_FETCH(pInfo)) { if (RSMA_NEED_FETCH(pInfo)) {
@ -1673,7 +1673,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
break; break;
} }
} }
atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0); (void)atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0);
} }
} }
} else { } else {

View File

@ -123,7 +123,7 @@ static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t ver, const char *pMsg
TAOS_CHECK_EXIT(metaCreateTSma(SMA_META(pSma), ver, pCfg)); TAOS_CHECK_EXIT(metaCreateTSma(SMA_META(pSma), ver, pCfg));
// create stable to save tsma result in dstVgId // create stable to save tsma result in dstVgId
tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); (void)tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
pReq.name = (char *)tNameGetTableName(&stbFullName); pReq.name = (char *)tNameGetTableName(&stbFullName);
pReq.suid = pCfg->dstTbUid; pReq.suid = pCfg->dstTbUid;
pReq.schemaRow = pCfg->schemaRow; pReq.schemaRow = pCfg->schemaRow;
@ -283,7 +283,7 @@ static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq *
SEncoder encoder; SEncoder encoder;
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len); tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len);
tEncodeSBatchDeleteReq(&encoder, pDelReq); (void)tEncodeSBatchDeleteReq(&encoder, pDelReq);
tEncoderClear(&encoder); tEncoderClear(&encoder);
((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode); ((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode);