From ebe7276c2c9f57e8d222a9bca80af87e94ba6527 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 25 Jul 2024 17:15:41 +0800 Subject: [PATCH 01/17] fix:[TD-31017]process return value in client for tmq --- include/util/tutil.h | 3 + source/client/src/clientEnv.c | 9 +- source/client/src/clientImpl.c | 4 +- source/client/src/clientMonitor.c | 147 ++++++++------- source/client/src/clientMonitorSlow.c | 2 +- source/client/src/clientMonitorSql.c | 2 +- source/client/src/clientMsgHandler.c | 245 ++++++++++++++++--------- source/client/src/clientStmt.c | 103 +++++++---- source/client/src/clientTmqConnector.c | 8 +- source/libs/parser/src/parInsertStmt.c | 8 + 10 files changed, 331 insertions(+), 200 deletions(-) diff --git a/include/util/tutil.h b/include/util/tutil.h index 305af76dea..cd40daf8aa 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -152,6 +152,9 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, #define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member))) +#define TAOS_GET_TERRNO(code) \ + (terrno == 0 ? code : terrno) + #define TAOS_RETURN(CODE) \ do { \ return (terrno = (CODE)); \ diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index f640618897..4153282489 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -162,7 +162,7 @@ static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_ data.clusterId = pTscObj->pAppInfo->clusterId; data.type = SLOW_LOG_WRITE; data.data = value; - if(monitorPutData2MonitorQueue(data) < 0){ + if(monitorPutData2MonitorQueue(data) != 0){ taosMemoryFree(value); } @@ -479,7 +479,10 @@ void *createRequest(uint64_t connId, int32_t type, int64_t reqid) { pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE; - tsem_init(&pRequest->body.rspSem, 0, 0); + if (tsem2_init(&pRequest->body.rspSem, 0, 0) != 0) { + doDestroyRequest(pRequest); + return NULL; + } if (registerRequest(pRequest, pTscObj)) { doDestroyRequest(pRequest); @@ -601,7 +604,7 @@ void doDestroyRequest(void *p) { taosMemoryFreeClear(pRequest->msgBuf); doFreeReqResultInfo(&pRequest->body.resInfo); - tsem_destroy(&pRequest->body.rspSem); + (void)tsem2_destroy(&pRequest->body.rspSem); taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->targetTableList); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 3fb61b6902..26e5d83b56 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -324,7 +324,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { int64_t transporterId = 0; asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg); - tsem_wait(&pRequest->body.rspSem); + (void)tsem2_wait(&pRequest->body.rspSem); return TSDB_CODE_SUCCESS; } @@ -1427,7 +1427,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t int64_t transporterId = 0; asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); - tsem_wait(&pRequest->body.rspSem); + (void)tsem_wait(&pRequest->body.rspSem); if (pRequest->code != TSDB_CODE_SUCCESS) { const char* errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code); diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index e3b073dbc8..d47b074658 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -21,13 +21,10 @@ SHashObj* monitorSlowLogHash; char tmpSlowLogPath[PATH_MAX] = {0}; static int32_t getSlowLogTmpDir(char* tmpPath, int32_t size) { - if (tsTempDir == NULL) { - return -1; - } int ret = snprintf(tmpPath, size, "%s/tdengine_slow_log/", tsTempDir); if (ret < 0) { tscError("failed to get tmp path ret:%d", ret); - return ret; + return TSDB_CODE_TSC_INTERNAL_ERROR; } return 0; } @@ -71,10 +68,9 @@ static void destroyMonitorClient(void* data) { if (pMonitor == NULL) { return; } - taosTmrStopA(&pMonitor->timer); + (void)taosTmrStopA(&pMonitor->timer); taosHashCleanup(pMonitor->counters); - taos_collector_registry_destroy(pMonitor->registry); - // taos_collector_destroy(pMonitor->colector); + (void)taos_collector_registry_destroy(pMonitor->registry); taosMemoryFree(pMonitor); } @@ -142,15 +138,17 @@ static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITO void* buf = taosMemoryMalloc(tlen); if (buf == NULL) { tscError("sendReport failed, out of memory, len:%d", tlen); - terrno = TSDB_CODE_OUT_OF_MEMORY; goto FAILED; } - tSerializeSStatisReq(buf, tlen, &sStatisReq); + tlen = tSerializeSStatisReq(buf, tlen, &sStatisReq); + if (tlen < 0) { + taosMemoryFree(buf); + goto FAILED; + } SMsgSendInfo* pInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (pInfo == NULL) { tscError("sendReport failed, out of memory send info"); - terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(buf); goto FAILED; } @@ -168,12 +166,12 @@ static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITO FAILED: monitorFreeSlowLogDataEx(param); - return -1; + return TAOS_GET_TERRNO(TSDB_CODE_TSC_INTERNAL_ERROR); } static void generateClusterReport(taos_collector_registry_t* registry, void* pTransporter, SEpSet* epSet) { char ts[50] = {0}; - sprintf(ts, "%" PRId64, taosGetTimestamp(TSDB_TIME_PRECISION_MILLI)); + (void)sprintf(ts, "%" PRId64, taosGetTimestamp(TSDB_TIME_PRECISION_MILLI)); char* pCont = (char*)taos_collector_registry_bridge_new(registry, ts, "%" PRId64, NULL); if (NULL == pCont) { tscError("generateClusterReport failed, get null content."); @@ -181,7 +179,7 @@ static void generateClusterReport(taos_collector_registry_t* registry, void* pTr } if (strlen(pCont) != 0 && sendReport(pTransporter, epSet, pCont, MONITOR_TYPE_COUNTER, NULL) == 0) { - taos_collector_registry_clear_batch(registry); + (void)taos_collector_registry_clear_batch(registry); } taosMemoryFreeClear(pCont); } @@ -202,7 +200,7 @@ static void reportSendProcess(void* param, void* tmrId) { SEpSet ep = getEpSet_s(&pInst->mgmtEp); generateClusterReport(pMonitor->registry, pInst->pTransporter, &ep); - taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId); + (void)taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId); taosRUnLockLatch(&monitorLock); } @@ -257,7 +255,6 @@ void monitorCreateClient(int64_t clusterId) { tscError("failed to create monitor counters"); goto fail; } - // taosHashSetFreeFp(pMonitor->counters, destroyCounter); if (taosHashPut(monitorCounterHash, &clusterId, LONG_BYTES, &pMonitor, POINTER_BYTES) != 0) { tscError("failed to put monitor client to hash"); @@ -300,10 +297,14 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* taos_counter_t* newCounter = taos_counter_new(name, help, label_key_count, label_keys); if (newCounter == NULL) return; MonitorClient* pMonitor = *ppMonitor; - taos_collector_add_metric(pMonitor->colector, newCounter); + if (taos_collector_add_metric(pMonitor->colector, newCounter) != 0){ + tscError("failed to add metric to collector"); + (void)taos_counter_destroy(newCounter); + goto end; +} if (taosHashPut(pMonitor->counters, name, strlen(name), &newCounter, POINTER_BYTES) != 0) { tscError("failed to put counter to monitor"); - taos_counter_destroy(newCounter); + (void)taos_counter_destroy(newCounter); goto end; } tscInfo("[monitor] monitorCreateClientCounter %" PRIx64 "(%p):%s : %p.", pMonitor->clusterId, pMonitor, name, @@ -332,7 +333,10 @@ void monitorCounterInc(int64_t clusterId, const char* counterName, const char** tscError("monitorCounterInc not found pCounter %" PRIx64 ":%s.", clusterId, counterName); goto end; } - taos_counter_inc(*ppCounter, label_values); + if (taos_counter_inc(*ppCounter, label_values) != 0){ + tscError("monitorCounterInc failed to inc %" PRIx64 ":%s.", clusterId, counterName); + goto end; + } tscDebug("[monitor] monitorCounterInc %" PRIx64 "(%p):%s", pMonitor->clusterId, pMonitor, counterName); end: @@ -360,24 +364,23 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP tscInfo("[monitor] create slow log file:%s", path); pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - tscError("failed to open file:%s since %s", path, terrstr()); + tscError("failed to open file:%s since %d", path, errno); return; } SlowLogClient* pClient = taosMemoryCalloc(1, sizeof(SlowLogClient)); if (pClient == NULL) { tscError("failed to allocate memory for slow log client"); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return; } pClient->lastCheckTime = taosGetMonoTimestampMs(); - strcpy(pClient->path, path); + (void)strcpy(pClient->path, path); pClient->offset = 0; pClient->pFile = pFile; if (taosHashPut(monitorSlowLogHash, &slowLogData->clusterId, LONG_BYTES, &pClient, POINTER_BYTES) != 0) { tscError("failed to put clusterId:%" PRId64 " to hash table", slowLogData->clusterId); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); taosMemoryFree(pClient); return; } @@ -423,7 +426,7 @@ static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) { return NULL; } char* buf = pCont; - strcat(buf++, "["); + (void)strcat(buf++, "["); int64_t readSize = taosReadFile(pFile, buf, SLOW_LOG_SEND_SIZE_MAX); if (readSize <= 0) { if (readSize < 0) { @@ -454,7 +457,7 @@ static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) { static int64_t getFileSize(char* path) { int64_t fileSize = 0; if (taosStatFile(path, &fileSize, NULL, NULL) < 0) { - return -1; + return TSDB_CODE_TSC_INTERNAL_ERROR; } return fileSize; @@ -464,13 +467,13 @@ static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64 char* fileName, void* pTransporter, SEpSet* epSet) { if (data == NULL) { taosMemoryFree(fileName); - return -1; + return TSDB_CODE_INVALID_PARA; } MonitorSlowLogData* pParam = taosMemoryMalloc(sizeof(MonitorSlowLogData)); if (pParam == NULL) { taosMemoryFree(data); taosMemoryFree(fileName); - return -1; + return terrno; } pParam->data = data; pParam->offset = offset; @@ -486,7 +489,7 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs SAppInstInfo* pInst = getAppInstByClusterId(clusterId); if (pInst == NULL) { tscError("failed to get app instance by clusterId:%" PRId64, clusterId); - return -1; + return terrno; } SEpSet ep = getEpSet_s(&pInst->mgmtEp); char* data = readFile(pFile, offset, size); @@ -495,13 +498,20 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs } static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, TdFilePtr pFile, int64_t offset) { + if (fileName == NULL){ + return; + } int64_t size = getFileSize(*fileName); if (size <= offset) { processFileInTheEnd(pFile, *fileName); tscDebug("[monitor] monitorSendSlowLogAtBeginning delete file:%s", *fileName); } else { int32_t code = monitorReadSend(clusterId, pFile, &offset, size, SLOW_LOG_READ_BEGINNIG, *fileName); - tscDebug("[monitor] monitorSendSlowLogAtBeginning send slow log clusterId:%" PRId64 ",ret:%d", clusterId, code); + if (code == 0){ + tscDebug("[monitor] monitorSendSlowLogAtBeginning send slow log succ, clusterId:%" PRId64, clusterId); + }else{ + tscError("[monitor] monitorSendSlowLogAtBeginning send slow log failed, clusterId:%" PRId64 ",ret:%d", clusterId, code); + } *fileName = NULL; } } @@ -509,10 +519,12 @@ static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, Td static void monitorSendSlowLogAtRunning(int64_t clusterId) { void* tmp = taosHashGet(monitorSlowLogHash, &clusterId, LONG_BYTES); if (tmp == NULL) { + tscError("failed to get slow log client by clusterId:%" PRId64, clusterId); return; } SlowLogClient* pClient = (*(SlowLogClient**)tmp); if (pClient == NULL) { + tscError("failed to get slow log client by clusterId:%" PRId64, clusterId); return; } int64_t size = getFileSize(pClient->path); @@ -574,14 +586,16 @@ static void monitorSendAllSlowLogAtQuit() { } static void processFileRemoved(SlowLogClient* pClient) { - taosUnLockFile(pClient->pFile); - taosCloseFile(&(pClient->pFile)); + if (taosUnLockFile(pClient->pFile) != 0) { + tscError("failed to unlock file:%s since %d", pClient->path, errno); + return; + } + (void)taosCloseFile(&(pClient->pFile)); TdFilePtr pFile = taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - tscError("failed to open file:%s since %s", pClient->path, terrstr()); + tscError("failed to open file:%s since %d", pClient->path, errno); } else { pClient->pFile = pFile; } @@ -594,7 +608,7 @@ static void monitorSendAllSlowLog() { int64_t* clusterId = (int64_t*)taosHashGetKey(pIter, NULL); SAppInstInfo* pInst = getAppInstByClusterId(*clusterId); SlowLogClient* pClient = (*(SlowLogClient**)pIter); - if (pClient == NULL) { + if (pClient == NULL || pInst == NULL) { taosHashCancelIterate(monitorSlowLogHash, pIter); return; } @@ -604,7 +618,7 @@ static void monitorSendAllSlowLog() { continue; } - if (pInst != NULL && pClient->offset == 0) { + if (pClient->offset == 0) { int64_t size = getFileSize(pClient->path); if (size <= 0) { if (size < 0) { @@ -657,7 +671,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) { } char filename[PATH_MAX] = {0}; - snprintf(filename, sizeof(filename), "%s%s", tmpPath, name); + (void)snprintf(filename, sizeof(filename), "%s%s", tmpPath, name); TdFilePtr pFile = taosOpenFile(filename, TD_FILE_READ | TD_FILE_WRITE); if (pFile == NULL) { tscError("failed to open file:%s since %s", filename, terrstr()); @@ -665,7 +679,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) { } if (taosLockFile(pFile) < 0) { tscError("failed to lock file:%s since %s, maybe used by other process", filename, terrstr()); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); continue; } char* tmp = taosStrdup(filename); @@ -673,7 +687,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) { taosMemoryFree(tmp); } - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); } static void* monitorThreadFunc(void* param) { @@ -707,7 +721,7 @@ static void* monitorThreadFunc(void* param) { } MonitorSlowLogData* slowLogData = NULL; - taosReadQitem(monitorQueue, (void**)&slowLogData); + (void)taosReadQitem(monitorQueue, (void**)&slowLogData); if (slowLogData != NULL) { if (slowLogData->type == SLOW_LOG_READ_BEGINNIG) { if (slowLogData->pFile != NULL) { @@ -735,7 +749,7 @@ static void* monitorThreadFunc(void* param) { if (quitCnt == 0) { monitorSendAllSlowLog(); } - tsem2_timewait(&monitorSem, 100); + (void)tsem2_timewait(&monitorSem, 100); } atomic_store_32(&slowLogFlag, -2); return NULL; @@ -743,12 +757,19 @@ static void* monitorThreadFunc(void* param) { static int32_t tscMonitortInit() { TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + if (taosThreadAttrInit(&thAttr) != 0) { + tscError("failed to init thread attr since %s", strerror(errno)); + return TSDB_CODE_TSC_INTERNAL_ERROR; + } + if (taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE) != 0) { + tscError("failed to set thread attr since %s", strerror(errno)); + return TSDB_CODE_TSC_INTERNAL_ERROR; + } + TdThread monitorThread; if (taosThreadCreate(&monitorThread, &thAttr, monitorThreadFunc, NULL) != 0) { tscError("failed to create monitor thread since %s", strerror(errno)); - return -1; + return TSDB_CODE_TSC_INTERNAL_ERROR; } taosThreadAttrDestroy(&thAttr); @@ -767,15 +788,14 @@ static void tscMonitorStop() { } int32_t monitorInit() { - int32_t code; + int32_t code = 0; tscInfo("[monitor] tscMonitor init"); monitorCounterHash = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (monitorCounterHash == NULL) { tscError("failed to create monitorCounterHash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } taosHashSetFreeFp(monitorCounterHash, destroyMonitorClient); @@ -783,46 +803,39 @@ int32_t monitorInit() { (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (monitorSlowLogHash == NULL) { tscError("failed to create monitorSlowLogHash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } taosHashSetFreeFp(monitorSlowLogHash, destroySlowLogClient); monitorTimer = taosTmrInit(0, 0, 0, "MONITOR"); if (monitorTimer == NULL) { tscError("failed to create monitor timer"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } - if (getSlowLogTmpDir(tmpSlowLogPath, sizeof(tmpSlowLogPath)) < 0) { - terrno = TSDB_CODE_TSC_INTERNAL_ERROR; - return -1; + code = getSlowLogTmpDir(tmpSlowLogPath, sizeof(tmpSlowLogPath)); + if (code != 0) { + return code; } if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) { tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr()); - return terrno; + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } if (tsem2_init(&monitorSem, 0, 0) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); tscError("sem init error since %s", terrstr()); - return -1; + return TAOS_SYSTEM_ERROR(errno); } code = taosOpenQueue(&monitorQueue); if (code) { - terrno = code; tscError("open queue error since %s", terrstr()); - return -1; + return TAOS_GET_TERRNO(code); } taosInitRWLatch(&monitorLock); - if (tscMonitortInit() != 0) { - return -1; - } - return 0; + return tscMonitortInit(); } void monitorClose() { @@ -838,13 +851,13 @@ void monitorClose() { taosHashCleanup(monitorSlowLogHash); taosTmrCleanUp(monitorTimer); taosCloseQueue(monitorQueue); - tsem2_destroy(&monitorSem); + (void)tsem2_destroy(&monitorSem); taosWUnLockLatch(&monitorLock); } int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) { - int32_t code; - MonitorSlowLogData* slowLogData; + int32_t code = 0; + MonitorSlowLogData* slowLogData = NULL; if (atomic_load_32(&slowLogFlag) == -2) { tscError("[monitor] slow log thread is exiting"); @@ -854,13 +867,13 @@ int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) { code = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0, (void**)&slowLogData); if (code) { tscError("[monitor] failed to allocate slow log data"); - return terrno = code; + return code; } *slowLogData = data; tscDebug("[monitor] write slow log to queue, clusterId:%" PRIx64 " type:%s, data:%s", slowLogData->clusterId, queueTypeStr[slowLogData->type], slowLogData->data); if (taosWriteQitem(monitorQueue, slowLogData) == 0) { - tsem2_post(&monitorSem); + (void)tsem2_post(&monitorSem); } else { monitorFreeSlowLogData(slowLogData); taosFreeQitem(slowLogData); diff --git a/source/client/src/clientMonitorSlow.c b/source/client/src/clientMonitorSlow.c index 192792f43e..5945f28884 100644 --- a/source/client/src/clientMonitorSlow.c +++ b/source/client/src/clientMonitorSlow.c @@ -69,7 +69,7 @@ void slowQueryLog(int64_t rid, bool killed, int32_t code, int32_t cost) { } else { clientSlowQueryLog(pTscObj->pAppInfo->clusterId, pTscObj->user, result, cost); } - releaseTscObj(rid); + (void)releaseTscObj(rid); } else { tscLog("slowQueryLog, not found rid"); } diff --git a/source/client/src/clientMonitorSql.c b/source/client/src/clientMonitorSql.c index 19d5b7506e..2556cf123a 100644 --- a/source/client/src/clientMonitorSql.c +++ b/source/client/src/clientMonitorSql.c @@ -65,7 +65,7 @@ void sqlReqLog(int64_t rid, bool killed, int32_t code, int8_t type) { } else { clientSQLReqLog(pTscObj->pAppInfo->clusterId, pTscObj->user, result, type); } - releaseTscObj(rid); + (void)releaseTscObj(rid); } else { tscLog("sqlReqLog, not found rid"); } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index d587deffc5..1e8c2720bf 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -40,7 +40,10 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + code = removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + if (code != 0){ + setErrno(pRequest, code); + } } taosMemoryFree(pMsg->pEpSet); @@ -48,7 +51,7 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } @@ -61,7 +64,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } @@ -70,7 +73,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (NULL == pTscObj->pAppInfo) { code = TSDB_CODE_TSC_DISCONNECTED; setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } @@ -78,14 +81,14 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) { code = TSDB_CODE_TSC_INVALID_VERSION; setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 3)) != 0) { tscError("version not compatible. client version: %s, server version: %s", version, connectRsp.sVer); setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } @@ -95,14 +98,14 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { code = TSDB_CODE_TIME_UNSYNCED; tscError("time diff:%ds is too big", delta); setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } if (connectRsp.epSet.numOfEps == 0) { code = TSDB_CODE_APP_ERROR; setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } @@ -111,8 +114,13 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { SEpSet srcEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); SEpSet dstEpSet = connectRsp.epSet; if (srcEpSet.numOfEps == 1) { - rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, + code = rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, dstEpSet.eps[dstEpSet.inUse].fqdn); + if (code != 0){ + setErrno(pRequest, code); + (void)tsem2_post(&pRequest->body.rspSem); + goto End; + } updateEpSet = 0; } } @@ -158,7 +166,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { MonitorSlowLogData data = {0}; data.clusterId = pTscObj->pAppInfo->clusterId; data.type = SLOW_LOG_READ_BEGINNIG; - monitorPutData2MonitorQueue(data); + (void)monitorPutData2MonitorQueue(data); monitorClientSlowQueryInit(connectRsp.clusterId); monitorClientSQLReqInit(connectRsp.clusterId); } @@ -167,12 +175,17 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { taosThreadMutexLock(&clientHbMgr.lock); SAppHbMgr* pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, pTscObj->appHbMgrIdx); if (pAppHbMgr) { - hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); + code = hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); + if (code != 0){ + setErrno(pRequest, code); + (void)tsem2_post(&pRequest->body.rspSem); + goto End; + } } else { taosThreadMutexUnlock(&clientHbMgr.lock); code = TSDB_CODE_TSC_DISCONNECTED; setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); goto End; } taosThreadMutexUnlock(&clientHbMgr.lock); @@ -180,7 +193,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); End: if (pRequest) { @@ -216,7 +229,7 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); } else { struct SCatalog* pCatalog = NULL; - int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (TSDB_CODE_SUCCESS == code) { STscObj* pTscObj = pRequest->pTscObj; @@ -225,28 +238,39 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { .requestObjRefId = pRequest->self, .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; char dbFName[TSDB_DB_FNAME_LEN]; - snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); + code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + } + if (code == TSDB_CODE_SUCCESS) { + (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); + code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + } + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + } } } if (pRequest->body.queryFp) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; + SUseDbRsp usedbRsp = {0}; + code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if (code != 0){ + goto END; + } if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { - SUseDbRsp usedbRsp = {0}; - tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); struct SCatalog* pCatalog = NULL; if (usedbRsp.vgVersion >= 0) { // cached in local @@ -256,42 +280,35 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1)); } else { - catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); + code = catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); + if (code != 0){ + goto END; + } } } - tFreeSUsedbRsp(&usedbRsp); } if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pMsg->pData); - taosMemoryFree(pMsg->pEpSet); - setErrno(pRequest, code); - - if (pRequest->body.queryFp != NULL) { - doRequestCallback(pRequest, pRequest->code); - - } else { - tsem_post(&pRequest->body.rspSem); - } - - return code; + goto END; } - SUseDbRsp usedbRsp = {0}; - tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { - return usedbRsp.errCode; + code = usedbRsp.errCode; } else { - return TSDB_CODE_APP_ERROR; + code = TSDB_CODE_APP_ERROR; } + goto END; } tscTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum); for (int32_t i = 0; i < usedbRsp.vgNum; ++i) { SVgroupInfo* pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i); + if (pInfo == NULL){ + code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + goto END; + } tscTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse); for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) { tscTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port); @@ -299,11 +316,13 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SName name = {0}; - tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); + code = tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); + if (code != 0){ + goto END; + } SUseDbOutput output = {0}; code = queryBuildUseDbOutput(&output, &usedbRsp); - if (code != 0) { terrno = code; if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash); @@ -317,28 +336,32 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); } else { - catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); - output.dbVgroup = NULL; + code = catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + if (code == 0){ + output.dbVgroup = NULL; + } } } taosMemoryFreeClear(output.dbVgroup); - tFreeSUsedbRsp(&usedbRsp); - char db[TSDB_DB_NAME_LEN] = {0}; - tNameGetDbName(&name, db); + (void)tNameGetDbName(&name, db); setConnectionDB(pRequest->pTscObj, db); + +END: + setErrno(pRequest, code); + tFreeSUsedbRsp(&usedbRsp); taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, pRequest->code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } - return 0; + return code; } int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { @@ -353,7 +376,10 @@ int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { SMCreateStbRsp createRsp = {0}; SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); - tDecodeSMCreateStbRsp(&coder, &createRsp); + code = tDecodeSMCreateStbRsp(&coder, &createRsp); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + } tDecoderClear(&coder); pRequest->body.resInfo.execRes.msgType = TDMT_MND_CREATE_STB; @@ -380,7 +406,7 @@ int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } @@ -391,33 +417,49 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); } else { SDropDbRsp dropdbRsp = {0}; - tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); - + code = tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + goto END; + } struct SCatalog* pCatalog = NULL; - int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (TSDB_CODE_SUCCESS == code) { - catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); + code = catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + goto END; + } STscObj* pTscObj = pRequest->pTscObj; SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self, .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; - char dbFName[TSDB_DB_FNAME_LEN]; - snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); + code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + goto END; + } + (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); + code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + goto END; + } } } +END: taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } @@ -430,7 +472,10 @@ int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) { SMAlterStbRsp alterRsp = {0}; SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); - tDecodeSMAlterStbRsp(&coder, &alterRsp); + code = tDecodeSMAlterStbRsp(&coder, &alterRsp); + if (code != 0){ + setErrno(pRequest, TAOS_GET_TERRNO(code)); + } tDecoderClear(&coder); pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB; @@ -457,57 +502,72 @@ int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { + int32_t code = 0; + int32_t line = 0; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + TSDB_CHECK_NULL(pBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(SHOW_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); - + TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD1_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD2_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD3_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); int32_t numOfCfg = taosArrayGetSize(pVars); - blockDataEnsureCapacity(pBlock, numOfCfg); + code = blockDataEnsureCapacity(pBlock, numOfCfg); + TSDB_CHECK_CODE(code, line, END); for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { SVariablesInfo* pInfo = taosArrayGet(pVars, i); + TSDB_CHECK_NULL(pInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(name, pInfo->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - colDataSetVal(pColInfo, i, name, false); + TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + code = colDataSetVal(pColInfo, i, name, false); + TSDB_CHECK_CODE(code, line, END); char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(value, pInfo->value, TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - colDataSetVal(pColInfo, i, value, false); + TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + code = colDataSetVal(pColInfo, i, value, false); + TSDB_CHECK_CODE(code, line, END); char scope[TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(scope, pInfo->scope, TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, c++); - colDataSetVal(pColInfo, i, scope, false); + TSDB_CHECK_NULL(pColInfo, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + code = colDataSetVal(pColInfo, i, scope, false); + TSDB_CHECK_CODE(code, line, END); } pBlock->info.rows = numOfCfg; *block = pBlock; + return code; - return TSDB_CODE_SUCCESS; +END: + taosArrayDestroy(pBlock->pDataBlock); + taosMemoryFree(pBlock); + return code; } static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) { @@ -577,55 +637,72 @@ int32_t processShowVariablesRsp(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } static int32_t buildCompactDbBlock(SCompactDbRsp* pRsp, SSDataBlock** block) { + int32_t code = 0; + int32_t line = 0; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + TSDB_CHECK_NULL(pBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(COMPACT_DB_RESULT_COLS, sizeof(SColumnInfoData)); - + TSDB_CHECK_NULL(pBlock->pDataBlock, code, line, END, TSDB_CODE_OUT_OF_MEMORY); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = COMPACT_DB_RESULT_FIELD1_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); infoData.info.type = TSDB_DATA_TYPE_INT; infoData.info.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = COMPACT_DB_RESULT_FIELD3_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, TSDB_CODE_OUT_OF_MEMORY); - blockDataEnsureCapacity(pBlock, 1); + code = blockDataEnsureCapacity(pBlock, 1); + TSDB_CHECK_CODE(code, line, END); SColumnInfoData* pResultCol = taosArrayGet(pBlock->pDataBlock, 0); + TSDB_CHECK_NULL(pResultCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); SColumnInfoData* pIdCol = taosArrayGet(pBlock->pDataBlock, 1); + TSDB_CHECK_NULL(pIdCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); SColumnInfoData* pReasonCol = taosArrayGet(pBlock->pDataBlock, 2); + TSDB_CHECK_NULL(pReasonCol, code, line, END, TSDB_CODE_OUT_OF_MEMORY); + char result[COMPACT_DB_RESULT_FIELD1_LEN] = {0}; char reason[COMPACT_DB_RESULT_FIELD3_LEN] = {0}; if (pRsp->bAccepted) { STR_TO_VARSTR(result, "accepted"); - colDataSetVal(pResultCol, 0, result, false); - colDataSetVal(pIdCol, 0, (void*)&pRsp->compactId, false); + code = colDataSetVal(pResultCol, 0, result, false); + TSDB_CHECK_CODE(code, line, END); + code = colDataSetVal(pIdCol, 0, (void*)&pRsp->compactId, false); + TSDB_CHECK_CODE(code, line, END); STR_TO_VARSTR(reason, "success"); - colDataSetVal(pReasonCol, 0, reason, false); + code = colDataSetVal(pReasonCol, 0, reason, false); + TSDB_CHECK_CODE(code, line, END); } else { STR_TO_VARSTR(result, "rejected"); - colDataSetVal(pResultCol, 0, result, false); + code = colDataSetVal(pResultCol, 0, result, false); + TSDB_CHECK_CODE(code, line, END); colDataSetNULL(pIdCol, 0); STR_TO_VARSTR(reason, "compaction is ongoing"); - colDataSetVal(pReasonCol, 0, reason, false); + code = colDataSetVal(pReasonCol, 0, reason, false); + TSDB_CHECK_CODE(code, line, END); } pBlock->info.rows = 1; *block = pBlock; return TSDB_CODE_SUCCESS; +END: + taosMemoryFree(pBlock); + taosArrayDestroy(pBlock->pDataBlock); + return code; } static int32_t buildRetriveTableRspForCompactDb(SCompactDbRsp* pCompactDb, SRetrieveTableRsp** pRsp) { @@ -696,7 +773,7 @@ int32_t processCompactDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { pRequest->body.queryFp(((SSyncQueryParam *)pRequest->body.interParam)->userParam, pRequest, code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem2_post(&pRequest->body.rspSem); } return code; } diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 17b52521b8..11c27b409d 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -14,15 +14,20 @@ static FORCE_INLINE int32_t stmtAllocQNodeFromBuf(STableBufInfo* pTblBuf, void** pTblBuf->buffOffset += pTblBuf->buffUnit; } else if (pTblBuf->buffIdx < taosArrayGetSize(pTblBuf->pBufList)) { pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, pTblBuf->buffIdx++); + if (NULL == pTblBuf->pCurBuff) { + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + } *pBuf = pTblBuf->pCurBuff; pTblBuf->buffOffset = pTblBuf->buffUnit; } else { void* buff = taosMemoryMalloc(pTblBuf->buffSize); if (NULL == buff) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } - taosArrayPush(pTblBuf->pBufList, &buff); + if(taosArrayPush(pTblBuf->pBufList, &buff) == NULL){ + return terrno; + } pTblBuf->buffIdx++; pTblBuf->pCurBuff = buff; @@ -48,7 +53,7 @@ bool stmtDequeue(STscStmt* pStmt, SStmtQNode** param) { *param = node; - atomic_sub_fetch_64(&pStmt->queue.qRemainNum, 1); + (void)atomic_sub_fetch_64(&pStmt->queue.qRemainNum, 1); return true; } @@ -58,7 +63,7 @@ void stmtEnqueue(STscStmt* pStmt, SStmtQNode* param) { pStmt->queue.tail = param; pStmt->stat.bindDataNum++; - atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); + (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); } static int32_t stmtCreateRequest(STscStmt* pStmt) { @@ -183,8 +188,8 @@ int32_t stmtBackupQueryFields(STscStmt* pStmt) { if (NULL == pRes->fields || NULL == pRes->userFields) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size); - memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size); + (void)memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size); + (void)memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size); return TSDB_CODE_SUCCESS; } @@ -201,7 +206,7 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) { if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size); + (void)memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size); } if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { @@ -209,7 +214,7 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) { if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size); + (void)memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size); } return TSDB_CODE_SUCCESS; @@ -219,10 +224,13 @@ int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags, bool autoCreateTbl) { STscStmt* pStmt = (STscStmt*)stmt; char tbFName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(tbName, tbFName); + int32_t code = tNameExtractFullName(tbName, tbFName); + if (code != 0){ + return code; + } - memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName)); - strncpy(pStmt->bInfo.tbFName, tbFName, sizeof(pStmt->bInfo.tbFName) - 1); + (void)memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName)); + (void)strncpy(pStmt->bInfo.tbFName, tbFName, sizeof(pStmt->bInfo.tbFName) - 1); pStmt->bInfo.tbFName[sizeof(pStmt->bInfo.tbFName) - 1] = 0; pStmt->bInfo.tbUid = autoCreateTbl ? 0 : pTableMeta->uid; @@ -383,17 +391,21 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) { taosMemoryFreeClear(pStmt->bInfo.boundTags); } pStmt->bInfo.stbFName[0] = 0; - ; + return TSDB_CODE_SUCCESS; } void stmtFreeTableBlkList(STableColsData* pTb) { - qResetStmtColumns(pTb->aCol, true); + (void)qResetStmtColumns(pTb->aCol, true); taosArrayDestroy(pTb->aCol); } void stmtResetQueueTableBuf(STableBufInfo* pTblBuf, SStmtQueue* pQueue) { pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, 0); + if (NULL == pTblBuf->pCurBuff) { + tscError("QInfo:%p, failed to get buffer from list", pTblBuf); + return; + } pTblBuf->buffIdx = 1; pTblBuf->buffOffset = sizeof(*pQueue->head); @@ -505,7 +517,7 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) { qDestroyStmtDataBlock(pStmt->sql.siInfo.pDataCtx); taosArrayDestroyEx(pStmt->sql.siInfo.pTableCols, stmtFreeTbCols); - memset(&pStmt->sql, 0, sizeof(pStmt->sql)); + (void)memset(&pStmt->sql, 0, sizeof(pStmt->sql)); pStmt->sql.siInfo.tableColsReady = true; STMT_DLOG_E("end to free SQL info"); @@ -726,6 +738,9 @@ int32_t stmtAsyncOutput(STscStmt* pStmt, void* param) { for (int32_t i = 0; i < pStmt->sql.siInfo.pTableColsIdx; ++i) { SArray** p = (SArray**)TARRAY_GET_ELEM(pStmt->sql.siInfo.pTableCols, i); *p = taosArrayInit(20, POINTER_BYTES); + if (*p == NULL) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } } atomic_store_8((int8_t*)&pStmt->sql.siInfo.tableColsReady, true); @@ -735,7 +750,7 @@ int32_t stmtAsyncOutput(STscStmt* pStmt, void* param) { // taosMemoryFree(pParam->pTbData); - atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); + (void)atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); } return TSDB_CODE_SUCCESS; } @@ -757,7 +772,7 @@ void* stmtBindThreadFunc(void* param) { continue; } - stmtAsyncOutput(pStmt, asyncParam); + (void)stmtAsyncOutput(pStmt, asyncParam); } qInfo("stmt bind thread stopped"); @@ -767,8 +782,12 @@ void* stmtBindThreadFunc(void* param) { int32_t stmtStartBindThread(STscStmt* pStmt) { TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + if (taosThreadAttrInit(&thAttr) != 0) { + return TSDB_CODE_TSC_INTERNAL_ERROR; + } + if (taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE) != 0) { + return TSDB_CODE_TSC_INTERNAL_ERROR; + } if (taosThreadCreate(&pStmt->bindThread, &thAttr, stmtBindThreadFunc, pStmt) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -777,7 +796,7 @@ int32_t stmtStartBindThread(STscStmt* pStmt) { pStmt->bindThreadInUse = true; - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); return TSDB_CODE_SUCCESS; } @@ -800,7 +819,9 @@ int32_t stmtInitTableBuf(STableBufInfo* pTblBuf) { return TSDB_CODE_OUT_OF_MEMORY; } - taosArrayPush(pTblBuf->pBufList, &buff); + if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL){ + return TSDB_CODE_OUT_OF_MEMORY; + } pTblBuf->pCurBuff = buff; pTblBuf->buffIdx = 1; @@ -834,7 +855,7 @@ TAOS_STMT* stmtInit(STscObj* taos, int64_t reqid, TAOS_STMT_OPTIONS* pOptions) { pStmt->errCode = TSDB_CODE_SUCCESS; if (NULL != pOptions) { - memcpy(&pStmt->options, pOptions, sizeof(pStmt->options)); + (void)memcpy(&pStmt->options, pOptions, sizeof(pStmt->options)); if (pOptions->singleStbInsert && pOptions->singleTableBindOnce) { pStmt->stbInterlaceMode = true; } @@ -848,24 +869,26 @@ TAOS_STMT* stmtInit(STscObj* taos, int64_t reqid, TAOS_STMT_OPTIONS* pOptions) { pStmt->sql.siInfo.pTableHash = tSimpleHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY)); if (NULL == pStmt->sql.siInfo.pTableHash) { terrno = TSDB_CODE_OUT_OF_MEMORY; - stmtClose(pStmt); + (void)stmtClose(pStmt); return NULL; } pStmt->sql.siInfo.pTableCols = taosArrayInit(STMT_TABLE_COLS_NUM, POINTER_BYTES); if (NULL == pStmt->sql.siInfo.pTableCols) { terrno = TSDB_CODE_OUT_OF_MEMORY; - stmtClose(pStmt); + (void)stmtClose(pStmt); return NULL; } code = stmtInitTableBuf(&pStmt->sql.siInfo.tbBuf); if (TSDB_CODE_SUCCESS == code) { - stmtInitQueue(pStmt); + code = stmtInitQueue(pStmt); + } + if (TSDB_CODE_SUCCESS == code) { code = stmtStartBindThread(pStmt); } if (TSDB_CODE_SUCCESS != code) { terrno = code; - stmtClose(pStmt); + (void)stmtClose(pStmt); return NULL; } } @@ -904,7 +927,7 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { char* dbName = NULL; if (qParseDbName(sql, length, &dbName)) { - stmtSetDbName(stmt, dbName); + STMT_ERR_RET(stmtSetDbName(stmt, dbName)); taosMemoryFreeClear(dbName); } @@ -928,7 +951,9 @@ int32_t stmtInitStbInterlaceTableInfo(STscStmt* pStmt) { return TSDB_CODE_OUT_OF_MEMORY; } - taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols); + if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols)) { + return TSDB_CODE_OUT_OF_MEMORY; + } } pStmt->sql.siInfo.boundTags = pStmt->bInfo.boundTags; @@ -977,18 +1002,18 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); - tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName); + STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName)); STMT_ERR_RET(stmtGetFromCache(pStmt)); if (pStmt->bInfo.needParse) { - strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); + (void)strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0; STMT_ERR_RET(stmtParseSql(pStmt)); } } else { - strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); + (void)strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0; pStmt->exec.pRequest->requestId++; pStmt->bInfo.needParse = false; @@ -1142,7 +1167,7 @@ int32_t stmtAppendTablePostHandle(STscStmt* pStmt, SStmtQNode* param) { param->tblData.getFromHash = pStmt->sql.siInfo.tbFromHash; param->next = NULL; - atomic_add_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); + (void)atomic_add_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); stmtEnqueue(pStmt, param); @@ -1162,7 +1187,9 @@ static FORCE_INLINE int32_t stmtGetTableColsFromCache(STscStmt* pStmt, SArray** return TSDB_CODE_OUT_OF_MEMORY; } - taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols); + if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL){ + return TSDB_CODE_OUT_OF_MEMORY; + } } } } @@ -1428,7 +1455,7 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { .requestId = pStmt->exec.pRequest->requestId, .requestObjRefId = pStmt->exec.pRequest->self, .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; - int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); + code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); pStmt->stat.ctgGetTbMetaNum++; @@ -1515,7 +1542,7 @@ int stmtExec(TAOS_STMT* stmt) { STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); if (STMT_TYPE_QUERY == pStmt->sql.type) { - launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); + (void)launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); } else { if (pStmt->sql.stbInterlaceMode) { int64_t startTs = taosGetTimestampUs(); @@ -1537,7 +1564,7 @@ int stmtExec(TAOS_STMT* stmt) { STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pBlockHash)); } - launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); + (void)launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); } if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) { @@ -1562,7 +1589,7 @@ _return: taosUsleep(1); } - stmtCleanExecInfo(pStmt, (code ? false : true), false); + STMT_ERR_RET(stmtCleanExecInfo(pStmt, (code ? false : true), false)); tFreeSSubmitRsp(pRsp); @@ -1582,7 +1609,7 @@ int stmtClose(TAOS_STMT* stmt) { pStmt->queue.stopQueue = true; if (pStmt->bindThreadInUse) { - taosThreadJoin(pStmt->bindThread, NULL); + (void)taosThreadJoin(pStmt->bindThread, NULL); pStmt->bindThreadInUse = false; } @@ -1597,7 +1624,7 @@ int stmtClose(TAOS_STMT* stmt) { pStmt->stat.bindDataUs1, pStmt->stat.bindDataUs2, pStmt->stat.bindDataUs3, pStmt->stat.bindDataUs4, pStmt->stat.addBatchUs, pStmt->stat.execWaitUs, pStmt->stat.execUseUs); - stmtCleanSQLInfo(pStmt); + STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); taosMemoryFree(stmt); return TSDB_CODE_SUCCESS; diff --git a/source/client/src/clientTmqConnector.c b/source/client/src/clientTmqConnector.c index 2bea738c23..be00ec34c9 100644 --- a/source/client/src/clientTmqConnector.c +++ b/source/client/src/clientTmqConnector.c @@ -41,7 +41,7 @@ void tmqGlobalMethod(JNIEnv *env) { } if (g_vm == NULL) { - (*env)->GetJavaVM(env, &g_vm); + (void)((*env)->GetJavaVM(env, &g_vm)); } jclass offset = (*env)->FindClass(env, "com/taosdata/jdbc/tmq/OffsetWaitCallback"); @@ -68,7 +68,7 @@ void tmqAssignmentMethod(JNIEnv *env) { } if (g_vm == NULL) { - (*env)->GetJavaVM(env, &g_vm); + (void)((*env)->GetJavaVM(env, &g_vm)); } jclass assignment = (*env)->FindClass(env, "com/taosdata/jdbc/tmq/Assignment"); @@ -104,7 +104,7 @@ void commit_cb(tmq_t *tmq, int32_t code, void *param) { param = NULL; if (needDetach) { - (*g_vm)->DetachCurrentThread(g_vm); + (void)((*g_vm)->DetachCurrentThread(g_vm)); } env = NULL; } @@ -126,7 +126,7 @@ void consumer_callback(tmq_t *tmq, int32_t code, void *param) { param = NULL; if (needDetach) { - (*g_vm)->DetachCurrentThread(g_vm); + (void)((*g_vm)->DetachCurrentThread(g_vm)); } env = NULL; } diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 2bcc7501fb..6ae6898af2 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -518,6 +518,10 @@ int32_t qResetStmtColumns(SArray* pCols, bool deepClear) { for (int32_t i = 0; i < colNum; ++i) { SColData* pCol = (SColData*)taosArrayGet(pCols, i); + if (pCol == NULL){ + qError("qResetStmtColumns column is NULL"); + return TSDB_CODE_OUT_OF_MEMORY; + } if (deepClear) { tColDataDeepClear(pCol); } else { @@ -534,6 +538,10 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) { for (int32_t i = 0; i < colNum; ++i) { SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i); + if (pCol == NULL){ + qError("qResetStmtDataBlock column is NULL"); + return TSDB_CODE_OUT_OF_MEMORY; + } if (deepClear) { tColDataDeepClear(pCol); } else { From 26f566834ae6f08aa829ff2b0bcb940cb7f1cc22 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 25 Jul 2024 19:37:39 +0800 Subject: [PATCH 02/17] fix:[TD-31017]process return value in client --- source/client/inc/clientInt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 507738acc9..4bc802f6d2 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -207,7 +207,7 @@ typedef struct SReqResultInfo { } SReqResultInfo; typedef struct SRequestSendRecvBody { - tsem_t rspSem; // not used now + tsem2_t rspSem; // not used now __taos_async_fn_t queryFp; __taos_async_fn_t fetchFp; EQueryExecMode execMode; From 8e9b81539209f467238e38db7e44aec1948ae5c6 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 25 Jul 2024 23:27:32 +0800 Subject: [PATCH 03/17] fix:[TD-31017]process return value in client --- source/client/src/clientImpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 26e5d83b56..06bb19223a 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -1427,7 +1427,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t int64_t transporterId = 0; asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); - (void)tsem_wait(&pRequest->body.rspSem); + (void)tsem2_wait(&pRequest->body.rspSem); if (pRequest->code != TSDB_CODE_SUCCESS) { const char* errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code); From 8875863d07db3b9f13c92a259f60091306273f84 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 26 Jul 2024 23:43:36 +0800 Subject: [PATCH 04/17] fix:[TD-31017]process return value in client --- source/client/inc/clientInt.h | 2 +- source/client/src/clientEnv.c | 4 ++-- source/client/src/clientImpl.c | 4 ++-- source/client/src/clientMsgHandler.c | 36 ++++++++++++++-------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 2fc43786e8..928afdaecf 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -207,7 +207,7 @@ typedef struct SReqResultInfo { } SReqResultInfo; typedef struct SRequestSendRecvBody { - tsem2_t rspSem; // not used now + tsem_t rspSem; // not used now __taos_async_fn_t queryFp; __taos_async_fn_t fetchFp; EQueryExecMode execMode; diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 7c3d7689e8..a16a779665 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -561,7 +561,7 @@ int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj goto _return; } (*pRequest)->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE; - TSC_ERR_JRET(tsem2_init(&(*pRequest)->body.rspSem, 0, 0)); + TSC_ERR_JRET(tsem_init(&(*pRequest)->body.rspSem, 0, 0)); TSC_ERR_JRET(registerRequest(*pRequest, pTscObj)); return TSDB_CODE_SUCCESS; @@ -684,7 +684,7 @@ void doDestroyRequest(void *p) { taosMemoryFreeClear(pRequest->msgBuf); doFreeReqResultInfo(&pRequest->body.resInfo); - (void)tsem2_destroy(&pRequest->body.rspSem); + (void)tsem_destroy(&pRequest->body.rspSem); taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->targetTableList); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index b5220c7f37..6a981a7eb7 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -332,7 +332,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { int64_t transporterId = 0; TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg)); - (void)tsem2_wait(&pRequest->body.rspSem); + (void)tsem_wait(&pRequest->body.rspSem); return TSDB_CODE_SUCCESS; } @@ -1563,7 +1563,7 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta tscError("failed to send connect msg to server, code:%s", tstrerror(code)); return code; } - (void)tsem2_wait(&pRequest->body.rspSem); + (void)tsem_wait(&pRequest->body.rspSem); if (pRequest->code != TSDB_CODE_SUCCESS) { const char* errorMsg = (code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code); tscError("failed to connect to server, reason: %s", errorMsg); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 1e8c2720bf..e50399bf65 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -51,7 +51,7 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -64,7 +64,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } @@ -73,7 +73,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (NULL == pTscObj->pAppInfo) { code = TSDB_CODE_TSC_DISCONNECTED; setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } @@ -81,14 +81,14 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) { code = TSDB_CODE_TSC_INVALID_VERSION; setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 3)) != 0) { tscError("version not compatible. client version: %s, server version: %s", version, connectRsp.sVer); setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } @@ -98,14 +98,14 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { code = TSDB_CODE_TIME_UNSYNCED; tscError("time diff:%ds is too big", delta); setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } if (connectRsp.epSet.numOfEps == 0) { code = TSDB_CODE_APP_ERROR; setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } @@ -118,7 +118,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { dstEpSet.eps[dstEpSet.inUse].fqdn); if (code != 0){ setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } updateEpSet = 0; @@ -178,14 +178,14 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { code = hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); if (code != 0){ setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } } else { taosThreadMutexUnlock(&clientHbMgr.lock); code = TSDB_CODE_TSC_DISCONNECTED; setErrno(pRequest, code); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); goto End; } taosThreadMutexUnlock(&clientHbMgr.lock); @@ -193,7 +193,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); End: if (pRequest) { @@ -256,7 +256,7 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -359,7 +359,7 @@ END: if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, pRequest->code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -406,7 +406,7 @@ int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -459,7 +459,7 @@ END: if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -502,7 +502,7 @@ int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -637,7 +637,7 @@ int32_t processShowVariablesRsp(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { doRequestCallback(pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } @@ -773,7 +773,7 @@ int32_t processCompactDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (pRequest->body.queryFp != NULL) { pRequest->body.queryFp(((SSyncQueryParam *)pRequest->body.interParam)->userParam, pRequest, code); } else { - (void)tsem2_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } From 7aaa7189d7033bdfecf429fe5e87fb5cb124f884 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 15:29:25 +0800 Subject: [PATCH 05/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 10 ++-------- source/dnode/mnode/impl/src/mndTrans.c | 4 ++-- tests/system-test/2-query/ttl_comment.py | 3 +++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e50399bf65..a154ff1d90 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -376,10 +376,7 @@ int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { SMCreateStbRsp createRsp = {0}; SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); - code = tDecodeSMCreateStbRsp(&coder, &createRsp); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - } + (void)tDecodeSMCreateStbRsp(&coder, &createRsp); // pMsg->len == 0 tDecoderClear(&coder); pRequest->body.resInfo.execRes.msgType = TDMT_MND_CREATE_STB; @@ -472,10 +469,7 @@ int32_t processAlterStbRsp(void* param, SDataBuf* pMsg, int32_t code) { SMAlterStbRsp alterRsp = {0}; SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); - code = tDecodeSMAlterStbRsp(&coder, &alterRsp); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - } + (void)tDecodeSMAlterStbRsp(&coder, &alterRsp); // pMsg->len = 0 tDecoderClear(&coder); pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 6417e6564e..d2a6f1eab7 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -1146,13 +1146,13 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) { } else if (pTrans->originRpcType == TDMT_MND_CREATE_STB) { void *pCont = NULL; int32_t contLen = 0; - if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen) != 0) { + if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen)) { mndTransSetRpcRsp(pTrans, pCont, contLen); } } else if (pTrans->originRpcType == TDMT_MND_CREATE_INDEX) { void *pCont = NULL; int32_t contLen = 0; - if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen) != 0) { + if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen)) { mndTransSetRpcRsp(pTrans, pCont, contLen); } } diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py index ba24579611..8d31ed8b5e 100644 --- a/tests/system-test/2-query/ttl_comment.py +++ b/tests/system-test/2-query/ttl_comment.py @@ -18,6 +18,9 @@ from util.cases import tdCases from util.sql import tdSql class TDTestCase: + clientCfgDict = {'debugFlag': 135} + updatecfgDict = {'debugFlag': 135, 'asynclog': 0} + updatecfgDict["clientCfg"] = clientCfgDict def caseDescription(self): ''' ttl/comment test From 073d7f7117238b8321383763522c9f9794f5fd53 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 25 Jul 2024 11:30:56 +0000 Subject: [PATCH 06/17] fix/TD-30989-scan1-4-2 --- source/dnode/mnode/impl/src/mndQnode.c | 18 ++++++------- source/dnode/mnode/impl/src/mndQuery.c | 7 +++-- source/dnode/mnode/impl/src/mndScheduler.c | 31 ++++++++++++++++------ source/dnode/mnode/impl/src/mndShow.c | 10 +++---- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index d6647f88f2..2e352915d8 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -224,7 +224,7 @@ int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeOb terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); + (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -252,7 +252,7 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S code = TSDB_CODE_OUT_OF_MEMORY; TAOS_RETURN(code); } - tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); + (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -330,7 +330,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - sprintf(obj, "%d", createReq.dnodeId); + (void)sprintf(obj, "%d", createReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "createQnode", "", obj, createReq.sql, createReq.sqlLen); _OVER: @@ -383,7 +383,7 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn code = TSDB_CODE_OUT_OF_MEMORY; TAOS_RETURN(code); } - tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); + (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -459,7 +459,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; char obj[33] = {0}; - sprintf(obj, "%d", dropReq.dnodeId); + (void)sprintf(obj, "%d", dropReq.dnodeId); auditRecord(pReq, pMnode->clusterId, "dropQnode", "", obj, dropReq.sql, dropReq.sqlLen); @@ -531,7 +531,7 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) { goto _OVER; } - tSerializeSQnodeListRsp(pRsp, rspLen, &qlistRsp); + (void)tSerializeSQnodeListRsp(pRsp, rspLen, &qlistRsp); pReq->info.rspLen = rspLen; pReq->info.rsp = pRsp; @@ -556,15 +556,15 @@ static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)ep, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)ep, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); numOfRows++; sdbRelease(pSdb, pObj); diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index 7c86b9aa74..c743aafd13 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -27,7 +27,7 @@ int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg) { void mndPostProcessQueryMsg(SRpcMsg *pMsg) { if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return; SMnode *pMnode = pMsg->info.node; - qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg); + (void)qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg); } int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) { @@ -134,7 +134,10 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { rsp.msgLen = reqMsg.info.rspLen; rsp.msg = reqMsg.info.rsp; - taosArrayPush(batchRsp.pRsps, &rsp); + if (taosArrayPush(batchRsp.pRsps, &rsp) == NULL) { + mError("msg:%p, failed to put array since %s, app:%p type:%s", pMsg, terrstr(), pMsg->info.ahandle, + TMSG_INFO(pMsg->msgType)); + } } rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 3593e21e11..3f03102a7a 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -115,7 +115,7 @@ int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) { } else { pInfo->type = TASK_OUTPUT__TABLE; pInfo->tbSink.stbUid = pStream->targetStbUid; - memcpy(pInfo->tbSink.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); + (void)memcpy(pInfo->tbSink.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); pInfo->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema); if (pInfo->tbSink.pSchemaWrapper == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -145,7 +145,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr int32_t numOfSinkNodes = taosArrayGetSize(pSinkNodeList); if (isShuffle) { - memcpy(pTask->outputInfo.shuffleDispatcher.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); + (void)memcpy(pTask->outputInfo.shuffleDispatcher.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); SArray* pVgs = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos; int32_t numOfVgroups = taosArrayGetSize(pVgs); @@ -363,10 +363,14 @@ static int32_t buildSourceTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillh static void addNewTaskList(SStreamObj* pStream) { SArray* pTaskList = taosArrayInit(0, POINTER_BYTES); - taosArrayPush(pStream->tasks, &pTaskList); + if (taosArrayPush(pStream->tasks, &pTaskList) == NULL) { + mError("failed to put array"); + } if (pStream->conf.fillHistory) { pTaskList = taosArrayInit(0, POINTER_BYTES); - taosArrayPush(pStream->pHTasksList, &pTaskList); + if (taosArrayPush(pStream->pHTasksList, &pTaskList) == NULL) { + mError("failed to put array"); + } } } @@ -584,10 +588,15 @@ static int32_t addSinkTask(SMnode* pMnode, SStreamObj* pStream, SEpSet* pEpset) } static void bindTaskToSinkTask(SStreamObj* pStream, SMnode* pMnode, SArray* pSinkTaskList, SStreamTask* task) { - mndAddDispatcherForInternalTask(pMnode, pStream, pSinkTaskList, task); + int32_t code = 0; + if ((code = mndAddDispatcherForInternalTask(pMnode, pStream, pSinkTaskList, task)) != 0) { + mError("failed bind task to sink task since %s", tstrerror(code)); + } for (int32_t k = 0; k < taosArrayGetSize(pSinkTaskList); k++) { SStreamTask* pSinkTask = taosArrayGetP(pSinkTaskList, k); - streamTaskSetUpstreamInfo(pSinkTask, task); + if ((code = streamTaskSetUpstreamInfo(pSinkTask, task)) != 0) { + mError("failed bind task to sink task since %s", tstrerror(code)); + } } mDebug("bindTaskToSinkTask taskId:%s to sink task list", task->id.idStr); } @@ -604,6 +613,7 @@ static void bindAggSink(SStreamObj* pStream, SMnode* pMnode, SArray* tasks) { } static void bindSourceSink(SStreamObj* pStream, SMnode* pMnode, SArray* tasks, bool hasExtraSink) { + int32_t code = 0; SArray* pSinkTaskList = taosArrayGetP(tasks, SINK_NODE_LEVEL); SArray* pSourceTaskList = taosArrayGetP(tasks, hasExtraSink ? SINK_NODE_LEVEL + 1 : SINK_NODE_LEVEL); @@ -614,12 +624,15 @@ static void bindSourceSink(SStreamObj* pStream, SMnode* pMnode, SArray* tasks, b if (hasExtraSink) { bindTaskToSinkTask(pStream, pMnode, pSinkTaskList, pSourceTask); } else { - mndSetSinkTaskInfo(pStream, pSourceTask); + if ((code = mndSetSinkTaskInfo(pStream, pSourceTask)) != 0) { + mError("failed bind task to sink task since %s", tstrerror(code)); + } } } } static void bindTwoLevel(SArray* tasks, int32_t begin, int32_t end) { + int32_t code = 0; size_t size = taosArrayGetSize(tasks); ASSERT(size >= 2); SArray* pDownTaskList = taosArrayGetP(tasks, size - 1); @@ -631,7 +644,9 @@ static void bindTwoLevel(SArray* tasks, int32_t begin, int32_t end) { SStreamTask* pUpTask = taosArrayGetP(pUpTaskList, i); pUpTask->info.selfChildId = i - begin; streamTaskSetFixedDownstreamInfo(pUpTask, *pDownTask); - streamTaskSetUpstreamInfo(*pDownTask, pUpTask); + if ((code = streamTaskSetUpstreamInfo(*pDownTask, pUpTask)) != 0) { + mError("failed bind task to sink task since %s", tstrerror(code)); + } } mDebug("bindTwoLevel task list(%d-%d) to taskId:%s", begin, end - 1, (*(pDownTask))->id.idStr); } diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 894d888e2d..a07f0e1f4d 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -158,7 +158,7 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) { showObj.id = showId; showObj.pMnode = pMnode; showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb)); - memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); + (void)memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); tstrncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN); int32_t keepTime = tsShellActivityTimer * 6 * 1000; @@ -270,9 +270,9 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { 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); + (void)memcpy(pReq->info.conn.user, retrieveReq.user, TSDB_USER_LEN); } else { - memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1); + (void)memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1); } code = -1; if (retrieveReq.db[0] && @@ -298,10 +298,10 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { idata.info.bytes = p->bytes; idata.info.type = p->type; idata.info.colId = p->colId; - blockDataAppendColInfo(pBlock, &idata); + TAOS_CHECK_RETURN(blockDataAppendColInfo(pBlock, &idata)); } - blockDataEnsureCapacity(pBlock, rowsToRead); + TAOS_CHECK_RETURN(blockDataEnsureCapacity(pBlock, rowsToRead)); if (mndCheckRetrieveFinished(pShow)) { mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); From 410aff27689c6dad0fcc4cdae74a9e4c84c9c20b Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 18:17:45 +0800 Subject: [PATCH 07/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 77 +++++------------------- tests/system-test/2-query/ttl_comment.py | 3 - 2 files changed, 14 insertions(+), 66 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index a154ff1d90..c84822de49 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -40,10 +40,7 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - code = removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); - if (code != 0){ - setErrno(pRequest, code); - } + (void)removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); } taosMemoryFree(pMsg->pEpSet); @@ -114,13 +111,8 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { SEpSet srcEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); SEpSet dstEpSet = connectRsp.epSet; if (srcEpSet.numOfEps == 1) { - code = rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, + (void)rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, dstEpSet.eps[dstEpSet.inUse].fqdn); - if (code != 0){ - setErrno(pRequest, code); - (void)tsem_post(&pRequest->body.rspSem); - goto End; - } updateEpSet = 0; } } @@ -175,12 +167,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { taosThreadMutexLock(&clientHbMgr.lock); SAppHbMgr* pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, pTscObj->appHbMgrIdx); if (pAppHbMgr) { - code = hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); - if (code != 0){ - setErrno(pRequest, code); - (void)tsem_post(&pRequest->body.rspSem); - goto End; - } + (void)hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); } else { taosThreadMutexUnlock(&clientHbMgr.lock); code = TSDB_CODE_TSC_DISCONNECTED; @@ -239,17 +226,9 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; char dbFName[TSDB_DB_FNAME_LEN]; (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - if (code != TSDB_CODE_SUCCESS) { - setErrno(pRequest, code); - } - if (code == TSDB_CODE_SUCCESS) { - (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - } - if (code != TSDB_CODE_SUCCESS) { - setErrno(pRequest, code); - } + (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); + (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); } } @@ -264,10 +243,7 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; SUseDbRsp usedbRsp = {0}; - code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if (code != 0){ - goto END; - } + (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { @@ -280,10 +256,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1)); } else { - code = catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); - if (code != 0){ - goto END; - } + (void)catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); } } @@ -316,10 +289,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SName name = {0}; - code = tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); - if (code != 0){ - goto END; - } + (void)tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); SUseDbOutput output = {0}; code = queryBuildUseDbOutput(&output, &usedbRsp); @@ -336,10 +306,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); } else { - code = catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); - if (code == 0){ - output.dbVgroup = NULL; - } + (void)catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); } } @@ -414,19 +381,11 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); } else { SDropDbRsp dropdbRsp = {0}; - code = tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - goto END; - } + (void)tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); struct SCatalog* pCatalog = NULL; code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (TSDB_CODE_SUCCESS == code) { - code = catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - goto END; - } + (void)catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); STscObj* pTscObj = pRequest->pTscObj; SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, @@ -435,17 +394,9 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; char dbFName[TSDB_DB_FNAME_LEN] = {0}; (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - goto END; - } + (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - code = catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); - if (code != 0){ - setErrno(pRequest, TAOS_GET_TERRNO(code)); - goto END; - } + (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); } } diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py index 8d31ed8b5e..ba24579611 100644 --- a/tests/system-test/2-query/ttl_comment.py +++ b/tests/system-test/2-query/ttl_comment.py @@ -18,9 +18,6 @@ from util.cases import tdCases from util.sql import tdSql class TDTestCase: - clientCfgDict = {'debugFlag': 135} - updatecfgDict = {'debugFlag': 135, 'asynclog': 0} - updatecfgDict["clientCfg"] = clientCfgDict def caseDescription(self): ''' ttl/comment test From f17c8bb54f83cbdbea6fab4a2690f391cd243325 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 18:29:45 +0800 Subject: [PATCH 08/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index c84822de49..f9b28a4ded 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -242,11 +242,10 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; - SUseDbRsp usedbRsp = {0}; - (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { + SUseDbRsp usedbRsp = {0}; + (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); struct SCatalog* pCatalog = NULL; if (usedbRsp.vgVersion >= 0) { // cached in local @@ -263,24 +262,36 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } if (code != TSDB_CODE_SUCCESS) { - goto END; + taosMemoryFree(pMsg->pData); + taosMemoryFree(pMsg->pEpSet); + setErrno(pRequest, code); + + if (pRequest->body.queryFp != NULL) { + doRequestCallback(pRequest, pRequest->code); + + } else { + tsem_post(&pRequest->body.rspSem); + } + + return code; } + SUseDbRsp usedbRsp = {0}; + tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { - code = usedbRsp.errCode; + return usedbRsp.errCode; } else { - code = TSDB_CODE_APP_ERROR; + return TSDB_CODE_APP_ERROR; } - goto END; } tscTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum); for (int32_t i = 0; i < usedbRsp.vgNum; ++i) { SVgroupInfo* pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i); if (pInfo == NULL){ - code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); - goto END; + continue; } tscTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse); for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) { @@ -311,15 +322,13 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } taosMemoryFreeClear(output.dbVgroup); + tFreeSUsedbRsp(&usedbRsp); char db[TSDB_DB_NAME_LEN] = {0}; (void)tNameGetDbName(&name, db); setConnectionDB(pRequest->pTscObj, db); -END: - setErrno(pRequest, code); - tFreeSUsedbRsp(&usedbRsp); taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); From 2b700e51112d25158da87d62c7dc250090d80294 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 18:37:16 +0800 Subject: [PATCH 09/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index f9b28a4ded..e0657e2893 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -258,7 +258,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { (void)catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); } } - + tFreeSUsedbRsp(&usedbRsp); } if (code != TSDB_CODE_SUCCESS) { From d4e8a541dc85c2291db4c1569ab54063b839b829 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 18:38:46 +0800 Subject: [PATCH 10/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e0657e2893..73924a4e8e 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -337,7 +337,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } else { (void)tsem_post(&pRequest->body.rspSem); } - return code; + return 0; } int32_t processCreateSTableRsp(void* param, SDataBuf* pMsg, int32_t code) { From ce324cf4bcd65a7f58ec874d18c35402a47910b2 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 27 Jul 2024 23:59:15 +0800 Subject: [PATCH 11/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 73924a4e8e..798c40dd9f 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -277,7 +277,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SUseDbRsp usedbRsp = {0}; - tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { @@ -318,6 +318,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tstrerror(code1)); } else { (void)catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + output.dbVgroup = NULL; } } From 3e8daeeb91a3bb8cc0f83e8bf6685146a3ca8396 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sun, 28 Jul 2024 01:07:07 +0800 Subject: [PATCH 12/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 37 +- source/client/test/clientMonitorTests.cpp | 4 +- source/client/test/clientTests.cpp | 446 ++++++++++--------- source/dnode/mnode/impl/test/topic/topic.cpp | 15 +- 4 files changed, 270 insertions(+), 232 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 798c40dd9f..dd8cf87c74 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -245,7 +245,12 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { SUseDbRsp usedbRsp = {0}; - (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if(code != 0){ + tscError("0x%" PRIx64 " failed to deserialize SUseDbRsp", pRequest->requestId); + tFreeSUsedbRsp(&usedbRsp); + return TAOS_GET_TERRNO(code); + } struct SCatalog* pCatalog = NULL; if (usedbRsp.vgVersion >= 0) { // cached in local @@ -255,7 +260,13 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1)); } else { - (void)catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); + code = catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); + if (code != TSDB_CODE_SUCCESS) { + tscError("0x%" PRIx64 "catalogRemoveDB failed, db:%s, uid:%" PRId64 ", error:%s", pRequest->requestId, + usedbRsp.db, usedbRsp.uid, tstrerror(code)); + tFreeSUsedbRsp(&usedbRsp); + return TAOS_GET_TERRNO(code); + } } } tFreeSUsedbRsp(&usedbRsp); @@ -270,14 +281,19 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { doRequestCallback(pRequest, pRequest->code); } else { - tsem_post(&pRequest->body.rspSem); + (void)tsem_post(&pRequest->body.rspSem); } return code; } SUseDbRsp usedbRsp = {0}; - (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if (code != 0){ + tscError("0x%" PRIx64 " failed to deserialize SUseDbRsp", pRequest->requestId); + tFreeSUsedbRsp(&usedbRsp); + return TAOS_GET_TERRNO(code); + } if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { @@ -300,7 +316,9 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SName name = {0}; - (void)tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); + if(tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB) != TSDB_CODE_SUCCESS) { + tscError("0x%" PRIx64 " failed to parse db name:%s", pRequest->requestId, usedbRsp.db); + } SUseDbOutput output = {0}; code = queryBuildUseDbOutput(&output, &usedbRsp); @@ -317,7 +335,10 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); } else { - (void)catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + code = catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + if(code != 0){ + tscError("0x%" PRIx64 " failed to update db vgroup info since %s", pRequest->requestId, tstrerror(code)); + } output.dbVgroup = NULL; } } @@ -326,7 +347,9 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tFreeSUsedbRsp(&usedbRsp); char db[TSDB_DB_NAME_LEN] = {0}; - (void)tNameGetDbName(&name, db); + if(tNameGetDbName(&name, db) != TSDB_CODE_SUCCESS) { + tscError("0x%" PRIx64 " failed to get db name since %s", pRequest->requestId, tstrerror(code)); + } setConnectionDB(pRequest->pTscObj, db); diff --git a/source/client/test/clientMonitorTests.cpp b/source/client/test/clientMonitorTests.cpp index e0518a2ce2..65adb7cdae 100644 --- a/source/client/test/clientMonitorTests.cpp +++ b/source/client/test/clientMonitorTests.cpp @@ -86,7 +86,7 @@ static char* readFile(TdFilePtr pFile, int64_t *offset, int64_t size){ return NULL; } char* buf = pCont; - strcat(buf++, "["); + (void)strcat(buf++, "["); int64_t readSize = taosReadFile(pFile, buf, SLOW_LOG_SEND_SIZE_MAX); if (readSize <= 0) { if (readSize < 0){ @@ -153,7 +153,7 @@ TEST(clientMonitorTest, ReadOneFile) { const int size = 10; for(int i = 0; i < batch; i++){ char value[size] = {0}; - memset(value, '0' + i, size - 1); + (void)memset(value, '0' + i, size - 1); if (taosWriteFile(pFile, value, strlen(value) + 1) < 0){ uError("failed to write len to file:%p since %s", pFile, terrstr()); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 836a171ad7..e318ff1972 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -32,7 +32,7 @@ namespace { void printSubResults(void* pRes, int32_t* totalRows) { - char buf[1024]; + char buf[1024] = {0}; int32_t vgId = tmq_get_vgroup_id(pRes); int64_t offset = tmq_get_vgroup_offset(pRes); @@ -43,9 +43,10 @@ void printSubResults(void* pRes, int32_t* totalRows) { } TAOS_FIELD* fields = taos_fetch_fields(pRes); + assert(fields != NULL); int32_t numOfFields = taos_field_count(pRes); int32_t precision = taos_result_precision(pRes); - taos_print_row(buf, row, fields, numOfFields); + (void)taos_print_row(buf, row, fields, numOfFields); *totalRows += 1; std::cout << "vgId:" << vgId << ", offset:" << offset << ", precision:" << precision << ", row content:" << buf << std::endl; @@ -59,12 +60,13 @@ void showDB(TAOS* pConn) { TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); + assert(pFields != NULL); int32_t numOfFields = taos_num_fields(pRes); char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } } @@ -78,19 +80,19 @@ void printResult(TAOS_RES* pRes) { while ((pRow = taos_fetch_row(pRes)) != NULL) { // int32_t* length = taos_fetch_lengths(pRes); // for(int32_t i = 0; i < numOfFields; ++i) { - // printf("(%d):%d " , i, length[i]); + // (void)printf("(%d):%d " , i, length[i]); // } - // printf("\n"); + // (void)printf("\n"); // // int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - // printf("%s\n", str); + // (void)printf("%s\n", str); // memset(str, 0, sizeof(str)); } } void fetchCallback(void* param, void* res, int32_t numOfRow) { #if 0 - printf("numOfRow = %d \n", numOfRow); + (void)printf("numOfRow = %d \n", numOfRow); int numFields = taos_num_fields(res); TAOS_FIELD *fields = taos_fetch_fields(res); TAOS *_taos = (TAOS *)param; @@ -100,18 +102,18 @@ void fetchCallback(void* param, void* res, int32_t numOfRow) { char temp[256] = {0}; taos_print_row(temp, row, fields, numFields); - printf("%s\n", temp); + (void)printf("%s\n", temp); } taos_fetch_rows_a(res, fetchCallback, _taos); } else { - printf("no more data, close the connection.\n"); + (void)printf("no more data, close the connection.\n"); // taos_free_result(res); // taos_close(_taos); // taos_cleanup(); } #endif if (numOfRow == 0) { - printf("completed\n"); + (void)printf("completed\n"); return; } @@ -120,26 +122,26 @@ void fetchCallback(void* param, void* res, int32_t numOfRow) { void queryCallback(void* param, void* res, int32_t code) { if (code != TSDB_CODE_SUCCESS) { - printf("failed to execute, reason:%s\n", taos_errstr(res)); + (void)printf("failed to execute, reason:%s\n", taos_errstr(res)); } - printf("start to fetch data\n"); + (void)printf("start to fetch data\n"); taos_fetch_raw_block_a(res, fetchCallback, param); } void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t startTs, const char* pVarchar) { char str[1024] = {0}; - sprintf(str, "create table if not exists tu%d using st2 tags(%d)", index, index); + (void)sprintf(str, "create table if not exists tu%d using st2 tags(%d)", index, index); TAOS_RES* pRes = taos_query(pConn, str); if (taos_errno(pRes) != 0) { - printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); if (startTs == 0) { for (int32_t i = 0; i < numOfRows; i += 20) { char sql[1024] = {0}; - sprintf(sql, + (void)sprintf(sql, "insert into tu%d values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" @@ -149,7 +151,7 @@ void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t start i + 14, i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19); TAOS_RES* p = taos_query(pConn, sql); if (taos_errno(p) != 0) { - printf("failed to insert data, reason:%s\n", taos_errstr(p)); + (void)printf("failed to insert data, reason:%s\n", taos_errstr(p)); } taos_free_result(p); @@ -157,7 +159,7 @@ void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t start } else { for (int32_t i = 0; i < numOfRows; i += 20) { char sql[1024*50] = {0}; - sprintf(sql, + (void)sprintf(sql, "insert into tu%d values(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, " "%d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, " "'%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')(%ld, %d, '%s')", @@ -167,8 +169,9 @@ void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t start i + 14, pVarchar, startTs + 15, i + 15, pVarchar, startTs + 16, i + 16, pVarchar, startTs + 17, i + 17, pVarchar, startTs + 18, i + 18, pVarchar, startTs + 19, i + 19, pVarchar); TAOS_RES* p = taos_query(pConn, sql); + assert(p != NULL); if (taos_errno(p) != 0) { - printf("failed to insert data, reason:%s\n", taos_errstr(p)); + (void)printf("failed to insert data, reason:%s\n", taos_errstr(p)); } // startTs += 20; @@ -180,7 +183,7 @@ void createNewTable(TAOS* pConn, int32_t index, int32_t numOfRows, int64_t start void* queryThread(void* arg) { TAOS* pConn = taos_connect("192.168.0.209", "root", "taosdata", NULL, 0); if (pConn == NULL) { - printf("failed to connect to db, reason:%s", taos_errstr(pConn)); + (void)printf("failed to connect to db, reason:%s", taos_errstr(pConn)); return NULL; } @@ -192,7 +195,7 @@ void* queryThread(void* arg) { "SELECT _wstart as ts,max(usage_user) FROM benchmarkcpu.host_49 WHERE ts >= " "1451618560000 AND ts < 1451622160000 INTERVAL(1m) ;"); if (taos_errno(pRes) != 0) { - printf("failed, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed, reason:%s\n", taos_errstr(pRes)); } else { printResult(pRes); } @@ -200,7 +203,7 @@ void* queryThread(void* arg) { taos_free_result(pRes); el += (taosGetTimestampUs() - st); if (i % 1000 == 0 && i != 0) { - printf("total:%d, avg time:%.2fms\n", i, el / (double)(i * 1000)); + (void)printf("total:%d, avg time:%.2fms\n", i, el / (double)(i * 1000)); } } @@ -211,32 +214,35 @@ void* queryThread(void* arg) { int32_t numOfThreads = 1; void tmq_commit_cb_print(tmq_t* pTmq, int32_t code, void* param) { -// printf("auto commit success, code:%d\n", code); +// (void)printf("auto commit success, code:%d\n", code); } void* doConsumeData(void* param) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - + assert(pConn != NULL); tmq_conf_t* conf = tmq_conf_new(); - tmq_conf_set(conf, "enable.auto.commit", "true"); - tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); - tmq_conf_set(conf, "group.id", "cgrpName41"); - tmq_conf_set(conf, "td.connect.user", "root"); - tmq_conf_set(conf, "td.connect.pass", "taosdata"); - tmq_conf_set(conf, "auto.offset.reset", "earliest"); - tmq_conf_set(conf, "experimental.snapshot.enable", "true"); - tmq_conf_set(conf, "msg.with.table.name", "true"); - tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + assert(conf != NULL); + (void)tmq_conf_set(conf, "enable.auto.commit", "true"); + (void)tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); + (void)tmq_conf_set(conf, "group.id", "cgrpName41"); + (void)tmq_conf_set(conf, "td.connect.user", "root"); + (void)tmq_conf_set(conf, "td.connect.pass", "taosdata"); + (void)tmq_conf_set(conf, "auto.offset.reset", "earliest"); + (void)tmq_conf_set(conf, "experimental.snapshot.enable", "true"); + (void)tmq_conf_set(conf, "msg.with.table.name", "true"); + (void)tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq != NULL); tmq_conf_destroy(conf); // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); - tmq_list_append(topicList, "topic_t2"); + assert(topicList != NULL); + (void)tmq_list_append(topicList, "topic_t2"); // 启动订阅 - tmq_subscribe(tmq, topicList); + (void)tmq_subscribe(tmq, topicList); tmq_list_destroy(topicList); @@ -252,15 +258,15 @@ void* doConsumeData(void* param) { while (1) { TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout); if (pRes) { - char buf[1024]; + char buf[1024] = {0}; const char* topicName = tmq_get_topic_name(pRes); const char* dbName = tmq_get_db_name(pRes); int32_t vgroupId = tmq_get_vgroup_id(pRes); - printf("topic: %s\n", topicName); - printf("db: %s\n", dbName); - printf("vgroup id: %d\n", vgroupId); + (void)printf("topic: %s\n", topicName); + (void)printf("db: %s\n", dbName); + (void)printf("vgroup id: %d\n", vgroupId); while (1) { TAOS_ROW row = taos_fetch_row(pRes); @@ -269,11 +275,12 @@ void* doConsumeData(void* param) { } fields = taos_fetch_fields(pRes); + assert(fields != NULL); numOfFields = taos_field_count(pRes); precision = taos_result_precision(pRes); - taos_print_row(buf, row, fields, numOfFields); + (void)taos_print_row(buf, row, fields, numOfFields); totalRows += 1; - // printf("precision: %d, row content: %s\n", precision, buf); + // (void)printf("precision: %d, row content: %s\n", precision, buf); } taos_free_result(pRes); @@ -282,9 +289,9 @@ void* doConsumeData(void* param) { } } - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return NULL; } @@ -297,7 +304,7 @@ int main(int argc, char** argv) { } numOfThreads = TMAX(numOfThreads, 1); - printf("the runing threads is:%d", numOfThreads); + (void)printf("the runing threads is:%d", numOfThreads); return RUN_ALL_TESTS(); } @@ -311,7 +318,7 @@ TEST(clientCase, connect_Test) { taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg"); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (pConn == NULL) { - printf("failed to connect to server, reason:%s\n", taos_errstr(NULL)); + (void)printf("failed to connect to server, reason:%s\n", taos_errstr(NULL)); } taos_close(pConn); } @@ -322,7 +329,7 @@ TEST(clientCase, create_user_Test) { TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create user, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -335,7 +342,7 @@ TEST(clientCase, create_account_Test) { TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create user, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -348,7 +355,7 @@ TEST(clientCase, drop_account_Test) { TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create user, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -363,12 +370,13 @@ TEST(clientCase, show_user_Test) { TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); + assert(pFields != NULL); int32_t numOfFields = taos_num_fields(pRes); char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } taos_free_result(pRes); @@ -381,7 +389,7 @@ TEST(clientCase, drop_user_Test) { TAOS_RES* pRes = taos_query(pConn, "drop user abc"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create user, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -396,12 +404,13 @@ TEST(clientCase, show_db_Test) { TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); + assert(pFields != NULL); int32_t numOfFields = taos_num_fields(pRes); char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } taos_close(pConn); @@ -413,7 +422,7 @@ TEST(clientCase, create_db_Test) { TAOS_RES* pRes = taos_query(pConn, "create database abc1 vgroups 2"); if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in create db, reason:%s\n", taos_errstr(pRes)); } TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -426,7 +435,7 @@ TEST(clientCase, create_db_Test) { pRes = taos_query(pConn, "create database abc1 vgroups 4"); if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in create db, reason:%s\n", taos_errstr(pRes)); } taos_close(pConn); } @@ -437,13 +446,13 @@ TEST(clientCase, create_dnode_Test) { TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); if (taos_errno(pRes) != 0) { - printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); if (taos_errno(pRes) != 0) { - printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -456,7 +465,7 @@ TEST(clientCase, drop_dnode_Test) { TAOS_RES* pRes = taos_query(pConn, "drop dnode 3"); if (taos_errno(pRes) != 0) { - printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); } TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -467,7 +476,7 @@ TEST(clientCase, drop_dnode_Test) { pRes = taos_query(pConn, "drop dnode 4"); if (taos_errno(pRes) != 0) { - printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -480,7 +489,7 @@ TEST(clientCase, use_db_test) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in use db, reason:%s\n", taos_errstr(pRes)); } TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -500,7 +509,7 @@ TEST(clientCase, use_db_test) { // // TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); // if (taos_errno(pRes) != 0) { -// printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); +// (void)printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // @@ -508,7 +517,7 @@ TEST(clientCase, use_db_test) { // // pRes = taos_query(pConn, "create database abc1"); // if (taos_errno(pRes) != 0) { -// printf("create to drop db, reason:%s\n", taos_errstr(pRes)); +// (void)printf("create to drop db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // taos_close(pConn); @@ -520,7 +529,7 @@ TEST(clientCase, create_stable_Test) { TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); if (taos_errno(pRes) != 0) { - printf("error in create db, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in create db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -528,7 +537,7 @@ TEST(clientCase, create_stable_Test) { pRes = taos_query(pConn, "create table if not exists abc1.st1(ts timestamp, k int) tags(a int)"); if (taos_errno(pRes) != 0) { - printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + (void)printf("error in create stable, reason:%s\n", taos_errstr(pRes)); } TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -540,14 +549,14 @@ TEST(clientCase, create_stable_Test) { // pRes = taos_query(pConn, "create stable if not exists abc1.`123_$^)` (ts timestamp, `abc` int) tags(a int)"); // if (taos_errno(pRes) != 0) { - // printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes)); + // (void)printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes)); // } // // pRes = taos_query(pConn, "use abc1"); // taos_free_result(pRes); // pRes = taos_query(pConn, "drop stable `123_$^)`"); // if (taos_errno(pRes) != 0) { - // printf("failed to drop super table 123_$^), reason:%s\n", taos_errstr(pRes)); + // (void)printf("failed to drop super table 123_$^), reason:%s\n", taos_errstr(pRes)); // } taos_close(pConn); @@ -578,19 +587,19 @@ TEST(clientCase, create_ctable_Test) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to use db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int ) tags(a int)"); if (taos_errno(pRes) != 0) { - printf("failed to create stable, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create stable, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); pRes = taos_query(pConn, "create table tu using st1 tags('2021-10-10 1:1:1');"); if (taos_errno(pRes) != 0) { - printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -603,7 +612,7 @@ TEST(clientCase, show_stable_Test) { TAOS_RES* pRes = taos_query(pConn, "show abc1.stables"); if (taos_errno(pRes) != 0) { - printf("failed to show stables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to show stables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -615,7 +624,7 @@ TEST(clientCase, show_stable_Test) { char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } taos_free_result(pRes); @@ -628,13 +637,13 @@ TEST(clientCase, show_vgroup_Test) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to use db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); pRes = taos_query(pConn, "show vgroups"); if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -647,7 +656,7 @@ TEST(clientCase, show_vgroup_Test) { char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } taos_free_result(pRes); @@ -660,7 +669,7 @@ TEST(clientCase, create_multiple_tables) { TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1"); if (taos_errno(pRes) != 0) { - printf("failed to create db, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create db, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); taos_close(pConn); return; @@ -669,7 +678,7 @@ TEST(clientCase, create_multiple_tables) { pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to use db, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); taos_close(pConn); return; @@ -679,14 +688,14 @@ TEST(clientCase, create_multiple_tables) { pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int) tags(a int)"); if (taos_errno(pRes) != 0) { - printf("failed to create stable tables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create stable tables, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); pRes = taos_query(pConn, "create table if not exists t_2 using st1 tags(1)"); if (taos_errno(pRes) != 0) { - printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -694,7 +703,7 @@ TEST(clientCase, create_multiple_tables) { taos_free_result(pRes); pRes = taos_query(pConn, "create table if not exists t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { - printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -706,17 +715,17 @@ TEST(clientCase, create_multiple_tables) { char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); + (void)printf("%s\n", str); } taos_free_result(pRes); for (int32_t i = 0; i < 500; i += 2) { char sql[512] = {0}; - snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5)", i, i + 1); + (void)snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5)", i, i + 1); TAOS_RES* pres = taos_query(pConn, sql); if (taos_errno(pres) != 0) { - printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); + (void)printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); } taos_free_result(pres); } @@ -730,15 +739,15 @@ TEST(clientCase, show_table_Test) { TAOS_RES* pRes = taos_query(pConn, "show tables"); if (taos_errno(pRes) != 0) { - printf("failed to show tables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to show tables, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); - taos_query(pConn, "use abc1"); + (void)taos_query(pConn, "use abc1"); pRes = taos_query(pConn, "show tables"); if (taos_errno(pRes) != 0) { - printf("failed to show tables, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to show tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); } @@ -751,7 +760,7 @@ TEST(clientCase, show_table_Test) { while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%d: %s\n", ++count, str); + (void)printf("%d: %s\n", ++count, str); } taos_free_result(pRes); @@ -764,19 +773,19 @@ TEST(clientCase, show_table_Test) { // // TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1"); // if (taos_errno(pRes) != 0) { -// printf("error in creating db, reason:%s\n", taos_errstr(pRes)); +// (void)printf("error in creating db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // // pRes = taos_query(pConn, "use abc1"); // if (taos_errno(pRes) != 0) { -// printf("error in using db, reason:%s\n", taos_errstr(pRes)); +// (void)printf("error in using db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // // pRes = taos_query(pConn, "drop stable st1"); // if (taos_errno(pRes) != 0) { -// printf("failed to drop stable, reason:%s\n", taos_errstr(pRes)); +// (void)printf("failed to drop stable, reason:%s\n", taos_errstr(pRes)); // } // // taos_free_result(pRes); @@ -790,10 +799,10 @@ TEST(clientCase, generated_request_id_test) { uint64_t v = generateRequestId(); void* result = taosHashGet(phash, &v, sizeof(v)); if (result != nullptr) { - // printf("0x%llx, index:%d\n", v, i); + // (void)printf("0x%llx, index:%d\n", v, i); } assert(result == nullptr); - taosHashPut(phash, &v, sizeof(v), NULL, 0); + (void)taosHashPut(phash, &v, sizeof(v), NULL, 0); } taosHashCleanup(phash); @@ -808,7 +817,7 @@ TEST(clientCase, insert_test) { pRes = taos_query(pConn, "insert into t_2 values(now, 1)"); if (taos_errno(pRes) != 0) { - printf("failed to create into table t_2, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create into table t_2, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -825,7 +834,7 @@ TEST(clientCase, projection_query_tables) { // TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); // if (taos_errno(pRes) != 0) { - // printf("error in create db, reason:%s\n", taos_errstr(pRes)); + // (void)printf("error in create db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); pRes= taos_query(pConn, "use abc1"); @@ -833,7 +842,7 @@ TEST(clientCase, projection_query_tables) { pRes = taos_query(pConn, "create table tu using st2 tags(2)"); if (taos_errno(pRes) != 0) { - printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); @@ -848,11 +857,11 @@ TEST(clientCase, projection_query_tables) { for(int32_t i = 0; i < 1; ++i) { char str[1024] = {0}; - sprintf(str, "create table if not exists tu%d using st2 tags(%d)", i, i); + (void)sprintf(str, "create table if not exists tu%d using st2 tags(%d)", i, i); TAOS_RES* px = taos_query(pConn, str); if (taos_errno(px) != 0) { - printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); } taos_free_result(px); } @@ -866,7 +875,7 @@ TEST(clientCase, projection_query_tables) { pRes = taos_query(pConn, "select * from abc1.st2"); if (taos_errno(pRes) != 0) { - printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -878,7 +887,7 @@ TEST(clientCase, projection_query_tables) { char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { // int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); +// (void)printf("%s\n", str); } taos_free_result(pRes); @@ -889,7 +898,7 @@ TEST(clientCase, tsbs_perf_test) { TdThread qid[20] = {0}; for (int32_t i = 0; i < numOfThreads; ++i) { - taosThreadCreate(&qid[i], NULL, queryThread, NULL); + (void)taosThreadCreate(&qid[i], NULL, queryThread, NULL); } getchar(); } @@ -903,7 +912,7 @@ TEST(clientCase, projection_query_stables) { // pRes = taos_query(pConn, "select * from st2"); // if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); +// (void)printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); // taos_free_result(pRes); // ASSERT_TRUE(false); // } @@ -925,15 +934,15 @@ TEST(clientCase, projection_query_stables) { i += numOfRows; if ( (i / 1000000) > prev) { - printf("%d\n", i); + (void)printf("%d\n", i); prev = i/1000000; } - //printf("%d\n", i); + //(void)printf("%d\n", i); } // while ((pRow = taos_fetch_row(pRes)) != NULL) { // int32_t code = taos_print_row(str, pRow, pFields, numOfFields); // if (i++ % 100000 == 0) { -// printf("%d\n", i); +// (void)printf("%d\n", i); // } // } @@ -947,7 +956,7 @@ TEST(clientCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { - printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed to use db, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -958,7 +967,7 @@ TEST(clientCase, agg_query_tables) { char s[256] = {0}; while (1) { - sprintf(s, "insert into t1 values(%ld, %d)", st + i, i); + (void)sprintf(s, "insert into t1 values(%ld, %d)", st + i, i); pRes = taos_query(pConn, s); int32_t ret = taos_errno(pRes); @@ -982,7 +991,7 @@ TEST(clientCase, agg_query_tables) { // pRes = taos_query(pConn, "show table distributed tup"); // if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); +// (void)printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); // taos_free_result(pRes); // ASSERT_TRUE(false); // } @@ -1008,11 +1017,11 @@ TEST(clientCase, async_api_test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - taos_query(pConn, "use abc1"); + (void)taos_query(pConn, "use abc1"); TAOS_RES* pRes = taos_query(pConn, "insert into tu(ts) values('2022-02-27 12:12:61')"); if (taos_errno(pRes) != 0) { - printf("failed, reason:%s\n", taos_errstr(pRes)); + (void)printf("failed, reason:%s\n", taos_errstr(pRes)); } int32_t n = 0; @@ -1024,17 +1033,17 @@ TEST(clientCase, async_api_test) { while ((pRow = taos_fetch_row(pRes)) != NULL) { int32_t* length = taos_fetch_lengths(pRes); for (int32_t i = 0; i < numOfFields; ++i) { - printf("(%d):%d ", i, length[i]); + (void)printf("(%d):%d ", i, length[i]); } - printf("\n"); + (void)printf("\n"); int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); - memset(str, 0, sizeof(str)); + (void)printf("%s\n", str); + (void)memset(str, 0, sizeof(str)); } taos_query_a(pConn, "select count(*) from tu", queryCallback, pConn); - getchar(); + (void)getchar(); taos_close(pConn); } @@ -1044,7 +1053,7 @@ TEST(clientCase, update_test) { TAOS_RES* pRes = taos_query(pConn, "select cast(0 as timestamp)-1y"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create database, code:%s", taos_errstr(pRes)); + (void)printf("failed to create database, code:%s", taos_errstr(pRes)); taos_free_result(pRes); return; } @@ -1053,7 +1062,7 @@ TEST(clientCase, update_test) { pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to use db, code:%s", taos_errstr(pRes)); + (void)printf("failed to use db, code:%s", taos_errstr(pRes)); taos_free_result(pRes); return; } @@ -1061,14 +1070,14 @@ TEST(clientCase, update_test) { pRes = taos_query(pConn, "create table tup (ts timestamp, k int);"); if (taos_errno(pRes) != 0) { - printf("failed to create table, reason:%s", taos_errstr(pRes)); + (void)printf("failed to create table, reason:%s", taos_errstr(pRes)); } taos_free_result(pRes); char s[256] = {0}; for (int32_t i = 0; i < 17000; ++i) { - sprintf(s, "insert into tup values(now+%da, %d)", i, i); + (void)sprintf(s, "insert into tup values(now+%da, %d)", i, i); pRes = taos_query(pConn, s); taos_free_result(pRes); } @@ -1080,32 +1089,32 @@ TEST(clientCase, sub_db_test) { // TAOS_RES* pRes = taos_query(pConn, "create topic topic_t1 as select * from t1"); // if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - // printf("failed to create topic, code:%s", taos_errstr(pRes)); + // (void)printf("failed to create topic, code:%s", taos_errstr(pRes)); // taos_free_result(pRes); // return; // } tmq_conf_t* conf = tmq_conf_new(); - tmq_conf_set(conf, "enable.auto.commit", "true"); - tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); - tmq_conf_set(conf, "group.id", "cgrpNamedb"); - tmq_conf_set(conf, "td.connect.user", "root"); - tmq_conf_set(conf, "td.connect.pass", "taosdata"); - tmq_conf_set(conf, "auto.offset.reset", "earliest"); - tmq_conf_set(conf, "experimental.snapshot.enable", "false"); - tmq_conf_set(conf, "msg.with.table.name", "true"); - tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + (void)tmq_conf_set(conf, "enable.auto.commit", "true"); + (void)tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); + (void)tmq_conf_set(conf, "group.id", "cgrpNamedb"); + (void)tmq_conf_set(conf, "td.connect.user", "root"); + (void)tmq_conf_set(conf, "td.connect.pass", "taosdata"); + (void)tmq_conf_set(conf, "auto.offset.reset", "earliest"); + (void)tmq_conf_set(conf, "experimental.snapshot.enable", "false"); + (void)tmq_conf_set(conf, "msg.with.table.name", "true"); + (void)tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); tmq_conf_destroy(conf); // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); - tmq_list_append(topicList, "topic_t1"); + (void)tmq_list_append(topicList, "topic_t1"); // tmq_list_append(topicList, "topic_s2"); // 启动订阅 - tmq_subscribe(tmq, topicList); + (void)tmq_subscribe(tmq, topicList); tmq_list_destroy(topicList); TAOS_FIELD* fields = NULL; @@ -1127,12 +1136,12 @@ TEST(clientCase, sub_db_test) { const char* dbName = tmq_get_db_name(pRes); int32_t vgroupId = tmq_get_vgroup_id(pRes); - printf("topic: %s\n", topicName); - printf("db: %s\n", dbName); - printf("vgroup id: %d\n", vgroupId); + (void)printf("topic: %s\n", topicName); + (void)printf("db: %s\n", dbName); + (void)printf("vgroup id: %d\n", vgroupId); if (count++ > 200) { - tmq_unsubscribe(tmq); + (void)tmq_unsubscribe(tmq); break; } @@ -1141,17 +1150,18 @@ TEST(clientCase, sub_db_test) { if (row == NULL) break; fields = taos_fetch_fields(pRes); + assert(fields != NULL); numOfFields = taos_field_count(pRes); precision = taos_result_precision(pRes); rows++; - taos_print_row(buf, row, fields, numOfFields); - printf("precision: %d, row content: %s\n", precision, buf); + (void)taos_print_row(buf, row, fields, numOfFields); + (void)printf("precision: %d, row content: %s\n", precision, buf); } taos_free_result(pRes); } } - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); } TEST(clientCase, tmq_commit) { @@ -1162,13 +1172,13 @@ TEST(clientCase, tmq_commit) { tmq_conf_t* conf = tmq_conf_new(); - tmq_conf_set(conf, "enable.auto.commit", "false"); - tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); - tmq_conf_set(conf, "group.id", "group_id_2"); - tmq_conf_set(conf, "td.connect.user", "root"); - tmq_conf_set(conf, "td.connect.pass", "taosdata"); - tmq_conf_set(conf, "auto.offset.reset", "earliest"); - tmq_conf_set(conf, "msg.with.table.name", "true"); + (void)tmq_conf_set(conf, "enable.auto.commit", "false"); + (void)tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); + (void)tmq_conf_set(conf, "group.id", "group_id_2"); + (void)tmq_conf_set(conf, "td.connect.user", "root"); + (void)tmq_conf_set(conf, "td.connect.pass", "taosdata"); + (void)tmq_conf_set(conf, "auto.offset.reset", "earliest"); + (void)tmq_conf_set(conf, "msg.with.table.name", "true"); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); tmq_conf_destroy(conf); @@ -1176,10 +1186,10 @@ TEST(clientCase, tmq_commit) { char topicName[128] = "tp"; // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); - tmq_list_append(topicList, topicName); + (void)tmq_list_append(topicList, topicName); // 启动订阅 - tmq_subscribe(tmq, topicList); + (void)tmq_subscribe(tmq, topicList); tmq_list_destroy(topicList); int32_t totalRows = 0; @@ -1191,11 +1201,11 @@ TEST(clientCase, tmq_commit) { int32_t code = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1210,13 +1220,13 @@ TEST(clientCase, tmq_commit) { int64_t position = tmq_position(tmq, topicName, pa->vgId); std::cout << "position vgId:" << pa->vgId << ", position:" << position << std::endl; - tmq_offset_seek(tmq, topicName, pa->vgId, 1); + (void)tmq_offset_seek(tmq, topicName, pa->vgId, 1); position = tmq_position(tmq, topicName, pa->vgId); std::cout << "after seek 1, position vgId:" << pa->vgId << " position:" << position << std::endl; } while (1) { - printf("start to poll\n"); + (void)printf("start to poll\n"); TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout); if (pRes) { printSubResults(pRes, &totalRows); @@ -1224,13 +1234,13 @@ TEST(clientCase, tmq_commit) { break; } - tmq_commit_sync(tmq, pRes); + (void)tmq_commit_sync(tmq, pRes); for(int i = 0; i < numOfAssign; i++) { int64_t committed = tmq_committed(tmq, topicName, pAssign[i].vgId); std::cout << "committed vgId:" << pAssign[i].vgId << " , committed:" << committed << std::endl; if(committed > 0){ int32_t code = tmq_commit_offset_sync(tmq, topicName, pAssign[i].vgId, 4); - printf("tmq_commit_offset_sync vgId:%d, offset:4, code:%d\n", pAssign[i].vgId, code); + (void)printf("tmq_commit_offset_sync vgId:%d, offset:4, code:%d\n", pAssign[i].vgId, code); int64_t committed = tmq_committed(tmq, topicName, pAssign[i].vgId); std::cout << "after tmq_commit_offset_sync, committed vgId:" << pAssign[i].vgId << ", committed:" << committed @@ -1246,9 +1256,9 @@ TEST(clientCase, tmq_commit) { tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); } namespace { void doPrintInfo(tmq_topic_assignment* pa, int32_t index) { @@ -1264,24 +1274,25 @@ TEST(clientCase, td_25129) { tmq_conf_t* conf = tmq_conf_new(); - tmq_conf_set(conf, "enable.auto.commit", "false"); - tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); - tmq_conf_set(conf, "group.id", "group_id_2"); - tmq_conf_set(conf, "td.connect.user", "root"); - tmq_conf_set(conf, "td.connect.pass", "taosdata"); - tmq_conf_set(conf, "auto.offset.reset", "earliest"); - tmq_conf_set(conf, "msg.with.table.name", "true"); + (void)tmq_conf_set(conf, "enable.auto.commit", "false"); + (void)tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); + (void)tmq_conf_set(conf, "group.id", "group_id_2"); + (void)tmq_conf_set(conf, "td.connect.user", "root"); + (void)tmq_conf_set(conf, "td.connect.pass", "taosdata"); + (void)tmq_conf_set(conf, "auto.offset.reset", "earliest"); + (void)tmq_conf_set(conf, "msg.with.table.name", "true"); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq != NULL); tmq_conf_destroy(conf); char topicName[128] = "tp"; // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); - tmq_list_append(topicList, topicName); + (void)tmq_list_append(topicList, topicName); // 启动订阅 - tmq_subscribe(tmq, topicList); + (void)tmq_subscribe(tmq, topicList); tmq_list_destroy(topicList); TAOS_FIELD* fields = NULL; @@ -1298,11 +1309,11 @@ TEST(clientCase, td_25129) { int32_t code = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1315,11 +1326,11 @@ TEST(clientCase, td_25129) { code = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1331,11 +1342,11 @@ TEST(clientCase, td_25129) { code = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1345,7 +1356,7 @@ TEST(clientCase, td_25129) { } while (1) { - printf("start to poll\n"); + (void)printf("start to poll\n"); TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout); if (pRes) { char buf[128]; @@ -1354,19 +1365,19 @@ TEST(clientCase, td_25129) { // const char* dbName = tmq_get_db_name(pRes); // int32_t vgroupId = tmq_get_vgroup_id(pRes); // -// printf("topic: %s\n", topicName); -// printf("db: %s\n", dbName); -// printf("vgroup id: %d\n", vgroupId); +// (void)printf("topic: %s\n", topicName); +// (void)printf("db: %s\n", dbName); +// (void)printf("vgroup id: %d\n", vgroupId); printSubResults(pRes, &totalRows); code = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1375,9 +1386,9 @@ TEST(clientCase, td_25129) { } } else { for(int i = 0; i < numOfAssign; i++) { - tmq_offset_seek(tmq, topicName, pAssign[i].vgId, pAssign[i].currentOffset); + (void)tmq_offset_seek(tmq, topicName, pAssign[i].vgId, pAssign[i].currentOffset); } - tmq_commit_sync(tmq, pRes); + (void)tmq_commit_sync(tmq, pRes); break; } @@ -1398,11 +1409,11 @@ TEST(clientCase, td_25129) { code = tmq_get_topic_assignment(tmq, "tp", &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); + (void)printf("error occurs:%s\n", tmq_err2str(code)); tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } @@ -1411,13 +1422,13 @@ TEST(clientCase, td_25129) { } tmq_free_assignment(pAssign); - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); } TEST(clientCase, sub_tb_test) { - taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg"); + (void)taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg"); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); @@ -1426,27 +1437,28 @@ TEST(clientCase, sub_tb_test) { int32_t ts = taosGetTimestampMs()%INT32_MAX; char consumerGroupid[128] = {0}; - sprintf(consumerGroupid, "group_id_%d", ts); + (void)sprintf(consumerGroupid, "group_id_%d", ts); - tmq_conf_set(conf, "enable.auto.commit", "true"); - tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); - tmq_conf_set(conf, "group.id", consumerGroupid); - tmq_conf_set(conf, "td.connect.user", "root"); - tmq_conf_set(conf, "td.connect.pass", "taosdata"); - tmq_conf_set(conf, "auto.offset.reset", "earliest"); - tmq_conf_set(conf, "experimental.snapshot.enable", "false"); - tmq_conf_set(conf, "msg.with.table.name", "true"); - tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + (void)tmq_conf_set(conf, "enable.auto.commit", "true"); + (void)tmq_conf_set(conf, "auto.commit.interval.ms", "2000"); + (void)tmq_conf_set(conf, "group.id", consumerGroupid); + (void)tmq_conf_set(conf, "td.connect.user", "root"); + (void)tmq_conf_set(conf, "td.connect.pass", "taosdata"); + (void)tmq_conf_set(conf, "auto.offset.reset", "earliest"); + (void)tmq_conf_set(conf, "experimental.snapshot.enable", "false"); + (void)tmq_conf_set(conf, "msg.with.table.name", "true"); + (void)tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq != NULL); tmq_conf_destroy(conf); // 创建订阅 topics 列表 tmq_list_t* topicList = tmq_list_new(); - tmq_list_append(topicList, "t1"); + (void)tmq_list_append(topicList, "t1"); // 启动订阅 - tmq_subscribe(tmq, topicList); + (void)tmq_subscribe(tmq, topicList); tmq_list_destroy(topicList); TAOS_FIELD* fields = NULL; @@ -1463,36 +1475,36 @@ TEST(clientCase, sub_tb_test) { int32_t code = tmq_get_topic_assignment(tmq, "t1", &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); - tmq_consumer_close(tmq); + (void)printf("error occurs:%s\n", tmq_err2str(code)); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } - tmq_offset_seek(tmq, "t1", pAssign[0].vgId, 4); + (void)tmq_offset_seek(tmq, "t1", pAssign[0].vgId, 4); code = tmq_get_topic_assignment(tmq, "t1", &pAssign, &numOfAssign); if (code != 0) { - printf("error occurs:%s\n", tmq_err2str(code)); - tmq_consumer_close(tmq); + (void)printf("error occurs:%s\n", tmq_err2str(code)); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); return; } while (1) { TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout); if (pRes) { - char buf[128]; + char buf[128] = {0}; const char* topicName = tmq_get_topic_name(pRes); // const char* dbName = tmq_get_db_name(pRes); // int32_t vgroupId = tmq_get_vgroup_id(pRes); // -// printf("topic: %s\n", topicName); -// printf("db: %s\n", dbName); -// printf("vgroup id: %d\n", vgroupId); +// (void)printf("topic: %s\n", topicName); +// (void)printf("db: %s\n", dbName); +// (void)printf("vgroup id: %d\n", vgroupId); printSubResults(pRes, &totalRows); } else { @@ -1500,7 +1512,7 @@ TEST(clientCase, sub_tb_test) { // break; } - tmq_commit_sync(tmq, pRes); + (void)tmq_commit_sync(tmq, pRes); if (pRes != NULL) { taos_free_result(pRes); // if ((++count) > 1) { @@ -1510,12 +1522,12 @@ TEST(clientCase, sub_tb_test) { break; } - tmq_offset_seek(tmq, "topic_t1", pAssign[0].vgId, pAssign[0].begin); + (void)tmq_offset_seek(tmq, "topic_t1", pAssign[0].vgId, pAssign[0].begin); } - tmq_consumer_close(tmq); + (void)tmq_consumer_close(tmq); taos_close(pConn); - fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); + (void)fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows); } TEST(clientCase, sub_tb_mt_test) { @@ -1524,17 +1536,17 @@ TEST(clientCase, sub_tb_mt_test) { char *ip = NULL; int port = 0; char key[512] = {0}; - snprintf(key, sizeof(key), "%s:%s:%s:%d", user, auth, ip, port); + (void)snprintf(key, sizeof(key), "%s:%s:%s:%d", user, auth, ip, port); - taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg"); + (void)taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg"); TdThread qid[20] = {0}; for (int32_t i = 0; i < 1; ++i) { - taosThreadCreate(&qid[i], NULL, doConsumeData, NULL); + (void)taosThreadCreate(&qid[i], NULL, doConsumeData, NULL); } for (int32_t i = 0; i < 4; ++i) { - taosThreadJoin(qid[i], NULL); + (void)taosThreadJoin(qid[i], NULL); } } @@ -1552,12 +1564,12 @@ TEST(clientCase, sub_tb_mt_test) { // } // int ret = snprintf(buf + len, size - len, "%s", db); // if (ret < 0) { -// printf("snprintf failed, buf:%s, ret:%d", buf, ret); +// (void)printf("snprintf failed, buf:%s, ret:%d", buf, ret); // break; // } // len += ret; // if (len >= size){ -// printf("dbList is truncated, buf:%s, len:%d", buf, len); +// (void)printf("dbList is truncated, buf:%s, len:%d", buf, len); // break; // } // } diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 84b3a21a8f..4c2213b700 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -31,7 +31,7 @@ Testbase MndTestTopic::test; void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { SCreateDbReq createReq = {0}; - strcpy(createReq.db, dbname); + (void)strcpy(createReq.db, dbname); createReq.numOfVgroups = 2; createReq.buffer = -1; createReq.pageSize = -1; @@ -53,7 +53,8 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); void* pReq = rpcMallocCont(contLen); - tSerializeSCreateDbReq(pReq, contLen, &createReq); + assert(pReq != NULL); + (void)tSerializeSCreateDbReq(pReq, contLen, &createReq); *pContLen = contLen; return pReq; @@ -61,14 +62,15 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql, int32_t* pContLen) { SCMCreateTopicReq createReq = {0}; - strcpy(createReq.name, topicName); + (void)strcpy(createReq.name, topicName); createReq.igExists = 0; createReq.sql = (char*)sql; createReq.ast = NULL; int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); void* pReq = rpcMallocCont(contLen); - tSerializeSCMCreateTopicReq(pReq, contLen, &createReq); + assert(pReq != NULL); + (void)tSerializeSCMCreateTopicReq(pReq, contLen, &createReq); *pContLen = contLen; return pReq; @@ -76,11 +78,12 @@ void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql, void* MndTestTopic::BuildDropTopicReq(const char* topicName, int32_t* pContLen) { SMDropTopicReq dropReq = {0}; - strcpy(dropReq.name, topicName); + (void)strcpy(dropReq.name, topicName); int32_t contLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq); void* pReq = rpcMallocCont(contLen); - tSerializeSMDropTopicReq(pReq, contLen, &dropReq); + assert(pReq != NULL); + (void)tSerializeSMDropTopicReq(pReq, contLen, &dropReq); *pContLen = contLen; return pReq; From 7cb5c2ef014248f516d60e7c79abf2f7d28953a2 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sun, 28 Jul 2024 01:29:13 +0800 Subject: [PATCH 13/17] fix:[TD-31017]process return value in client --- source/client/src/clientJniConnector.c | 2 +- source/client/src/clientMonitor.c | 4 ++-- source/client/src/clientMsgHandler.c | 8 ++++---- source/client/src/clientStmt.c | 14 +++++++------- source/client/src/clientTmq.c | 2 +- source/client/src/clientTmqConnector.c | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/client/src/clientJniConnector.c b/source/client/src/clientJniConnector.c index 4a200179f9..d783c6d8e4 100644 --- a/source/client/src/clientJniConnector.c +++ b/source/client/src/clientJniConnector.c @@ -484,7 +484,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getSchemaMetaData (*env)->SetIntField(env, metadataObj, g_metadataColindexField, i); jstring metadataObjColname = (*env)->NewStringUTF(env, fields[i].name); (*env)->SetObjectField(env, metadataObj, g_metadataColnameField, metadataObjColname); - (*env)->CallBooleanMethod(env, arrayListObj, g_arrayListAddFp, metadataObj); + (void)(*env)->CallBooleanMethod(env, arrayListObj, g_arrayListAddFp, metadataObj); } } diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index d47b074658..40cea644fd 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -248,7 +248,7 @@ void monitorCreateClient(int64_t clusterId) { goto fail; } - taos_collector_registry_register_collector(pMonitor->registry, pMonitor->colector); + (void)taos_collector_registry_register_collector(pMonitor->registry, pMonitor->colector); pMonitor->counters = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pMonitor->counters == NULL) { @@ -772,7 +772,7 @@ static int32_t tscMonitortInit() { return TSDB_CODE_TSC_INTERNAL_ERROR; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); return 0; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index dd8cf87c74..9a6945b021 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -164,18 +164,18 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { } } - taosThreadMutexLock(&clientHbMgr.lock); + (void)taosThreadMutexLock(&clientHbMgr.lock); SAppHbMgr* pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, pTscObj->appHbMgrIdx); if (pAppHbMgr) { (void)hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); } else { - taosThreadMutexUnlock(&clientHbMgr.lock); + (void)taosThreadMutexUnlock(&clientHbMgr.lock); code = TSDB_CODE_TSC_DISCONNECTED; setErrno(pRequest, code); (void)tsem_post(&pRequest->body.rspSem); goto End; } - taosThreadMutexUnlock(&clientHbMgr.lock); + (void)taosThreadMutexUnlock(&clientHbMgr.lock); tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); @@ -184,7 +184,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { End: if (pRequest) { - releaseRequest(pRequest->self); + (void)releaseRequest(pRequest->self); } taosMemoryFree(param); diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 11c27b409d..821dffce86 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -450,7 +450,7 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) { } qDestroyStmtDataBlock(pBlocks); - taosHashRemove(pStmt->exec.pBlockHash, key, keyLen); + STMT_ERR_RET(taosHashRemove(pStmt->exec.pBlockHash, key, keyLen)); pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); } @@ -640,7 +640,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { tscDebug("tb %s not exist", pStmt->bInfo.tbFName); - stmtCleanBindInfo(pStmt); + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); STMT_ERR_RET(code); } @@ -991,7 +991,7 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); int32_t insert = 0; - stmtIsInsert(stmt, &insert); + STMT_ERR_RET(stmtIsInsert(stmt, &insert)); if (0 == insert) { tscError("set tb name not available for none insert statement"); STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); @@ -1161,7 +1161,7 @@ int32_t stmtAppendTablePostHandle(STscStmt* pStmt, SStmtQNode* param) { } if (0 == pStmt->sql.siInfo.firstName[0]) { - strcpy(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName); + (void)strcpy(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName); } param->tblData.getFromHash = pStmt->sql.siInfo.tbFromHash; @@ -1248,8 +1248,8 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { STMT_ERR_RET(qStmtParseQuerySql(&ctx, pStmt->sql.pQuery)); if (pStmt->sql.pQuery->haveResultSet) { - setResSchemaInfo(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->pResSchema, - pStmt->sql.pQuery->numOfResCols); + STMT_ERR_RET(setResSchemaInfo(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->pResSchema, + pStmt->sql.pQuery->numOfResCols)); taosMemoryFreeClear(pStmt->sql.pQuery->pResSchema); setResPrecision(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->precision); } @@ -1301,7 +1301,7 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { // param->tblData.aCol = taosArrayInit(20, POINTER_BYTES); param->restoreTbCols = false; - strcpy(param->tblData.tbName, pStmt->bInfo.tbName); + (void)strcpy(param->tblData.tbName, pStmt->bInfo.tbName); } int64_t startUs3 = taosGetTimestampUs(); diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 6d9956122c..e53a72814a 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -2940,7 +2940,7 @@ int32_t tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4, SReqResultInfo** pRes doFreeReqResultInfo(&pRspObj->resInfo); SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(common->blockSchema, pRspObj->resIter); if (pSW){ - setResSchemaInfo(&pRspObj->resInfo, pSW->pSchema, pSW->nCols); + TAOS_CHECK_RETURN(setResSchemaInfo(&pRspObj->resInfo, pSW->pSchema, pSW->nCols)); } } diff --git a/source/client/src/clientTmqConnector.c b/source/client/src/clientTmqConnector.c index be00ec34c9..26eed6fedf 100644 --- a/source/client/src/clientTmqConnector.c +++ b/source/client/src/clientTmqConnector.c @@ -493,7 +493,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_fetchRawBlockImp( (*env)->SetIntField(env, metadataObj, g_metadataColindexField, i); jstring metadataObjColname = (*env)->NewStringUTF(env, fields[i].name); (*env)->SetObjectField(env, metadataObj, g_metadataColnameField, metadataObjColname); - (*env)->CallBooleanMethod(env, arrayListObj, g_arrayListAddFp, metadataObj); + (void)(*env)->CallBooleanMethod(env, arrayListObj, g_arrayListAddFp, metadataObj); } (*env)->CallVoidMethod(env, rowobj, g_blockdataSetNumOfRowsFp, (jint)numOfRows); @@ -567,7 +567,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssign (*env)->CallVoidMethod(env, jassignment, g_assignmentSetCurrentOffset, assignment.currentOffset); (*env)->CallVoidMethod(env, jassignment, g_assignmentSetBegin, assignment.begin); (*env)->CallVoidMethod(env, jassignment, g_assignmentSetEnd, assignment.end); - (*env)->CallBooleanMethod(env, jarrayList, g_arrayListAddFp, jassignment); + (void)(*env)->CallBooleanMethod(env, jarrayList, g_arrayListAddFp, jassignment); } tmq_free_assignment(pAssign); return JNI_SUCCESS; From 50afa39ab43e5dfbf7812c34e89c25563fec769f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sun, 28 Jul 2024 03:34:48 +0800 Subject: [PATCH 14/17] fix:[TD-31017]process return value in vnode for tmq --- source/client/src/clientMsgHandler.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 9a6945b021..dc99d50222 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -245,12 +245,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { SUseDbRsp usedbRsp = {0}; - code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if(code != 0){ - tscError("0x%" PRIx64 " failed to deserialize SUseDbRsp", pRequest->requestId); - tFreeSUsedbRsp(&usedbRsp); - return TAOS_GET_TERRNO(code); - } + (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); struct SCatalog* pCatalog = NULL; if (usedbRsp.vgVersion >= 0) { // cached in local @@ -260,13 +255,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1)); } else { - code = catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); - if (code != TSDB_CODE_SUCCESS) { - tscError("0x%" PRIx64 "catalogRemoveDB failed, db:%s, uid:%" PRId64 ", error:%s", pRequest->requestId, - usedbRsp.db, usedbRsp.uid, tstrerror(code)); - tFreeSUsedbRsp(&usedbRsp); - return TAOS_GET_TERRNO(code); - } + (void)catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); } } tFreeSUsedbRsp(&usedbRsp); @@ -288,12 +277,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SUseDbRsp usedbRsp = {0}; - code = tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if (code != 0){ - tscError("0x%" PRIx64 " failed to deserialize SUseDbRsp", pRequest->requestId); - tFreeSUsedbRsp(&usedbRsp); - return TAOS_GET_TERRNO(code); - } + (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { @@ -335,10 +319,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); } else { - code = catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); - if(code != 0){ - tscError("0x%" PRIx64 " failed to update db vgroup info since %s", pRequest->requestId, tstrerror(code)); - } + (void)catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); output.dbVgroup = NULL; } } From b9e3741898c373bc25ac301bf9f947509d40f3bb Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sun, 28 Jul 2024 21:23:16 +0800 Subject: [PATCH 15/17] fix:[TD-31017]process return value in client --- source/client/src/clientMsgHandler.c | 58 +++++++++++++++++++++------- source/client/src/clientStmt.c | 2 +- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index dc99d50222..cc1ed7f3fa 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -40,7 +40,9 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - (void)removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + if (removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)) != 0){ + tscError("failed to remove meta data for table"); + } } taosMemoryFree(pMsg->pEpSet); @@ -111,8 +113,10 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { SEpSet srcEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); SEpSet dstEpSet = connectRsp.epSet; if (srcEpSet.numOfEps == 1) { - (void)rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, - dstEpSet.eps[dstEpSet.inUse].fqdn); + if (rpcSetDefaultAddr(pTscObj->pAppInfo->pTransporter, srcEpSet.eps[srcEpSet.inUse].fqdn, + dstEpSet.eps[dstEpSet.inUse].fqdn) != 0){ + tscError("failed to set default addr for rpc"); + } updateEpSet = 0; } } @@ -158,7 +162,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { MonitorSlowLogData data = {0}; data.clusterId = pTscObj->pAppInfo->clusterId; data.type = SLOW_LOG_READ_BEGINNIG; - (void)monitorPutData2MonitorQueue(data); + (void)monitorPutData2MonitorQueue(data); // ignore monitorClientSlowQueryInit(connectRsp.clusterId); monitorClientSQLReqInit(connectRsp.clusterId); } @@ -167,7 +171,9 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { (void)taosThreadMutexLock(&clientHbMgr.lock); SAppHbMgr* pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, pTscObj->appHbMgrIdx); if (pAppHbMgr) { - (void)hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); + if (hbRegisterConn(pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType) != 0){ + tscError("0x%" PRIx64 " failed to register conn to hbMgr", pRequest->requestId); + } } else { (void)taosThreadMutexUnlock(&clientHbMgr.lock); code = TSDB_CODE_TSC_DISCONNECTED; @@ -226,9 +232,13 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; char dbFName[TSDB_DB_FNAME_LEN]; (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (catalogRefreshDBVgInfo(pCatalog, &conn, dbFName) != 0){ + tscError("0x%" PRIx64 " failed to refresh db vg info", pRequest->requestId); + } (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (catalogRefreshDBVgInfo(pCatalog, &conn, dbFName) != 0){ + tscError("0x%" PRIx64 " failed to refresh db vg info", pRequest->requestId); + } } } @@ -245,7 +255,9 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || TSDB_CODE_MND_DB_IN_DROPPING == code) { SUseDbRsp usedbRsp = {0}; - (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if (tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp) != 0){ + tscError("0x%" PRIx64 " deserialize SUseDbRsp failed", pRequest->requestId); + } struct SCatalog* pCatalog = NULL; if (usedbRsp.vgVersion >= 0) { // cached in local @@ -255,7 +267,10 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1)); } else { - (void)catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); + if (catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid) != 0){ + tscError("0x%" PRIx64 "catalogRemoveDB failed, db:%s, uid:%" PRId64, pRequest->requestId, usedbRsp.db, + usedbRsp.uid); + } } } tFreeSUsedbRsp(&usedbRsp); @@ -277,7 +292,9 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { } SUseDbRsp usedbRsp = {0}; - (void)tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); + if (tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp) != 0){ + tscError("0x%" PRIx64 " deserialize SUseDbRsp failed", pRequest->requestId); + } if (strlen(usedbRsp.db) == 0) { if (usedbRsp.errCode != 0) { @@ -319,7 +336,10 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); } else { - (void)catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + if (catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup) != 0){ + tscError("0x%" PRIx64 " failed to update db vg info, db:%s, dbId:%" PRId64, pRequest->requestId, output.db, + output.dbId); + } output.dbVgroup = NULL; } } @@ -395,11 +415,15 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { setErrno(pRequest, code); } else { SDropDbRsp dropdbRsp = {0}; - (void)tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); + if (tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp) != 0){ + tscError("0x%" PRIx64 " deserialize SDropDbRsp failed", pRequest->requestId); + } struct SCatalog* pCatalog = NULL; code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (TSDB_CODE_SUCCESS == code) { - (void)catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); + if (catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid) != 0){ + tscError("0x%" PRIx64 " failed to remove db:%s", pRequest->requestId, dropdbRsp.db); + } STscObj* pTscObj = pRequest->pTscObj; SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, @@ -408,9 +432,13 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; char dbFName[TSDB_DB_FNAME_LEN] = {0}; (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_INFORMATION_SCHEMA_DB); - (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (catalogRefreshDBVgInfo(pCatalog, &conn, dbFName) != TSDB_CODE_SUCCESS) { + tscError("0x%" PRIx64 " failed to refresh db vg info, db:%s", pRequest->requestId, dbFName); + } (void)snprintf(dbFName, sizeof(dbFName) - 1, "%d.%s", pTscObj->acctId, TSDB_PERFORMANCE_SCHEMA_DB); - (void)catalogRefreshDBVgInfo(pCatalog, &conn, dbFName); + if (catalogRefreshDBVgInfo(pCatalog, &conn, dbFName) != 0) { + tscError("0x%" PRIx64 " failed to refresh db vg info, db:%s", pRequest->requestId, dbFName); + } } } diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 821dffce86..9f7aeabbe4 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -951,7 +951,7 @@ int32_t stmtInitStbInterlaceTableInfo(STscStmt* pStmt) { return TSDB_CODE_OUT_OF_MEMORY; } - if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols)) { + if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } } From 98c6541427fd515f27ed7bd8f3c26c6c90bb35e1 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 29 Jul 2024 09:48:04 +0800 Subject: [PATCH 16/17] fix: array push issue --- source/libs/executor/src/dynqueryctrloperator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/dynqueryctrloperator.c b/source/libs/executor/src/dynqueryctrloperator.c index 3b025685dc..5359cc0980 100644 --- a/source/libs/executor/src/dynqueryctrloperator.c +++ b/source/libs/executor/src/dynqueryctrloperator.c @@ -248,7 +248,11 @@ static int32_t buildExchangeOperatorParam(SOperatorParam** ppRes, int32_t downst taosMemoryFree(pExc); return terrno; } - taosArrayPush(pExc->basic.uidList, pUid); + if (NULL == taosArrayPush(pExc->basic.uidList, pUid)) { + taosArrayDestroy(pExc->basic.uidList); + taosMemoryFree(pExc); + return terrno; + } (*ppRes)->opType = QUERY_NODE_PHYSICAL_PLAN_EXCHANGE; (*ppRes)->downstreamIdx = downstreamIdx; From bb142d8c9c22b90f9955b021f99f9d4edc0acbb7 Mon Sep 17 00:00:00 2001 From: sima Date: Mon, 29 Jul 2024 10:11:04 +0800 Subject: [PATCH 17/17] enh:[TD-30996] Handling return value --- source/util/src/tcompare.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 42bedf01b7..4cb48bffe5 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1282,7 +1282,7 @@ int32_t checkRegexPattern(const char *pPattern) { int32_t ret = regcomp(®ex, pPattern, cflags); if (ret != 0) { char msgbuf[256] = {0}; - regerror(ret, ®ex, msgbuf, tListLen(msgbuf)); + (void)regerror(ret, ®ex, msgbuf, tListLen(msgbuf)); uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf); return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; } @@ -1307,7 +1307,7 @@ static UsingRegex **getRegComp(const char *pPattern) { int32_t ret = regcomp(&pUsingRegex->pRegex, pPattern, cflags); if (ret != 0) { char msgbuf[256] = {0}; - regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf)); + (void)regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf)); uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf); taosMemoryFree(pUsingRegex); terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; @@ -1354,7 +1354,7 @@ static int32_t doExecRegexMatch(const char *pString, const char *pPattern) { releaseRegComp(pUsingRegex); if (ret != 0 && ret != REG_NOMATCH) { terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; - regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf)); + (void)regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf)); uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf) }