diff --git a/deps/arm/dm_static/libdmodule.a b/deps/arm/dm_static/libdmodule.a index 989676d14d..06d509b51b 100644 Binary files a/deps/arm/dm_static/libdmodule.a and b/deps/arm/dm_static/libdmodule.a differ diff --git a/deps/mips/dm_static/libdmodule.a b/deps/mips/dm_static/libdmodule.a index 167b932121..b60727d440 100644 Binary files a/deps/mips/dm_static/libdmodule.a and b/deps/mips/dm_static/libdmodule.a differ diff --git a/deps/x86/dm_static/libdmodule.a b/deps/x86/dm_static/libdmodule.a index 9f17b4c118..f2d3f600ce 100644 Binary files a/deps/x86/dm_static/libdmodule.a and b/deps/x86/dm_static/libdmodule.a differ diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md index 8bfdaeb9c8..33236c0173 100755 --- a/docs/en/12-taos-sql/06-select.md +++ b/docs/en/12-taos-sql/06-select.md @@ -65,10 +65,16 @@ interp_clause: RANGE(ts_val [, ts_val]) EVERY(every_val) FILL(fill_mod_and_val) partition_by_clause: - PARTITION BY expr [, expr] ... + PARTITION BY partition_by_expr [, partition_by_expr] ... + +partition_by_expr: + {expr | position | c_alias} group_by_clause: - GROUP BY expr [, expr] ... HAVING condition + GROUP BY group_by_expr [, group_by_expr] ... HAVING condition + +group_by_expr: + {expr | position | c_alias} order_by_clasue: ORDER BY order_expr [, order_expr] ... @@ -274,7 +280,13 @@ If you use a GROUP BY clause, the SELECT list can only include the following ite The GROUP BY clause groups each row of data by the value of the expression following the clause and returns a combined result for each group. -The expressions in a GROUP BY clause can include any column in any table or view. It is not necessary that the expressions appear in the SELECT list. +In the GROUP BY clause, columns from a table or view can be grouped by specifying the column name. These columns do not need to be included in the SELECT list. + +You can specify integers in GROUP BY expression to indicate the expressions in the select list used for grouping. For example, 1 indicates the first item in the select list. + +You can specify column names in result set to indicate the expressions in the select list used for grouping. + +When using position and result set column names for grouping in the GROUP BY clause, the corresponding expressions in the select list must not be aggregate functions. The GROUP BY clause does not guarantee that the results are ordered. If you want to ensure that grouped data is ordered, use the ORDER BY clause. diff --git a/docs/examples/c/multi_bind_example.c b/docs/examples/c/multi_bind_example.c index 3d0bd3ccef..0134899a1d 100644 --- a/docs/examples/c/multi_bind_example.c +++ b/docs/examples/c/multi_bind_example.c @@ -33,7 +33,7 @@ void executeSQL(TAOS *taos, const char *sql) { void checkErrorCode(TAOS_STMT *stmt, int code, const char *msg) { if (code != 0) { printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + (void)taos_stmt_close(stmt); exit(EXIT_FAILURE); } } @@ -123,7 +123,7 @@ void insertData(TAOS *taos) { int affectedRows = taos_stmt_affected_rows(stmt); printf("successfully inserted %d rows\n", affectedRows); // close - taos_stmt_close(stmt); + (void)taos_stmt_close(stmt); } int main() { diff --git a/docs/examples/c/stmt_example.c b/docs/examples/c/stmt_example.c index 290a6bee66..3b9efe49d7 100644 --- a/docs/examples/c/stmt_example.c +++ b/docs/examples/c/stmt_example.c @@ -33,7 +33,7 @@ void executeSQL(TAOS *taos, const char *sql) { void checkErrorCode(TAOS_STMT *stmt, int code, const char* msg) { if (code != 0) { printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + (void)taos_stmt_close(stmt); exit(EXIT_FAILURE); } } @@ -119,7 +119,7 @@ void insertData(TAOS *taos) { int affectedRows = taos_stmt_affected_rows(stmt); printf("successfully inserted %d rows\n", affectedRows); // close - taos_stmt_close(stmt); + (void)taos_stmt_close(stmt); } int main() { diff --git a/docs/examples/c/subscribe_demo.c b/docs/examples/c/subscribe_demo.c deleted file mode 100644 index 2fe62c24eb..0000000000 --- a/docs/examples/c/subscribe_demo.c +++ /dev/null @@ -1,66 +0,0 @@ -// A simple demo for asynchronous subscription. -// compile with: -// gcc -o subscribe_demo subscribe_demo.c -ltaos - -#include -#include -#include -#include - -int nTotalRows; - -/** - * @brief callback function of subscription. - * - * @param tsub - * @param res - * @param param. the additional parameter passed to taos_subscribe - * @param code. error code - */ -void subscribe_callback(TAOS_SUB* tsub, TAOS_RES* res, void* param, int code) { - if (code != 0) { - printf("error: %d\n", code); - exit(EXIT_FAILURE); - } - - TAOS_ROW row = NULL; - int num_fields = taos_num_fields(res); - TAOS_FIELD* fields = taos_fetch_fields(res); - int nRows = 0; - - while ((row = taos_fetch_row(res))) { - char buf[4096] = {0}; - taos_print_row(buf, row, fields, num_fields); - puts(buf); - nRows++; - } - - nTotalRows += nRows; - printf("%d rows consumed.\n", nRows); -} - -int main() { - TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 6030); - if (taos == NULL) { - printf("failed to connect to server\n"); - exit(EXIT_FAILURE); - } - - int restart = 1; // if the topic already exists, where to subscribe from the begin. - const char* topic = "topic-meter-current-bg-10"; - const char* sql = "select * from power.meters where current > 10"; - void* param = NULL; // additional parameter. - int interval = 2000; // consumption interval in microseconds. - TAOS_SUB* tsub = taos_subscribe(taos, restart, topic, sql, subscribe_callback, NULL, interval); - - // wait for insert from others process. you can open TDengine CLI to insert some records for test. - - getchar(); // press Enter to stop - - printf("total rows consumed: %d\n", nTotalRows); - int keep = 0; // whether to keep subscribe process - taos_unsubscribe(tsub, keep); - - taos_close(taos); - taos_cleanup(); -} diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md index f10c5ebb69..af19559c81 100755 --- a/docs/zh/12-taos-sql/06-select.md +++ b/docs/zh/12-taos-sql/06-select.md @@ -65,10 +65,16 @@ interp_clause: RANGE(ts_val [, ts_val]) EVERY(every_val) FILL(fill_mod_and_val) partition_by_clause: - PARTITION BY expr [, expr] ... + PARTITION BY partition_by_expr [, partition_by_expr] ... + +partition_by_expr: + {expr | position | c_alias} group_by_clause: - GROUP BY expr [, expr] ... HAVING condition + GROUP BY group_by_expr [, group_by_expr] ... HAVING condition + +group_by_expr: + {expr | position | c_alias} order_by_clasue: ORDER BY order_expr [, order_expr] ... @@ -274,7 +280,13 @@ TDengine 支持基于时间戳主键的 INNER JOIN,规则如下: GROUP BY 子句对每行数据按 GROUP BY 后的表达式的值进行分组,并为每个组返回一行汇总信息。 -GROUP BY 子句中的表达式可以包含表或视图中的任何列,这些列不需要出现在 SELECT 列表中。 +GROUP BY 子句中可以通过指定表或视图的列名来按照表或视图中的任何列分组,这些列不需要出现在 SELECT 列表中。 + +GROUP BY 子句中可以使用位置语法,位置标识为正整数,从 1 开始,表示使用 SELECT 列表的第几个表达式进行分组。 + +GROUP BY 子句中可以使用结果集列名,表示使用 SELECT 列表的指定表达式进行分组。 + +GROUP BY 子句中在使用位置语法和结果集列名进行分组时,其对应的 SELECT 列表中的表达式不能是聚集函数。 该子句对行进行分组,但不保证结果集的顺序。若要对分组进行排序,请使用 ORDER BY 子句 diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 75a67ea484..70cf9c8b58 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1075,10 +1075,10 @@ typedef struct { SUpdateUserIpWhite* pUserIpWhite; } SUpdateIpWhite; -int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq); -int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq); -void tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq); -SUpdateIpWhite* cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq); +int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq); +int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq); +void tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq); +int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate); typedef struct { int64_t ipWhiteVer; @@ -1763,6 +1763,14 @@ int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); void tFreeSStatusReq(SStatusReq* pReq); +typedef struct { + int32_t dnodeId; + char machineId[TSDB_MACHINE_ID_LEN + 1]; +} SDnodeInfoReq; + +int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq); +int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq); + typedef enum { MONITOR_TYPE_COUNTER = 0, MONITOR_TYPE_SLOW_LOG = 1, @@ -1827,12 +1835,19 @@ typedef struct { int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq); // int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq); -typedef struct { - int64_t tick; -} SMStreamTickReq; +typedef struct SOrphanTask { + int64_t streamId; + int32_t taskId; + int32_t nodeId; +} SOrphanTask; -int32_t tSerializeSMStreamTickMsg(void* buf, int32_t bufLen, SMStreamTickReq* pReq); -// int32_t tDeserializeSMStreamTickMsg(void* buf, int32_t bufLen, SMStreamTickReq* pReq); +typedef struct SMStreamDropOrphanMsg { + SArray* pList; // SArray +} SMStreamDropOrphanMsg; + +int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg); +int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg); +void tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg); typedef struct { int32_t id; @@ -2796,6 +2811,9 @@ enum { TOPIC_SUB_TYPE__COLUMN, }; +#define DEFAULT_MAX_POLL_INTERVAL 3000000 +#define DEFAULT_SESSION_TIMEOUT 12000 + typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; // accout.topic int8_t igExists; @@ -2818,7 +2836,7 @@ typedef struct { typedef struct { int64_t consumerId; char cgroup[TSDB_CGROUP_LEN]; - char clientId[256]; + char clientId[TSDB_CLIENT_ID_LEN]; SArray* topicNames; // SArray int8_t withTbName; @@ -2827,6 +2845,8 @@ typedef struct { int8_t resetOffsetCfg; int8_t enableReplay; int8_t enableBatchMeta; + int32_t sessionTimeoutMs; + int32_t maxPollIntervalMs; } SCMSubscribeReq; static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) { @@ -2848,11 +2868,14 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg); tlen += taosEncodeFixedI8(buf, pReq->enableReplay); tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta); + tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs); + tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs); return tlen; } -static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) { +static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) { + void* start = buf; buf = taosDecodeFixedI64(buf, &pReq->consumerId); buf = taosDecodeStringTo(buf, pReq->cgroup); buf = taosDecodeStringTo(buf, pReq->clientId); @@ -2878,6 +2901,14 @@ static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeR buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg); buf = taosDecodeFixedI8(buf, &pReq->enableReplay); buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta); + if ((char*)buf - (char*)start < len) { + buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs); + buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs); + } else { + pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT; + pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL; + } + return 0; } @@ -3639,9 +3670,9 @@ static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ve int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal); int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal); -int32_t tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal); +void tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal); bool tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight); -int32_t tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight); +void tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight); void tOffsetDestroy(void* pVal); typedef struct { @@ -4105,6 +4136,7 @@ typedef struct { int64_t consumerId; int32_t epoch; SArray* topics; + int8_t pollFlag; } SMqHbReq; typedef struct { diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 3515df3127..572e26bc62 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -224,9 +224,9 @@ TD_DEF_MSG_TYPE(TDMT_MND_RESTORE_DNODE, "restore-dnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_PAUSE_STREAM, "pause-stream", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_RESUME_STREAM, "resume-stream", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHECKPOINT_TIMER, "stream-checkpoint-tmr", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHECKPOINT_TIMER, "stream-checkpoint-tmr", NULL, NULL) // not used TD_DEF_MSG_TYPE(TDMT_MND_STREAM_BEGIN_CHECKPOINT, "stream-begin-checkpoint", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHECKPOINT_CANDIDITATE, "stream-checkpoint-remain", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHECKPOINT_CANDIDITATE, "stream-checkpoint-remain", NULL, NULL) // not used TD_DEF_MSG_TYPE(TDMT_MND_STREAM_NODECHANGE_CHECK, "stream-nodechange-check", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TRIM_DB_TIMER, "trim-db-tmr", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GRANT_NOTIFY, "grant-notify", NULL, NULL) @@ -251,7 +251,9 @@ TD_DEF_MSG_TYPE(TDMT_MND_STREAM_UPDATE_CHKPT_EVT, "stream-update-chkpt-evt", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHKPT_REPORT, "stream-chkpt-report", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CONSEN_TIMER, "stream-consen-tmr", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STREAM_DROP_ORPHANTASKS, "stream-drop-orphan-tasks", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_STREAM_TASK_RESET, "stream-reset-tasks", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_UPDATE_DNODE_INFO, "update-dnode-info", NULL, NULL) TD_CLOSE_MSG_SEG(TDMT_END_MND_MSG) TD_NEW_MSG_SEG(TDMT_VND_MSG) // 2<<8 diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 50137cbee9..ef0f5bdd45 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -203,7 +203,7 @@ void qStreamSetOpen(qTaskInfo_t tinfo); void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded); -void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset); +int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset); SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo); diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 54c8686161..bb06b65898 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -60,6 +60,7 @@ typedef struct SExprNode { bool orderAlias; bool asAlias; bool asParam; + bool asPosition; } SExprNode; typedef enum EColumnType { diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 5f322be99b..0d1e62cdbe 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -682,13 +682,13 @@ void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo); // fill-history task int32_t streamLaunchFillHistoryTask(SStreamTask* pTask); int32_t streamStartScanHistoryAsync(SStreamTask* pTask, int8_t igUntreated); -int32_t streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration); +void streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration); bool streamHistoryTaskSetVerRangeStep2(SStreamTask* pTask, int64_t latestVer); // checkpoint related void streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId); int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeCheckpointId); -int32_t streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId); +void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId); bool streamTaskAlreadySendTrigger(SStreamTask* pTask, int32_t downstreamNodeId); void streamTaskGetTriggerRecvStatus(SStreamTask* pTask, int32_t* pRecved, int32_t* pTotal); void streamTaskInitTriggerDispatchInfo(SStreamTask* pTask); diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index b7a459f957..6c0d04354a 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -164,13 +164,13 @@ int rpcRegisterBrokenLinkArg(SRpcMsg *msg); int rpcReleaseHandle(void *handle, int8_t type); // just release conn to rpc instance, no close sock // These functions will not be called in the child process -int rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx); -int rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); -int rpcSendRecvWithTimeout(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp, int8_t *epUpdated, - int32_t timeoutMs); -int rpcSetDefaultAddr(void *thandle, const char *ip, const char *fqdn); -void *rpcAllocHandle(); -void rpcSetIpWhite(void *thandl, void *arg); +int rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx); +int rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +int rpcSendRecvWithTimeout(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp, int8_t *epUpdated, + int32_t timeoutMs); +int rpcSetDefaultAddr(void *thandle, const char *ip, const char *fqdn); +void *rpcAllocHandle(); +int32_t rpcSetIpWhite(void *thandl, void *arg); int32_t rpcUtilSIpRangeToStr(SIpV4Range *pRange, char *buf); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 3c6a1b5192..e26b147381 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -90,6 +90,8 @@ int32_t taosGetErrSize(); #define TSDB_CODE_RPC_NETWORK_ERROR TAOS_DEF_ERROR_CODE(0, 0x0023) #define TSDB_CODE_RPC_NETWORK_BUSY TAOS_DEF_ERROR_CODE(0, 0x0024) #define TSDB_CODE_HTTP_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0025) +#define TSDB_CODE_RPC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0026) +#define TSDB_CODE_RPC_ASYNC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0027) @@ -488,6 +490,7 @@ int32_t taosGetErrSize(); //mnode-compact #define TSDB_CODE_MND_INVALID_COMPACT_ID TAOS_DEF_ERROR_CODE(0, 0x04B1) #define TSDB_CODE_MND_COMPACT_DETAIL_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x04B2) +#define TSDB_CODE_MND_COMPACT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x04B3) // vnode // #define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) // 2.x diff --git a/include/util/tarray2.h b/include/util/tarray2.h index ce24a1d2ce..0781b3ac4e 100644 --- a/include/util/tarray2.h +++ b/include/util/tarray2.h @@ -116,7 +116,7 @@ static FORCE_INLINE int32_t tarray2SortInsert(void *arr, const void *elePtr, int if ((cb) && (a)->size > 0) { \ TArray2Cb cb_ = (TArray2Cb)(cb); \ for (int32_t i = 0; i < (a)->size; ++i) { \ - cb_((a)->data + i); \ + (void)cb_((a)->data + i); \ } \ } \ (a)->size = 0; \ diff --git a/include/util/tdef.h b/include/util/tdef.h index c9677845ac..39c65d2c71 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -221,6 +221,8 @@ typedef enum ELogicConditionType { #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string #define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string #define TSDB_CGROUP_LEN 193 // it is a null-terminated string +#define TSDB_CLIENT_ID_LEN 256 // it is a null-terminated string +#define TSDB_CONSUMER_ID_LEN 32 // it is a null-terminated string #define TSDB_OFFSET_LEN 64 // it is a null-terminated string #define TSDB_USER_CGROUP_LEN (TSDB_USER_LEN + TSDB_CGROUP_LEN) // it is a null-terminated string #define TSDB_STREAM_NAME_LEN 193 // it is a null-terminated string diff --git a/include/util/tlockfree.h b/include/util/tlockfree.h index 82dd5a0e8b..1a575f8ea1 100644 --- a/include/util/tlockfree.h +++ b/include/util/tlockfree.h @@ -84,7 +84,7 @@ int32_t taosWTryLockLatch(SRWLatch *pLatch); int32_t old_ = atomic_add_fetch_32((x), 0); \ if (old_ & 0x00000001) { \ if (i_ % 1000 == 0) { \ - sched_yield(); \ + (void)sched_yield(); \ } \ continue; \ } @@ -98,9 +98,9 @@ int32_t taosWTryLockLatch(SRWLatch *pLatch); #define taosCorBeginWrite(x) \ taosCorBeginRead(x) if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { continue; } -#define taosCorEndWrite(x) \ - atomic_add_fetch_32((x), 1); \ - break; \ +#define taosCorEndWrite(x) \ + (void)atomic_add_fetch_32((x), 1); \ + break; \ } #ifdef __cplusplus diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 000a82b6b4..3e23e29a40 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -80,8 +80,8 @@ if [ -f %{_compiledir}/../../../explorer/target/taos-explorer.service ]; then cp %{_compiledir}/../../../explorer/target/taos-explorer.service %{buildroot}%{homepath}/cfg ||: fi -if [ -f %{_compiledir}/../../../explorer/server/example/explorer.toml ]; then - cp %{_compiledir}/../../../explorer/server/example/explorer.toml %{buildroot}%{homepath}/cfg ||: +if [ -f %{_compiledir}/../../../explorer/server/examples/explorer.toml ]; then + cp %{_compiledir}/../../../explorer/server/examples/explorer.toml %{buildroot}%{homepath}/cfg ||: fi #cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index a458edcad9..75c1eabe7e 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2920,8 +2920,10 @@ void taosAsyncFetchImpl(SRequestObj* pRequest, __taos_async_fn_t fp, void* param .cbParam = pRequest, }; - if (TSDB_CODE_SUCCESS != schedulerFetchRows(pRequest->body.queryJob, &req)) { - tscError("0x%" PRIx64 " failed to schedule fetch rows", pRequest->self); + int32_t code = schedulerFetchRows(pRequest->body.queryJob, &req); + if (TSDB_CODE_SUCCESS != code) { + tscError("0x%" PRIx64 " failed to schedule fetch rows", pRequest->requestId); + pRequest->body.fetchFp(param, pRequest, code); } } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 01a4fd5640..0a5fb1a7b4 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -85,7 +85,6 @@ void taos_cleanup(void) { tscWarn("failed to close clientReqRefPool"); } - DestroyRegexCache(); rpcCleanup(); tscDebug("rpc cleanup"); @@ -93,6 +92,8 @@ void taos_cleanup(void) { tmqMgmtClose(); + DestroyRegexCache(); + tscInfo("all local resources released"); taosCleanupCfg(); taosCloseLog(); diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index acdfd72c03..01435d51e3 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -12,13 +12,13 @@ SRWLatch monitorLock; void* monitorTimer; SHashObj* monitorCounterHash; -int32_t slowLogFlag = -1; -int32_t monitorFlag = -1; +int32_t monitorFlag = 0; int32_t quitCnt = 0; tsem2_t monitorSem; STaosQueue* monitorQueue; SHashObj* monitorSlowLogHash; char tmpSlowLogPath[PATH_MAX] = {0}; +TdThread monitorThread; static int32_t getSlowLogTmpDir(char* tmpPath, int32_t size) { int ret = snprintf(tmpPath, size, "%s/tdengine_slow_log/", tsTempDir); @@ -113,11 +113,11 @@ static int32_t monitorReportAsyncCB(void* param, SDataBuf* pMsg, int32_t code) { tscError("failed to send slow log:%s, clusterId:%" PRIx64, p->data, p->clusterId); } MonitorSlowLogData tmp = {.clusterId = p->clusterId, - .type = p->type, - .fileName = p->fileName, - .pFile = p->pFile, - .offset = p->offset, - .data = NULL}; + .type = p->type, + .fileName = p->fileName, + .pFile = p->pFile, + .offset = p->offset, + .data = NULL}; if (monitorPutData2MonitorQueue(tmp) == 0) { p->fileName = NULL; } @@ -164,7 +164,7 @@ static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITO int64_t transporterId = 0; return asyncSendMsgToServer(pTransporter, epSet, &transporterId, pInfo); -FAILED: + FAILED: monitorFreeSlowLogDataEx(param); return TAOS_GET_TERRNO(TSDB_CODE_TSC_INTERNAL_ERROR); } @@ -276,12 +276,10 @@ void monitorCreateClient(int64_t clusterId) { tscInfo("[monitor] monitorCreateClient for %" PRIx64 "finished %p.", clusterId, pMonitor); } taosWUnLockLatch(&monitorLock); - if (-1 != atomic_val_compare_exchange_32(&monitorFlag, -1, 0)) { - tscDebug("[monitor] monitorFlag already is 0"); - } + return; -fail: + fail: destroyMonitorClient(&pMonitor); taosWUnLockLatch(&monitorLock); } @@ -301,7 +299,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* 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"); (void)taos_counter_destroy(newCounter); @@ -310,7 +308,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* tscInfo("[monitor] monitorCreateClientCounter %" PRIx64 "(%p):%s : %p.", pMonitor->clusterId, pMonitor, name, newCounter); -end: + end: taosWUnLockLatch(&monitorLock); } @@ -339,7 +337,7 @@ void monitorCounterInc(int64_t clusterId, const char* counterName, const char** } tscDebug("[monitor] monitorCounterInc %" PRIx64 "(%p):%s", pMonitor->clusterId, pMonitor, counterName); -end: + end: taosWUnLockLatch(&monitorLock); } @@ -348,8 +346,6 @@ const char* monitorResultStr(SQL_RESULT_CODE code) { return result_state[code]; } -static void monitorThreadFuncUnexpectedStopped(void) { atomic_store_32(&slowLogFlag, -1); } - static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpPath) { TdFilePtr pFile = NULL; void* tmp = taosHashGet(monitorSlowLogHash, &slowLogData->clusterId, LONG_BYTES); @@ -489,6 +485,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); + taosMemoryFree(fileName); return terrno; } SEpSet ep = getEpSet_s(&pInst->mgmtEp); @@ -692,20 +689,10 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) { static void* monitorThreadFunc(void* param) { setThreadName("client-monitor-slowlog"); - -#ifdef WINDOWS - if (taosCheckCurrentInDll()) { - atexit(monitorThreadFuncUnexpectedStopped); - } -#endif - - if (-1 != atomic_val_compare_exchange_32(&slowLogFlag, -1, 0)) { - return NULL; - } tscDebug("monitorThreadFunc start"); int64_t quitTime = 0; while (1) { - if (atomic_load_32(&slowLogFlag) > 0) { + if (atomic_load_32(&monitorFlag) == 1) { if (quitCnt == 0) { monitorSendAllSlowLogAtQuit(); if (quitCnt == 0) { @@ -751,7 +738,6 @@ static void* monitorThreadFunc(void* param) { } (void)tsem2_timewait(&monitorSem, 100); } - atomic_store_32(&slowLogFlag, -2); return NULL; } @@ -766,7 +752,6 @@ static int32_t tscMonitortInit() { 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 TSDB_CODE_TSC_INTERNAL_ERROR; @@ -777,13 +762,9 @@ static int32_t tscMonitortInit() { } static void tscMonitorStop() { - if (atomic_val_compare_exchange_32(&slowLogFlag, 0, 1)) { - tscDebug("monitor thread already stopped"); - return; - } - - while (atomic_load_32(&slowLogFlag) > 0) { - taosMsleep(100); + if (taosCheckPthreadValid(monitorThread)) { + (void)taosThreadJoin(monitorThread, NULL); + (void)taosThreadClear(&monitorThread); } } @@ -841,10 +822,7 @@ int32_t monitorInit() { void monitorClose() { tscInfo("[monitor] tscMonitor close"); taosWLockLatch(&monitorLock); - - if (atomic_val_compare_exchange_32(&monitorFlag, 0, 1)) { - tscDebug("[monitor] monitorFlag is not 0"); - } + atomic_store_32(&monitorFlag, 1); tscMonitorStop(); sendAllCounter(); taosHashCleanup(monitorCounterHash); @@ -859,7 +837,7 @@ int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) { int32_t code = 0; MonitorSlowLogData* slowLogData = NULL; - if (atomic_load_32(&slowLogFlag) == -2) { + if (atomic_load_32(&monitorFlag) == 1) { tscError("[monitor] slow log thread is exiting"); return -1; } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index c63b31ddbe..d827357d5a 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -37,6 +37,7 @@ struct SMqMgmt { static TdThreadOnce tmqInit = PTHREAD_ONCE_INIT; // initialize only once volatile int32_t tmqInitRes = 0; // initialize rsp code static struct SMqMgmt tmqMgmt = {0}; +static int8_t pollFlag = 0; typedef struct { int32_t code; @@ -56,7 +57,7 @@ struct tmq_list_t { }; struct tmq_conf_t { - char clientId[256]; + char clientId[TSDB_CLIENT_ID_LEN]; char groupId[TSDB_CGROUP_LEN]; int8_t autoCommit; int8_t resetOffset; @@ -66,6 +67,9 @@ struct tmq_conf_t { int8_t sourceExcluded; // do not consume, bit uint16_t port; int32_t autoCommitInterval; + int32_t sessionTimeoutMs; + int32_t heartBeatIntervalMs; + int32_t maxPollIntervalMs; char* ip; char* user; char* pass; @@ -77,15 +81,18 @@ struct tmq_conf_t { struct tmq_t { int64_t refId; char groupId[TSDB_CGROUP_LEN]; - char clientId[256]; + char clientId[TSDB_CLIENT_ID_LEN]; int8_t withTbName; int8_t useSnapshot; int8_t autoCommit; int32_t autoCommitInterval; + int32_t sessionTimeoutMs; + int32_t heartBeatIntervalMs; + int32_t maxPollIntervalMs; int8_t resetOffsetCfg; int8_t replayEnable; int8_t sourceExcluded; // do not consume, bit - uint64_t consumerId; + int64_t consumerId; tmq_commit_cb* commitCb; void* commitCbUserParam; int8_t enableBatchMeta; @@ -240,7 +247,7 @@ typedef struct { SMqCommitCbParamSet* params; char topicName[TSDB_TOPIC_FNAME_LEN]; int32_t vgId; - tmq_t* pTmq; + int64_t consumerId; } SMqCommitCbParam; typedef struct SSyncCommitInfo { @@ -266,6 +273,9 @@ tmq_conf_t* tmq_conf_new() { conf->autoCommitInterval = DEFAULT_AUTO_COMMIT_INTERVAL; conf->resetOffset = TMQ_OFFSET__RESET_LATEST; conf->enableBatchMeta = false; + conf->heartBeatIntervalMs = DEFAULT_HEARTBEAT_INTERVAL; + conf->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL; + conf->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT; return conf; } @@ -295,7 +305,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "client.id") == 0) { - tstrncpy(conf->clientId, value, 256); + tstrncpy(conf->clientId, value, TSDB_CLIENT_ID_LEN); return TMQ_CONF_OK; } @@ -312,7 +322,38 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "auto.commit.interval.ms") == 0) { - conf->autoCommitInterval = taosStr2int64(value); + int64_t tmp = taosStr2int64(value); + if (tmp < 0 || EINVAL == errno || ERANGE == errno) { + return TMQ_CONF_INVALID; + } + conf->autoCommitInterval = (tmp > INT32_MAX ? INT32_MAX : tmp); + return TMQ_CONF_OK; + } + + if (strcasecmp(key, "session.timeout.ms") == 0) { + int64_t tmp = taosStr2int64(value); + if (tmp < 6000 || tmp > 1800000){ + return TMQ_CONF_INVALID; + } + conf->sessionTimeoutMs = tmp; + return TMQ_CONF_OK; + } + + if (strcasecmp(key, "heartbeat.interval.ms") == 0) { + int64_t tmp = taosStr2int64(value); + if (tmp < 1000 || tmp >= conf->sessionTimeoutMs){ + return TMQ_CONF_INVALID; + } + conf->heartBeatIntervalMs = tmp; + return TMQ_CONF_OK; + } + + if (strcasecmp(key, "max.poll.interval.ms") == 0) { + int64_t tmp = taosStr2int64(value); + if (tmp < 1000 || tmp > INT32_MAX){ + return TMQ_CONF_INVALID; + } + conf->maxPollIntervalMs = tmp; return TMQ_CONF_OK; } @@ -371,7 +412,12 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } if (strcasecmp(key, "td.connect.port") == 0) { - conf->port = taosStr2int64(value); + int64_t tmp = taosStr2int64(value); + if (tmp <= 0 || tmp > 65535) { + return TMQ_CONF_INVALID; + } + + conf->port = tmp; return TMQ_CONF_OK; } @@ -439,7 +485,7 @@ static int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) { taosMemoryFree(pBuf->pData); taosMemoryFree(pBuf->pEpSet); - return commitRspCountDown(pParamSet, pParam->pTmq->consumerId, pParam->topicName, pParam->vgId); + return commitRspCountDown(pParamSet, pParam->consumerId, pParam->topicName, pParam->vgId); } static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffsetVal* offset, const char* pTopicName, @@ -483,7 +529,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse pParam->params = pParamSet; pParam->vgId = vgId; - pParam->pTmq = tmq; + pParam->consumerId = tmq->consumerId; tstrncpy(pParam->topicName, pTopicName, tListLen(pParam->topicName)); @@ -825,6 +871,7 @@ void tmqSendHbReq(void* param, void* tmrId) { SMqHbReq req = {0}; req.consumerId = tmq->consumerId; req.epoch = tmq->epoch; + req.pollFlag = atomic_load_8(&pollFlag); req.topics = taosArrayInit(taosArrayGetSize(tmq->clientTopics), sizeof(TopicOffsetRows)); if (req.topics == NULL){ return; @@ -906,10 +953,11 @@ void tmqSendHbReq(void* param, void* tmrId) { tscError("tmqSendHbReq asyncSendMsgToServer failed"); } + atomic_val_compare_exchange_8(&pollFlag, 1, 0); OVER: tDestroySMqHbReq(&req); - if (tmrId != NULL) { - (void)taosTmrReset(tmqSendHbReq, DEFAULT_HEARTBEAT_INTERVAL, param, tmqMgmt.timer, &tmq->hbLiveTimer); + if(tmrId != NULL){ + (void)taosTmrReset(tmqSendHbReq, tmq->heartBeatIntervalMs, param, tmqMgmt.timer, &tmq->hbLiveTimer); } (void)taosReleaseRef(tmqMgmt.rsetId, refId); } @@ -1208,6 +1256,9 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { pTmq->useSnapshot = conf->snapEnable; pTmq->autoCommit = conf->autoCommit; pTmq->autoCommitInterval = conf->autoCommitInterval; + pTmq->sessionTimeoutMs = conf->sessionTimeoutMs; + pTmq->heartBeatIntervalMs = conf->heartBeatIntervalMs; + pTmq->maxPollIntervalMs = conf->maxPollIntervalMs; pTmq->commitCb = conf->commitCb; pTmq->commitCbUserParam = conf->commitCbUserParam; pTmq->resetOffsetCfg = conf->resetOffset; @@ -1246,7 +1297,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { goto _failed; } - pTmq->hbLiveTimer = taosTmrStart(tmqSendHbReq, DEFAULT_HEARTBEAT_INTERVAL, (void*)pTmq->refId, tmqMgmt.timer); + pTmq->hbLiveTimer = taosTmrStart(tmqSendHbReq, pTmq->heartBeatIntervalMs, (void*)pTmq->refId, tmqMgmt.timer); if (pTmq->hbLiveTimer == NULL) { SET_ERROR_MSG_TMQ("start heartbeat timer failed") goto _failed; @@ -1279,7 +1330,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { tscInfo("consumer:0x%" PRIx64 " cgroup:%s, subscribe %d topics", tmq->consumerId, tmq->groupId, sz); req.consumerId = tmq->consumerId; - tstrncpy(req.clientId, tmq->clientId, 256); + tstrncpy(req.clientId, tmq->clientId, TSDB_CLIENT_ID_LEN); tstrncpy(req.cgroup, tmq->groupId, TSDB_CGROUP_LEN); req.topicNames = taosArrayInit(sz, sizeof(void*)); @@ -1291,6 +1342,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { req.withTbName = tmq->withTbName; req.autoCommit = tmq->autoCommit; req.autoCommitInterval = tmq->autoCommitInterval; + req.sessionTimeoutMs = tmq->sessionTimeoutMs; + req.maxPollIntervalMs = tmq->maxPollIntervalMs; req.resetOffsetCfg = tmq->resetOffsetCfg; req.enableReplay = tmq->replayEnable; req.enableBatchMeta = tmq->enableBatchMeta; @@ -1452,22 +1505,22 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { tmq_t* tmq = NULL; SMqPollCbParam* pParam = (SMqPollCbParam*)param; if (pParam == NULL || pMsg == NULL) { - goto FAIL2; + return TSDB_CODE_TSC_INTERNAL_ERROR; } int64_t refId = pParam->refId; int32_t vgId = pParam->vgId; uint64_t requestId = pParam->requestId; tmq = taosAcquireRef(tmqMgmt.rsetId, refId); if (tmq == NULL) { - code = TSDB_CODE_TMQ_CONSUMER_CLOSED; - goto FAIL2; + return TSDB_CODE_TMQ_CONSUMER_CLOSED; } SMqPollRspWrapper* pRspWrapper = NULL; - code = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0, (void**)&pRspWrapper); - if (code) { + int32_t ret = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0, (void**)&pRspWrapper); + if (ret) { + code = ret; tscWarn("consumer:0x%" PRIx64 " msg discard from vgId:%d, since out of memory", tmq->consumerId, vgId); - goto FAIL1; + goto END; } if (code != 0) { @@ -1550,25 +1603,23 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { } END: - pRspWrapper->code = code; - pRspWrapper->vgId = vgId; - (void)strcpy(pRspWrapper->topicName, pParam->topicName); - code = taosWriteQitem(tmq->mqueue, pRspWrapper); - if(code != 0){ - tscError("consumer:0x%" PRIx64 " put poll res into mqueue failed, code:%d", tmq->consumerId, code); + if (pRspWrapper){ + pRspWrapper->code = code; + pRspWrapper->vgId = vgId; + (void)strcpy(pRspWrapper->topicName, pParam->topicName); + code = taosWriteQitem(tmq->mqueue, pRspWrapper); + if(code != 0){ + tscError("consumer:0x%" PRIx64 " put poll res into mqueue failed, code:%d", tmq->consumerId, code); + } } - int32_t total = taosQueueItemSize(tmq->mqueue); tscDebug("consumer:0x%" PRIx64 " put poll res into mqueue, type:%d, vgId:%d, total in queue:%d, reqId:0x%" PRIx64, tmq->consumerId, rspType, vgId, total, requestId); -FAIL1: - (void)taosReleaseRef(tmqMgmt.rsetId, refId); - -FAIL2: if (tmq) (void)tsem2_post(&tmq->rspSem); if (pMsg) taosMemoryFreeClear(pMsg->pData); if (pMsg) taosMemoryFreeClear(pMsg->pEpSet); + (void)taosReleaseRef(tmqMgmt.rsetId, refId); return code; } @@ -2343,6 +2394,8 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { } } + atomic_val_compare_exchange_8(&pollFlag, 0, 1); + while (1) { tmqHandleAllDelayedTask(tmq); diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 96309ece86..335c654acd 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -1178,6 +1178,13 @@ int32_t s3GetObjectBlock(const char *object_name, int64_t offset, int64_t size, &getObjectDataCallback}; TS3SizeCBD cbd = {0}; + int retryCount = 0; + static int maxRetryCount = 5; + static int minRetryInterval = 1000; // ms + static int maxRetryInterval = 3000; // ms + +_retry: + (void)memset(&cbd, 0, sizeof(cbd)); cbd.content_length = size; cbd.buf_pos = 0; do { @@ -1185,6 +1192,11 @@ int32_t s3GetObjectBlock(const char *object_name, int64_t offset, int64_t size, } while (S3_status_is_retryable(cbd.status) && should_retry()); if (cbd.status != S3StatusOK) { + if (S3StatusErrorSlowDown == cbd.status && retryCount++ < maxRetryCount) { + taosMsleep(taosRand() % (maxRetryInterval - minRetryInterval + 1) + minRetryInterval); + uInfo("%s: %d/%s(%s) retry get object", __func__, cbd.status, S3_get_status_name(cbd.status), cbd.err_msg); + goto _retry; + } uError("%s: %d/%s(%s)", __func__, cbd.status, S3_get_status_name(cbd.status), cbd.err_msg); TAOS_RETURN(TAOS_SYSTEM_ERROR(EIO)); diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index 5e51f62a1f..c7044864ae 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -32,10 +32,10 @@ static void removeEmptyDir() { empty = false; } if (empty) taosRemoveDir(filename); - taosCloseDir(&pDirTmp); + (void)taosCloseDir(&pDirTmp); } - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); } #ifdef WINDOWS @@ -92,12 +92,12 @@ static int32_t generateConfigFile(char* confDir) { uDebug("[rsync] conf:%s", confContent); if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) { uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); code = TAOS_SYSTEM_ERROR(errno); return code; } - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return 0; } diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 0c0073b4a7..2d69a687a6 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -482,16 +482,16 @@ static const SSysDbTableSchema connectionsSchema[] = { static const SSysDbTableSchema consumerSchema[] = { - {.name = "consumer_id", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, - {.name = "consumer_group", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, - {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, + {.name = "consumer_id", .bytes = TSDB_CONSUMER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, + {.name = "consumer_group", .bytes = TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, + {.name = "client_id", .bytes = TSDB_CLIENT_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, {.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, {.name = "topics", .bytes = TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, /*{.name = "end_point", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},*/ {.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, {.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, {.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false}, - {.name = "parameters", .bytes = 64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, + {.name = "parameters", .bytes = 128 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false}, }; static const SSysDbTableSchema offsetSchema[] = { diff --git a/source/common/src/tcol.c b/source/common/src/tcol.c index a949d0793a..17972c6777 100644 --- a/source/common/src/tcol.c +++ b/source/common/src/tcol.c @@ -238,7 +238,7 @@ const char* columnLevelStr(uint8_t type) { bool checkColumnEncode(char encode[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(encode)) return true; - strtolower(encode, encode); + (void)strtolower(encode, encode); for (int i = 0; i < supportedEncodeNum; ++i) { if (0 == strcmp((const char*)encode, supportedEncode[i])) { return true; @@ -255,7 +255,7 @@ bool checkColumnEncodeOrSetDefault(uint8_t type, char encode[TSDB_CL_COMPRESS_OP } bool checkColumnCompress(char compress[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(compress)) return true; - strtolower(compress, compress); + (void)strtolower(compress, compress); for (int i = 0; i < supportedCompressNum; ++i) { if (0 == strcmp((const char*)compress, supportedCompress[i])) { return true; @@ -273,7 +273,7 @@ bool checkColumnCompressOrSetDefault(uint8_t type, char compress[TSDB_CL_COMPRES } bool checkColumnLevel(char level[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(level)) return true; - strtolower(level, level); + (void)strtolower(level, level); if (1 == strlen(level)) { if ('h' == level[0] || 'm' == level[0] || 'l' == level[0]) return true; } else { diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index eecadcda71..56539c7f57 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -87,7 +87,7 @@ int32_t getJsonValueLen(const char* data) { } int32_t colDataSetVal(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const char* pData, bool isNull) { - if (isNull) { + if (isNull || pData == NULL) { // There is a placehold for each NULL value of binary or nchar type. if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { pColumnInfoData->varmeta.offset[rowIndex] = -1; // it is a null value of VAR type. diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 371fc130f0..5caf93de65 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -706,7 +706,10 @@ static int32_t tRowMergeImpl(SArray *aRowP, STSchema *pTSchema, int32_t iStart, if (code) goto _exit; taosArrayRemoveBatch(aRowP, iStart, nRow, (FDelete)tRowPDestroy); - taosArrayInsert(aRowP, iStart, &pRow); + if (taosArrayInsert(aRowP, iStart, &pRow) == NULL) { + code = terrno; + goto _exit; + } _exit: if (aIter) { @@ -1708,7 +1711,7 @@ bool tTagGet(const STag *pTag, STagVal *pTagVal) { offset = pTag->idx[midx]; } - tGetTagVal(p + offset, &tv, isJson); + (void)tGetTagVal(p + offset, &tv, isJson); if (isJson) { c = tTagValJsonCmprFn(pTagVal, &tv); } else { @@ -1758,7 +1761,7 @@ int32_t tTagToValArray(const STag *pTag, SArray **ppArray) { } else { offset = pTag->idx[iTag]; } - tGetTagVal(p + offset, &tv, pTag->flags & TD_TAG_JSON); + (void)tGetTagVal(p + offset, &tv, pTag->flags & TD_TAG_JSON); if (taosArrayPush(*ppArray, &tv) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -1788,7 +1791,7 @@ void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid) { offset = pTag->idx[iTag]; } - tPutI16v(p + offset, cid); + (void)tPutI16v(p + offset, cid); } // STSchema ======================================== @@ -3152,16 +3155,16 @@ static int32_t tColDataCopyRowSingleCol(SColData *pFromColData, int32_t iFromRow SET_BIT1(pToColData->pBitMap, iToRow, GET_BIT1(pFromColData->pBitMap, iFromRow)); } break; case HAS_VALUE: { - tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); } break; case (HAS_VALUE | HAS_NONE): case (HAS_VALUE | HAS_NULL): { SET_BIT1(pToColData->pBitMap, iToRow, GET_BIT1(pFromColData->pBitMap, iFromRow)); - tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); } break; case (HAS_VALUE | HAS_NULL | HAS_NONE): { SET_BIT2(pToColData->pBitMap, iToRow, GET_BIT2(pFromColData->pBitMap, iFromRow)); - tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); } break; default: return -1; @@ -3235,24 +3238,24 @@ static int32_t tColDataMergeSortMerge(SColData *aColData, int32_t start, int32_t tColDataArrGetRowKey(aColData, nColData, j, &keyj); while (i <= mid && j <= end) { if (tRowKeyCompare(&keyi, &keyj) <= 0) { - tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); + (void)tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); tColDataArrGetRowKey(aColData, nColData, i, &keyi); } else { - tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); + (void)tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); tColDataArrGetRowKey(aColData, nColData, j, &keyj); } } while (i <= mid) { - tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); + (void)tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); } while (j <= end) { - tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); + (void)tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); } for (i = start, k = 0; i <= end; ++i, ++k) { - tColDataCopyRow(aDstColData, k, aColData, i, nColData); + (void)tColDataCopyRow(aDstColData, k, aColData, i, nColData); } if (aDstColData) { @@ -3551,7 +3554,7 @@ void tColDataSortMerge(SArray *colDataArr) { // sort ------- if (doSort) { - tColDataSort(aColData, nColData); + (void)tColDataSort(aColData, nColData); } if (doMerge != 1) { @@ -4209,17 +4212,17 @@ int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value) { int32_t offset, nextOffset; SBufferReader reader = BUFFER_READER_INITIALIZER(idx * sizeof(offset), &valCol->offsets); - tBufferGetI32(&reader, &offset); + (void)tBufferGetI32(&reader, &offset); if (idx == valCol->numOfValues - 1) { nextOffset = tBufferGetSize(&valCol->data); } else { - tBufferGetI32(&reader, &nextOffset); + (void)tBufferGetI32(&reader, &nextOffset); } value->nData = nextOffset - offset; value->pData = (uint8_t *)tBufferGetDataAt(&valCol->data, offset); } else { SBufferReader reader = BUFFER_READER_INITIALIZER(idx * tDataTypes[value->type].bytes, &valCol->data); - tBufferGet(&reader, tDataTypes[value->type].bytes, &value->val); + (void)tBufferGet(&reader, tDataTypes[value->type].bytes, &value->val); } return 0; } @@ -4269,7 +4272,7 @@ int32_t tValueColumnDecompress(void *input, const SValueColumnCompressInfo *info SBuffer *assist) { int32_t code; - tValueColumnClear(valCol); + (void)tValueColumnClear(valCol); valCol->type = info->type; // offset if (IS_VAR_DATA_TYPE(valCol->type)) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index f4f3dafcf0..a3576504e2 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -329,9 +329,15 @@ int32_t tsMaxTsmaNum = 3; int32_t tsMaxTsmaCalcDelay = 600; int64_t tsmaDataDeleteMark = 1000 * 60 * 60 * 24; // in ms, default to 1d +#define TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, pName) \ + if ((pItem = cfgGetItem(pCfg, pName)) == NULL) { \ + TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); \ + } + #ifndef _STORAGE int32_t taosSetTfsCfg(SConfig *pCfg) { - SConfigItem *pItem = cfgGetItem(pCfg, "dataDir"); + SConfigItem *pItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "dataDir"); (void)memset(tsDataDir, 0, PATH_MAX); int32_t size = taosArrayGetSize(pItem->array); @@ -353,7 +359,10 @@ int32_t taosSetTfsCfg(SConfig *pCfg); #endif int32_t taosSetS3Cfg(SConfig *pCfg) { - tstrncpy(tsS3AccessKey, cfgGetItem(pCfg, "s3Accesskey")->str, TSDB_FQDN_LEN); + SConfigItem *pItem = NULL; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3Accesskey"); + tstrncpy(tsS3AccessKey, pItem->str, TSDB_FQDN_LEN); if (tsS3AccessKey[0] == '<') { TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -365,8 +374,10 @@ int32_t taosSetS3Cfg(SConfig *pCfg) { *colon = '\0'; tstrncpy(tsS3AccessKeyId, tsS3AccessKey, TSDB_FQDN_LEN); tstrncpy(tsS3AccessKeySecret, colon + 1, TSDB_FQDN_LEN); - tstrncpy(tsS3Endpoint, cfgGetItem(pCfg, "s3Endpoint")->str, TSDB_FQDN_LEN); - tstrncpy(tsS3BucketName, cfgGetItem(pCfg, "s3BucketName")->str, TSDB_FQDN_LEN); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3Endpoint"); + tstrncpy(tsS3Endpoint, pItem->str, TSDB_FQDN_LEN); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3BucketName"); + tstrncpy(tsS3BucketName, pItem->str, TSDB_FQDN_LEN); char *proto = strstr(tsS3Endpoint, "https://"); if (!proto) { tsS3Https = false; @@ -406,8 +417,9 @@ struct SConfig *taosGetCfg() { return tsCfg; } static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) { - char cfgDir[PATH_MAX] = {0}; - char cfgFile[PATH_MAX + 100] = {0}; + int32_t code = 0; + char cfgDir[PATH_MAX] = {0}; + char cfgFile[PATH_MAX + 100] = {0}; TAOS_CHECK_RETURN(taosExpandDir(inputCfgDir, cfgDir, PATH_MAX)); char lastC = cfgDir[strlen(cfgDir) - 1]; @@ -434,32 +446,32 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input } if (apolloUrl != NULL && apolloUrl[0] == '\0') { - TAOS_CHECK_RETURN(cfgGetApollUrl(envCmd, envFile, apolloUrl)); + (void)(cfgGetApollUrl(envCmd, envFile, apolloUrl)); } - if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) { - uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr()); - TAOS_RETURN(TSDB_CODE_INVALID_CFG); + if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) { + uError("failed to load from apollo url:%s since %s", apolloUrl, tstrerror(code)); + TAOS_RETURN(code); } - if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) { - uError("failed to load from cfg file:%s since %s", cfgFile, terrstr()); - TAOS_RETURN(TSDB_CODE_INVALID_CFG); + if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) { + uError("failed to load from cfg file:%s since %s", cfgFile, tstrerror(code)); + TAOS_RETURN(code); } - if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) { - uError("failed to load from env file:%s since %s", envFile, terrstr()); - TAOS_RETURN(TSDB_CODE_INVALID_CFG); + if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) { + uError("failed to load from env file:%s since %s", envFile, tstrerror(code)); + TAOS_RETURN(code); } - if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) { - uError("failed to load from global env variables since %s", terrstr()); - TAOS_RETURN(TSDB_CODE_INVALID_CFG); + if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) { + uError("failed to load from global env variables since %s", tstrerror(code)); + TAOS_RETURN(code); } - if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) { - uError("failed to load from cmd env variables since %s", terrstr()); - TAOS_RETURN(TSDB_CODE_INVALID_CFG); + if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) { + uError("failed to load from cmd env variables since %s", tstrerror(code)); + TAOS_RETURN(code); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -798,7 +810,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { int32_t numOfCores; int64_t totalMemoryKB; - pItem = cfgGetItem(tsCfg, "numOfCores"); + pItem = cfgGetItem(pCfg, "numOfCores"); if (pItem == NULL) { TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); } else { @@ -806,7 +818,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { numOfCores = pItem->fval; } - pItem = cfgGetItem(tsCfg, "supportVnodes"); + pItem = cfgGetItem(pCfg, "supportVnodes"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfSupportVnodes = numOfCores * 2 + 5; tsNumOfSupportVnodes = TMAX(tsNumOfSupportVnodes, 2); @@ -814,7 +826,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfRpcThreads"); + pItem = cfgGetItem(pCfg, "numOfRpcThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfRpcThreads = numOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); @@ -822,21 +834,21 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfRpcSessions"); + pItem = cfgGetItem(pCfg, "numOfRpcSessions"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfRpcSessions = TRANGE(tsNumOfRpcSessions, 100, 10000); pItem->i32 = tsNumOfRpcSessions; pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "timeToGetAvailableConn"); + pItem = cfgGetItem(pCfg, "timeToGetAvailableConn"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 1000000); pItem->i32 = tsTimeToGetAvailableConn; pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfCommitThreads"); + pItem = cfgGetItem(pCfg, "numOfCommitThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfCommitThreads = numOfCores / 2; tsNumOfCommitThreads = TRANGE(tsNumOfCommitThreads, 2, 4); @@ -844,7 +856,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfMnodeReadThreads"); + pItem = cfgGetItem(pCfg, "numOfMnodeReadThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfMnodeReadThreads = numOfCores / 8; tsNumOfMnodeReadThreads = TRANGE(tsNumOfMnodeReadThreads, 1, 4); @@ -852,7 +864,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfVnodeQueryThreads"); + pItem = cfgGetItem(pCfg, "numOfVnodeQueryThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfVnodeQueryThreads = numOfCores * 2; tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 16); @@ -860,13 +872,13 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "ratioOfVnodeStreamThreads"); + pItem = cfgGetItem(pCfg, "ratioOfVnodeStreamThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { pItem->fval = tsRatioOfVnodeStreamThreads; pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfVnodeFetchThreads"); + pItem = cfgGetItem(pCfg, "numOfVnodeFetchThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfVnodeFetchThreads = numOfCores / 4; tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); @@ -874,7 +886,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfVnodeRsmaThreads"); + pItem = cfgGetItem(pCfg, "numOfVnodeRsmaThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfVnodeRsmaThreads = numOfCores; tsNumOfVnodeRsmaThreads = TMAX(tsNumOfVnodeRsmaThreads, 4); @@ -882,7 +894,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfQnodeQueryThreads"); + pItem = cfgGetItem(pCfg, "numOfQnodeQueryThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfQnodeQueryThreads = numOfCores * 2; tsNumOfQnodeQueryThreads = TMAX(tsNumOfQnodeQueryThreads, 16); @@ -890,17 +902,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - /* - pItem = cfgGetItem(tsCfg, "numOfQnodeFetchThreads"); - if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfQnodeFetchThreads = numOfCores / 2; - tsNumOfQnodeFetchThreads = TMAX(tsNumOfQnodeFetchThreads, 4); - pItem->i32 = tsNumOfQnodeFetchThreads; - pItem->stype = stype; - } - */ - - pItem = cfgGetItem(tsCfg, "numOfSnodeSharedThreads"); + pItem = cfgGetItem(pCfg, "numOfSnodeSharedThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfSnodeStreamThreads = numOfCores / 4; tsNumOfSnodeStreamThreads = TRANGE(tsNumOfSnodeStreamThreads, 2, 4); @@ -908,7 +910,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfSnodeUniqueThreads"); + pItem = cfgGetItem(pCfg, "numOfSnodeUniqueThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfSnodeWriteThreads = numOfCores / 4; tsNumOfSnodeWriteThreads = TRANGE(tsNumOfSnodeWriteThreads, 2, 4); @@ -916,7 +918,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "totalMemoryKB"); + pItem = cfgGetItem(pCfg, "totalMemoryKB"); if (pItem == NULL) { TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); } else { @@ -924,7 +926,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { totalMemoryKB = pItem->i64; } - pItem = cfgGetItem(tsCfg, "rpcQueueMemoryAllowed"); + pItem = cfgGetItem(pCfg, "rpcQueueMemoryAllowed"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsRpcQueueMemoryAllowed = totalMemoryKB * 1024 * 0.1; tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10LL, TSDB_MAX_MSG_SIZE * 10000LL); @@ -935,39 +937,97 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { TAOS_RETURN(TSDB_CODE_SUCCESS); } -static void taosSetClientLogCfg(SConfig *pCfg) { - SConfigItem *pItem = cfgGetItem(pCfg, "logDir"); - tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX); - taosExpandDir(tsLogDir, tsLogDir, PATH_MAX); - tsLogSpace.reserved = (int64_t)(((double)cfgGetItem(pCfg, "minimalLogDirGB")->fval) * 1024 * 1024 * 1024); - tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; - tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; - tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32; - tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32; - uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32; - jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32; - rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32; - qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; - cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; - simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32; +static int32_t taosSetClientLogCfg(SConfig *pCfg) { + SConfigItem *pItem = NULL; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "logDir"); + tstrncpy(tsLogDir, pItem->str, PATH_MAX); + TAOS_CHECK_RETURN(taosExpandDir(tsLogDir, tsLogDir, PATH_MAX)); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minimalLogDirGB"); + tsLogSpace.reserved = (int64_t)(((double)pItem->fval) * 1024 * 1024 * 1024); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfLogLines"); + tsNumOfLogLines = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "asyncLog"); + tsAsyncLog = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "logKeepDays"); + tsLogKeepDays = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tmrDebugFlag"); + tmrDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "uDebugFlag"); + uDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "jniDebugFlag"); + jniDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "rpcDebugFlag"); + rpcDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "qDebugFlag"); + qDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "cDebugFlag"); + cDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "simDebugFlag"); + simDebugFlag = pItem->i32; + + TAOS_RETURN(TSDB_CODE_SUCCESS); } -static void taosSetServerLogCfg(SConfig *pCfg) { - dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; - vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32; - mDebugFlag = cfgGetItem(pCfg, "mDebugFlag")->i32; - wDebugFlag = cfgGetItem(pCfg, "wDebugFlag")->i32; - sDebugFlag = cfgGetItem(pCfg, "sDebugFlag")->i32; - tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32; - tqDebugFlag = cfgGetItem(pCfg, "tqDebugFlag")->i32; - fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32; - udfDebugFlag = cfgGetItem(pCfg, "udfDebugFlag")->i32; - smaDebugFlag = cfgGetItem(pCfg, "smaDebugFlag")->i32; - idxDebugFlag = cfgGetItem(pCfg, "idxDebugFlag")->i32; - tdbDebugFlag = cfgGetItem(pCfg, "tdbDebugFlag")->i32; - metaDebugFlag = cfgGetItem(pCfg, "metaDebugFlag")->i32; - stDebugFlag = cfgGetItem(pCfg, "stDebugFlag")->i32; - sndDebugFlag = cfgGetItem(pCfg, "sndDebugFlag")->i32; +static int32_t taosSetServerLogCfg(SConfig *pCfg) { + SConfigItem *pItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "dDebugFlag"); + dDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "vDebugFlag"); + vDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "mDebugFlag"); + mDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "wDebugFlag"); + wDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "sDebugFlag"); + sDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tsdbDebugFlag"); + tsdbDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tqDebugFlag"); + tqDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "fsDebugFlag"); + fsDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udfDebugFlag"); + udfDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smaDebugFlag"); + smaDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "idxDebugFlag"); + idxDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tdbDebugFlag"); + tdbDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "metaDebugFlag"); + metaDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "stDebugFlag"); + stDebugFlag = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "sndDebugFlag"); + sndDebugFlag = pItem->i32; + + TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope) { @@ -1021,105 +1081,159 @@ int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope) { // for common configs static int32_t taosSetClientCfg(SConfig *pCfg) { - tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); - tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + SConfigItem *pItem = NULL; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "fqdn"); + tstrncpy(tsLocalFqdn, pItem->str, TSDB_FQDN_LEN); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "serverPort"); + tsServerPort = (uint16_t)pItem->i32; (void)snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "firstEp"); SEp firstEp = {0}; - TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp)); + TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? defaultFirstEp : pItem->str, &firstEp)); (void)snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); - TAOS_CHECK_RETURN(cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype, true)); + TAOS_CHECK_RETURN(cfgSetItem(pCfg, "firstEp", tsFirst, pItem->stype, true)); - SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp"); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "secondEp"); SEp secondEp = {0}; - TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pSecondpItem->str) == 0 ? defaultFirstEp : pSecondpItem->str, &secondEp)); + TAOS_CHECK_RETURN(taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? defaultFirstEp : pItem->str, &secondEp)); (void)snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port); - TAOS_CHECK_RETURN(cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype, true)); + TAOS_CHECK_RETURN(cfgSetItem(pCfg, "secondEp", tsSecond, pItem->stype, true)); - tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tempDir"); + tstrncpy(tsTempDir, pItem->str, PATH_MAX); TAOS_CHECK_RETURN(taosExpandDir(tsTempDir, tsTempDir, PATH_MAX)); - tsTempSpace.reserved = (int64_t)(((double)cfgGetItem(pCfg, "minimalTmpDirGB")->fval) * 1024 * 1024 * 1024); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minimalTmpDirGB"); + tsTempSpace.reserved = (int64_t)(((double)pItem->fval) * 1024 * 1024 * 1024); if (taosMulMkDir(tsTempDir) != 0) { int32_t code = TAOS_SYSTEM_ERROR(errno); uError("failed to create tempDir:%s since %s", tsTempDir, tstrerror(code)); TAOS_RETURN(code); } - tstrncpy(tsSmlAutoChildTableNameDelimiter, cfgGetItem(pCfg, "smlAutoChildTableNameDelimiter")->str, - TSDB_TABLE_NAME_LEN); - tstrncpy(tsSmlChildTableName, cfgGetItem(pCfg, "smlChildTableName")->str, TSDB_TABLE_NAME_LEN); - tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagName")->str, TSDB_COL_NAME_LEN); - tstrncpy(tsSmlTsDefaultName, cfgGetItem(pCfg, "smlTsDefaultName")->str, TSDB_COL_NAME_LEN); - tsSmlDot2Underline = cfgGetItem(pCfg, "smlDot2Underline")->bval; - // tsSmlDataFormat = cfgGetItem(pCfg, "smlDataFormat")->bval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlAutoChildTableNameDelimiter"); + tstrncpy(tsSmlAutoChildTableNameDelimiter, pItem->str, TSDB_TABLE_NAME_LEN); - // tsSmlBatchSize = cfgGetItem(pCfg, "smlBatchSize")->i32; - tsMaxInsertBatchRows = cfgGetItem(pCfg, "maxInsertBatchRows")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlChildTableName"); + tstrncpy(tsSmlChildTableName, pItem->str, TSDB_TABLE_NAME_LEN); - tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; - tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32; - tsNumOfTaskQueueThreads = cfgGetItem(pCfg, "numOfTaskQueueThreads")->i32; - tsQueryPolicy = cfgGetItem(pCfg, "queryPolicy")->i32; - tsEnableQueryHb = cfgGetItem(pCfg, "enableQueryHb")->bval; - tsEnableScience = cfgGetItem(pCfg, "enableScience")->bval; - tsQuerySmaOptimize = cfgGetItem(pCfg, "querySmaOptimize")->i32; - tsQueryPlannerTrace = cfgGetItem(pCfg, "queryPlannerTrace")->bval; - tsQueryNodeChunkSize = cfgGetItem(pCfg, "queryNodeChunkSize")->i32; - tsQueryUseNodeAllocator = cfgGetItem(pCfg, "queryUseNodeAllocator")->bval; - tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval; - tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval; - tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval; - tsQueryMaxConcurrentTables = cfgGetItem(pCfg, "queryMaxConcurrentTables")->i64; - tsMetaCacheMaxSize = cfgGetItem(pCfg, "metaCacheMaxSize")->i32; - tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlTagName"); + tstrncpy(tsSmlTagName, pItem->str, TSDB_COL_NAME_LEN); - tsMaxRetryWaitTime = cfgGetItem(pCfg, "maxRetryWaitTime")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlTsDefaultName"); + tstrncpy(tsSmlTsDefaultName, pItem->str, TSDB_COL_NAME_LEN); - tsNumOfRpcThreads = cfgGetItem(pCfg, "numOfRpcThreads")->i32; - tsNumOfRpcSessions = cfgGetItem(pCfg, "numOfRpcSessions")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "smlDot2Underline"); + tsSmlDot2Underline = pItem->bval; - tsTimeToGetAvailableConn = cfgGetItem(pCfg, "timeToGetAvailableConn")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxInsertBatchRows"); + tsMaxInsertBatchRows = pItem->i32; - tsKeepAliveIdle = cfgGetItem(pCfg, "keepAliveIdle")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shellActivityTimer"); + tsShellActivityTimer = pItem->i32; - tsExperimental = cfgGetItem(pCfg, "experimental")->bval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compressMsgSize"); + tsCompressMsgSize = pItem->i32; - tsMultiResultFunctionStarReturnTags = cfgGetItem(pCfg, "multiResultFunctionStarReturnTags")->bval; - tsMaxTsmaCalcDelay = cfgGetItem(pCfg, "maxTsmaCalcDelay")->i32; - tsmaDataDeleteMark = cfgGetItem(pCfg, "tsmaDataDeleteMark")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfTaskQueueThreads"); + tsNumOfTaskQueueThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryPolicy"); + tsQueryPolicy = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "enableQueryHb"); + tsEnableQueryHb = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "enableScience"); + tsEnableScience = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "querySmaOptimize"); + tsQuerySmaOptimize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryPlannerTrace"); + tsQueryPlannerTrace = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryNodeChunkSize"); + tsQueryNodeChunkSize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryUseNodeAllocator"); + tsQueryUseNodeAllocator = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "keepColumnName"); + tsKeepColumnName = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "useAdapter"); + tsUseAdapter = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "crashReporting"); + tsEnableCrashReport = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryMaxConcurrentTables"); + tsQueryMaxConcurrentTables = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "metaCacheMaxSize"); + tsMetaCacheMaxSize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "countAlwaysReturnValue"); + tsCountAlwaysReturnValue = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxRetryWaitTime"); + tsMaxRetryWaitTime = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcThreads"); + tsNumOfRpcThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); + tsNumOfRpcSessions = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); + tsTimeToGetAvailableConn = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "keepAliveIdle"); + tsKeepAliveIdle = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "experimental"); + tsExperimental = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "multiResultFunctionStarReturnTags"); + tsMultiResultFunctionStarReturnTags = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxTsmaCalcDelay"); + tsMaxTsmaCalcDelay = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tsmaDataDeleteMark"); + tsmaDataDeleteMark = pItem->i32; TAOS_RETURN(TSDB_CODE_SUCCESS); } static int32_t taosSetSystemCfg(SConfig *pCfg) { - SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + SConfigItem *pItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timezone"); TAOS_CHECK_RETURN(osSetTimezone(pItem->str)); uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr); TAOS_CHECK_RETURN(cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype, true)); - pItem = cfgGetItem(pCfg, "locale"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "locale"); const char *locale = pItem->str; - pItem = cfgGetItem(pCfg, "charset"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "charset"); const char *charset = pItem->str; - taosSetSystemLocale(locale, charset); + (void)taosSetSystemLocale(locale, charset); // ignore this error temporarily osSetSystemLocale(locale, charset); - pItem = cfgGetItem(pCfg, "enableCoreFile"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "enableCoreFile"); bool enableCore = pItem->bval; taosSetCoreDump(enableCore); - pItem = cfgGetItem(pCfg, "assert"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "assert"); tsAssert = pItem->bval; // todo @@ -1130,140 +1244,321 @@ static int32_t taosSetSystemCfg(SConfig *pCfg) { // for server configs static int32_t taosSetServerCfg(SConfig *pCfg) { - tsDataSpace.reserved = (int64_t)(((double)cfgGetItem(pCfg, "minimalDataDirGB")->fval) * 1024 * 1024 * 1024); - tsNumOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; - tsMaxShellConns = cfgGetItem(pCfg, "maxShellConns")->i32; - tsStatusInterval = cfgGetItem(pCfg, "statusInterval")->i32; - tsMinSlidingTime = cfgGetItem(pCfg, "minSlidingTime")->i32; - tsMinIntervalTime = cfgGetItem(pCfg, "minIntervalTime")->i32; - tsQueryBufferSize = cfgGetItem(pCfg, "queryBufferSize")->i32; - tstrncpy(tsEncryptAlgorithm, cfgGetItem(pCfg, "encryptAlgorithm")->str, 16); - tstrncpy(tsEncryptScope, cfgGetItem(pCfg, "encryptScope")->str, 100); - // tstrncpy(tsAuthCode, cfgGetItem(pCfg, "authCode")->str, 100); + SConfigItem *pItem = NULL; - tsNumOfRpcThreads = cfgGetItem(pCfg, "numOfRpcThreads")->i32; - tsNumOfRpcSessions = cfgGetItem(pCfg, "numOfRpcSessions")->i32; - tsTimeToGetAvailableConn = cfgGetItem(pCfg, "timeToGetAvailableConn")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minimalDataDirGB"); + tsDataSpace.reserved = (int64_t)(((double)pItem->fval) * 1024 * 1024 * 1024); - tsQueryUseMemoryPool = (bool)cfgGetItem(pCfg, "queryUseMemoryPool")->bval; - tsSingleQueryMaxMemorySize = cfgGetItem(pCfg, "singleQueryMaxMemorySize")->i32; - tsQueryBufferPoolSize = cfgGetItem(pCfg, "queryBufferPoolSize")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "supportVnodes"); + tsNumOfSupportVnodes = pItem->i32; - tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32; - tsRetentionSpeedLimitMB = cfgGetItem(pCfg, "retentionSpeedLimitMB")->i32; - tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32; - tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32; - tsRatioOfVnodeStreamThreads = cfgGetItem(pCfg, "ratioOfVnodeStreamThreads")->fval; - tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; - tsNumOfVnodeRsmaThreads = cfgGetItem(pCfg, "numOfVnodeRsmaThreads")->i32; - tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; - // tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchTereads")->i32; - tsNumOfSnodeStreamThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; - tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; - tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxShellConns"); + tsMaxShellConns = pItem->i32; - tsSIMDEnable = (bool)cfgGetItem(pCfg, "simdEnable")->bval; - tsTagFilterCache = (bool)cfgGetItem(pCfg, "tagFilterCache")->bval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "statusInterval"); + tsStatusInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minSlidingTime"); + tsMinSlidingTime = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minIntervalTime"); + tsMinIntervalTime = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryBufferSize"); + tsQueryBufferSize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "encryptAlgorithm"); + tstrncpy(tsEncryptAlgorithm, pItem->str, 16); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "encryptScope"); + tstrncpy(tsEncryptScope, pItem->str, 100); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcThreads"); + tsNumOfRpcThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); + tsNumOfRpcSessions = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); + tsTimeToGetAvailableConn = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfCommitThreads"); + tsNumOfCommitThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "retentionSpeedLimitMB"); + tsRetentionSpeedLimitMB = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfMnodeReadThreads"); + tsNumOfMnodeReadThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfVnodeQueryThreads"); + tsNumOfVnodeQueryThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ratioOfVnodeStreamThreads"); + tsRatioOfVnodeStreamThreads = pItem->fval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfVnodeFetchThreads"); + tsNumOfVnodeFetchThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfVnodeRsmaThreads"); + tsNumOfVnodeRsmaThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfQnodeQueryThreads"); + tsNumOfQnodeQueryThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfSnodeSharedThreads"); + tsNumOfSnodeStreamThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfSnodeUniqueThreads"); + tsNumOfSnodeWriteThreads = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "rpcQueueMemoryAllowed"); + tsRpcQueueMemoryAllowed = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "simdEnable"); + tsSIMDEnable = (bool)pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tagFilterCache"); + tsTagFilterCache = (bool)pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogExceptDb"); + tstrncpy(tsSlowLogExceptDb, pItem->str, TSDB_DB_NAME_LEN); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogThresholdTest"); + tsSlowLogThresholdTest = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogThreshold"); + tsSlowLogThreshold = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogMaxLen"); + tsSlowLogMaxLen = pItem->i32; - tstrncpy(tsSlowLogExceptDb, cfgGetItem(pCfg, "slowLogExceptDb")->str, TSDB_DB_NAME_LEN); - tsSlowLogThresholdTest = cfgGetItem(pCfg, "slowLogThresholdTest")->i32; - tsSlowLogThreshold = cfgGetItem(pCfg, "slowLogThreshold")->i32; - tsSlowLogMaxLen = cfgGetItem(pCfg, "slowLogMaxLen")->i32; int32_t scope = 0; - TAOS_CHECK_RETURN(taosSetSlowLogScope(cfgGetItem(pCfg, "slowLogScope")->str, &scope)); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "slowLogScope"); + TAOS_CHECK_RETURN(taosSetSlowLogScope(pItem->str, &scope)); tsSlowLogScope = scope; - tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; - tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32; - tstrncpy(tsMonitorFqdn, cfgGetItem(pCfg, "monitorFqdn")->str, TSDB_FQDN_LEN); - tsMonitorPort = (uint16_t)cfgGetItem(pCfg, "monitorPort")->i32; - tsMonitorMaxLogs = cfgGetItem(pCfg, "monitorMaxLogs")->i32; - tsMonitorComp = cfgGetItem(pCfg, "monitorComp")->bval; - tsQueryRspPolicy = cfgGetItem(pCfg, "queryRspPolicy")->i32; - tsMonitorLogProtocol = cfgGetItem(pCfg, "monitorLogProtocol")->bval; - tsMonitorForceV2 = cfgGetItem(pCfg, "monitorForceV2")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitor"); + tsEnableMonitor = pItem->bval; - tsEnableAudit = cfgGetItem(pCfg, "audit")->bval; - tsEnableAuditCreateTable = cfgGetItem(pCfg, "auditCreateTable")->bval; - tsAuditInterval = cfgGetItem(pCfg, "auditInterval")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorInterval"); + tsMonitorInterval = pItem->i32; - tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; - tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval; - tsTtlChangeOnWrite = cfgGetItem(pCfg, "ttlChangeOnWrite")->bval; - tsTtlFlushThreshold = cfgGetItem(pCfg, "ttlFlushThreshold")->i32; - tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32; - tsRsyncPort = cfgGetItem(pCfg, "rsyncPort")->i32; - tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN); - tstrncpy(tsSnodeAddress, cfgGetItem(pCfg, "snodeAddress")->str, TSDB_FQDN_LEN); - tstrncpy(tsCheckpointBackupDir, cfgGetItem(pCfg, "checkpointBackupDir")->str, PATH_MAX); - tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorFqdn"); + tstrncpy(tsMonitorFqdn, pItem->str, TSDB_FQDN_LEN); - tmqMaxTopicNum = cfgGetItem(pCfg, "tmqMaxTopicNum")->i32; - tmqRowSize = cfgGetItem(pCfg, "tmqRowSize")->i32; - tsMaxTsmaNum = cfgGetItem(pCfg, "maxTsmaNum")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorPort"); + tsMonitorPort = (uint16_t)pItem->i32; - tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32; - tsCompactPullupInterval = cfgGetItem(pCfg, "compactPullupInterval")->i32; - tsMqRebalanceInterval = cfgGetItem(pCfg, "mqRebalanceInterval")->i32; - tsTtlUnit = cfgGetItem(pCfg, "ttlUnit")->i32; - tsTtlPushIntervalSec = cfgGetItem(pCfg, "ttlPushInterval")->i32; - tsTtlBatchDropNum = cfgGetItem(pCfg, "ttlBatchDropNum")->i32; - tsTrimVDbIntervalSec = cfgGetItem(pCfg, "trimVDbIntervalSec")->i32; - tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32; - tsQueryRsmaTolerance = cfgGetItem(pCfg, "queryRsmaTolerance")->i32; - tsTimeSeriesThreshold = cfgGetItem(pCfg, "timeseriesThreshold")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorMaxLogs"); + tsMonitorMaxLogs = pItem->i32; - tsWalFsyncDataSizeLimit = cfgGetItem(pCfg, "walFsyncDataSizeLimit")->i64; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorComp"); + tsMonitorComp = pItem->bval; - tsElectInterval = cfgGetItem(pCfg, "syncElectInterval")->i32; - tsHeartbeatInterval = cfgGetItem(pCfg, "syncHeartbeatInterval")->i32; - tsHeartbeatTimeout = cfgGetItem(pCfg, "syncHeartbeatTimeout")->i32; - tsSnapReplMaxWaitN = cfgGetItem(pCfg, "syncSnapReplMaxWaitN")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryRspPolicy"); + tsQueryRspPolicy = pItem->i32; - tsArbHeartBeatIntervalSec = cfgGetItem(pCfg, "arbHeartBeatIntervalSec")->i32; - tsArbCheckSyncIntervalSec = cfgGetItem(pCfg, "arbCheckSyncIntervalSec")->i32; - tsArbSetAssignedTimeoutSec = cfgGetItem(pCfg, "arbSetAssignedTimeoutSec")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorLogProtocol"); + tsMonitorLogProtocol = pItem->bval; - tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64; - tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64; - tsMndSkipGrant = cfgGetItem(pCfg, "skipGrant")->bval; - tsEnableWhiteList = cfgGetItem(pCfg, "enableWhiteList")->bval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "monitorForceV2"); + tsMonitorForceV2 = pItem->i32; - tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; - tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs)); - tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath)); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "audit"); + tsEnableAudit = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "auditCreateTable"); + tsEnableAuditCreateTable = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "auditInterval"); + tsAuditInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryReporting"); + tsEnableTelem = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "crashReporting"); + tsEnableCrashReport = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ttlChangeOnWrite"); + tsTtlChangeOnWrite = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ttlFlushThreshold"); + tsTtlFlushThreshold = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryInterval"); + tsTelemInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "rsyncPort"); + tsRsyncPort = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryServer"); + tstrncpy(tsTelemServer, pItem->str, TSDB_FQDN_LEN); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "snodeAddress"); + tstrncpy(tsSnodeAddress, pItem->str, TSDB_FQDN_LEN); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "checkpointBackupDir"); + tstrncpy(tsCheckpointBackupDir, pItem->str, PATH_MAX); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "telemetryPort"); + tsTelemPort = (uint16_t)pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tmqMaxTopicNum"); + tmqMaxTopicNum = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "tmqRowSize"); + tmqRowSize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxTsmaNum"); + tsMaxTsmaNum = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "transPullupInterval"); + tsTransPullupInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compactPullupInterval"); + tsCompactPullupInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "mqRebalanceInterval"); + tsMqRebalanceInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ttlUnit"); + tsTtlUnit = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ttlPushInterval"); + tsTtlPushIntervalSec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ttlBatchDropNum"); + tsTtlBatchDropNum = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "trimVDbIntervalSec"); + tsTrimVDbIntervalSec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "uptimeInterval"); + tsUptimeInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryRsmaTolerance"); + tsQueryRsmaTolerance = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeseriesThreshold"); + tsTimeSeriesThreshold = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "walFsyncDataSizeLimit"); + tsWalFsyncDataSizeLimit = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "syncElectInterval"); + tsElectInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "syncHeartbeatInterval"); + tsHeartbeatInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "syncHeartbeatTimeout"); + tsHeartbeatTimeout = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "syncSnapReplMaxWaitN"); + tsSnapReplMaxWaitN = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "arbHeartBeatIntervalSec"); + tsArbHeartBeatIntervalSec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "arbCheckSyncIntervalSec"); + tsArbCheckSyncIntervalSec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "arbSetAssignedTimeoutSec"); + tsArbSetAssignedTimeoutSec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "mndSdbWriteDelta"); + tsMndSdbWriteDelta = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "mndLogRetention"); + tsMndLogRetention = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "skipGrant"); + tsMndSkipGrant = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "enableWhiteList"); + tsEnableWhiteList = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udf"); + tsStartUdfd = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udfdResFuncs"); + tstrncpy(tsUdfdResFuncs, pItem->str, sizeof(tsUdfdResFuncs)); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "udfdLdLibPath"); + tstrncpy(tsUdfdLdLibPath, pItem->str, sizeof(tsUdfdLdLibPath)); if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } - tsCacheLazyLoadThreshold = cfgGetItem(pCfg, "cacheLazyLoadThreshold")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "cacheLazyLoadThreshold"); + tsCacheLazyLoadThreshold = pItem->i32; - tsFPrecision = cfgGetItem(pCfg, "fPrecision")->fval; - tsDPrecision = cfgGetItem(pCfg, "dPrecision")->fval; - tsMaxRange = cfgGetItem(pCfg, "maxRange")->i32; - tsCurRange = cfgGetItem(pCfg, "curRange")->i32; - tsIfAdtFse = cfgGetItem(pCfg, "ifAdtFse")->bval; - tstrncpy(tsCompressor, cfgGetItem(pCfg, "compressor")->str, sizeof(tsCompressor)); + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "fPrecision"); + tsFPrecision = pItem->fval; - tsDisableStream = cfgGetItem(pCfg, "disableStream")->bval; - tsStreamBufferSize = cfgGetItem(pCfg, "streamBufferSize")->i64; - tsStreamAggCnt = cfgGetItem(pCfg, "streamAggCnt")->i32; - tsStreamBufferSize = cfgGetItem(pCfg, "streamBufferSize")->i64; - tsStreamCheckpointInterval = cfgGetItem(pCfg, "checkpointInterval")->i32; - tsSinkDataRate = cfgGetItem(pCfg, "streamSinkDataRate")->fval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "dPrecision"); + tsDPrecision = pItem->fval; - tsFilterScalarMode = cfgGetItem(pCfg, "filterScalarMode")->bval; - tsMaxStreamBackendCache = cfgGetItem(pCfg, "maxStreamBackendCache")->i32; - tsPQSortMemThreshold = cfgGetItem(pCfg, "pqSortMemThreshold")->i32; - tsResolveFQDNRetryTime = cfgGetItem(pCfg, "resolveFQDNRetryTime")->i32; - tsMinDiskFreeSize = cfgGetItem(pCfg, "minDiskFreeSize")->i64; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxRange"); + tsMaxRange = pItem->i32; - // tsS3BlockSize = cfgGetItem(pCfg, "s3BlockSize")->i32; - // tsS3BlockCacheSize = cfgGetItem(pCfg, "s3BlockCacheSize")->i32; - tsS3PageCacheSize = cfgGetItem(pCfg, "s3PageCacheSize")->i32; - tsS3UploadDelaySec = cfgGetItem(pCfg, "s3UploadDelaySec")->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "curRange"); + tsCurRange = pItem->i32; - tsExperimental = cfgGetItem(pCfg, "experimental")->bval; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ifAdtFse"); + tsIfAdtFse = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compressor"); + tstrncpy(tsCompressor, pItem->str, sizeof(tsCompressor)); + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "disableStream"); + tsDisableStream = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "streamBufferSize"); + tsStreamBufferSize = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "streamAggCnt"); + tsStreamAggCnt = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "checkpointInterval"); + tsStreamCheckpointInterval = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "streamSinkDataRate"); + tsSinkDataRate = pItem->fval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "filterScalarMode"); + tsFilterScalarMode = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "maxStreamBackendCache"); + tsMaxStreamBackendCache = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "pqSortMemThreshold"); + tsPQSortMemThreshold = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "resolveFQDNRetryTime"); + tsResolveFQDNRetryTime = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "minDiskFreeSize"); + tsMinDiskFreeSize = pItem->i64; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3PageCacheSize"); + tsS3PageCacheSize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "s3UploadDelaySec"); + tsS3UploadDelaySec = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "experimental"); + tsExperimental = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryUseMemoryPool"); + tsQueryUseMemoryPool = pItem->bval; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "singleQueryMaxMemorySize"); + tsSingleQueryMaxMemorySize = pItem->i32; + + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "queryBufferPoolSize"); + tsQueryBufferPoolSize = pItem->i32; // GRANT_CFG_GET; TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -1280,6 +1575,7 @@ static int32_t taosSetAllDebugFlag(SConfig *pCfg, int32_t flag); int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (tsCfg == NULL) { TAOS_CHECK_RETURN(osDefaultInit()); @@ -1290,46 +1586,49 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi if (tsc) { tsLogEmbedded = 0; - TAOS_CHECK_GOTO(taosAddClientLogCfg(pCfg), NULL, _exit); + TAOS_CHECK_GOTO(taosAddClientLogCfg(pCfg), &lino, _exit); } else { tsLogEmbedded = 1; - TAOS_CHECK_GOTO(taosAddClientLogCfg(pCfg), NULL, _exit); - TAOS_CHECK_GOTO(taosAddServerLogCfg(pCfg), NULL, _exit); + TAOS_CHECK_GOTO(taosAddClientLogCfg(pCfg), &lino, _exit); + TAOS_CHECK_GOTO(taosAddServerLogCfg(pCfg), &lino, _exit); } if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != TSDB_CODE_SUCCESS) { - printf("failed to load cfg since %s", tstrerror(code)); + printf("failed to load cfg since %s\n", tstrerror(code)); goto _exit; } if ((code = cfgLoadFromArray(pCfg, pArgs)) != TSDB_CODE_SUCCESS) { - printf("failed to load cfg from array since %s", tstrerror(code)); + printf("failed to load cfg from array since %s\n", tstrerror(code)); goto _exit; } if (tsc) { - taosSetClientLogCfg(pCfg); + TAOS_CHECK_GOTO(taosSetClientLogCfg(pCfg), &lino, _exit); } else { - taosSetClientLogCfg(pCfg); - taosSetServerLogCfg(pCfg); + TAOS_CHECK_GOTO(taosSetClientLogCfg(pCfg), &lino, _exit); + TAOS_CHECK_GOTO(taosSetServerLogCfg(pCfg), &lino, _exit); } - SConfigItem *pDebugItem = cfgGetItem(pCfg, "debugFlag"); - if (NULL == pDebugItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); - + SConfigItem *pDebugItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pDebugItem, "debugFlag"); TAOS_CHECK_RETURN(taosSetAllDebugFlag(pCfg, pDebugItem->i32)); if ((code = taosMulModeMkDir(tsLogDir, 0777, true)) != TSDB_CODE_SUCCESS) { - printf("failed to create dir:%s since %s", tsLogDir, tstrerror(code)); + printf("failed to create dir:%s since %s\n", tsLogDir, tstrerror(code)); goto _exit; } if ((code = taosInitLog(logname, logFileNum)) != 0) { - printf("failed to init log file since %s", terrstr()); + printf("failed to init log file since %s\n", tstrerror(code)); goto _exit; } _exit: + if (TSDB_CODE_SUCCESS != code) { + printf("failed to create log at %d since %s:", lino, tstrerror(code)); + } + cfgCleanup(pCfg); TAOS_RETURN(code); } @@ -1343,21 +1642,28 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char * SConfig *pCfg = NULL; TAOS_CHECK_RETURN(cfgInit(&pCfg)); - if (cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1; - if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; + TAOS_CHECK_GOTO(cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE), NULL, _exit); + TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) ,NULL, _exit); if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { - printf("failed to load cfg since %s", terrstr()); + printf("failed to load cfg since %s\n", tstrerror(code)); goto _exit; } if ((code = cfgLoadFromArray(pCfg, pArgs)) != 0) { - printf("failed to load cfg from array since %s", terrstr()); + printf("failed to load cfg from array since %s\n", tstrerror(code)); goto _exit; } TAOS_CHECK_GOTO(taosSetTfsCfg(pCfg), NULL, _exit); - dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; + + SConfigItem *pItem = NULL; + if ((pItem = cfgGetItem(pCfg, "dDebugFlag")) == NULL) { + code = TSDB_CODE_CFG_NOT_FOUND; + goto _exit; + } + + dDebugFlag = pItem->i32; _exit: cfgCleanup(pCfg); @@ -1713,7 +2019,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { const char *locale = pLocaleItem->str; const char *charset = pCharsetItem->str; - taosSetSystemLocale(locale, charset); + TAOS_CHECK_GOTO(taosSetSystemLocale(locale, charset), &lino, _out); osSetSystemLocale(locale, charset); uInfo("locale set to '%s', charset set to '%s'", locale, charset); matched = true; @@ -1766,20 +2072,22 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { tstrncpy(tsSmlTsDefaultName, pItem->str, TSDB_COL_NAME_LEN); matched = true; } else if (strcasecmp("serverPort", name) == 0) { - tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); - tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + SConfigItem *pFqdnItem = cfgGetItem(pCfg, "fqdn"); + SConfigItem *pServerPortItem = cfgGetItem(pCfg, "serverPort"); + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); + if (pFqdnItem == NULL || pServerPortItem == NULL || pFirstEpItem == NULL) { + uError("failed to get fqdn or serverPort or firstEp from cfg"); + code = TSDB_CODE_CFG_NOT_FOUND; + goto _out; + } + + tstrncpy(tsLocalFqdn, pFqdnItem->str, TSDB_FQDN_LEN); + tsServerPort = (uint16_t)pServerPortItem->i32; (void)snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); - if (pFirstEpItem == NULL) { - uError("failed to get firstEp from cfg"); - code = TSDB_CODE_CFG_NOT_FOUND; - goto _out; - } - SEp firstEp = {0}; TAOS_CHECK_GOTO( taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp), &lino, @@ -1878,9 +2186,8 @@ int32_t taosCfgDynamicOptions(SConfig *pCfg, const char *name, bool forServer) { } int32_t taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal) { - SConfigItem *pItem = cfgGetItem(tsCfg, flagName); - if (!pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); - + SConfigItem *pItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(tsCfg, pItem, flagName); pItem->i32 = flagVal; if (pFlagPtr != NULL) { *pFlagPtr = flagVal; @@ -1909,8 +2216,8 @@ static int32_t taosSetAllDebugFlag(SConfig *pCfg, int32_t flag) { if (flag == 0) TAOS_RETURN(TSDB_CODE_SUCCESS); // just ignore SArray *noNeedToSetVars = NULL; - SConfigItem *pItem = cfgGetItem(pCfg, "debugFlag"); - if (NULL == pItem) TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + SConfigItem *pItem = NULL; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "debugFlag"); pItem->i32 = flag; noNeedToSetVars = pItem->array; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b66c8fa09a..d024e329ea 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -522,7 +522,7 @@ int32_t tDeserializeSClientHbBatchReq(void *buf, int32_t bufLen, SClientHbBatchR } if (!tDecodeIsEnd(&decoder)) { - tDecodeI64(&decoder, &pBatchReq->ipWhiteList); + if (tDecodeI64(&decoder, &pBatchReq->ipWhiteList) < 0) return -1; } tEndDecode(&decoder); @@ -1457,6 +1457,39 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); } +int32_t tSerializeSDnodeInfoReq(void *buf, int32_t bufLen, SDnodeInfoReq *pReq) { + int32_t code = 0, lino = 0; + int32_t tlen = 0; + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->dnodeId)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->machineId)); + + tEndEncode(&encoder); + + tlen = encoder.pos; +_exit: + tEncoderClear(&encoder); + return code < 0 ? code : tlen; +} + +int32_t tDeserializeSDnodeInfoReq(void *buf, int32_t bufLen, SDnodeInfoReq *pReq) { + int32_t code = 0, lino = 0; + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->dnodeId)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->machineId)); + +_exit: + tEndDecode(&decoder); + tDecoderClear(&decoder); + return code; +} + int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -1764,23 +1797,33 @@ int32_t tDeserializeSUpdateIpWhite(void *buf, int32_t bufLen, SUpdateIpWhite *pR return 0; } void tFreeSUpdateIpWhiteReq(SUpdateIpWhite *pReq) { - for (int i = 0; i < pReq->numOfUser; i++) { - SUpdateUserIpWhite *pUserWhite = &pReq->pUserIpWhite[i]; - taosMemoryFree(pUserWhite->pIpRanges); + if (pReq == NULL) return; + + if (pReq->pUserIpWhite) { + for (int i = 0; i < pReq->numOfUser; i++) { + SUpdateUserIpWhite *pUserWhite = &pReq->pUserIpWhite[i]; + taosMemoryFree(pUserWhite->pIpRanges); + } } taosMemoryFree(pReq->pUserIpWhite); - // impl later return; } -SUpdateIpWhite *cloneSUpdateIpWhiteReq(SUpdateIpWhite *pReq) { +int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite *pReq, SUpdateIpWhite **pUpdateMsg) { + int32_t code = 0; + if (pReq == NULL) { + return 0; + } SUpdateIpWhite *pClone = taosMemoryCalloc(1, sizeof(SUpdateIpWhite)); - if (pClone == NULL) return NULL; + if (pClone == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } pClone->numOfUser = pReq->numOfUser; pClone->ver = pReq->ver; - if ((pClone->pUserIpWhite = taosMemoryCalloc(1, sizeof(SUpdateUserIpWhite) * pReq->numOfUser)) == NULL) { + pClone->pUserIpWhite = taosMemoryCalloc(1, sizeof(SUpdateUserIpWhite) * pReq->numOfUser); + if (pClone->pUserIpWhite == NULL) { taosMemoryFree(pClone); - return NULL; + return TSDB_CODE_OUT_OF_MEMORY; } for (int i = 0; i < pReq->numOfUser; i++) { @@ -1792,17 +1835,21 @@ SUpdateIpWhite *cloneSUpdateIpWhiteReq(SUpdateIpWhite *pReq) { pNew->numOfRange = pOld->numOfRange; int32_t sz = pOld->numOfRange * sizeof(SIpV4Range); - if ((pNew->pIpRanges = taosMemoryCalloc(1, sz)) == NULL) { - for (int j = 0; j < i; j++) { - taosMemoryFree(pClone->pUserIpWhite[j].pIpRanges); - } - taosMemoryFree(pClone->pUserIpWhite); - taosMemoryFree(pClone); - return NULL; + pNew->pIpRanges = taosMemoryCalloc(1, sz); + if (pNew->pIpRanges == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; } memcpy(pNew->pIpRanges, pOld->pIpRanges, sz); } - return pClone; +_return: + if (code < 0) { + tFreeSUpdateIpWhiteReq(pClone); + taosMemoryFree(pClone); + } else { + *pUpdateMsg = pClone; + } + return code; } int32_t tSerializeRetrieveIpWhite(void *buf, int32_t bufLen, SRetrieveIpWhiteReq *pReq) { SEncoder encoder = {0}; @@ -2149,21 +2196,21 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) goto _err; int32_t len = strlen(db); - taosHashPut(pRsp->createdDbs, db, len + 1, db, len + 1); + if (taosHashPut(pRsp->createdDbs, db, len + 1, db, len + 1) < 0) goto _err; } for (int32_t i = 0; i < numOfReadDbs; ++i) { char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) goto _err; int32_t len = strlen(db); - taosHashPut(pRsp->readDbs, db, len + 1, db, len + 1); + if (taosHashPut(pRsp->readDbs, db, len + 1, db, len + 1) < 0) goto _err; } for (int32_t i = 0; i < numOfWriteDbs; ++i) { char db[TSDB_DB_FNAME_LEN] = {0}; if (tDecodeCStrTo(pDecoder, db) < 0) goto _err; int32_t len = strlen(db); - taosHashPut(pRsp->writeDbs, db, len + 1, db, len + 1); + if (taosHashPut(pRsp->writeDbs, db, len + 1, db, len + 1) < 0) goto _err; } if (!tDecodeIsEnd(pDecoder)) { @@ -2195,7 +2242,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->readTbs, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->readTbs, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2214,7 +2261,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->writeTbs, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->writeTbs, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2233,7 +2280,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->alterTbs, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->alterTbs, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2252,7 +2299,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->readViews, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->readViews, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2271,7 +2318,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->writeViews, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->writeViews, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2290,7 +2337,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if ((value = taosMemoryCalloc(valuelen + 1, sizeof(char))) == NULL) goto _err; if (tDecodeCStrTo(pDecoder, value) < 0) goto _err; - taosHashPut(pRsp->alterViews, key, keyLen, value, valuelen + 1); + if (taosHashPut(pRsp->alterViews, key, keyLen, value, valuelen + 1) < 0) goto _err; taosMemoryFreeClear(key); taosMemoryFreeClear(value); @@ -2306,7 +2353,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs int32_t ref = 0; if (tDecodeI32(pDecoder, &ref) < 0) goto _err; - taosHashPut(pRsp->useDbs, key, keyLen, &ref, sizeof(ref)); + if (taosHashPut(pRsp->useDbs, key, keyLen, &ref, sizeof(ref)) < 0) goto _err; taosMemoryFreeClear(key); } // since 3.0.7.0 @@ -4226,7 +4273,7 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { tEncoderInit(&encoder, buf, bufLen); if (tStartEncode(&encoder) < 0) return -1; - tSerializeSDbCfgRspImpl(&encoder, pRsp); + if (tSerializeSDbCfgRspImpl(&encoder, pRsp) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; tEncoderClear(&encoder); @@ -5261,12 +5308,22 @@ int32_t tSerializeSMTimerMsg(void *buf, int32_t bufLen, SMTimerReq *pReq) { // return 0; // } -int32_t tSerializeSMStreamTickMsg(void *buf, int32_t bufLen, SMStreamTickReq *pReq) { +int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI64(&encoder, pReq->tick) < 0) return -1; + + int32_t size = taosArrayGetSize(pMsg->pList); + if (tEncodeI32(&encoder, size) < 0) return -1; + + for (int32_t i = 0; i < size; i++) { + SOrphanTask *pTask = taosArrayGet(pMsg->pList, i); + if (tEncodeI64(&encoder, pTask->streamId) < 0) return -1; + if (tEncodeI32(&encoder, pTask->taskId) < 0) return -1; + if (tEncodeI32(&encoder, pTask->nodeId) < 0) return -1; + } + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -5274,17 +5331,42 @@ int32_t tSerializeSMStreamTickMsg(void *buf, int32_t bufLen, SMStreamTickReq *pR return tlen; } -// int32_t tDeserializeSMStreamTickMsg(void *buf, int32_t bufLen, SMStreamTickReq *pReq) { -// SDecoder decoder = {0}; -// tDecoderInit(&decoder, buf, bufLen); +int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); -// if (tStartDecode(&decoder) < 0) return -1; -// if (tDecodeI64(&decoder, &pReq->tick) < 0) return -1; -// tEndDecode(&decoder); + if (tStartDecode(&decoder) < 0) return -1; -// tDecoderClear(&decoder); -// return 0; -// } + int32_t num = 0; + if (tDecodeI32(&decoder, &num) < 0) return -1; + + if (num > 0) { + pMsg->pList = taosArrayInit(num, sizeof(SOrphanTask)); + if (NULL == pMsg->pList) return -1; + for (int32_t i = 0; i < num; ++i) { + SOrphanTask info = {0}; + if (tDecodeI64(&decoder, &info.streamId) < 0) return -1; + if (tDecodeI32(&decoder, &info.taskId) < 0) return -1; + if (tDecodeI32(&decoder, &info.nodeId) < 0) return -1; + + if (taosArrayPush(pMsg->pList, &info) == NULL) { + return -1; + } + } + } + + tEndDecode(&decoder); + tDecoderClear(&decoder); + return 0; +} + +void tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg *pMsg) { + if (pMsg == NULL) { + return; + } + + taosArrayDestroy(pMsg->pList); +} int32_t tEncodeSReplica(SEncoder *pEncoder, SReplica *pReplica) { if (tEncodeI32(pEncoder, pReplica->id) < 0) return -1; @@ -7009,6 +7091,7 @@ int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) { } } + if (tEncodeI8(&encoder, pReq->pollFlag) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -7048,6 +7131,9 @@ int32_t tDeserializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) { } } } + if (!tDecodeIsEnd(&decoder)) { + if (tDecodeI8(&decoder, &pReq->pollFlag) < 0) return -1; + } tEndDecode(&decoder); tDecoderClear(&decoder); @@ -7087,7 +7173,7 @@ int32_t tDeserializeSMqSeekReq(void *buf, int32_t bufLen, SMqSeekReq *pReq) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI64(&decoder, &pReq->consumerId) < 0) return -1; - tDecodeCStrTo(&decoder, pReq->subKey); + if (tDecodeCStrTo(&decoder, pReq->subKey) < 0) return -1; tEndDecode(&decoder); @@ -7342,6 +7428,7 @@ int32_t tSerializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) { if (tEncodeSTqOffsetVal(&encoder, &pReq->reqOffset) < 0) return -1; if (tEncodeI8(&encoder, pReq->enableReplay) < 0) return -1; if (tEncodeI8(&encoder, pReq->sourceExcluded) < 0) return -1; + if (tEncodeI8(&encoder, pReq->enableBatchMeta) < 0) return -1; tEndEncode(&encoder); @@ -7353,7 +7440,6 @@ int32_t tSerializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) { pHead->vgId = htonl(pReq->head.vgId); pHead->contLen = htonl(tlen + headLen); } - if (tEncodeI8(&encoder, pReq->enableBatchMeta) < 0) return -1; return tlen + headLen; } @@ -7801,8 +7887,8 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) { if (tEncodeCStr(pCoder, pSma->tagsFilter) < 0) return -1; } - tEncodeSSchemaWrapper(pCoder, &pSma->schemaRow); - tEncodeSSchemaWrapper(pCoder, &pSma->schemaTag); + if (tEncodeSSchemaWrapper(pCoder, &pSma->schemaRow) < 0) return -1; + if (tEncodeSSchemaWrapper(pCoder, &pSma->schemaTag) < 0) return -1; return 0; } @@ -7847,8 +7933,8 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma, bool deepCopy) { pSma->tagsFilter = NULL; } // only needed in dstVgroup - tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaRow); - tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaTag); + if (tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaRow) < 0) return -1; + if (tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaTag) < 0) return -1; return 0; } @@ -7856,7 +7942,7 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma, bool deepCopy) { int32_t tEncodeSVCreateTSmaReq(SEncoder *pCoder, const SVCreateTSmaReq *pReq) { if (tStartEncode(pCoder) < 0) return -1; - tEncodeTSma(pCoder, pReq); + if (tEncodeTSma(pCoder, pReq) < 0) return -1; tEndEncode(pCoder); return 0; @@ -7865,7 +7951,7 @@ int32_t tEncodeSVCreateTSmaReq(SEncoder *pCoder, const SVCreateTSmaReq *pReq) { int32_t tDecodeSVCreateTSmaReq(SDecoder *pCoder, SVCreateTSmaReq *pReq) { if (tStartDecode(pCoder) < 0) return -1; - tDecodeTSma(pCoder, pReq, false); + if (tDecodeTSma(pCoder, pReq, false) < 0) return -1; tEndDecode(pCoder); return 0; @@ -9180,7 +9266,7 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) { return 0; } -int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { +void tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { if (pVal->type == TMQ_OFFSET__RESET_NONE) { (void)snprintf(buf, maxLen, "none"); } else if (pVal->type == TMQ_OFFSET__RESET_EARLIEST) { @@ -9192,7 +9278,7 @@ int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { } else if (pVal->type == TMQ_OFFSET__SNAPSHOT_DATA || pVal->type == TMQ_OFFSET__SNAPSHOT_META) { if (IS_VAR_DATA_TYPE(pVal->primaryKey.type)) { char *tmp = taosMemoryCalloc(1, pVal->primaryKey.nData + 1); - if (tmp == NULL) return terrno; + if (tmp == NULL) return; (void)memcpy(tmp, pVal->primaryKey.pData, pVal->primaryKey.nData); (void)snprintf(buf, maxLen, "tsdb:%" PRId64 "|%" PRId64 ",pk type:%d,val:%s", pVal->uid, pVal->ts, pVal->primaryKey.type, tmp); @@ -9202,8 +9288,6 @@ int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { pVal->primaryKey.type, pVal->primaryKey.val); } } - - return 0; } bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) { @@ -9226,16 +9310,17 @@ bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) { return false; } -int32_t tOffsetCopy(STqOffsetVal *pLeft, const STqOffsetVal *pRight) { +void tOffsetCopy(STqOffsetVal *pLeft, const STqOffsetVal *pRight) { tOffsetDestroy(pLeft); *pLeft = *pRight; if (IS_VAR_DATA_TYPE(pRight->primaryKey.type)) { - if ((pLeft->primaryKey.pData = taosMemoryMalloc(pRight->primaryKey.nData)) == NULL) { - return terrno; + pLeft->primaryKey.pData = taosMemoryMalloc(pRight->primaryKey.nData); + if (pLeft->primaryKey.pData == NULL) { + uError("failed to allocate memory for offset"); + return; } (void)memcpy(pLeft->primaryKey.pData, pRight->primaryKey.pData, pRight->primaryKey.nData); } - return 0; } void tOffsetDestroy(void *param) { @@ -10727,7 +10812,7 @@ void tFreeSMDropTbReqOnSingleVg(void *p) { int32_t tSerializeSMDropTbsReq(void *buf, int32_t bufLen, const SMDropTbsReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); - tStartEncode(&encoder); + if (tStartEncode(&encoder) < 0) return -1; int32_t size = pReq->pVgReqs ? pReq->pVgReqs->size : 0; if (tEncodeI32(&encoder, size) < 0) return -1; for (int32_t i = 0; i < size; ++i) { @@ -10743,7 +10828,7 @@ int32_t tSerializeSMDropTbsReq(void *buf, int32_t bufLen, const SMDropTbsReq *pR int32_t tDeserializeSMDropTbsReq(void *buf, int32_t bufLen, SMDropTbsReq *pReq) { SDecoder decoder = {0}; tDecoderInit(&decoder, buf, bufLen); - tStartDecode(&decoder); + if (tStartDecode(&decoder) < 0) return -1; int32_t size = 0; if (tDecodeI32(&decoder, &size) < 0) return -1; pReq->pVgReqs = taosArrayInit(size, sizeof(SMDropTbReqsOnSingleVg)); diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 1dc4a6f9ba..942255cd7c 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -68,7 +68,7 @@ bool tdSTSRowIterFetch(STSRowIter *pIter, col_id_t colId, col_type_t colType, SC return false; } } - tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); + (void)tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); ++pIter->colIdx; } else if (TD_IS_KV_ROW(pIter->pRow)) { return tdSTSRowIterGetKvVal(pIter, colId, &pIter->kvIdx, pVal); diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 2d748706b5..b3e5015706 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -80,11 +80,11 @@ static void dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert static void dmStopDnode(int signum, void *sigInfo, void *context) { // taosIgnSignal(SIGUSR1); // taosIgnSignal(SIGUSR2); - taosIgnSignal(SIGTERM); - taosIgnSignal(SIGHUP); - taosIgnSignal(SIGINT); - taosIgnSignal(SIGABRT); - taosIgnSignal(SIGBREAK); + (void)taosIgnSignal(SIGTERM); + (void)taosIgnSignal(SIGHUP); + (void)taosIgnSignal(SIGINT); + (void)taosIgnSignal(SIGABRT); + (void)taosIgnSignal(SIGBREAK); dInfo("shut down signal is %d", signum); #ifndef WINDOWS @@ -102,11 +102,11 @@ void dmLogCrash(int signum, void *sigInfo, void *context) { // taosIgnSignal(SIGBREAK); #ifndef WINDOWS - taosIgnSignal(SIGBUS); + (void)taosIgnSignal(SIGBUS); #endif - taosIgnSignal(SIGABRT); - taosIgnSignal(SIGFPE); - taosIgnSignal(SIGSEGV); + (void)taosIgnSignal(SIGABRT); + (void)taosIgnSignal(SIGFPE); + (void)taosIgnSignal(SIGSEGV); char *pMsg = NULL; const char *flags = "UTL FATAL "; @@ -135,23 +135,23 @@ _return: } static void dmSetSignalHandle() { - taosSetSignal(SIGUSR1, dmSetDebugFlag); - taosSetSignal(SIGUSR2, dmSetAssert); - taosSetSignal(SIGTERM, dmStopDnode); - taosSetSignal(SIGHUP, dmStopDnode); - taosSetSignal(SIGINT, dmStopDnode); - taosSetSignal(SIGBREAK, dmStopDnode); + (void)taosSetSignal(SIGUSR1, dmSetDebugFlag); + (void)taosSetSignal(SIGUSR2, dmSetAssert); + (void)taosSetSignal(SIGTERM, dmStopDnode); + (void)taosSetSignal(SIGHUP, dmStopDnode); + (void)taosSetSignal(SIGINT, dmStopDnode); + (void)taosSetSignal(SIGBREAK, dmStopDnode); #ifndef WINDOWS - taosSetSignal(SIGTSTP, dmStopDnode); - taosSetSignal(SIGQUIT, dmStopDnode); + (void)taosSetSignal(SIGTSTP, dmStopDnode); + (void)taosSetSignal(SIGQUIT, dmStopDnode); #endif #ifndef WINDOWS - taosSetSignal(SIGBUS, dmLogCrash); + (void)taosSetSignal(SIGBUS, dmLogCrash); #endif - taosSetSignal(SIGABRT, dmLogCrash); - taosSetSignal(SIGFPE, dmLogCrash); - taosSetSignal(SIGSEGV, dmLogCrash); + (void)taosSetSignal(SIGABRT, dmLogCrash); + (void)taosSetSignal(SIGFPE, dmLogCrash); + (void)taosSetSignal(SIGSEGV, dmLogCrash); } static int32_t dmParseArgs(int32_t argc, char const *argv[]) { diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index f50754992c..374bb1a673 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -21,32 +21,45 @@ extern SConfig *tsCfg; static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { + int32_t code = 0; if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) { dInfo("set local info, dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); - taosThreadRwlockWrlock(&pMgmt->pData->lock); + (void)taosThreadRwlockWrlock(&pMgmt->pData->lock); pMgmt->pData->dnodeId = pCfg->dnodeId; pMgmt->pData->clusterId = pCfg->clusterId; - dmWriteEps(pMgmt->pData); - taosThreadRwlockUnlock(&pMgmt->pData->lock); + code = dmWriteEps(pMgmt->pData); + if (code != 0) { + dInfo("failed to set local info, dnodeId:%d clusterId:%" PRId64 " reason:%s", pCfg->dnodeId, pCfg->clusterId, + tstrerror(code)); + } + (void)taosThreadRwlockUnlock(&pMgmt->pData->lock); } } static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) { + int32_t code = 0; dDebug("ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64 "", pMgmt->pData->ipWhiteVer, ver); if (pMgmt->pData->ipWhiteVer == ver) { if (ver == 0) { dDebug("disable ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64 "", pMgmt->pData->ipWhiteVer, ver); - rpcSetIpWhite(pMgmt->msgCb.serverRpc, NULL); - // pMgmt->ipWhiteVer = ver; + (void)rpcSetIpWhite(pMgmt->msgCb.serverRpc, NULL); } return; } int64_t oldVer = pMgmt->pData->ipWhiteVer; - // pMgmt->ipWhiteVer = ver; SRetrieveIpWhiteReq req = {.ipWhiteVer = oldVer}; int32_t contLen = tSerializeRetrieveIpWhite(NULL, 0, &req); - void *pHead = rpcMallocCont(contLen); - tSerializeRetrieveIpWhite(pHead, contLen, &req); + if (contLen < 0) { + dError("failed to serialize ip white list request since: %s", tstrerror(contLen)); + return; + } + void *pHead = rpcMallocCont(contLen); + contLen = tSerializeRetrieveIpWhite(pHead, contLen, &req); + if (contLen < 0) { + rpcFreeCont(pHead); + dError("failed to serialize ip white list request since:%s", tstrerror(contLen)); + return; + } SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, @@ -57,9 +70,12 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) { .info.handle = 0}; SEpSet epset = {0}; - dmGetMnodeEpSet(pMgmt->pData, &epset); + (void)dmGetMnodeEpSet(pMgmt->pData, &epset); - rpcSendRequest(pMgmt->msgCb.clientRpc, &epset, &rpcMsg, NULL); + code = rpcSendRequest(pMgmt->msgCb.clientRpc, &epset, &rpcMsg, NULL); + if (code != 0) { + dError("failed to send retrieve ip white list request since:%s", tstrerror(code)); + } } static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { const STraceId *trace = &pRsp->info.traceId; @@ -70,9 +86,9 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { dGInfo("dnode:%d, set to dropped since not exist in mnode, statusSeq:%d", pMgmt->pData->dnodeId, pMgmt->statusSeq); pMgmt->pData->dropped = 1; - dmWriteEps(pMgmt->pData); + (void)dmWriteEps(pMgmt->pData); dInfo("dnode will exit since it is in the dropped state"); - raise(SIGINT); + (void)raise(SIGINT); } } else { SStatusRsp statusRsp = {0}; @@ -93,9 +109,10 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { } void dmSendStatusReq(SDnodeMgmt *pMgmt) { + int32_t code = 0; SStatusReq req = {0}; - taosThreadRwlockRdlock(&pMgmt->pData->lock); + (void)taosThreadRwlockRdlock(&pMgmt->pData->lock); req.sver = tsVersion; req.dnodeVer = pMgmt->pData->dnodeVer; req.dnodeId = pMgmt->pData->dnodeId; @@ -129,7 +146,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); - taosThreadRwlockUnlock(&pMgmt->pData->lock); + (void)taosThreadRwlockUnlock(&pMgmt->pData->lock); SMonVloadInfo vinfo = {0}; (*pMgmt->getVnodeLoadsFp)(&vinfo); @@ -146,8 +163,18 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { req.ipWhiteVer = pMgmt->pData->ipWhiteVer; int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); - void *pHead = rpcMallocCont(contLen); - tSerializeSStatusReq(pHead, contLen, &req); + if (contLen < 0) { + dError("failed to serialize status req since %s", tstrerror(contLen)); + return; + } + + void *pHead = rpcMallocCont(contLen); + contLen = tSerializeSStatusReq(pHead, contLen, &req); + if (contLen < 0) { + rpcFreeCont(pHead); + dError("failed to serialize status req since %s", tstrerror(contLen)); + return; + } tFreeSStatusReq(&req); SRpcMsg rpcMsg = {.pCont = pHead, @@ -163,8 +190,15 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SEpSet epSet = {0}; int8_t epUpdated = 0; - dmGetMnodeEpSet(pMgmt->pData, &epSet); - rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusInterval * 5 * 1000); + (void)dmGetMnodeEpSet(pMgmt->pData, &epSet); + + code = + rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusInterval * 5 * 1000); + if (code != 0) { + dError("failed to send status req since %s", tstrerror(code)); + return; + } + if (rpcRsp.code != 0) { dmRotateMnodeEpSet(pMgmt->pData); char tbuf[512]; @@ -180,8 +214,17 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) { int32_t contLen = tSerializeSNotifyReq(NULL, 0, pReq); - void *pHead = rpcMallocCont(contLen); - tSerializeSNotifyReq(pHead, contLen, pReq); + if (contLen < 0) { + dError("failed to serialize notify req since %s", tstrerror(contLen)); + return; + } + void *pHead = rpcMallocCont(contLen); + contLen = tSerializeSNotifyReq(pHead, contLen, pReq); + if (contLen < 0) { + rpcFreeCont(pHead); + dError("failed to serialize notify req since %s", tstrerror(contLen)); + return; + } SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, @@ -193,7 +236,7 @@ void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) { SEpSet epSet = {0}; dmGetMnodeEpSet(pMgmt->pData, &epSet); - rpcSendRequest(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, NULL); + (void)rpcSendRequest(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, NULL); } int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index add62d1edc..a3e1a64012 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -266,22 +266,22 @@ static void *dmCrashReportThreadFp(void *param) { int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create status thread since %s", tstrerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("dnode-status", "initialized"); return 0; } void dmStopStatusThread(SDnodeMgmt *pMgmt) { if (taosCheckPthreadValid(pMgmt->statusThread)) { - taosThreadJoin(pMgmt->statusThread, NULL); + (void)taosThreadJoin(pMgmt->statusThread, NULL); taosThreadClear(&pMgmt->statusThread); } } @@ -289,40 +289,40 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) { int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create notify thread since %s", strerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("dnode-notify", "initialized"); return 0; } void dmStopNotifyThread(SDnodeMgmt *pMgmt) { if (taosCheckPthreadValid(pMgmt->notifyThread)) { - tsem_post(&dmNotifyHdl.sem); - taosThreadJoin(pMgmt->notifyThread, NULL); + (void)tsem_post(&dmNotifyHdl.sem); + (void)taosThreadJoin(pMgmt->notifyThread, NULL); taosThreadClear(&pMgmt->notifyThread); } - tsem_destroy(&dmNotifyHdl.sem); + (void)tsem_destroy(&dmNotifyHdl.sem); } int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create monitor thread since %s", tstrerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("dnode-monitor", "initialized"); return 0; } @@ -330,30 +330,30 @@ int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) { int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create audit thread since %s", tstrerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("dnode-audit", "initialized"); return 0; } void dmStopMonitorThread(SDnodeMgmt *pMgmt) { if (taosCheckPthreadValid(pMgmt->monitorThread)) { - taosThreadJoin(pMgmt->monitorThread, NULL); - taosThreadClear(&pMgmt->monitorThread); + (void)taosThreadJoin(pMgmt->monitorThread, NULL); + (void)taosThreadClear(&pMgmt->monitorThread); } } void dmStopAuditThread(SDnodeMgmt *pMgmt) { if (taosCheckPthreadValid(pMgmt->auditThread)) { - taosThreadJoin(pMgmt->auditThread, NULL); - taosThreadClear(&pMgmt->auditThread); + (void)taosThreadJoin(pMgmt->auditThread, NULL); + (void)taosThreadClear(&pMgmt->auditThread); } } @@ -364,15 +364,15 @@ int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) { } TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create crashReport thread since %s", tstrerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("dnode-crashReport", "initialized"); return 0; } @@ -383,8 +383,8 @@ void dmStopCrashReportThread(SDnodeMgmt *pMgmt) { } if (taosCheckPthreadValid(pMgmt->crashReportThread)) { - taosThreadJoin(pMgmt->crashReportThread, NULL); - taosThreadClear(&pMgmt->crashReportThread); + (void)taosThreadJoin(pMgmt->crashReportThread, NULL); + (void)taosThreadClear(&pMgmt->crashReportThread); } } @@ -454,7 +454,11 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { .contLen = pMsg->info.rspLen, .info = pMsg->info, }; - rpcSendResponse(&rsp); + + code = rpcSendResponse(&rsp); + if (code != 0) { + dError("failed to send response since %s", tstrerror(code)); + } } dTrace("msg:%p, is freed, code:0x%x", pMsg, code); @@ -463,6 +467,7 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { } int32_t dmStartWorker(SDnodeMgmt *pMgmt) { + int32_t code = 0; SSingleWorkerCfg cfg = { .min = 1, .max = 1, @@ -470,9 +475,9 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { .fp = (FItem)dmProcessMgmtQueue, .param = pMgmt, }; - if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { - dError("failed to start dnode-mgmt worker since %s", terrstr()); - return -1; + if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg)) != 0) { + dError("failed to start dnode-mgmt worker since %s", tstrerror(code)); + return code; } dDebug("dnode workers are initialized"); @@ -487,6 +492,5 @@ void dmStopWorker(SDnodeMgmt *pMgmt) { int32_t dmPutNodeMsgToMgmtQueue(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { SSingleWorker *pWorker = &pMgmt->mgmtWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; + return taosWriteQitem(pWorker->queue, pMsg); } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 067ce528d5..43c40c65c3 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -17,12 +17,12 @@ #include "mmInt.h" void mmGetMonitorInfo(SMnodeMgmt *pMgmt, SMonMmInfo *pInfo) { - mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant); + (void)mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant); } void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) { pInfo->isMnode = 1; - mndGetLoad(pMgmt->pMnode, &pInfo->load); + (void)mndGetLoad(pMgmt->pMnode, &pInfo->load); } int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { @@ -173,6 +173,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TSMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_STB_DROP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_STB_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_UPDATE_DNODE_INFO, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TB_WITH_TSMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TABLE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 57436adcd0..20802e33d9 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -68,7 +68,7 @@ static void mmClose(SMnodeMgmt *pMgmt) { if (pMgmt->pMnode != NULL) { mmStopWorker(pMgmt); mndClose(pMgmt->pMnode); - taosThreadRwlockDestroy(&pMgmt->lock); + (void)taosThreadRwlockDestroy(&pMgmt->lock); pMgmt->pMnode = NULL; } @@ -107,7 +107,7 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { pMgmt->msgCb = pInput->msgCb; pMgmt->msgCb.putToQueueFp = (PutToQueueFp)mmPutMsgToQueue; pMgmt->msgCb.mgmt = pMgmt; - taosThreadRwlockInit(&pMgmt->lock, NULL); + (void)taosThreadRwlockInit(&pMgmt->lock, NULL); SMnodeOpt option = {0}; if ((code = mmReadFile(pMgmt->path, &option)) != 0) { @@ -163,9 +163,9 @@ static int32_t mmStart(SMnodeMgmt *pMgmt) { static void mmStop(SMnodeMgmt *pMgmt) { dDebug("mnode-mgmt start to stop"); mndPreClose(pMgmt->pMnode); - taosThreadRwlockWrlock(&pMgmt->lock); + (void)taosThreadRwlockWrlock(&pMgmt->lock); pMgmt->stopped = 1; - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); mndStop(pMgmt->pMnode); } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index cb45251282..336c57a333 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -20,20 +20,20 @@ static inline int32_t mmAcquire(SMnodeMgmt *pMgmt) { int32_t code = 0; - taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); if (pMgmt->stopped) { code = -1; } else { - atomic_add_fetch_32(&pMgmt->refCount, 1); + (void)atomic_add_fetch_32(&pMgmt->refCount, 1); } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); return code; } static inline void mmRelease(SMnodeMgmt *pMgmt) { - taosThreadRwlockRdlock(&pMgmt->lock); - atomic_sub_fetch_32(&pMgmt->refCount, 1); - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); + (void)atomic_sub_fetch_32(&pMgmt->refCount, 1); + (void)taosThreadRwlockUnlock(&pMgmt->lock); } static inline void mmSendRsp(SRpcMsg *pMsg, int32_t code) { @@ -100,16 +100,16 @@ static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { static inline int32_t mmPutMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pMsg) { const STraceId *trace = &pMsg->info.traceId; - - if (mmAcquire(pMgmt) == 0) { + int32_t code = 0; + if ((code = mmAcquire(pMgmt)) == 0) { dGTrace("msg:%p, put into %s queue, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType)); - taosWriteQitem(pWorker->queue, pMsg); + code = taosWriteQitem(pWorker->queue, pMsg); mmRelease(pMgmt); - return 0; + return code; } else { - dGTrace("msg:%p, failed to put into %s queue since %s, type:%s", pMsg, pWorker->name, terrstr(), + dGTrace("msg:%p, failed to put into %s queue since %s, type:%s", pMsg, pWorker->name, tstrerror(code), TMSG_INFO(pMsg->msgType)); - return -1; + return code; } } diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index ae7125811e..a8ad26f006 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -18,13 +18,13 @@ void qmGetMonitorInfo(SQnodeMgmt *pMgmt, SMonQmInfo *qmInfo) { SQnodeLoad qload = {0}; - qndGetLoad(pMgmt->pQnode, &qload); + (void)qndGetLoad(pMgmt->pQnode, &qload); qload.dnodeId = pMgmt->pData->dnodeId; } void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) { - qndGetLoad(pMgmt->pQnode, pInfo); + (void)qndGetLoad(pMgmt->pQnode, pInfo); pInfo->dnodeId = pMgmt->pData->dnodeId; } diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c index cf58ababc3..d83c502237 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c @@ -23,7 +23,7 @@ static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) { .contLen = pMsg->info.rspLen, .info = pMsg->info, }; - tmsgSendRsp(&rsp); + (void)tmsgSendRsp(&rsp); } static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { @@ -43,8 +43,7 @@ static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { static int32_t qmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) { dTrace("msg:%p, put into worker %s, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType)); - taosWriteQitem(pWorker->queue, pMsg); - return 0; + return taosWriteQitem(pWorker->queue, pMsg); } int32_t qmPutNodeMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) { @@ -69,18 +68,18 @@ int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { switch (qtype) { case QUERY_QUEUE: dTrace("msg:%p, is created and will put into qnode-query queue, len:%d", pMsg, pRpc->contLen); - taosWriteQitem(pMgmt->queryWorker.queue, pMsg); - return 0; + code = taosWriteQitem(pMgmt->queryWorker.queue, pMsg); + return code; case READ_QUEUE: case FETCH_QUEUE: dTrace("msg:%p, is created and will put into qnode-fetch queue, len:%d", pMsg, pRpc->contLen); - taosWriteQitem(pMgmt->fetchWorker.queue, pMsg); - return 0; + code = taosWriteQitem(pMgmt->fetchWorker.queue, pMsg); + return code; default: terrno = TSDB_CODE_INVALID_PARA; rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); - return -1; + return terrno; } } diff --git a/source/dnode/mgmt/mgmt_snode/src/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c index 6d20e076dd..ad602313e0 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smWorker.c +++ b/source/dnode/mgmt/mgmt_snode/src/smWorker.c @@ -23,7 +23,7 @@ static inline void smSendRsp(SRpcMsg *pMsg, int32_t code) { .contLen = pMsg->info.rspLen, .info = pMsg->info, }; - tmsgSendRsp(&rsp); + (void)tmsgSendRsp(&rsp); } static void smProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { @@ -31,7 +31,7 @@ static void smProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO for (int32_t i = 0; i < numOfMsgs; i++) { SRpcMsg *pMsg = NULL; - taosGetQitem(qall, (void **)&pMsg); + (void)taosGetQitem(qall, (void **)&pMsg); const STraceId *trace = &pMsg->info.traceId; dTrace("msg:%p, get from snode-write queue", pMsg); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index 47ae2a1395..4f2c04c6a5 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -20,13 +20,13 @@ #define MAX_CONTENT_LEN 2 * 1024 * 1024 int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) { - taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); int32_t num = 0; int32_t size = taosHashGetSize(pMgmt->hash); SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *)); if (pVnodes == NULL) { - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); return TSDB_CODE_OUT_OF_MEMORY; } @@ -44,7 +44,7 @@ int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeOb } } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); *numOfVnodes = num; *ppVnodes = pVnodes; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index b193206e5e..fe438c4396 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -22,7 +22,7 @@ void vmGetVnodeLoads(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo, bool isReset) { tfsUpdateSize(pMgmt->pTfs); - taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); void *pIter = taosHashIterate(pMgmt->hash, NULL); while (pIter) { @@ -32,21 +32,21 @@ void vmGetVnodeLoads(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo, bool isReset) { SVnodeObj *pVnode = *ppVnode; SVnodeLoad vload = {.vgId = pVnode->vgId}; if (!pVnode->failed) { - vnodeGetLoad(pVnode->pImpl, &vload); + (void)vnodeGetLoad(pVnode->pImpl, &vload); if (isReset) vnodeResetLoad(pVnode->pImpl, &vload); } - taosArrayPush(pInfo->pVloads, &vload); + (void)taosArrayPush(pInfo->pVloads, &vload); pIter = taosHashIterate(pMgmt->hash, pIter); } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); } void vmGetVnodeLoadsLite(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo) { pInfo->pVloads = taosArrayInit(pMgmt->state.totalVnodes, sizeof(SVnodeLoadLite)); if (!pInfo->pVloads) return; - taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); void *pIter = taosHashIterate(pMgmt->hash, NULL); while (pIter) { @@ -57,13 +57,13 @@ void vmGetVnodeLoadsLite(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo) { if (!pVnode->failed) { SVnodeLoadLite vload = {0}; if (vnodeGetLoadLite(pVnode->pImpl, &vload) == 0) { - taosArrayPush(pInfo->pVloads, &vload); + (void)taosArrayPush(pInfo->pVloads, &vload); } } pIter = taosHashIterate(pMgmt->hash, pIter); } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); } void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) { @@ -109,7 +109,7 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) { pMgmt->state.numOfBatchInsertReqs = numOfBatchInsertReqs; pMgmt->state.numOfBatchInsertSuccessReqs = numOfBatchInsertSuccessReqs; - tfsGetMonitorInfo(pMgmt->pTfs, &pInfo->tfs); + (void)tfsGetMonitorInfo(pMgmt->pTfs, &pInfo->tfs); taosArrayDestroy(pVloads); } @@ -200,7 +200,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pNode->nodePort = pCreate->replicas[pCfg->syncCfg.replicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_VOTER; tstrncpy(pNode->nodeFqdn, pCreate->replicas[pCfg->syncCfg.replicaNum].fqdn, TSDB_FQDN_LEN); - tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); pCfg->syncCfg.replicaNum++; } if (pCreate->selfIndex != -1) { @@ -212,7 +212,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pNode->nodePort = pCreate->learnerReplicas[pCfg->syncCfg.totalReplicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER; tstrncpy(pNode->nodeFqdn, pCreate->learnerReplicas[pCfg->syncCfg.totalReplicaNum].fqdn, TSDB_FQDN_LEN); - tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); pCfg->syncCfg.totalReplicaNum++; } pCfg->syncCfg.totalReplicaNum += pCfg->syncCfg.replicaNum; @@ -323,7 +323,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { SVnodeObj *pVnode = vmAcquireVnodeImpl(pMgmt, req.vgId, false); if (pVnode != NULL && (req.replica == 1 || !pVnode->failed)) { dError("vgId:%d, already exist", req.vgId); - tFreeSCreateVnodeReq(&req); + (void)tFreeSCreateVnodeReq(&req); vmReleaseVnode(pMgmt, pVnode); code = TSDB_CODE_VND_ALREADY_EXIST; return 0; @@ -340,7 +340,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { if (vnodeCreate(path, &vnodeCfg, diskPrimary, pMgmt->pTfs) < 0) { dError("vgId:%d, failed to create vnode since %s", req.vgId, terrstr()); vmReleaseVnode(pMgmt, pVnode); - tFreeSCreateVnodeReq(&req); + (void)tFreeSCreateVnodeReq(&req); code = terrno != 0 ? terrno : -1; return code; } @@ -374,14 +374,14 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { goto _OVER; } - //taosThreadMutexLock(&pMgmt->createLock); + // taosThreadMutexLock(&pMgmt->createLock); code = vmWriteVnodeListToFile(pMgmt); if (code != 0) { code = terrno != 0 ? terrno : code; - //taosThreadMutexUnlock(&pMgmt->createLock); + // taosThreadMutexUnlock(&pMgmt->createLock); goto _OVER; } - //taosThreadMutexUnlock(&pMgmt->createLock); + // taosThreadMutexUnlock(&pMgmt->createLock); _OVER: if (code != 0) { @@ -392,7 +392,7 @@ _OVER: TMSG_INFO(pMsg->msgType)); } - tFreeSCreateVnodeReq(&req); + (void)tFreeSCreateVnodeReq(&req); terrno = code; return code; } @@ -779,10 +779,11 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { + int32_t code = 0; SDropVnodeReq dropReq = {0}; if (tDeserializeSDropVnodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; - return -1; + return terrno; } int32_t vgId = dropReq.vgId; @@ -791,25 +792,25 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { if (dropReq.dnodeId != pMgmt->pData->dnodeId) { terrno = TSDB_CODE_INVALID_MSG; dError("vgId:%d, dnodeId:%d not matched with local dnode", dropReq.vgId, dropReq.dnodeId); - return -1; + return terrno; } SVnodeObj *pVnode = vmAcquireVnodeImpl(pMgmt, vgId, false); if (pVnode == NULL) { dInfo("vgId:%d, failed to drop since %s", vgId, terrstr()); terrno = TSDB_CODE_VND_NOT_EXIST; - return -1; + return terrno; } pVnode->dropped = 1; - if (vmWriteVnodeListToFile(pMgmt) != 0) { + if ((code = vmWriteVnodeListToFile(pMgmt)) != 0) { pVnode->dropped = 0; vmReleaseVnode(pMgmt, pVnode); - return -1; + return code; } vmCloseVnode(pMgmt, pVnode, false); - vmWriteVnodeListToFile(pMgmt); + (void)vmWriteVnodeListToFile(pMgmt); dInfo("vgId:%d, is dropped", vgId); return 0; @@ -864,7 +865,7 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { continue; } - taosArrayPush(arbHbRsp.hbMembers, &rspMember); + (void)taosArrayPush(arbHbRsp.hbMembers, &rspMember); vmReleaseVnode(pMgmt, pVnode); } @@ -895,7 +896,7 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { _OVER: tFreeSVArbHeartBeatReq(&arbHbReq); tFreeSVArbHeartBeatRsp(&arbHbRsp); - return terrno == TSDB_CODE_SUCCESS ? 0 : -1; + return terrno; } SArray *vmGetMsgHandles() { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 41ee392b4d..6bc0b5fe93 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -23,12 +23,12 @@ int32_t vmGetPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) { int32_t diskId = -1; SVnodeObj *pVnode = NULL; - taosThreadRwlockRdlock(&pMgmt->lock); - taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode); + (void)taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode); if (pVnode != NULL) { diskId = pVnode->diskPrimary; } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); return diskId; } @@ -96,8 +96,8 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) { SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict) { SVnodeObj *pVnode = NULL; - taosThreadRwlockRdlock(&pMgmt->lock); - taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode); + (void)taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode); if (pVnode == NULL || strict && (pVnode->dropped || pVnode->failed)) { terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; pVnode = NULL; @@ -105,7 +105,7 @@ SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict) { int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); // dTrace("vgId:%d, acquire vnode, ref:%d", pVnode->vgId, refCount); } - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); return pVnode; } @@ -115,10 +115,10 @@ SVnodeObj *vmAcquireVnode(SVnodeMgmt *pMgmt, int32_t vgId) { return vmAcquireVno void vmReleaseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { if (pVnode == NULL) return; - taosThreadRwlockRdlock(&pMgmt->lock); + (void)taosThreadRwlockRdlock(&pMgmt->lock); int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1); // dTrace("vgId:%d, release vnode, ref:%d", pVnode->vgId, refCount); - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); } static void vmFreeVnodeObj(SVnodeObj **ppVnode) { @@ -163,15 +163,15 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { pVnode->failed = 1; } - taosThreadRwlockWrlock(&pMgmt->lock); + (void)taosThreadRwlockWrlock(&pMgmt->lock); SVnodeObj *pOld = NULL; - taosHashGetDup(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), (void *)&pOld); + (void)taosHashGetDup(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), (void *)&pOld); if (pOld) { ASSERT(pOld->failed); vmFreeVnodeObj(&pOld); } int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *)); - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockUnlock(&pMgmt->lock); return code; } @@ -184,9 +184,9 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal) vnodeProposeCommitOnNeed(pVnode->pImpl, atExit); } - taosThreadRwlockWrlock(&pMgmt->lock); - taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t)); - taosThreadRwlockUnlock(&pMgmt->lock); + (void)taosThreadRwlockWrlock(&pMgmt->lock); + (void)taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t)); + (void)taosThreadRwlockUnlock(&pMgmt->lock); vmReleaseVnode(pMgmt, pVnode); if (pVnode->failed) { @@ -235,8 +235,8 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal) if (commitAndRemoveWal) { dInfo("vgId:%d, commit data for vnode split", pVnode->vgId); - vnodeSyncCommit(pVnode->pImpl); - vnodeBegin(pVnode->pImpl); + (void)vnodeSyncCommit(pVnode->pImpl); + (void)vnodeBegin(pVnode->pImpl); dInfo("vgId:%d, commit data finished", pVnode->vgId); } @@ -250,8 +250,8 @@ _closed: if (commitAndRemoveWal) { snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d%swal", TD_DIRSEP, pVnode->vgId, TD_DIRSEP); dInfo("vgId:%d, remove all wals, path:%s", pVnode->vgId, path); - tfsRmdir(pMgmt->pTfs, path); - tfsMkdir(pMgmt->pTfs, path); + (void)tfsRmdir(pMgmt->pTfs, path); + (void)tfsMkdir(pMgmt->pTfs, path); } if (pVnode->dropped) { @@ -332,7 +332,7 @@ static void *vmOpenVnodeInThread(void *param) { dInfo("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex); pThread->opened++; - atomic_add_fetch_32(&pMgmt->state.openVnodes, 1); + (void)atomic_add_fetch_32(&pMgmt->state.openVnodes, 1); } dInfo("thread:%d, numOfVnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened, @@ -381,13 +381,13 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) { if (pThread->vnodeNum == 0) continue; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pThread->thread, &thAttr, vmOpenVnodeInThread, pThread) != 0) { dError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno)); } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); } bool updateVnodesList = false; @@ -395,7 +395,7 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) { for (int32_t t = 0; t < threadNum; ++t) { SVnodeThread *pThread = &threads[t]; if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) { - taosThreadJoin(pThread->thread, NULL); + (void)taosThreadJoin(pThread->thread, NULL); taosThreadClear(&pThread->thread); } taosMemoryFree(pThread->pCfgs); @@ -484,19 +484,19 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) { if (pThread->vnodeNum == 0) continue; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pThread->thread, &thAttr, vmCloseVnodeInThread, pThread) != 0) { dError("thread:%d, failed to create thread to close vnode since %s", pThread->threadIndex, strerror(errno)); } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); } for (int32_t t = 0; t < threadNum; ++t) { SVnodeThread *pThread = &threads[t]; if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) { - taosThreadJoin(pThread->thread, NULL); + (void)taosThreadJoin(pThread->thread, NULL); taosThreadClear(&pThread->thread); } taosMemoryFree(pThread->ppVnodes); @@ -519,8 +519,8 @@ static void vmCleanup(SVnodeMgmt *pMgmt) { vmCloseVnodes(pMgmt); vmStopWorker(pMgmt); vnodeCleanup(); - taosThreadRwlockDestroy(&pMgmt->lock); - taosThreadMutexDestroy(&pMgmt->createLock); + (void)taosThreadRwlockDestroy(&pMgmt->lock); + (void)taosThreadMutexDestroy(&pMgmt->createLock); taosMemoryFree(pMgmt); } @@ -569,22 +569,22 @@ static void *vmThreadFp(void *param) { static int32_t vmInitTimer(SVnodeMgmt *pMgmt) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) { code = TAOS_SYSTEM_ERROR(errno); dError("failed to create vnode timer thread since %s", tstrerror(code)); return code; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); return 0; } static void vmCleanupTimer(SVnodeMgmt *pMgmt) { pMgmt->stop = true; if (taosCheckPthreadValid(pMgmt->thread)) { - taosThreadJoin(pMgmt->thread, NULL); + (void)taosThreadJoin(pMgmt->thread, NULL); taosThreadClear(&pMgmt->thread); } } @@ -707,7 +707,7 @@ static void *vmRestoreVnodeInThread(void *param) { } else { dInfo("vgId:%d, is restored by thread:%d", pVnode->vgId, pThread->threadIndex); pThread->opened++; - atomic_add_fetch_32(&pMgmt->state.openVnodes, 1); + (void)atomic_add_fetch_32(&pMgmt->state.openVnodes, 1); } } @@ -761,20 +761,20 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) { if (pThread->vnodeNum == 0) continue; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) { dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno)); ASSERT(errno == 0); } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); } for (int32_t t = 0; t < threadNum; ++t) { SVnodeThread *pThread = &threads[t]; if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) { - taosThreadJoin(pThread->thread, NULL); + (void)taosThreadJoin(pThread->thread, NULL); taosThreadClear(&pThread->thread); } taosMemoryFree(pThread->ppVnodes); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 8b4935985a..c2667d4f04 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -187,7 +187,7 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf static void vmSendResponse(SRpcMsg *pMsg) { if (pMsg->info.handle) { SRpcMsg rsp = {.info = pMsg->info, .code = terrno}; - rpcSendResponse(&rsp); + (void)rpcSendResponse(&rsp); } } @@ -236,7 +236,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code)); } else { dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pQueryQ, pMsg); + code = taosWriteQitem(pVnode->pQueryQ, pMsg); } break; case STREAM_QUEUE: diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index e6e065756f..9819c4f64e 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -47,8 +47,8 @@ static int32_t dmCheckRepeatInit(SDnode *pDnode) { } static int32_t dmInitSystem() { - taosIgnSIGPIPE(); - taosBlockSIGPIPE(); + (void)taosIgnSIGPIPE(); + (void)taosBlockSIGPIPE(); taosResolveCRC(); return 0; } @@ -200,10 +200,10 @@ void dmCleanup() { auditCleanup(); syncCleanUp(); walCleanUp(); - udfcClose(); + (void)udfcClose(); udfStopUdfd(); taosStopCacheRefreshWorker(); - dmDiskClose(); + (void)dmDiskClose(); DestroyRegexCache(); #if defined(USE_S3) diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index ccbfeb5aa5..fdce9fd4c9 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -47,7 +47,8 @@ int32_t dmInitDnode(SDnode *pDnode) { } // compress module init - tsCompressInit(tsLossyColumns, tsFPrecision, tsDPrecision, tsMaxRange, tsCurRange, (int)tsIfAdtFse, tsCompressor); + (void)tsCompressInit(tsLossyColumns, tsFPrecision, tsDPrecision, tsMaxRange, tsCurRange, (int)tsIfAdtFse, + tsCompressor); pDnode->wrappers[DNODE].func = dmGetMgmtFunc(); pDnode->wrappers[MNODE].func = mmGetMgmtFunc(); @@ -60,7 +61,7 @@ int32_t dmInitDnode(SDnode *pDnode) { pWrapper->pDnode = pDnode; pWrapper->name = dmNodeName(ntype); pWrapper->ntype = ntype; - taosThreadRwlockInit(&pWrapper->lock, NULL); + (void)taosThreadRwlockInit(&pWrapper->lock, NULL); snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name); pWrapper->path = taosStrdup(path); @@ -214,8 +215,8 @@ int32_t dmInitVars(SDnode *pDnode) { return -1; } - taosThreadRwlockInit(&pData->lock, NULL); - taosThreadMutexInit(&pDnode->mutex, NULL); + (void)taosThreadRwlockInit(&pData->lock, NULL); + (void)taosThreadMutexInit(&pDnode->mutex, NULL); return 0; } @@ -223,16 +224,16 @@ void dmClearVars(SDnode *pDnode) { for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; taosMemoryFreeClear(pWrapper->path); - taosThreadRwlockDestroy(&pWrapper->lock); + (void)taosThreadRwlockDestroy(&pWrapper->lock); } if (pDnode->lockfile != NULL) { - taosUnLockFile(pDnode->lockfile); - taosCloseFile(&pDnode->lockfile); + (void)taosUnLockFile(pDnode->lockfile); + (void)taosCloseFile(&pDnode->lockfile); pDnode->lockfile = NULL; } SDnodeData *pData = &pDnode->data; - taosThreadRwlockWrlock(&pData->lock); + (void)taosThreadRwlockWrlock(&pData->lock); if (pData->oldDnodeEps != NULL) { if (dmWriteEps(pData) == 0) { dmRemoveDnodePairs(pData); @@ -248,10 +249,10 @@ void dmClearVars(SDnode *pDnode) { taosHashCleanup(pData->dnodeHash); pData->dnodeHash = NULL; } - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); - taosThreadRwlockDestroy(&pData->lock); - taosThreadMutexDestroy(&pDnode->mutex); + (void)taosThreadRwlockDestroy(&pData->lock); + (void)taosThreadMutexDestroy(&pDnode->mutex); memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); } @@ -266,14 +267,14 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; SMgmtWrapper *pRetWrapper = pWrapper; - taosThreadRwlockRdlock(&pWrapper->lock); + (void)taosThreadRwlockRdlock(&pWrapper->lock); if (pWrapper->deployed) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); // dTrace("node:%s, is acquired, ref:%d", pWrapper->name, refCount); } else { pRetWrapper = NULL; } - taosThreadRwlockUnlock(&pWrapper->lock); + (void)taosThreadRwlockUnlock(&pWrapper->lock); return pRetWrapper; } @@ -281,7 +282,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { int32_t code = 0; - taosThreadRwlockRdlock(&pWrapper->lock); + (void)taosThreadRwlockRdlock(&pWrapper->lock); if (pWrapper->deployed) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); // dTrace("node:%s, is marked, ref:%d", pWrapper->name, refCount); @@ -304,7 +305,7 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { break; } } - taosThreadRwlockUnlock(&pWrapper->lock); + (void)taosThreadRwlockUnlock(&pWrapper->lock); return code; } @@ -312,9 +313,9 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { void dmReleaseWrapper(SMgmtWrapper *pWrapper) { if (pWrapper == NULL) return; - taosThreadRwlockRdlock(&pWrapper->lock); + (void)taosThreadRwlockRdlock(&pWrapper->lock); int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); - taosThreadRwlockUnlock(&pWrapper->lock); + (void)taosThreadRwlockUnlock(&pWrapper->lock); // dTrace("node:%s, is released, ref:%d", pWrapper->name, refCount); } @@ -343,7 +344,7 @@ void dmProcessNetTestReq(SDnode *pDnode, SRpcMsg *pMsg) { rsp.contLen = pMsg->contLen; } - rpcSendResponse(&rsp); + (void)rpcSendResponse(&rsp); rpcFreeCont(pMsg->pCont); } @@ -360,11 +361,11 @@ void dmProcessServerStartupStatus(SDnode *pDnode, SRpcMsg *pMsg) { } else { rsp.pCont = rpcMallocCont(contLen); if (rsp.pCont != NULL) { - tSerializeSServerStatusRsp(rsp.pCont, contLen, &statusRsp); + (void)tSerializeSServerStatusRsp(rsp.pCont, contLen, &statusRsp); rsp.contLen = contLen; } } - rpcSendResponse(&rsp); + (void)rpcSendResponse(&rsp); rpcFreeCont(pMsg->pCont); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index 175e470b4a..38bd9f6b92 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -77,12 +77,12 @@ void dmCloseNode(SMgmtWrapper *pWrapper) { taosMsleep(10); } - taosThreadRwlockWrlock(&pWrapper->lock); + (void)taosThreadRwlockWrlock(&pWrapper->lock); if (pWrapper->pMgmt != NULL) { (*pWrapper->func.closeFp)(pWrapper->pMgmt); pWrapper->pMgmt = NULL; } - taosThreadRwlockUnlock(&pWrapper->lock); + (void)taosThreadRwlockUnlock(&pWrapper->lock); dInfo("node:%s, has been closed", pWrapper->name); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index f0fa497eec..3d758e1fd3 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -18,18 +18,22 @@ #include "qworker.h" #include "tversion.h" -static inline void dmSendRsp(SRpcMsg *pMsg) { rpcSendResponse(pMsg); } +static inline void dmSendRsp(SRpcMsg *pMsg) { (void)rpcSendResponse(pMsg); } static inline void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dmGetMnodeEpSetForRedirect(&pDnode->data, pMsg, &epSet); - const int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet); + int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet); pMsg->pCont = rpcMallocCont(contLen); if (pMsg->pCont == NULL) { pMsg->code = TSDB_CODE_OUT_OF_MEMORY; } else { - tSerializeSEpSet(pMsg->pCont, contLen, &epSet); + contLen = tSerializeSEpSet(pMsg->pCont, contLen, &epSet); + if (contLen < 0) { + pMsg->code = contLen; + return; + } pMsg->contLen = contLen; } } @@ -65,13 +69,17 @@ static int32_t dmConvertErrCode(tmsg_t msgType, int32_t code) { return code; } static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) { + int32_t code = 0; SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite)); - tDeserializeSUpdateIpWhite(pRpc->pCont, pRpc->contLen, &ipWhite); - - rpcSetIpWhite(pTrans, &ipWhite); + code = tDeserializeSUpdateIpWhite(pRpc->pCont, pRpc->contLen, &ipWhite); + if (code < 0) { + dError("failed to update rpc ip-white since: %s", tstrerror(code)); + return; + } + code = rpcSetIpWhite(pTrans, &ipWhite); pData->ipWhiteVer = ipWhite.ver; - tFreeSUpdateIpWhiteReq(&ipWhite); + (void)tFreeSUpdateIpWhiteReq(&ipWhite); rpcFreeCont(pRpc->pCont); } @@ -80,7 +88,7 @@ static bool dmIsForbiddenIp(int8_t forbidden, char *user, uint32_t clientIp) { SIpV4Range range = {.ip = clientIp, .mask = 32}; char buf[36] = {0}; - rpcUtilSIpRangeToStr(&range, buf); + (void)rpcUtilSIpRangeToStr(&range, buf); dError("User:%s host:%s not in ip white list", user, buf); return true; } else { @@ -99,7 +107,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { pRpc->info.handle, pRpc->contLen, pRpc->code, pRpc->info.ahandle, pRpc->info.refId); int32_t svrVer = 0; - taosVersionStrToInt(version, &svrVer); + (void)taosVersionStrToInt(version, &svrVer); if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) { dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer); goto _OVER; @@ -238,7 +246,7 @@ _OVER: if (pWrapper != NULL) { dmSendRsp(&rsp); } else { - rpcSendResponse(&rsp); + (void)rpcSendResponse(&rsp); } } @@ -295,7 +303,7 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) { return code; } else { pMsg->info.handle = 0; - rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL); + (void)rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL); return 0; } } @@ -314,14 +322,13 @@ static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) { pMsg->info.handle); return code; } else { - rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL); - return 0; + return rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL); } } -static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { rpcRegisterBrokenLinkArg(pMsg); } +static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { (void)rpcRegisterBrokenLinkArg(pMsg); } -static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { rpcReleaseHandle(pHandle, type); } +static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { (void)rpcReleaseHandle(pHandle, type); } static bool rpcRfp(int32_t code, tmsg_t msgType) { if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_MNODE_NOT_FOUND || @@ -381,7 +388,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); + (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->clientRpc = rpcOpen(&rpcInit); if (pTrans->clientRpc == NULL) { @@ -425,7 +432,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); + (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->statusRpc = rpcOpen(&rpcInit); if (pTrans->statusRpc == NULL) { @@ -470,7 +477,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); + (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->syncRpc = rpcOpen(&rpcInit); if (pTrans->syncRpc == NULL) { @@ -521,7 +528,7 @@ int32_t dmInitServer(SDnode *pDnode) { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.compressSize = tsCompressMsgSize; - taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); + (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->serverRpc = rpcOpen(&rpcInit); if (pTrans->serverRpc == NULL) { dError("failed to init dnode rpc server"); diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 866dce1b87..af5530215b 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -33,7 +33,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData); void dmGetDnodeEp(void *data, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { SDnodeData *pData = data; - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); SDnodeEp *pDnodeEp = taosHashGet(pData->dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { @@ -48,7 +48,7 @@ void dmGetDnodeEp(void *data, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t } } - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); } static int32_t dmDecodeEps(SJson *pJson, SDnodeData *pData) { @@ -255,8 +255,8 @@ _OVER: if (taosArrayGetSize(pData->dnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; - taosGetFqdnPortFromEp(tsFirst, &dnodeEp.ep); - taosArrayPush(pData->dnodeEps, &dnodeEp); + (void)taosGetFqdnPortFromEp(tsFirst, &dnodeEp.ep); + (void)taosArrayPush(pData->dnodeEps, &dnodeEp); } if ((code = dmReadDnodePairs(pData)) != 0) { @@ -337,7 +337,7 @@ int32_t dmWriteEps(SDnodeData *pData) { if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); code = 0; @@ -348,7 +348,7 @@ int32_t dmWriteEps(SDnodeData *pData) { _OVER: if (pJson != NULL) tjsonDelete(pJson); if (buffer != NULL) taosMemoryFree(buffer); - if (pFile != NULL) taosCloseFile(&pFile); + if (pFile != NULL) (void)taosCloseFile(&pFile); if (code != 0) { dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer); @@ -358,18 +358,18 @@ _OVER: int32_t dmGetDnodeSize(SDnodeData *pData) { int32_t size = 0; - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); size = taosArrayGetSize(pData->dnodeEps); - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); return size; } void dmUpdateEps(SDnodeData *pData, SArray *eps) { - taosThreadRwlockWrlock(&pData->lock); + (void)taosThreadRwlockWrlock(&pData->lock); dDebug("new dnode list get from mnode, dnodeVer:%" PRId64, pData->dnodeVer); dmResetEps(pData, eps); - dmWriteEps(pData); - taosThreadRwlockUnlock(&pData->lock); + (void)dmWriteEps(pData); + (void)taosThreadRwlockUnlock(&pData->lock); } static void dmResetEps(SDnodeData *pData, SArray *dnodeEps) { @@ -398,7 +398,7 @@ static void dmResetEps(SDnodeData *pData, SArray *dnodeEps) { for (int32_t i = 0; i < numOfEps; i++) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); - taosHashPut(pData->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + (void)taosHashPut(pData->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); } pData->validMnodeEps = true; @@ -418,7 +418,7 @@ static void dmPrintEps(SDnodeData *pData) { static bool dmIsEpChanged(SDnodeData *pData, int32_t dnodeId, const char *ep) { bool changed = false; if (dnodeId == 0) return changed; - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); SDnodeEp *pDnodeEp = taosHashGet(pData->dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { @@ -430,14 +430,14 @@ static bool dmIsEpChanged(SDnodeData *pData, int32_t dnodeId, const char *ep) { } } - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); return changed; } void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) { - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); *pEpSet = pData->mnodeEps; - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); } void dmEpSetToStr(char *buf, int32_t len, SEpSet *epSet) { @@ -464,12 +464,12 @@ static FORCE_INLINE void dmSwapEps(SEp *epLhs, SEp *epRhs) { } void dmRotateMnodeEpSet(SDnodeData *pData) { - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); SEpSet *pEpSet = &pData->mnodeEps; for (int i = 1; i < pEpSet->numOfEps; i++) { dmSwapEps(&pEpSet->eps[i - 1], &pEpSet->eps[i]); } - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); } void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet) { @@ -486,9 +486,9 @@ void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) { if (memcmp(pEpSet, &pData->mnodeEps, sizeof(SEpSet)) == 0) return; - taosThreadRwlockWrlock(&pData->lock); + (void)taosThreadRwlockWrlock(&pData->lock); pData->mnodeEps = *pEpSet; - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { @@ -502,7 +502,7 @@ bool dmUpdateDnodeInfo(void *data, int32_t *did, int64_t *clusterId, char *fqdn, int32_t dnodeId = -1; if (did != NULL) dnodeId = *did; - taosThreadRwlockRdlock(&pData->lock); + (void)taosThreadRwlockRdlock(&pData->lock); if (pData->oldDnodeEps != NULL) { int32_t size = (int32_t)taosArrayGetSize(pData->oldDnodeEps); @@ -542,7 +542,7 @@ bool dmUpdateDnodeInfo(void *data, int32_t *did, int64_t *clusterId, char *fqdn, } } - taosThreadRwlockUnlock(&pData->lock); + (void)taosThreadRwlockUnlock(&pData->lock); return updated; } @@ -550,26 +550,26 @@ static int32_t dmDecodeEpPairs(SJson *pJson, SDnodeData *pData) { int32_t code = 0; SJson *dnodes = tjsonGetObjectItem(pJson, "dnodes"); - if (dnodes == NULL) return -1; + if (dnodes == NULL) return TSDB_CODE_INVALID_CFG_VALUE; int32_t numOfDnodes = tjsonGetArraySize(dnodes); for (int32_t i = 0; i < numOfDnodes; ++i) { SJson *dnode = tjsonGetArrayItem(dnodes, i); - if (dnode == NULL) return -1; + if (dnode == NULL) return TSDB_CODE_INVALID_CFG_VALUE; SDnodeEpPair pair = {0}; tjsonGetInt32ValueFromDouble(dnode, "id", pair.id, code); - if (code < 0) return -1; + if (code < 0) return TSDB_CODE_INVALID_CFG_VALUE; code = tjsonGetStringValue(dnode, "fqdn", pair.oldFqdn); - if (code < 0) return -1; + if (code < 0) return TSDB_CODE_INVALID_CFG_VALUE; tjsonGetUInt16ValueFromDouble(dnode, "port", pair.oldPort, code); - if (code < 0) return -1; + if (code < 0) return TSDB_CODE_INVALID_CFG_VALUE; code = tjsonGetStringValue(dnode, "new_fqdn", pair.newFqdn); - if (code < 0) return -1; + if (code < 0) return TSDB_CODE_INVALID_CFG_VALUE; tjsonGetUInt16ValueFromDouble(dnode, "new_port", pair.newPort, code); - if (code < 0) return -1; + if (code < 0) return TSDB_CODE_INVALID_CFG_VALUE; - if (taosArrayPush(pData->oldDnodeEps, &pair) == NULL) return -1; + if (taosArrayPush(pData->oldDnodeEps, &pair) == NULL) return TSDB_CODE_OUT_OF_MEMORY; } return code; diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index eee6ab3a41..c8b24d5469 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -211,7 +211,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) { if (ret < 0) { code = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(pFile); + (void)taosCloseFile(pFile); *pFile = NULL; return code; } @@ -239,7 +239,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool opts.source = DM_KEY_INDICATOR; opts.result = result; opts.unitLen = 16; - CBC_Encrypt(&opts); + (void)CBC_Encrypt(&opts); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { @@ -359,7 +359,7 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { opts.source = content; opts.result = result; opts.unitLen = 16; - CBC_Decrypt(&opts); + (void)CBC_Decrypt(&opts); if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) { code = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED; diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index bab7d068f3..68f4c9d0ff 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -57,8 +57,8 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) { taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine); taosGetCpuCores(&pInfo->cpu_cores, false); - taosGetProcMemory(&pInfo->mem_engine); - taosGetSysMemory(&pInfo->mem_system); + (void)taosGetProcMemory(&pInfo->mem_engine); + (void)taosGetSysMemory(&pInfo->mem_system); pInfo->mem_total = tsTotalMemoryKB; pInfo->disk_engine = 0; pInfo->disk_used = tsDataSpace.size.used; diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h index e1a790867e..a773c61986 100644 --- a/source/dnode/mnode/impl/inc/mndConsumer.h +++ b/source/dnode/mnode/impl/inc/mndConsumer.h @@ -25,7 +25,7 @@ extern "C" { enum { MQ_CONSUMER_STATUS_REBALANCE = 1, MQ_CONSUMER_STATUS_READY, - MQ_CONSUMER_STATUS_LOST, +// MQ_CONSUMER_STATUS_LOST, }; int32_t mndInitConsumer(SMnode *pMnode); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 5319cc88eb..62e77867f6 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -596,11 +596,12 @@ typedef struct { typedef struct { int64_t consumerId; char cgroup[TSDB_CGROUP_LEN]; - char clientId[256]; + char clientId[TSDB_CLIENT_ID_LEN]; int8_t updateType; // used only for update int32_t epoch; int32_t status; int32_t hbStatus; // hbStatus is not applicable to serialization + int32_t pollStatus; // pollStatus is not applicable to serialization SRWLatch lock; // lock is used for topics update SArray* currentTopics; // SArray SArray* rebNewTopics; // SArray @@ -620,6 +621,8 @@ typedef struct { int8_t autoCommit; int32_t autoCommitInterval; int32_t resetOffsetCfg; + int32_t sessionTimeoutMs; + int32_t maxPollIntervalMs; } SMqConsumerObj; int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index bd0d97e34d..d713de5158 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -52,6 +52,11 @@ typedef struct SStreamTransMgmt { SHashObj *pDBTrans; } SStreamTransMgmt; +typedef struct SStreamTaskResetMsg { + int64_t streamId; + int32_t transId; +} SStreamTaskResetMsg; + typedef struct SStreamExecInfo { bool initTaskList; SArray *pNodeList; @@ -63,6 +68,7 @@ typedef struct SStreamExecInfo { SHashObj *pTransferStateStreams; SHashObj *pChkptStreams; SHashObj *pStreamConsensus; + SArray *pKilledChkptTrans; // SArray } SStreamExecInfo; extern SStreamExecInfo execInfo; @@ -75,12 +81,6 @@ typedef struct SNodeEntry { int64_t hbTimestamp; // second } SNodeEntry; -typedef struct SOrphanTask { - int64_t streamId; - int32_t taskId; - int32_t nodeId; -} SOrphanTask; - typedef struct { SMsgHead head; } SMStreamReqCheckpointRsp, SMStreamUpdateChkptRsp, SMStreamReqConsensChkptRsp; @@ -152,6 +152,11 @@ void mndAddConsensusTasks(SCheckpointConsensusInfo *pInfo, const SRestoreChec void mndClearConsensusRspEntry(SCheckpointConsensusInfo *pInfo); int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId); +int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows); +int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t numOfRows); + +int32_t mndProcessResetStatusReq(SRpcMsg *pReq); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index da01a4b2f6..8b45b13dd1 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -523,6 +523,10 @@ static int32_t mndUpdateCompactProgress(SMnode *pMnode, SRpcMsg *pReq, int32_t c int32_t mndProcessQueryCompactRsp(SRpcMsg *pReq) { int32_t code = 0; SQueryCompactProgressRsp req = {0}; + if (pReq->code != 0) { + mError("received wrong compact response, req code is %s", tstrerror(pReq->code)); + TAOS_RETURN(pReq->code); + } code = tDeserializeSQueryCompactProgressRsp(pReq->pCont, pReq->contLen, &req); if (code != 0) { mError("failed to deserialize vnode-query-compact-progress-rsp, ret:%d, pCont:%p, len:%d", code, pReq->pCont, diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index cd793a185e..b05619c93f 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -25,7 +25,7 @@ #include "tcompare.h" #include "tname.h" -#define MND_CONSUMER_VER_NUMBER 2 +#define MND_CONSUMER_VER_NUMBER 3 #define MND_CONSUMER_RESERVE_SIZE 64 #define MND_MAX_GROUP_PER_TOPIC 100 @@ -55,7 +55,6 @@ int32_t mndInitConsumer(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_TMQ_SUBSCRIBE, mndProcessSubscribeReq); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_HB, mndProcessMqHbReq); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_ASK_EP, mndProcessAskEpReq); - // mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, mndProcessConsumerClearMsg); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer); @@ -238,11 +237,10 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) { MND_TMQ_RETURN_CHECK(mndAcquireConsumer(pMnode, consumerId, &pConsumer)); MND_TMQ_RETURN_CHECK(checkPrivilege(pMnode, pConsumer, &rsp, pMsg->info.conn.user)); atomic_store_32(&pConsumer->hbStatus, 0); - int32_t status = atomic_load_32(&pConsumer->status); - if (status == MQ_CONSUMER_STATUS_LOST) { - mInfo("try to recover consumer:0x%" PRIx64, consumerId); - MND_TMQ_RETURN_CHECK(mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_CONSUMER_RECOVER, &pMsg->info)); + if (req.pollFlag == 1){ + atomic_store_32(&pConsumer->pollStatus, 0); } + storeOffsetRows(pMnode, &req, pConsumer); code = buildMqHbRsp(pMsg, &rsp); @@ -389,11 +387,9 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { code = TSDB_CODE_MND_CONSUMER_NOT_EXIST; goto END; } - atomic_store_32(&pConsumer->hbStatus, 0); + + // 1. check consumer status int32_t status = atomic_load_32(&pConsumer->status); - if (status == MQ_CONSUMER_STATUS_LOST) { - MND_TMQ_RETURN_CHECK(mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_CONSUMER_RECOVER, &pMsg->info)); - } if (status != MQ_CONSUMER_STATUS_READY) { mInfo("consumer:0x%" PRIx64 " not ready, status: %s", consumerId, mndConsumerStatusName(status)); code = TSDB_CODE_MND_CONSUMER_NOT_READY; @@ -566,7 +562,7 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) { STrans *pTrans = NULL; SCMSubscribeReq subscribe = {0}; - MND_TMQ_RETURN_CHECK(tDeserializeSCMSubscribeReq(msgStr, &subscribe)); + MND_TMQ_RETURN_CHECK(tDeserializeSCMSubscribeReq(msgStr, &subscribe, pMsg->contLen)); if(taosArrayGetSize(subscribe.topicNames) == 0){ SMqConsumerObj *pConsumerTmp = NULL; MND_TMQ_RETURN_CHECK(mndAcquireConsumer(pMnode, subscribe.consumerId, &pConsumerTmp)); @@ -701,17 +697,17 @@ static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) { return 0; } -static void updateConsumerStatus(SMqConsumerObj *pConsumer) { - int32_t status = pConsumer->status; - - if (taosArrayGetSize(pConsumer->rebNewTopics) == 0 && taosArrayGetSize(pConsumer->rebRemovedTopics) == 0) { - if (status == MQ_CONSUMER_STATUS_REBALANCE) { - pConsumer->status = MQ_CONSUMER_STATUS_READY; - } else if (status == MQ_CONSUMER_STATUS_READY && taosArrayGetSize(pConsumer->currentTopics) == 0) { - pConsumer->status = MQ_CONSUMER_STATUS_LOST; - } - } -} +//static void updateConsumerStatus(SMqConsumerObj *pConsumer) { +// int32_t status = pConsumer->status; +// +// if (taosArrayGetSize(pConsumer->rebNewTopics) == 0 && taosArrayGetSize(pConsumer->rebRemovedTopics) == 0) { +// if (status == MQ_CONSUMER_STATUS_REBALANCE) { +// pConsumer->status = MQ_CONSUMER_STATUS_READY; +// } else if (status == MQ_CONSUMER_STATUS_READY && taosArrayGetSize(pConsumer->currentTopics) == 0) { +// pConsumer->status = MQ_CONSUMER_STATUS_LOST; +// } +// } +//} // remove from topic list static void removeFromTopicList(SArray *topicList, const char *pTopic, int64_t consumerId, char *type) { @@ -757,21 +753,6 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, pOldConsumer->subscribeTime = taosGetTimestampMs(); pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE; mInfo("consumer:0x%" PRIx64 " subscribe update, modify existed consumer", pOldConsumer->consumerId); - } else if (pNewConsumer->updateType == CONSUMER_UPDATE_REC) { - int32_t sz = taosArrayGetSize(pOldConsumer->assignedTopics); - for (int32_t i = 0; i < sz; i++) { - void * tmp = taosArrayGetP(pOldConsumer->assignedTopics, i); - if (tmp == NULL){ - return TSDB_CODE_TMQ_INVALID_MSG; - } - char *topic = taosStrdup(tmp); - if (taosArrayPush(pOldConsumer->rebNewTopics, &topic) == NULL) { - taosMemoryFree(topic); - return TSDB_CODE_TMQ_INVALID_MSG; - } - } - pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE; - mInfo("consumer:0x%" PRIx64 " recover update", pOldConsumer->consumerId); } else if (pNewConsumer->updateType == CONSUMER_UPDATE_REB) { (void)atomic_add_fetch_32(&pOldConsumer->epoch, 1); pOldConsumer->rebalanceTime = taosGetTimestampMs(); @@ -796,7 +777,11 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, } int32_t status = pOldConsumer->status; - updateConsumerStatus(pOldConsumer); +// updateConsumerStatus(pOldConsumer); + if (taosArrayGetSize(pOldConsumer->rebNewTopics) == 0 && taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0) { + pOldConsumer->status = MQ_CONSUMER_STATUS_READY; + } + pOldConsumer->rebalanceTime = taosGetTimestampMs(); (void)atomic_add_fetch_32(&pOldConsumer->epoch, 1); @@ -816,7 +801,10 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, removeFromTopicList(pOldConsumer->currentTopics, topic, pOldConsumer->consumerId, "current"); int32_t status = pOldConsumer->status; - updateConsumerStatus(pOldConsumer); +// updateConsumerStatus(pOldConsumer); + if (taosArrayGetSize(pOldConsumer->rebNewTopics) == 0 && taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0) { + pOldConsumer->status = MQ_CONSUMER_STATUS_READY; + } pOldConsumer->rebalanceTime = taosGetTimestampMs(); (void)atomic_add_fetch_32(&pOldConsumer->epoch, 1); @@ -852,6 +840,8 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * int32_t numOfRows = 0; SMqConsumerObj *pConsumer = NULL; int32_t code = 0; + char *parasStr = NULL; + char *status = NULL; while (numOfRows < rowsCapacity) { pShow->pIter = sdbFetch(pSdb, SDB_CONSUMER, pShow->pIter, (void **)&pConsumer); @@ -884,7 +874,7 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * int32_t cols = 0; // consumer id - char consumerIdHex[32] = {0}; + char consumerIdHex[TSDB_CONSUMER_ID_LEN + VARSTR_HEADER_SIZE] = {0}; (void)sprintf(varDataVal(consumerIdHex), "0x%" PRIx64, pConsumer->consumerId); varDataSetLen(consumerIdHex, strlen(varDataVal(consumerIdHex))); @@ -901,7 +891,7 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * MND_TMQ_RETURN_CHECK(colDataSetVal(pColInfo, numOfRows, (const char *)cgroup, false)); // client id - char clientId[256 + VARSTR_HEADER_SIZE] = {0}; + char clientId[TSDB_CLIENT_ID_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(clientId, pConsumer->clientId); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -909,13 +899,15 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * MND_TMQ_RETURN_CHECK(colDataSetVal(pColInfo, numOfRows, (const char *)clientId, false)); // status - char status[20 + VARSTR_HEADER_SIZE] = {0}; const char *pStatusName = mndConsumerStatusName(pConsumer->status); + status = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes); + MND_TMQ_NULL_CHECK(status); STR_TO_VARSTR(status, pStatusName); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); MND_TMQ_NULL_CHECK(pColInfo); MND_TMQ_RETURN_CHECK(colDataSetVal(pColInfo, numOfRows, (const char *)status, false)); + taosMemoryFreeClear(status); // one subscribed topic pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -948,7 +940,8 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * STqOffsetVal pVal = {.type = pConsumer->resetOffsetCfg}; tFormatOffset(buf, TSDB_OFFSET_LEN, &pVal); - char parasStr[64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE] = {0}; + parasStr = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes); + MND_TMQ_NULL_CHECK(parasStr); (void)sprintf(varDataVal(parasStr), "tbname:%d,commit:%d,interval:%dms,reset:%s", pConsumer->withTbName, pConsumer->autoCommit, pConsumer->autoCommitInterval, buf); varDataSetLen(parasStr, strlen(varDataVal(parasStr))); @@ -956,7 +949,7 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); MND_TMQ_NULL_CHECK(pColInfo); MND_TMQ_RETURN_CHECK(colDataSetVal(pColInfo, numOfRows, (const char *)parasStr, false)); - + taosMemoryFreeClear(parasStr); numOfRows++; } @@ -970,6 +963,8 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * return numOfRows; END: + taosMemoryFreeClear(status); + taosMemoryFreeClear(parasStr); return code; } @@ -982,8 +977,8 @@ const char *mndConsumerStatusName(int status) { switch (status) { case MQ_CONSUMER_STATUS_READY: return "ready"; - case MQ_CONSUMER_STATUS_LOST: - return "lost"; +// case MQ_CONSUMER_STATUS_LOST: +// return "lost"; case MQ_CONSUMER_STATUS_REBALANCE: return "rebalancing"; default: diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 973215fdbd..5a7831ac0e 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -791,12 +791,12 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, mndSetDefaultDbCfg(&dbObj.cfg); if ((code = mndCheckDbName(dbObj.name, pUser)) != 0) { - mError("db:%s, failed to create since %s", pCreate->db, terrstr()); + mError("db:%s, failed to create, check db name failed, since %s", pCreate->db, terrstr()); TAOS_RETURN(code); } if ((code = mndCheckDbCfg(pMnode, &dbObj.cfg)) != 0) { - mError("db:%s, failed to create since %s", pCreate->db, terrstr()); + mError("db:%s, failed to create, check db cfg failed, since %s", pCreate->db, terrstr()); TAOS_RETURN(code); } @@ -812,7 +812,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SVgObj *pVgroups = NULL; if ((code = mndAllocVgroup(pMnode, &dbObj, &pVgroups)) != 0) { - mError("db:%s, failed to create since %s", pCreate->db, terrstr()); + mError("db:%s, failed to create, alloc vgroup failed, since %s", pCreate->db, terrstr()); TAOS_RETURN(code); } @@ -965,7 +965,7 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) { TAOS_CHECK_GOTO(mndAcquireUser(pMnode, pReq->info.conn.user, &pUser), &lino, _OVER); - code = mndCreateDb(pMnode, pReq, &createReq, pUser); + TAOS_CHECK_GOTO(mndCreateDb(pMnode, pReq, &createReq, pUser), &lino, _OVER); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; SName name = {0}; @@ -1892,13 +1892,21 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs, rsp.pTsmaRsp = taosMemoryCalloc(1, sizeof(STableTSMAInfoRsp)); if (rsp.pTsmaRsp) rsp.pTsmaRsp->pTsmas = taosArrayInit(4, POINTER_BYTES); if (rsp.pTsmaRsp && rsp.pTsmaRsp->pTsmas) { - rsp.dbTsmaVersion = pDb->tsmaVersion; bool exist = false; - if (mndGetDbTsmas(pMnode, 0, pDb->uid, rsp.pTsmaRsp, &exist) != 0) { + int32_t code = mndGetDbTsmas(pMnode, 0, pDb->uid, rsp.pTsmaRsp, &exist); + if (TSDB_CODE_SUCCESS != code) { mndReleaseDb(pMnode, pDb); - mError("db:%s, failed to get db tsmas", pDb->name); + if (code != TSDB_CODE_NEED_RETRY) { + mError("db:%s, failed to get db tsmas", pDb->name); + } else { + mWarn("db:%s, need retry to get db tsmas", pDb->name); + } + taosArrayDestroyP(rsp.pTsmaRsp->pTsmas, tFreeAndClearTableTSMAInfo); + taosMemoryFreeClear(rsp.pTsmaRsp); continue; } + rsp.dbTsmaVersion = pDb->tsmaVersion; + mDebug("update tsma version to %d, got tsma num: %ld", pDb->tsmaVersion, rsp.pTsmaRsp->pTsmas->size); } } @@ -1909,6 +1917,8 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs, if (rsp.useDbRsp->pVgroupInfos == NULL) { mndReleaseDb(pMnode, pDb); mError("db:%s, failed to malloc usedb response", pDb->name); + taosArrayDestroyP(rsp.pTsmaRsp->pTsmas, tFreeAndClearTableTSMAInfo); + taosMemoryFreeClear(rsp.pTsmaRsp); continue; } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index ef6853d327..55ab5d44e6 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -288,6 +288,7 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, pConsumer->epoch = 0; pConsumer->status = MQ_CONSUMER_STATUS_REBALANCE; pConsumer->hbStatus = 0; + pConsumer->pollStatus = 0; taosInitRWLatch(&pConsumer->lock); pConsumer->createTime = taosGetTimestampMs(); @@ -322,6 +323,8 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, pConsumer->autoCommit = subscribe->autoCommit; pConsumer->autoCommitInterval = subscribe->autoCommitInterval; pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg; + pConsumer->maxPollIntervalMs = subscribe->maxPollIntervalMs; + pConsumer->sessionTimeoutMs = subscribe->sessionTimeoutMs; pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup); if (pConsumer->rebNewTopics == NULL){ @@ -424,6 +427,8 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) { tlen += taosEncodeFixedI8(buf, pConsumer->autoCommit); tlen += taosEncodeFixedI32(buf, pConsumer->autoCommitInterval); tlen += taosEncodeFixedI32(buf, pConsumer->resetOffsetCfg); + tlen += taosEncodeFixedI32(buf, pConsumer->maxPollIntervalMs); + tlen += taosEncodeFixedI32(buf, pConsumer->sessionTimeoutMs); return tlen; } @@ -495,6 +500,14 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer, int8_t s buf = taosDecodeFixedI32(buf, &pConsumer->autoCommitInterval); buf = taosDecodeFixedI32(buf, &pConsumer->resetOffsetCfg); } + if (sver > 2){ + buf = taosDecodeFixedI32(buf, &pConsumer->maxPollIntervalMs); + buf = taosDecodeFixedI32(buf, &pConsumer->sessionTimeoutMs); + } else{ + pConsumer->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL; + pConsumer->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT; + } + return (void *)buf; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index b02f754943..974beeccb6 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -86,6 +86,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq); static int32_t mndProcessNotifyReq(SRpcMsg *pReq); static int32_t mndProcessRestoreDnodeReq(SRpcMsg *pReq); static int32_t mndProcessStatisReq(SRpcMsg *pReq); +static int32_t mndProcessUpdateDnodeInfoReq(SRpcMsg *pReq); static int32_t mndProcessCreateEncryptKeyReq(SRpcMsg *pRsp); static int32_t mndProcessCreateEncryptKeyRsp(SRpcMsg *pRsp); @@ -126,6 +127,7 @@ int32_t mndInitDnode(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_STATIS, mndProcessStatisReq); mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_KEY, mndProcessCreateEncryptKeyReq); mndSetMsgHandle(pMnode, TDMT_DND_CREATE_ENCRYPT_KEY_RSP, mndProcessCreateEncryptKeyRsp); + mndSetMsgHandle(pMnode, TDMT_MND_UPDATE_DNODE_INFO, mndProcessUpdateDnodeInfoReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig); @@ -185,8 +187,8 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; - mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, - 1); // TODO: check the return value + (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, + 1); // TODO: check the return value _OVER: mndTransDrop(pTrans); @@ -601,37 +603,78 @@ static int32_t mndProcessStatisReq(SRpcMsg *pReq) { } static int32_t mndUpdateDnodeObj(SMnode *pMnode, SDnodeObj *pDnode) { - int32_t code = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-dnode-obj"); + int32_t code = 0, lino = 0; + SDnodeInfoReq infoReq = {0}; + int32_t contLen = 0; + void *pReq = NULL; + + infoReq.dnodeId = pDnode->id; + tstrncpy(infoReq.machineId, pDnode->machineId, TSDB_MACHINE_ID_LEN + 1); + + if ((contLen = tSerializeSDnodeInfoReq(NULL, 0, &infoReq)) <= 0) { + TAOS_RETURN(contLen ? contLen : TSDB_CODE_OUT_OF_MEMORY); + } + pReq = rpcMallocCont(contLen); + if (pReq == NULL) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + + (void)tSerializeSDnodeInfoReq(pReq, contLen, &infoReq); + + SRpcMsg rpcMsg = {.msgType = TDMT_MND_UPDATE_DNODE_INFO, .pCont = pReq, .contLen = contLen}; + TAOS_CHECK_EXIT(tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg)); +_exit: + if (code < 0) { + mError("dnode:%d, failed to update dnode info since %s", pDnode->id, tstrerror(code)); + } + TAOS_RETURN(code); +} + +static int32_t mndProcessUpdateDnodeInfoReq(SRpcMsg *pReq) { + int32_t code = 0, lino = 0; + SMnode *pMnode = pReq->info.node; + SDnodeInfoReq infoReq = {0}; + SDnodeObj *pDnode = NULL; + STrans *pTrans = NULL; + SSdbRaw *pCommitRaw = NULL; + + TAOS_CHECK_EXIT(tDeserializeSDnodeInfoReq(pReq->pCont, pReq->contLen, &infoReq)); + + pDnode = mndAcquireDnode(pMnode, infoReq.dnodeId); + if (pDnode == NULL) { + TAOS_CHECK_EXIT(terrno); + } + + pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-dnode-obj"); if (pTrans == NULL) { - code = TSDB_CODE_MND_RETURN_VALUE_NULL; - if (terrno != 0) code = terrno; - goto _exit; + TAOS_CHECK_EXIT(terrno); } pDnode->updateTime = taosGetTimestampMs(); - SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode); - if (pCommitRaw == NULL) { - code = TSDB_CODE_MND_RETURN_VALUE_NULL; - if (terrno != 0) code = terrno; - goto _exit; + if ((pCommitRaw = mndDnodeActionEncode(pDnode)) == NULL) { + TAOS_CHECK_EXIT(terrno); } if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) { mError("trans:%d, failed to append commit log since %s", pTrans->id, tstrerror(code)); - code = terrno; - goto _exit; + TAOS_CHECK_EXIT(code); } (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + pCommitRaw = NULL; if ((code = mndTransPrepare(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code)); - goto _exit; + TAOS_CHECK_EXIT(code); } _exit: + mndReleaseDnode(pMnode, pDnode); + if (code != 0) { + mError("dnode:%d, failed to update dnode info at line %d since %s", infoReq.dnodeId, lino, tstrerror(code)); + } mndTransDrop(pTrans); - return code; + sdbFreeRaw(pCommitRaw); + TAOS_RETURN(code); } static int32_t mndProcessStatusReq(SRpcMsg *pReq) { @@ -916,7 +959,8 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); code = 0; - mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, 1); // TODO: check the return value + (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD, + 1); // TODO: check the return value _OVER: mndTransDrop(pTrans); sdbFreeRaw(pRaw); @@ -1231,7 +1275,8 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); - mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, 1); // TODO: check the return value + (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP, + 1); // TODO: check the return value code = 0; _OVER: @@ -1749,7 +1794,7 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB #ifdef TD_ENTERPRISE STR_TO_VARSTR(buf, pDnode->machineId); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, buf, false); + (void)colDataSetVal(pColInfo, numOfRows, buf, false); #endif numOfRows++; diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index ca7b5bbac6..31e092f1a4 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -74,7 +74,7 @@ void dumpFunc(SSdb *pSdb, SJson *json) { void dumpDb(SSdb *pSdb, SJson *json) { void *pIter = NULL; SJson *items = tjsonCreateObject(); - tjsonAddItemToObject(json, "dbs", items); + (void)tjsonAddItemToObject(json, "dbs", items); while (1) { SDbObj *pObj = NULL; @@ -82,7 +82,7 @@ void dumpDb(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - tjsonAddItemToObject(items, "db", item); + (void)tjsonAddItemToObject(items, "db", item); (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); (void)tjsonAddStringToObject(item, "acct", pObj->acct); @@ -546,7 +546,7 @@ void dumpHeader(SSdb *pSdb, SJson *json) { (void)tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig)); SJson *maxIdsJson = tjsonCreateObject(); - tjsonAddItemToObject(json, "maxIds", maxIdsJson); + (void)tjsonAddItemToObject(json, "maxIds", maxIdsJson); for (int32_t i = 0; i < SDB_MAX; ++i) { if(i == 5) continue; int64_t maxId = 0; @@ -557,7 +557,7 @@ void dumpHeader(SSdb *pSdb, SJson *json) { } SJson *tableVersJson = tjsonCreateObject(); - tjsonAddItemToObject(json, "tableVers", tableVersJson); + (void)tjsonAddItemToObject(json, "tableVers", tableVersJson); for (int32_t i = 0; i < SDB_MAX; ++i) { int64_t tableVer = 0; if (i < SDB_MAX) { @@ -581,8 +581,8 @@ void mndDumpSdb() { msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack tmsgSetDefault(&msgCb); - walInit(); - syncInit(); + (void)walInit(); + (void)syncInit(); SMnodeOpt opt = {.msgCb = msgCb}; SMnode *pMnode = mndOpen(path, &opt); @@ -620,10 +620,10 @@ void mndDumpSdb() { mError("failed to write %s since %s", file, terrstr()); return; } - taosWriteFile(pFile, pCont, contLen); - taosWriteFile(pFile, "\n", 1); + (void)taosWriteFile(pFile, pCont, contLen); + (void)taosWriteFile(pFile, "\n", 1); UNUSED(taosFsyncFile(pFile)); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); tjsonDelete(json); taosMemoryFree(pCont); diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 442da63b31..f89394ee22 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -598,7 +598,7 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { goto RETRIEVE_FUNC_OVER; } - tSerializeSRetrieveFuncRsp(pRsp, contLen, &retrieveRsp); + (void)tSerializeSRetrieveFuncRsp(pRsp, contLen, &retrieveRsp); pReq->info.rsp = pRsp; pReq->info.rspLen = contLen; diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c index af60bc9e4b..c294e0defe 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -89,7 +89,7 @@ void grantRestore(EGrantType grant, uint64_t value) {} int64_t grantRemain(EGrantType grant) { return 0; } int32_t tGetMachineId(char **result) { *result = NULL; - return TSDB_CODE_APP_ERROR; + return 0; } int32_t dmProcessGrantReq(void *pInfo, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; } int32_t dmProcessGrantNotify(void *pInfo, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 6fc9194249..8786c3a934 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -159,7 +159,7 @@ static void *mndBuildDropIdxReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStbOb pHead->vgId = htonl(pVgroup->vgId); void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); - tSerializeSDropIdxReq(pBuf, len - sizeof(SMsgHead), &req); + (void)tSerializeSDropIdxReq(pBuf, len - sizeof(SMsgHead), &req); *contLen = len; return pHead; _err: @@ -333,10 +333,10 @@ void mndReleaseIdx(SMnode *pMnode, SIdxObj *pIdx) { SDbObj *mndAcquireDbByIdx(SMnode *pMnode, const char *idxName) { SName name = {0}; - tNameFromString(&name, idxName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&name, idxName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); char db[TSDB_TABLE_FNAME_LEN] = {0}; - tNameGetFullDbName(&name, db); + (void)tNameGetFullDbName(&name, db); return mndAcquireDb(pMnode, db); } @@ -578,7 +578,7 @@ int32_t mndRetrieveTagIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, i cols = 0; SName idxName = {0}; - tNameFromString(&idxName, pIdx->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&idxName, pIdx->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); char n1[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(n1, (char *)tNameGetTableName(&idxName)); @@ -587,37 +587,37 @@ int32_t mndRetrieveTagIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, i STR_TO_VARSTR(n2, (char *)mndGetDbStr(pIdx->db)); SName stbName = {0}; - tNameFromString(&stbName, pIdx->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&stbName, pIdx->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); char n3[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(n3, (char *)tNameGetTableName(&stbName)); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)n1, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)n1, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)n2, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)n2, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)n3, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)n3, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, NULL, true); + (void)colDataSetVal(pColInfo, numOfRows, NULL, true); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pIdx->createdTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pIdx->createdTime, false); char col[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(col, (char *)pIdx->colName); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)col, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)col, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); char tag[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(tag, (char *)"tag_index"); - colDataSetVal(pColInfo, numOfRows, (const char *)tag, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)tag, false); numOfRows++; sdbRelease(pSdb, pIdx); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 906d6aba28..37a171e9a4 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -48,32 +48,32 @@ static inline int32_t mndAcquireRpc(SMnode *pMnode) { int32_t code = 0; - taosThreadRwlockRdlock(&pMnode->lock); + (void)taosThreadRwlockRdlock(&pMnode->lock); if (pMnode->stopped) { code = TSDB_CODE_APP_IS_STOPPING; } else if (!mndIsLeader(pMnode)) { code = -1; } else { #if 1 - atomic_add_fetch_32(&pMnode->rpcRef, 1); + (void)atomic_add_fetch_32(&pMnode->rpcRef, 1); #else int32_t ref = atomic_add_fetch_32(&pMnode->rpcRef, 1); mTrace("mnode rpc is acquired, ref:%d", ref); #endif } - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); TAOS_RETURN(code); } static inline void mndReleaseRpc(SMnode *pMnode) { - taosThreadRwlockRdlock(&pMnode->lock); + (void)taosThreadRwlockRdlock(&pMnode->lock); #if 1 - atomic_sub_fetch_32(&pMnode->rpcRef, 1); + (void)atomic_sub_fetch_32(&pMnode->rpcRef, 1); #else int32_t ref = atomic_sub_fetch_32(&pMnode->rpcRef, 1); mTrace("mnode rpc is released, ref:%d", ref); #endif - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); } static void *mndBuildTimerMsg(int32_t *pContLen) { @@ -85,7 +85,7 @@ static void *mndBuildTimerMsg(int32_t *pContLen) { void *pReq = rpcMallocCont(contLen); if (pReq == NULL) return NULL; - tSerializeSMTimerMsg(pReq, contLen, &timerReq); + (void)tSerializeSMTimerMsg(pReq, contLen, &timerReq); *pContLen = contLen; return pReq; } @@ -96,7 +96,8 @@ static void mndPullupTrans(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + //TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -106,7 +107,8 @@ static void mndPullupCompacts(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_COMPACT_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + //TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -115,7 +117,8 @@ static void mndPullupTtl(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_TTL_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + //TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } static void mndPullupTrimDb(SMnode *pMnode) { @@ -123,7 +126,8 @@ static void mndPullupTrimDb(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_S3MIGRATE_DB_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } static void mndPullupS3MigrateDb(SMnode *pMnode) { @@ -131,7 +135,8 @@ static void mndPullupS3MigrateDb(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRIM_DB_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } static int32_t mndPullupArbHeartbeat(SMnode *pMnode) { @@ -155,7 +160,7 @@ static void mndCalMqRebalance(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -164,7 +169,8 @@ static void mndStreamCheckpointTimer(SMnode *pMnode) { if (pMsg != NULL) { int32_t size = sizeof(SMStreamDoCheckpointMsg); SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_BEGIN_CHECKPOINT, .pCont = pMsg, .contLen = size}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -173,7 +179,8 @@ static void mndStreamCheckNode(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_NODECHECK_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } } @@ -182,7 +189,8 @@ static void mndStreamConsensusChkpt(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_CONSEN_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -192,7 +200,8 @@ static void mndPullupTelem(SMnode *pMnode) { void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen}; - tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } } @@ -203,7 +212,8 @@ static void mndPullupGrant(SMnode *pMnode) { if (pReq != NULL) { SRpcMsg rpcMsg = { .msgType = TDMT_MND_GRANT_HB_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9527}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -214,7 +224,8 @@ static void mndIncreaseUpTime(SMnode *pMnode) { if (pReq != NULL) { SRpcMsg rpcMsg = { .msgType = TDMT_MND_UPTIME_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9528}; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + // TODO check return value + (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -287,24 +298,24 @@ static void mndCheckDnodeOffline(SMnode *pMnode) { static bool mnodeIsNotLeader(SMnode *pMnode) { terrno = 0; - taosThreadRwlockRdlock(&pMnode->lock); + (void)taosThreadRwlockRdlock(&pMnode->lock); SSyncState state = syncGetState(pMnode->syncMgmt.sync); if (terrno != 0) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); return true; } if (state.state != TAOS_SYNC_STATE_LEADER) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); terrno = TSDB_CODE_SYN_NOT_LEADER; return true; } if (!state.restored || !pMnode->restored) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); terrno = TSDB_CODE_SYN_RESTORING; return true; } - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); return false; } @@ -429,21 +440,21 @@ static void *mndThreadFp(void *param) { static int32_t mndInitTimer(SMnode *pMnode) { int32_t code = 0; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if ((code = taosThreadCreate(&pMnode->thread, &thAttr, mndThreadFp, pMnode)) != 0) { mError("failed to create timer thread since %s", strerror(errno)); TAOS_RETURN(code); } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); tmsgReportStartup("mnode-timer", "initialized"); TAOS_RETURN(code); } static void mndCleanupTimer(SMnode *pMnode) { if (taosCheckPthreadValid(pMnode->thread)) { - taosThreadJoin(pMnode->thread, NULL); + (void)taosThreadJoin(pMnode->thread, NULL); taosThreadClear(&pMnode->thread); } } @@ -467,7 +478,7 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) { static int32_t mndInitWal(SMnode *pMnode) { int32_t code = 0; char path[PATH_MAX + 20] = {0}; - snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); + (void)snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); SWalCfg cfg = {.vgId = 1, .fsyncPeriod = 0, .rollPeriod = -1, @@ -486,7 +497,7 @@ static int32_t mndInitWal(SMnode *pMnode) { TAOS_RETURN(code); } else{ - strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); + (void)strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } } #endif @@ -642,8 +653,8 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->syncMgmt.numOfReplicas = pOption->numOfReplicas; pMnode->syncMgmt.numOfTotalReplicas = pOption->numOfTotalReplicas; pMnode->syncMgmt.lastIndex = pOption->lastIndex; - memcpy(pMnode->syncMgmt.replicas, pOption->replicas, sizeof(pOption->replicas)); - memcpy(pMnode->syncMgmt.nodeRoles, pOption->nodeRoles, sizeof(pOption->nodeRoles)); + (void)memcpy(pMnode->syncMgmt.replicas, pOption->replicas, sizeof(pOption->replicas)); + (void)memcpy(pMnode->syncMgmt.nodeRoles, pOption->nodeRoles, sizeof(pOption->nodeRoles)); } SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { @@ -656,7 +667,14 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { mError("failed to open mnode since %s", terrstr()); return NULL; } - memset(pMnode, 0, sizeof(SMnode)); + (void)memset(pMnode, 0, sizeof(SMnode)); + + int32_t code = taosThreadRwlockInit(&pMnode->lock, NULL); + if (code != 0) { + taosMemoryFree(pMnode); + mError("failed to open mnode lock since %s", tstrerror(code)); + return NULL; + } char timestr[24] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); @@ -671,7 +689,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - int32_t code = mndCreateDir(pMnode, path); + code = mndCreateDir(pMnode, path); if (code != 0) { code = terrno; mError("failed to open mnode since %s", tstrerror(code)); @@ -704,9 +722,10 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { void mndPreClose(SMnode *pMnode) { if (pMnode != NULL) { - syncLeaderTransfer(pMnode->syncMgmt.sync); + // TODO check return value + (void)syncLeaderTransfer(pMnode->syncMgmt.sync); syncPreStop(pMnode->syncMgmt.sync); - sdbWriteFile(pMnode->pSdb, 0); + (void)sdbWriteFile(pMnode->pSdb, 0); } } @@ -785,9 +804,9 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { } SMnode *pMnode = pMsg->info.node; - taosThreadRwlockRdlock(&pMnode->lock); + (void)taosThreadRwlockRdlock(&pMnode->lock); if (pMnode->stopped) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); code = TSDB_CODE_APP_IS_STOPPING; TAOS_RETURN(code); } @@ -795,31 +814,31 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { terrno = 0; SSyncState state = syncGetState(pMnode->syncMgmt.sync); if (terrno != 0) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); code = terrno; TAOS_RETURN(code); } if (state.state != TAOS_SYNC_STATE_LEADER) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); code = TSDB_CODE_SYN_NOT_LEADER; goto _OVER; } if (!state.restored || !pMnode->restored) { - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); code = TSDB_CODE_SYN_RESTORING; goto _OVER; } #if 1 - atomic_add_fetch_32(&pMnode->rpcRef, 1); + (void)atomic_add_fetch_32(&pMnode->rpcRef, 1); #else int32_t ref = atomic_add_fetch_32(&pMnode->rpcRef, 1); mTrace("mnode rpc is acquired, ref:%d", ref); #endif - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); TAOS_RETURN(code); _OVER: @@ -854,7 +873,7 @@ _OVER: int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet); pMsg->info.rsp = rpcMallocCont(contLen); if (pMsg->info.rsp != NULL) { - tSerializeSEpSet(pMsg->info.rsp, contLen, &epSet); + (void)tSerializeSEpSet(pMsg->info.rsp, contLen, &epSet); pMsg->info.hasEpSet = 1; pMsg->info.rspLen = contLen; } @@ -973,7 +992,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } else { tstrncpy(desc.status, "offline", sizeof(desc.status)); } - taosArrayPush(pClusterInfo->dnodes, &desc); + (void)taosArrayPush(pClusterInfo->dnodes, &desc); sdbRelease(pSdb, pObj); } @@ -999,7 +1018,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr tstrncpy(desc.role, syncStr(pObj->syncState), sizeof(desc.role)); desc.syncState = pObj->syncState; } - taosArrayPush(pClusterInfo->mnodes, &desc); + (void)taosArrayPush(pClusterInfo->mnodes, &desc); sdbRelease(pSdb, pObj); } @@ -1017,8 +1036,8 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr desc.vgroup_id = pVgroup->vgId; SName name = {0}; - tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - tNameGetDbName(&name, desc.database_name); + (void)tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameGetDbName(&name, desc.database_name); desc.tables_num = pVgroup->numOfTables; pGrantInfo->timeseries_used += pVgroup->numOfTimeSeries; @@ -1039,7 +1058,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr pClusterInfo->vnodes_total++; } - taosArrayPush(pVgroupInfo->vgroups, &desc); + (void)taosArrayPush(pVgroupInfo->vgroups, &desc); sdbRelease(pSdb, pVgroup); } @@ -1053,14 +1072,14 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonStbDesc desc = {0}; SName name1 = {0}; - tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - tNameGetDbName(&name1, desc.database_name); + (void)tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameGetDbName(&name1, desc.database_name); SName name2 = {0}; - tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); tstrncpy(desc.stb_name, tNameGetTableName(&name2), TSDB_TABLE_NAME_LEN); - taosArrayPush(pStbInfo->stbs, &desc); + (void)taosArrayPush(pStbInfo->stbs, &desc); sdbRelease(pSdb, pStb); } @@ -1094,14 +1113,14 @@ int64_t mndGetRoleTimeMs(SMnode *pMnode) { void mndSetRestored(SMnode *pMnode, bool restored) { if (restored) { - taosThreadRwlockWrlock(&pMnode->lock); + (void)taosThreadRwlockWrlock(&pMnode->lock); pMnode->restored = true; - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); mInfo("mnode set restored:%d", restored); } else { - taosThreadRwlockWrlock(&pMnode->lock); + (void)taosThreadRwlockWrlock(&pMnode->lock); pMnode->restored = false; - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); mInfo("mnode set restored:%d", restored); while (1) { if (pMnode->rpcRef <= 0) break; @@ -1113,9 +1132,9 @@ void mndSetRestored(SMnode *pMnode, bool restored) { bool mndGetRestored(SMnode *pMnode) { return pMnode->restored; } void mndSetStop(SMnode *pMnode) { - taosThreadRwlockWrlock(&pMnode->lock); + (void)taosThreadRwlockWrlock(&pMnode->lock); pMnode->stopped = true; - taosThreadRwlockUnlock(&pMnode->lock); + (void)taosThreadRwlockUnlock(&pMnode->lock); mInfo("mnode set stopped"); } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 014d6468ff..67fdcc2466 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -270,7 +270,7 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { } } if (pObj->pDnode != NULL) { - addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port); + (void)addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port); } sdbRelease(pSdb, pObj); } @@ -341,7 +341,7 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq); void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + (void)tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); STransAction action = { .epSet = *pCreateEpSet, @@ -363,7 +363,7 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq); void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); + (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); STransAction action = { .epSet = *pAlterMnodeTypeEpSet, @@ -385,7 +385,7 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq); void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); + (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); STransAction action = { .epSet = *pAlterEpSet, @@ -407,7 +407,7 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop int32_t code = 0; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq); void *pReq = taosMemoryMalloc(contLen); - tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); + (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); STransAction action = { .epSet = *pDroprEpSet, @@ -881,13 +881,13 @@ static int32_t mndRetrieveMnodes(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 b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, TSDB_EP_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, b1, false); + (void)colDataSetVal(pColInfo, numOfRows, b1, false); char role[20] = "offline"; if (pObj->id == pMnode->selfDnodeId) { @@ -904,7 +904,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b2[12 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b2, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)b2, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)b2, false); const char *status = "ready"; if (objStatus == SDB_STATUS_CREATING) status = "creating"; @@ -913,14 +913,14 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b3[9 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b3, status, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); int64_t roleTimeMs = (isDnodeOnline) ? pObj->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); numOfRows++; sdbRelease(pSdb, pObj); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index f7b509b1cc..875ad562d2 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -263,7 +263,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { if (connReq.db[0]) { char db[TSDB_DB_FNAME_LEN] = {0}; - snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db); + (void)snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db); pDb = mndAcquireDb(pMnode, db); if (pDb == NULL) { if (0 != strcmp(connReq.db, TSDB_INFORMATION_SCHEMA_DB) && @@ -307,9 +307,9 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { tstrncpy(connectRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN); connectRsp.whiteListVer = pUser->ipWhiteListVer; - strcpy(connectRsp.sVer, version); - snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, - gitinfo); + (void)strcpy(connectRsp.sVer, version); + (void)snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", version, + buildinfo, gitinfo); mndGetMnodeEpSet(pMnode, &connectRsp.epSet); int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp); @@ -335,7 +335,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { code = 0; char detail[1000] = {0}; - sprintf(detail, "app:%s", connReq.app); + (void)sprintf(detail, "app:%s", connReq.app); auditRecord(pReq, pMnode->clusterId, "login", "", "", detail, strlen(detail)); @@ -371,9 +371,9 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq) app.appId = pReq->appId; app.ip = clientIp; app.pid = pReq->pid; - strcpy(app.name, pReq->name); + (void)strcpy(app.name, pReq->name); app.startTime = pReq->startTime; - memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary)); + (void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary)); app.lastAccessTimeMs = taosGetTimestampMs(); const int32_t keepTime = tsShellActivityTimer * 3; @@ -456,7 +456,7 @@ static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnIn } } - memcpy(&pApp->summary, &pReq->summary, sizeof(pReq->summary)); + (void)memcpy(&pApp->summary, &pReq->summary, sizeof(pReq->summary)); mndReleaseApp(pMnode, pApp); @@ -492,7 +492,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb SRpcConnInfo connInfo = pMsg->info.conn; if (0 != pHbReq->app.appId) { - mndUpdateAppInfo(pMnode, pHbReq, &connInfo); + TAOS_CHECK_RETURN(mndUpdateAppInfo(pMnode, pHbReq, &connInfo)); } if (pHbReq->query) { @@ -520,7 +520,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb TAOS_RETURN(code); } - mndSaveQueryList(pConn, pBasic); + TAOS_CHECK_RETURN(mndSaveQueryList(pConn, pBasic)); if (pConn->killed != 0) { rspBasic->killConnection = 1; } @@ -546,7 +546,8 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb int32_t kvNum = taosHashGetSize(pHbReq->info); if (NULL == pHbReq->info || kvNum <= 0) { - taosArrayPush(pBatchRsp->rsps, &hbRsp); + // TODO return value + (void)taosArrayPush(pBatchRsp->rsps, &hbRsp); return TSDB_CODE_SUCCESS; } @@ -574,7 +575,10 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb if (needCheck) { SKv kv1 = {.key = HEARTBEAT_KEY_DYN_VIEW, .valueLen = sizeof(*pDynViewVer), .value = pRspVer}; - taosArrayPush(hbRsp.info, &kv1); + if (taosArrayPush(hbRsp.info, &kv1) == NULL) { + if (terrno != 0) code = terrno; + TAOS_RETURN(code); + }; mTrace("need to check view ver, lastest bootTs:%" PRId64 ", ver:%" PRIu64, pRspVer->svrBootTs, pRspVer->dynViewVer); } @@ -589,31 +593,31 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb case HEARTBEAT_KEY_USER_AUTHINFO: { void *rspMsg = NULL; int32_t rspLen = 0; - mndValidateUserAuthInfo(pMnode, kv->value, kv->valueLen / sizeof(SUserAuthVersion), &rspMsg, &rspLen, - pObj->ipWhiteListVer); + (void)mndValidateUserAuthInfo(pMnode, kv->value, kv->valueLen / sizeof(SUserAuthVersion), &rspMsg, &rspLen, + pObj->ipWhiteListVer); if (rspMsg && rspLen > 0) { SKv kv1 = {.key = HEARTBEAT_KEY_USER_AUTHINFO, .valueLen = rspLen, .value = rspMsg}; - taosArrayPush(hbRsp.info, &kv1); + (void)taosArrayPush(hbRsp.info, &kv1); } break; } case HEARTBEAT_KEY_DBINFO: { void *rspMsg = NULL; int32_t rspLen = 0; - mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbCacheInfo), &rspMsg, &rspLen); + (void)mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbCacheInfo), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { SKv kv1 = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg}; - taosArrayPush(hbRsp.info, &kv1); + (void)taosArrayPush(hbRsp.info, &kv1); } break; } case HEARTBEAT_KEY_STBINFO: { void *rspMsg = NULL; int32_t rspLen = 0; - mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableVersion), &rspMsg, &rspLen); + (void)mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableVersion), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { SKv kv1 = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg}; - taosArrayPush(hbRsp.info, &kv1); + (void)taosArrayPush(hbRsp.info, &kv1); } break; } @@ -628,10 +632,10 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb void *rspMsg = NULL; int32_t rspLen = 0; - mndValidateViewInfo(pMnode, kv->value, kv->valueLen / sizeof(SViewVersion), &rspMsg, &rspLen); + (void)mndValidateViewInfo(pMnode, kv->value, kv->valueLen / sizeof(SViewVersion), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { SKv kv1 = {.key = HEARTBEAT_KEY_VIEWINFO, .valueLen = rspLen, .value = rspMsg}; - taosArrayPush(hbRsp.info, &kv1); + (void)taosArrayPush(hbRsp.info, &kv1); } break; } @@ -639,10 +643,10 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb case HEARTBEAT_KEY_TSMA: { void *rspMsg = NULL; int32_t rspLen = 0; - mndValidateTSMAInfo(pMnode, kv->value, kv->valueLen / sizeof(STSMAVersion), &rspMsg, &rspLen); + (void)mndValidateTSMAInfo(pMnode, kv->value, kv->valueLen / sizeof(STSMAVersion), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { SKv kv = {.key = HEARTBEAT_KEY_TSMA, .valueLen = rspLen, .value = rspMsg}; - taosArrayPush(hbRsp.info, &kv); + (void)taosArrayPush(hbRsp.info, &kv); } break; } @@ -655,9 +659,10 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb pIter = taosHashIterate(pHbReq->info, pIter); } - taosArrayPush(pBatchRsp->rsps, &hbRsp); - - return TSDB_CODE_SUCCESS; + if (taosArrayPush(pBatchRsp->rsps, &hbRsp) == NULL) { + if (terrno != 0) code = terrno; + } + TAOS_RETURN(code); } static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { @@ -675,9 +680,9 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { SConnPreparedObj obj = {0}; obj.totalDnodes = mndGetDnodeSize(pMnode); obj.ipWhiteListVer = batchReq.ipWhiteList; - mndGetOnlineDnodeNum(pMnode, &obj.onlineDnodes); + TAOS_CHECK_RETURN(mndGetOnlineDnodeNum(pMnode, &obj.onlineDnodes)); mndGetMnodeEpSet(pMnode, &obj.epSet); - mndCreateQnodeList(pMnode, &obj.pQnodeList, -1); + TAOS_CHECK_RETURN(mndCreateQnodeList(pMnode, &obj.pQnodeList, -1)); SClientHbBatchRsp batchRsp = {0}; batchRsp.svrTimestamp = taosGetTimestampSec(); @@ -701,7 +706,7 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) { } else if (pHbReq->connKey.connType == CONN_TYPE__TMQ) { SClientHbRsp *pRsp = mndMqHbBuildRsp(pMnode, pHbReq); if (pRsp != NULL) { - taosArrayPush(batchRsp.rsps, pRsp); + (void)taosArrayPush(batchRsp.rsps, pRsp); taosMemoryFree(pRsp); } } @@ -845,32 +850,32 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->id, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->id, false); char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(user, pConn->user); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)user, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)user, false); char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE]; STR_TO_VARSTR(app, pConn->app); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)app, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)app, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->pid, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->pid, false); char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port); + (void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port); varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->loginTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->loginTimeMs, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->lastAccessTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->lastAccessTimeMs, false); numOfRows++; } @@ -903,50 +908,50 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc cols = 0; char queryId[26 + VARSTR_HEADER_SIZE] = {0}; - sprintf(&queryId[VARSTR_HEADER_SIZE], "%x:%" PRIx64, pConn->id, pQuery->reqRid); + (void)sprintf(&queryId[VARSTR_HEADER_SIZE], "%x:%" PRIx64, pConn->id, pQuery->reqRid); varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->queryId, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->queryId, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->id, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->id, false); char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE]; STR_TO_VARSTR(app, pConn->app); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)app, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)app, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->pid, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->pid, false); char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(user, pConn->user); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)user, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)user, false); char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port); + (void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port); varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stime, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stime, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->useconds, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->useconds, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stableQuery, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stableQuery, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->isSubQuery, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->isSubQuery, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->subPlanNum, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->subPlanNum, false); char subStatus[TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE] = {0}; int64_t reserve = 64; @@ -965,12 +970,12 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc } varDataLen(subStatus) = strlen(&subStatus[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, subStatus, (varDataLen(subStatus) == 0) ? true : false); + (void)colDataSetVal(pColInfo, curRowIndex, subStatus, (varDataLen(subStatus) == 0) ? true : false); char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(sql, pQuery->sql); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, curRowIndex, (const char *)sql, false); + (void)colDataSetVal(pColInfo, curRowIndex, (const char *)sql, false); pBlock->info.rows++; } @@ -1037,55 +1042,55 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->appId, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->appId, false); char ip[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - sprintf(&ip[VARSTR_HEADER_SIZE], "%s", taosIpStr(pApp->ip)); + (void)sprintf(&ip[VARSTR_HEADER_SIZE], "%s", taosIpStr(pApp->ip)); varDataLen(ip) = strlen(&ip[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)ip, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)ip, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->pid, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->pid, false); char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name); + (void)sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name); varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)name, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)name, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->startTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->startTime, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertsReq, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertsReq, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertRows, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertRows, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertElapsedTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertElapsedTime, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertBytes, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertBytes, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.fetchBytes, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.fetchBytes, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.queryElapsedTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.queryElapsedTime, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfSlowQueries, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfSlowQueries, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.totalRequests, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.totalRequests, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.currentRequests, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.currentRequests, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->lastAccessTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->lastAccessTimeMs, false); numOfRows++; } 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 687f21845e..6989e1e4f1 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] && @@ -303,10 +303,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); diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index e63ff8b931..303e86bb82 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -1760,14 +1760,14 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) { SDbObj newDb = {0}; memcpy(&newDb, pCxt->pDb, sizeof(SDbObj)); newDb.tsmaVersion++; - TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); - TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); TAOS_CHECK_GOTO(mndSetCreateSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); TAOS_CHECK_GOTO(mndSetCreateSmaUndoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); TAOS_CHECK_GOTO(mndSetCreateSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &createStreamRedoAction), NULL, _OVER); TAOS_CHECK_GOTO(mndTransAppendUndoAction(pTrans, &createStreamUndoAction), NULL, _OVER); TAOS_CHECK_GOTO(mndTransAppendUndoAction(pTrans, &dropStbUndoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); TAOS_CHECK_GOTO(mndTransPrepare(pCxt->pMnode, pTrans), NULL, _OVER); code = TSDB_CODE_SUCCESS; @@ -2030,12 +2030,12 @@ static int32_t mndDropTSMA(SCreateTSMACxt* pCxt) { SDbObj newDb = {0}; memcpy(&newDb, pCxt->pDb, sizeof(SDbObj)); newDb.tsmaVersion++; - TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); - TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); TAOS_CHECK_GOTO(mndSetDropSmaRedoLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); TAOS_CHECK_GOTO(mndSetDropSmaCommitLogs(pCxt->pMnode, pTrans, pCxt->pSma), NULL, _OVER); TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &dropStreamRedoAction), NULL, _OVER); TAOS_CHECK_GOTO(mndTransAppendRedoAction(pTrans, &dropStbRedoAction), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionPrepareLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); + TAOS_CHECK_GOTO(mndSetUpdateDbTsmaVersionCommitLogs(pCxt->pMnode, pTrans, pCxt->pDb, &newDb), NULL, _OVER); TAOS_CHECK_GOTO(mndTransPrepare(pCxt->pMnode, pTrans), NULL, _OVER); code = TSDB_CODE_SUCCESS; _OVER: @@ -2450,13 +2450,14 @@ static int32_t mndGetTSMA(SMnode *pMnode, char *tsmaFName, STableTSMAInfoRsp *rs typedef bool (*tsmaFilter)(const SSmaObj* pSma, void* param); static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilter filtered, void* param, bool* exist) { - int32_t code = -1; + int32_t code = 0; SSmaObj * pSma = NULL; SSmaObj * pBaseTsma = NULL; SSdb * pSdb = pMnode->pSdb; void * pIter = NULL; SStreamObj * pStream = NULL; SStbObj * pStb = NULL; + bool shouldRetry = false; while (1) { pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma); @@ -2470,6 +2471,7 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt pStb = mndAcquireStb(pMnode, pSma->dstTbName); if (!pStb) { sdbRelease(pSdb, pSma); + shouldRetry = true; continue; } @@ -2478,16 +2480,24 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt code = tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); if (TSDB_CODE_SUCCESS != code) { sdbRelease(pSdb, pSma); + mndReleaseStb(pMnode, pStb); TAOS_RETURN(code); } sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname); pStream = NULL; code = mndAcquireStream(pMnode, streamName, &pStream); - if (!pStream || (code != 0)) { + if (!pStream) { + shouldRetry = true; sdbRelease(pSdb, pSma); + mndReleaseStb(pMnode, pStb); continue; } + if (code != 0) { + sdbRelease(pSdb, pSma); + mndReleaseStb(pMnode, pStb); + TAOS_RETURN(code); + } int64_t streamId = pStream->uid; mndReleaseStream(pMnode, pStream); @@ -2522,6 +2532,9 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt } *exist = true; } + if (shouldRetry) { + return TSDB_CODE_NEED_RETRY; + } return TSDB_CODE_SUCCESS; } @@ -2562,6 +2575,9 @@ static int32_t mndProcessGetTbTSMAReq(SRpcMsg *pReq) { code = mndGetTSMA(pMnode, tsmaReq.name, &rsp, &exist); } else { code = mndGetTableTSMA(pMnode, tsmaReq.name, &rsp, &exist); + if (TSDB_CODE_NEED_RETRY == code) { + code = TSDB_CODE_SUCCESS; + } } if (code) { goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index cca1e71f6a..cd5584022f 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -223,7 +223,7 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S code = TSDB_CODE_OUT_OF_MEMORY; TAOS_RETURN(code); } - tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); + (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); @@ -251,7 +251,7 @@ static int32_t mndSetCreateSnodeUndoActions(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); @@ -383,7 +383,7 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn 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); @@ -482,16 +482,16 @@ static int32_t mndRetrieveSnodes(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/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 55ccccf3b2..42a90cbdaf 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -278,7 +278,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < pStb->numOfFuncs; ++i) { char funcName[TSDB_FUNC_NAME_LEN] = {0}; SDB_GET_BINARY(pRaw, dataPos, funcName, TSDB_FUNC_NAME_LEN, _OVER) - taosArrayPush(pStb->pFuncs, funcName); + (void)taosArrayPush(pStb->pFuncs, funcName); } if (pStb->commentLen > 0) { @@ -479,10 +479,10 @@ void mndReleaseStb(SMnode *pMnode, SStbObj *pStb) { SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) { SName name = {0}; - tNameFromString(&name, stbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + if ((terrno = tNameFromString(&name, stbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) return NULL; char db[TSDB_TABLE_FNAME_LEN] = {0}; - tNameGetFullDbName(&name, db); + (void)tNameGetFullDbName(&name, db); return mndAcquireDb(pMnode, db); } @@ -503,9 +503,11 @@ void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int3 SName name = {0}; SVCreateStbReq req = {0}; - tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + if ((terrno = tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) { + goto _err; + } char dbFName[TSDB_DB_FNAME_LEN] = {0}; - tNameGetFullDbName(&name, dbFName); + (void)tNameGetFullDbName(&name, dbFName); req.name = (char *)tNameGetTableName(&name); req.suid = pStb->uid; @@ -600,7 +602,9 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, SMsgHead *pHead = NULL; SEncoder encoder = {0}; - tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + if ((terrno = tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) { + return NULL; + } req.name = (char *)tNameGetTableName(&name); req.suid = pStb->uid; @@ -621,7 +625,7 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead)); - tEncodeSVDropStbReq(&encoder, &req); + (void)tEncodeSVDropStbReq(&encoder, &req); tEncoderClear(&encoder); *pContLen = contLen; @@ -948,7 +952,9 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat } static int32_t mndGenIdxNameForFirstTag(char *fullname, char *dbname, char *stbname, char *tagname) { SName name = {0}; - tNameFromString(&name, stbname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + if ((terrno = tNameFromString(&name, stbname, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)) != 0) { + return -1; + } return snprintf(fullname, TSDB_INDEX_FNAME_LEN, "%s.%s_%s", dbname, tagname, tNameGetTableName(&name)); } @@ -969,7 +975,9 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea TAOS_CHECK_GOTO(mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb), NULL, _OVER); SSchema *pSchema = &(stbObj.pTags[0]); - mndGenIdxNameForFirstTag(fullIdxName, pDb->name, stbObj.name, pSchema->name); + if (mndGenIdxNameForFirstTag(fullIdxName, pDb->name, stbObj.name, pSchema->name) < 0) { + goto _OVER; + } SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) { code = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; @@ -995,7 +1003,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea _OVER: mndTransDrop(pTrans); - mndStbActionDelete(pMnode->pSdb, &stbObj); + (void)mndStbActionDelete(pMnode->pSdb, &stbObj); TAOS_RETURN(code); } @@ -1031,7 +1039,7 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) { } pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), reqLen, &ttlReq); + (void)tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), reqLen, &ttlReq); SRpcMsg rpcMsg = { .msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS, .pCont = pHead, .contLen = contLen, .info = pReq->info}; @@ -1069,7 +1077,7 @@ static int32_t mndProcessTrimDbTimer(SRpcMsg *pReq) { } pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &trimReq); + (void)tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &trimReq); SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen}; SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); @@ -1106,7 +1114,7 @@ static int32_t mndProcessS3MigrateDbTimer(SRpcMsg *pReq) { } pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSVS3MigrateDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &s3migrateReq); + (void)tSerializeSVS3MigrateDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &s3migrateReq); SRpcMsg rpcMsg = {.msgType = TDMT_VND_S3MIGRATE, .pCont = pHead, .contLen = contLen}; SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); @@ -1335,7 +1343,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; SName name = {0}; - tNameFromString(&name, createReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + TAOS_CHECK_RETURN(tNameFromString(&name, createReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)); if (createReq.sql == NULL && createReq.sqlLen == 0) { char detail[1000] = {0}; @@ -1499,7 +1507,12 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName, } SNodeList *pNodeList = NULL; - nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); + if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) != + 0) { + sdbRelease(pSdb, pTopic); + sdbCancelFetch(pSdb, pIter); + TAOS_RETURN(code); + } SNode *pNode = NULL; FOREACH(pNode, pNodeList) { SColumnNode *pCol = (SColumnNode *)pNode; @@ -1549,7 +1562,13 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName } SNodeList *pNodeList = NULL; - nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); + if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) != + 0) { + sdbRelease(pSdb, pStream); + sdbCancelFetch(pSdb, pIter); + TAOS_RETURN(code); + } + SNode *pNode = NULL; FOREACH(pNode, pNodeList) { SColumnNode *pCol = (SColumnNode *)pNode; @@ -1600,7 +1619,11 @@ static int32_t mndCheckAlterColForTSma(SMnode *pMnode, const char *stbFullName, } SNodeList *pNodeList = NULL; - nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); + if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) != + 0) { + sdbCancelFetch(pSdb, pIter); + TAOS_RETURN(code); + } SNode *pNode = NULL; FOREACH(pNode, pNodeList) { SColumnNode *pCol = (SColumnNode *)pNode; @@ -2291,7 +2314,7 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, i uint32_t contLen = 0; SMAlterStbRsp alterRsp = {0}; SName name = {0}; - tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + TAOS_CHECK_RETURN(tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)); alterRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); if (NULL == alterRsp.pMeta) { @@ -2313,7 +2336,7 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, i void *cont = taosMemoryMalloc(contLen); tEncoderInit(&ec, cont, contLen); - tEncodeSMAlterStbRsp(&ec, &alterRsp); + (void)tEncodeSMAlterStbRsp(&ec, &alterRsp); tEncoderClear(&ec); tFreeSMAlterStbRsp(&alterRsp); @@ -2344,7 +2367,7 @@ int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, vo uint32_t contLen = 0; SMCreateStbRsp stbRsp = {0}; SName name = {0}; - tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + TAOS_CHECK_GOTO(tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE), NULL, _OVER); stbRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); if (NULL == stbRsp.pMeta) { @@ -2366,7 +2389,7 @@ int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, vo void *cont = taosMemoryMalloc(contLen); tEncoderInit(&ec, cont, contLen); - tEncodeSMCreateStbRsp(&ec, &stbRsp); + (void)tEncodeSMCreateStbRsp(&ec, &stbRsp); tEncoderClear(&ec); tFreeSMCreateStbRsp(&stbRsp); @@ -2605,7 +2628,8 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; SName name = {0}; - tNameFromString(&name, alterReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + // TODO check return value + (void)tNameFromString(&name, alterReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); auditRecord(pReq, pMnode->clusterId, "alterStb", name.dbname, name.tname, alterReq.sql, alterReq.sqlLen); @@ -2755,7 +2779,12 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName, } SNodeList *pNodeList = NULL; - nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); + if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) != + 0) { + sdbRelease(pSdb, pTopic); + sdbCancelFetch(pSdb, pIter); + TAOS_RETURN(code); + } SNode *pNode = NULL; FOREACH(pNode, pNodeList) { SColumnNode *pCol = (SColumnNode *)pNode; @@ -2803,7 +2832,12 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName, } SNodeList *pNodeList = NULL; - nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); + if ((code = nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList)) != + 0) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pStream); + TAOS_RETURN(code); + } SNode *pNode = NULL; FOREACH(pNode, pNodeList) { SColumnNode *pCol = (SColumnNode *)pNode; @@ -2882,7 +2916,8 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; SName name = {0}; - tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + // TODO check return value + (void)tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); auditRecord(pReq, pMnode->clusterId, "dropStb", name.dbname, name.tname, dropReq.sql, dropReq.sqlLen); @@ -2933,7 +2968,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { goto _OVER; } - tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp); + (void)tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp); pReq->info.rsp = pRsp; pReq->info.rspLen = rspLen; code = 0; @@ -2984,7 +3019,7 @@ static int32_t mndProcessTableCfgReq(SRpcMsg *pReq) { goto _OVER; } - tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp); + (void)tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp); pReq->info.rsp = pRsp; pReq->info.rspLen = rspLen; code = 0; @@ -3034,7 +3069,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName)); tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName)); tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName)); - taosArrayPush(hbRsp.pMetaRsp, &metaRsp); + (void)taosArrayPush(hbRsp.pMetaRsp, &metaRsp); continue; } @@ -3047,11 +3082,11 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName)); tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName)); tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName)); - taosArrayPush(hbRsp.pMetaRsp, &metaRsp); + (void)taosArrayPush(hbRsp.pMetaRsp, &metaRsp); continue; } - taosArrayPush(hbRsp.pMetaRsp, &metaRsp); + (void)taosArrayPush(hbRsp.pMetaRsp, &metaRsp); } if (sma) { @@ -3075,7 +3110,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t strcpy(indexRsp.dbFName, pStbVersion->dbFName); strcpy(indexRsp.tbName, pStbVersion->stbName); - taosArrayPush(hbRsp.pIndexRsp, &indexRsp); + (void)taosArrayPush(hbRsp.pIndexRsp, &indexRsp); } } @@ -3093,7 +3128,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t TAOS_RETURN(code); } - tSerializeSSTbHbRsp(pRsp, rspLen, &hbRsp); + (void)tSerializeSSTbHbRsp(pRsp, rspLen, &hbRsp); tFreeSSTbHbRsp(&hbRsp); *ppRsp = pRsp; *pRspLen = rspLen; @@ -3130,23 +3165,23 @@ int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) { void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst) { SName name = {0}; - tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - tNameGetFullDbName(&name, dst); + (void)tNameGetFullDbName(&name, dst); } void mndExtractShortDbNameFromStbFullName(const char *stbFullName, char *dst) { SName name = {0}; - tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - tNameGetDbName(&name, dst); + (void)tNameGetDbName(&name, dst); } void mndExtractShortDbNameFromDbFullName(const char *stbFullName, char *dst) { SName name = {0}; - tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB); + (void)tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB); - tNameGetDbName(&name, dst); + (void)tNameGetDbName(&name, dst); } void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize) { @@ -3473,37 +3508,37 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); - tNameGetDbName(&name, varDataVal(db)); + (void)tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); + (void)tNameGetDbName(&name, varDataVal(db)); varDataSetLen(db, strlen(varDataVal(db))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)db, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->createdTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->createdTime, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfColumns, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfColumns, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfTags, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->numOfTags, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); if (pStb->commentLen > 0) { char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(comment, pStb->comment); - colDataSetVal(pColInfo, numOfRows, comment, false); + (void)colDataSetVal(pColInfo, numOfRows, comment, false); } else if (pStb->commentLen == 0) { char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(comment, ""); - colDataSetVal(pColInfo, numOfRows, comment, false); + (void)colDataSetVal(pColInfo, numOfRows, comment, false); } else { colDataSetNULL(pColInfo, numOfRows); } @@ -3513,14 +3548,14 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc varDataSetLen(watermark, strlen(varDataVal(watermark))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)watermark, false); char maxDelay[64 + VARSTR_HEADER_SIZE] = {0}; sprintf(varDataVal(maxDelay), "%" PRId64 "a,%" PRId64 "a", pStb->maxdelay[0], pStb->maxdelay[1]); varDataSetLen(maxDelay, strlen(varDataVal(maxDelay))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)maxDelay, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)maxDelay, false); char rollup[160 + VARSTR_HEADER_SIZE] = {0}; int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs); @@ -3530,16 +3565,16 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc for (int32_t i = 0; i < rollupNum; ++i) { char *funcName = taosArrayGet(pStb->pFuncs, i); if (i) { - strncat(varDataVal(rollup), sep, rollupLen); + (void)strncat(varDataVal(rollup), sep, rollupLen); rollupLen -= sepLen; } - strncat(varDataVal(rollup), funcName, rollupLen); + (void)strncat(varDataVal(rollup), funcName, rollupLen); rollupLen -= strlen(funcName); } varDataSetLen(rollup, strlen(varDataVal(rollup))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false); numOfRows++; sdbRelease(pSdb, pStb); @@ -3577,20 +3612,20 @@ static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *p for (int32_t j = 0; j < pm->colNum; j++) { // table name SColumnInfoData *pColInfoData = taosArrayGet(p->pDataBlock, 0); - colDataSetVal(pColInfoData, numOfRows, tName, false); + (void)colDataSetVal(pColInfoData, numOfRows, tName, false); // database name pColInfoData = taosArrayGet(p->pDataBlock, 1); - colDataSetVal(pColInfoData, numOfRows, dName, false); + (void)colDataSetVal(pColInfoData, numOfRows, dName, false); pColInfoData = taosArrayGet(p->pDataBlock, 2); - colDataSetVal(pColInfoData, numOfRows, typeName, false); + (void)colDataSetVal(pColInfoData, numOfRows, typeName, false); // col name char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(colName, pm->schema[j].name); pColInfoData = taosArrayGet(p->pDataBlock, 3); - colDataSetVal(pColInfoData, numOfRows, colName, false); + (void)colDataSetVal(pColInfoData, numOfRows, colName, false); // col type int8_t colType = pm->schema[j].type; @@ -3605,10 +3640,10 @@ static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *p (int32_t)((pm->schema[j].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } varDataSetLen(colTypeStr, colTypeLen); - colDataSetVal(pColInfoData, numOfRows, (char *)colTypeStr, false); + (void)colDataSetVal(pColInfoData, numOfRows, (char *)colTypeStr, false); pColInfoData = taosArrayGet(p->pDataBlock, 5); - colDataSetVal(pColInfoData, numOfRows, (const char *)&pm->schema[j].bytes, false); + (void)colDataSetVal(pColInfoData, numOfRows, (const char *)&pm->schema[j].bytes, false); for (int32_t k = 6; k <= 8; ++k) { pColInfoData = taosArrayGet(p->pDataBlock, k); colDataSetNULL(pColInfoData, numOfRows); @@ -3724,26 +3759,26 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db); char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); - tNameGetDbName(&name, varDataVal(db)); + (void)tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); + (void)tNameGetDbName(&name, varDataVal(db)); varDataSetLen(db, strlen(varDataVal(db))); for (int i = 0; i < pStb->numOfColumns; i++) { int32_t cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)db, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, typeName, false); + (void)colDataSetVal(pColInfo, numOfRows, typeName, false); // col name char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(colName, pStb->pColumns[i].name); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, colName, false); + (void)colDataSetVal(pColInfo, numOfRows, colName, false); // col type int8_t colType = pStb->pColumns[i].type; @@ -3758,10 +3793,10 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); } varDataSetLen(colTypeStr, colTypeLen); - colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false); + (void)colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->pColumns[i].bytes, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->pColumns[i].bytes, false); while (cols < pShow->numOfColumns) { pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataSetNULL(pColInfo, numOfRows); @@ -4064,7 +4099,7 @@ static void *mndBuildVDropTbsReq(SMnode *pMnode, const SVgroupInfo *pVgInfo, con void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead)); - tEncodeSVDropTbBatchReq(&encoder, pReq); + (void)tEncodeSVDropTbBatchReq(&encoder, pReq); tEncoderClear(&encoder); *len = contLen; @@ -4155,10 +4190,19 @@ static int32_t mndDropTbAdd(SMnode *pMnode, SHashObj *pVgHashMap, const SVgroupI if (pReqs == NULL) { reqs.info = *pVgInfo; reqs.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq)); - taosArrayPush(reqs.req.pArray, &req); - taosHashPut(pVgHashMap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &reqs, sizeof(reqs)); + if (reqs.req.pArray == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + if (taosArrayPush(reqs.req.pArray, &req) == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + if (taosHashPut(pVgHashMap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &reqs, sizeof(reqs)) != 0) { + return TSDB_CODE_OUT_OF_MEMORY; + } } else { - taosArrayPush(pReqs->req.pArray, &req); + if (taosArrayPush(pReqs->req.pArray, &req) == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } } return 0; } @@ -4231,7 +4275,10 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith code = TSDB_CODE_OUT_OF_MEMORY; goto _end; } - taosHashPut(pCtx->pTsmaMap, &pTb->suid, sizeof(pTb->suid), &infos, sizeof(infos)); + if (taosHashPut(pCtx->pTsmaMap, &pTb->suid, sizeof(pTb->suid), &infos, sizeof(infos)) != 0) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; + } } } @@ -4258,11 +4305,15 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith sdbRelease(pMnode->pSdb, pSma); goto _end; } - taosHashPut(pCtx->pDbMap, pSma->db, TSDB_DB_FNAME_LEN, &info.dbInfo, sizeof(SMDropTbDbInfo)); + if (taosHashPut(pCtx->pDbMap, pSma->db, TSDB_DB_FNAME_LEN, &info.dbInfo, sizeof(SMDropTbDbInfo)) != 0) { + sdbCancelFetch(pMnode->pSdb, pIter); + sdbRelease(pMnode->pSdb, pSma); + goto _end; + } } else { info.dbInfo = *pDbInfo; } - taosArrayPush(pInfos->pTsmaInfos, &info); + (void)taosArrayPush(pInfos->pTsmaInfos, &info); } sdbRelease(pMnode->pSdb, pSma); } @@ -4270,7 +4321,7 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith // generate vg req map for (int32_t i = 0; i < pTbs->size; ++i) { SVDropTbReq *pTb = taosArrayGet(pTbs, i); - mndDropTbAdd(pMnode, pCtx->pVgMap, &vgInfo, pTb->name, pTb->suid, pTb->igNotExists); + TAOS_CHECK_GOTO(mndDropTbAdd(pMnode, pCtx->pVgMap, &vgInfo, pTb->name, pTb->suid, pTb->igNotExists), NULL, _end); SMDropTbTsmaInfos *pInfos = taosHashGet(pCtx->pTsmaMap, &pTb->suid, sizeof(pTb->suid)); SArray *pVgInfos = NULL; @@ -4282,8 +4333,8 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith taosGetTbHashVal(buf, len, pInfo->dbInfo.hashMethod, pInfo->dbInfo.hashPrefix, pInfo->dbInfo.hashSuffix); const SVgroupInfo *pVgInfo = taosArraySearch(pInfo->dbInfo.dbVgInfos, &hashVal, vgHashValCmp, TD_EQ); void *p = taosStrdup(buf + strlen(pInfo->tsmaResTbDbFName) + TSDB_NAME_DELIMITER_LEN); - taosArrayPush(pCtx->pResTbNames, &p); - mndDropTbAdd(pMnode, pCtx->pVgMap, pVgInfo, p, pInfo->suid, true); + (void)taosArrayPush(pCtx->pResTbNames, &p); + TAOS_CHECK_GOTO(mndDropTbAdd(pMnode, pCtx->pVgMap, pVgInfo, p, pInfo->suid, true), NULL, _end); } } _end: diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 4dcd716f28..0b7562b923 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -61,9 +61,7 @@ static int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq); static int32_t mndProcessCheckpointReport(SRpcMsg *pReq); static int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg); static void doSendQuickRsp(SRpcHandleInfo *pInfo, int32_t msgSize, int32_t vgId, int32_t code); - - -static int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows); +static int32_t mndProcessDropOrphanTaskReq(SRpcMsg* pReq); static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList); @@ -121,6 +119,8 @@ int32_t mndInitStream(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_VND_STREAM_CHECK_POINT_SOURCE_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_STREAM_BEGIN_CHECKPOINT, mndProcessStreamCheckpoint); + mndSetMsgHandle(pMnode, TDMT_MND_STREAM_DROP_ORPHANTASKS, mndProcessDropOrphanTaskReq); + mndSetMsgHandle(pMnode, TDMT_MND_STREAM_TASK_RESET, mndProcessResetStatusReq); mndSetMsgHandle(pMnode, TDMT_MND_STREAM_REQ_CHKPT, mndProcessStreamReqCheckpoint); mndSetMsgHandle(pMnode, TDMT_MND_STREAM_CHKPT_REPORT, mndProcessCheckpointReport); mndSetMsgHandle(pMnode, TDMT_MND_STREAM_UPDATE_CHKPT_EVT, mndScanCheckpointReportInfo); @@ -154,6 +154,7 @@ int32_t mndInitStream(SMnode *pMnode) { void mndCleanupStream(SMnode *pMnode) { taosArrayDestroy(execInfo.pTaskList); taosArrayDestroy(execInfo.pNodeList); + taosArrayDestroy(execInfo.pKilledChkptTrans); taosHashCleanup(execInfo.pTaskMap); taosHashCleanup(execInfo.transMgmt.pDBTrans); taosHashCleanup(execInfo.pTransferStateStreams); @@ -271,38 +272,12 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream) { sdbRelease(pSdb, pStream); } -static void mndShowStreamStatus(char *dst, SStreamObj *pStream) { - int8_t status = atomic_load_8(&pStream->status); - if (status == STREAM_STATUS__NORMAL) { - strcpy(dst, "ready"); - } else if (status == STREAM_STATUS__STOP) { - strcpy(dst, "stop"); - } else if (status == STREAM_STATUS__FAILED) { - strcpy(dst, "failed"); - } else if (status == STREAM_STATUS__RECOVER) { - strcpy(dst, "recover"); - } else if (status == STREAM_STATUS__PAUSE) { - strcpy(dst, "paused"); - } -} - SSdbRaw *mndStreamSeqActionEncode(SStreamObj *pStream) { return NULL; } SSdbRow *mndStreamSeqActionDecode(SSdbRaw *pRaw) { return NULL; } int32_t mndStreamSeqActionInsert(SSdb *pSdb, SStreamSeq *pStream) { return 0; } int32_t mndStreamSeqActionDelete(SSdb *pSdb, SStreamSeq *pStream) { return 0; } int32_t mndStreamSeqActionUpdate(SSdb *pSdb, SStreamSeq *pOldStream, SStreamSeq *pNewStream) { return 0; } -static void mndShowStreamTrigger(char *dst, SStreamObj *pStream) { - int8_t trigger = pStream->conf.trigger; - if (trigger == STREAM_TRIGGER_AT_ONCE) { - strcpy(dst, "at once"); - } else if (trigger == STREAM_TRIGGER_WINDOW_CLOSE) { - strcpy(dst, "window close"); - } else if (trigger == STREAM_TRIGGER_MAX_DELAY) { - strcpy(dst, "max delay"); - } -} - static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0 || pCreate->sourceDB[0] == 0 || pCreate->targetStbFullName[0] == 0) { @@ -315,13 +290,16 @@ static int32_t createSchemaByFields(const SArray *pFields, SSchemaWrapper *pWrap pWrapper->nCols = taosArrayGetSize(pFields); pWrapper->pSchema = taosMemoryCalloc(pWrapper->nCols, sizeof(SSchema)); if (NULL == pWrapper->pSchema) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } - SNode *pNode; int32_t index = 0; for (int32_t i = 0; i < pWrapper->nCols; i++) { SField *pField = (SField *)taosArrayGet(pFields, i); + if (pField == NULL) { + return terrno; + } + if (TSDB_DATA_TYPE_NULL == pField->type) { pWrapper->pSchema[index].type = TSDB_DATA_TYPE_VARCHAR; pWrapper->pSchema[index].bytes = VARSTR_HEADER_SIZE; @@ -353,15 +331,18 @@ static bool hasDestPrimaryKey(SSchemaWrapper *pWrapper) { static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SCMCreateStreamReq *pCreate) { SNode *pAst = NULL; SQueryPlan *pPlan = NULL; + int32_t code = 0; mInfo("stream:%s to create", pCreate->name); memcpy(pObj->name, pCreate->name, TSDB_STREAM_FNAME_LEN); pObj->createTime = taosGetTimestampMs(); pObj->updateTime = pObj->createTime; pObj->version = 1; + if (pCreate->smaId > 0) { pObj->subTableWithoutMd5 = 1; } + pObj->smaId = pCreate->smaId; pObj->indexForMultiAggBalance = -1; @@ -385,8 +366,10 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB); if (pSourceDb == NULL) { mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, terrstr()); - return terrno; + code = terrno; + goto FAIL; } + pObj->sourceDbUid = pSourceDb->uid; mndReleaseDb(pMnode, pSourceDb); @@ -394,9 +377,11 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SDbObj *pTargetDb = mndAcquireDbByStb(pMnode, pObj->targetSTbName); if (pTargetDb == NULL) { - mInfo("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, terrstr()); - return terrno; + mError("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, terrstr()); + code = terrno; + goto FAIL; } + tstrncpy(pObj->targetDb, pTargetDb->name, TSDB_DB_FNAME_LEN); if (pCreate->createStb == STREAM_CREATE_STABLE_TRUE) { @@ -414,12 +399,12 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, pCreate->ast = NULL; // deserialize ast - if (nodesStringToNode(pObj->ast, &pAst) < 0) { + if ((code = nodesStringToNode(pObj->ast, &pAst)) < 0) { goto FAIL; } // create output schema - if (createSchemaByFields(pCreate->pCols, &pObj->outputSchema) != TSDB_CODE_SUCCESS) { + if ((code = createSchemaByFields(pCreate->pCols, &pObj->outputSchema)) != TSDB_CODE_SUCCESS) { goto FAIL; } @@ -428,6 +413,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, pObj->outputSchema.nCols += numOfNULL; SSchema *pFullSchema = taosMemoryCalloc(pObj->outputSchema.nCols, sizeof(SSchema)); if (!pFullSchema) { + code = terrno; goto FAIL; } @@ -435,6 +421,10 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, int32_t dataIndex = 0; for (int16_t i = 0; i < pObj->outputSchema.nCols; i++) { SColLocation *pos = taosArrayGet(pCreate->fillNullCols, nullIndex); + if (pos == NULL) { + continue; + } + if (nullIndex >= numOfNULL || i < pos->slotId) { pFullSchema[i].bytes = pObj->outputSchema.pSchema[dataIndex].bytes; pFullSchema[i].colId = i + 1; // pObj->outputSchema.pSchema[dataIndex].colId; @@ -469,22 +459,31 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, }; // using ast and param to build physical plan - if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) { + if ((code = qCreateQueryPlan(&cxt, &pPlan, NULL)) < 0) { goto FAIL; } // save physcial plan - if (nodesNodeToString((SNode *)pPlan, false, &pObj->physicalPlan, NULL) != 0) { + if ((code = nodesNodeToString((SNode *)pPlan, false, &pObj->physicalPlan, NULL)) != 0) { goto FAIL; } pObj->tagSchema.nCols = pCreate->numOfTags; if (pCreate->numOfTags) { pObj->tagSchema.pSchema = taosMemoryCalloc(pCreate->numOfTags, sizeof(SSchema)); + if (pObj->tagSchema.pSchema == NULL) { + code = terrno; + goto FAIL; + } } + /*A(pCreate->numOfTags == taosArrayGetSize(pCreate->pTags));*/ for (int32_t i = 0; i < pCreate->numOfTags; i++) { SField *pField = taosArrayGet(pCreate->pTags, i); + if (pField == NULL) { + continue; + } + pObj->tagSchema.pSchema[i].colId = pObj->outputSchema.nCols + i + 1; pObj->tagSchema.pSchema[i].bytes = pField->bytes; pObj->tagSchema.pSchema[i].flags = pField->flags; @@ -495,7 +494,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, FAIL: if (pAst != NULL) nodesDestroyNode(pAst); if (pPlan != NULL) qDestroyQueryPlan(pPlan); - return 0; + return code; } int32_t mndPersistTaskDeployReq(STrans *pTrans, SStreamTask *pTask) { @@ -600,16 +599,21 @@ int32_t mndPersistStream(STrans *pTrans, SStreamObj *pStream) { static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStreamObj *pStream, const char *user) { SStbObj *pStb = NULL; SDbObj *pDb = NULL; + int32_t code = 0; + int32_t lino = 0; SMCreateStbReq createReq = {0}; tstrncpy(createReq.name, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); createReq.numOfColumns = pStream->outputSchema.nCols; createReq.numOfTags = 1; // group id createReq.pColumns = taosArrayInit_s(sizeof(SFieldWithOptions), createReq.numOfColumns); + TSDB_CHECK_NULL(createReq.pColumns, code, lino, _OVER, terrno); // build fields for (int32_t i = 0; i < createReq.numOfColumns; i++) { SFieldWithOptions *pField = taosArrayGet(createReq.pColumns, i); + TSDB_CHECK_NULL(pField, code, lino, _OVER, terrno); + tstrncpy(pField->name, pStream->outputSchema.pSchema[i].name, TSDB_COL_NAME_LEN); pField->flags = pStream->outputSchema.pSchema[i].flags; pField->type = pStream->outputSchema.pSchema[i].type; @@ -620,8 +624,12 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre if (pStream->tagSchema.nCols == 0) { createReq.numOfTags = 1; createReq.pTags = taosArrayInit_s(sizeof(SField), 1); + TSDB_CHECK_NULL(createReq.pTags, code, lino, _OVER, terrno); + // build tags SField *pField = taosArrayGet(createReq.pTags, 0); + TSDB_CHECK_NULL(pField, code, lino, _OVER, terrno); + strcpy(pField->name, "group_id"); pField->type = TSDB_DATA_TYPE_UBIGINT; pField->flags = 0; @@ -629,8 +637,14 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre } else { createReq.numOfTags = pStream->tagSchema.nCols; createReq.pTags = taosArrayInit_s(sizeof(SField), createReq.numOfTags); + TSDB_CHECK_NULL(createReq.pTags, code, lino, _OVER, terrno); + for (int32_t i = 0; i < createReq.numOfTags; i++) { SField *pField = taosArrayGet(createReq.pTags, i); + if (pField == NULL) { + continue; + } + pField->bytes = pStream->tagSchema.pSchema[i].bytes; pField->flags = pStream->tagSchema.pSchema[i].flags; pField->type = pStream->tagSchema.pSchema[i].type; @@ -682,7 +696,7 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre mndReleaseStb(pMnode, pStb); mndReleaseDb(pMnode, pDb); mDebug("stream:%s create dst stable:%s, cols:%d", pStream->name, pStream->targetSTbName, pStream->outputSchema.nCols); - return 0; + return code; _OVER: tFreeSMCreateStbReq(&createReq); @@ -690,7 +704,7 @@ _OVER: mndReleaseDb(pMnode, pDb); mDebug("stream:%s failed to create dst stable:%s, code:%s", pStream->name, pStream->targetSTbName, tstrerror(terrno)); - return -1; + return code; } // 1. stream number check @@ -734,9 +748,10 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { char *sql = NULL; int32_t sqlLen = 0; const char *pMsg = "create stream tasks on dnodes"; - int32_t code = 0; - terrno = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + terrno = TSDB_CODE_SUCCESS; SCMCreateStreamReq createReq = {0}; if (tDeserializeSCMCreateStreamReq(pReq->pCont, pReq->contLen, &createReq) != 0) { code = TSDB_CODE_INVALID_MSG; @@ -774,6 +789,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { if (createReq.sql != NULL) { sqlLen = strlen(createReq.sql); sql = taosMemoryMalloc(sqlLen + 1); + TSDB_CHECK_NULL(sql, code, lino, _OVER, terrno); memset(sql, 0, sqlLen + 1); memcpy(sql, createReq.sql, sqlLen); } @@ -873,7 +889,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { _OVER: if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { - mError("stream:%s, failed to create since %s", createReq.name, terrstr(code)); + mError("stream:%s, failed to create since %s", createReq.name, terrstr()); } else { mDebug("stream:%s create stream completed", createReq.name); } @@ -912,10 +928,9 @@ int64_t mndStreamGenChkptId(SMnode *pMnode, bool lock) { } for (int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { - STaskId *p = taosArrayGet(execInfo.pTaskList, i); - + STaskId *p = taosArrayGet(execInfo.pTaskList, i); STaskStatusEntry *pEntry = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); - if (pEntry == NULL) { + if (p == NULL || pEntry == NULL) { continue; } @@ -959,16 +974,14 @@ static int32_t mndBuildStreamCheckpointSourceReq(void **pBuf, int32_t *pLen, int tEncodeSize(tEncodeStreamCheckpointSourceReq, &req, blen, code); if (code < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } int32_t tlen = sizeof(SMsgHead) + blen; void *buf = taosMemoryMalloc(tlen); if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + return terrno; } void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); @@ -995,18 +1008,20 @@ static int32_t doSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask int8_t mndTrigger) { void *buf; int32_t tlen; - if (mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, - pTask->id.taskId, pTrans->id, mndTrigger) < 0) { - taosMemoryFree(buf); - return -1; - } - + int32_t code = 0; SEpSet epset = {0}; bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + + if ((code = mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, + pTask->id.taskId, pTrans->id, mndTrigger)) < 0) { + taosMemoryFree(buf); + return code; + } + + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); if (code != TSDB_CODE_SUCCESS || !hasEpset) { taosMemoryFree(buf); - return -1; + return code; } code = setTransAction(pTrans, buf, tlen, TDMT_VND_STREAM_CHECK_POINT_SOURCE, &epset, TSDB_CODE_SYN_PROPOSE_NOT_READY, @@ -1020,10 +1035,10 @@ static int32_t doSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStream, int64_t checkpointId, int8_t mndTrigger, bool lock) { - int32_t code = -1; + int32_t code = TSDB_CODE_SUCCESS; int64_t ts = taosGetTimestampMs(); if (mndTrigger == 1 && (ts - pStream->checkpointFreq < tsStreamCheckpointInterval * 1000)) { - return TSDB_CODE_SUCCESS; + return code; } bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_CHECKPOINT_NAME, lock); @@ -1087,13 +1102,11 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre goto _ERR; } - if ((code = mndTransPrepare(pMnode, pTrans)) != TSDB_CODE_SUCCESS) { - code = terrno; + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("failed to prepare checkpoint trans since %s", terrstr()); - goto _ERR; } - code = 0; _ERR: mndTransDrop(pTrans); return code; @@ -1125,6 +1138,10 @@ static bool taskNodeIsUpdated(SMnode *pMnode) { for (int32_t i = 0; i < numOfNodes; ++i) { SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); + if (pNodeEntry == NULL) { + continue; + } + if (pNodeEntry->stageUpdated) { mDebug("stream task not ready due to node update detected, checkpoint not issued"); streamMutexUnlock(&execInfo.lock); @@ -1165,7 +1182,7 @@ static bool taskNodeIsUpdated(SMnode *pMnode) { static int32_t mndCheckTaskAndNodeStatus(SMnode *pMnode) { bool ready = true; if (taskNodeIsUpdated(pMnode)) { - return -1; + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } streamMutexLock(&execInfo.lock); @@ -1177,7 +1194,11 @@ static int32_t mndCheckTaskAndNodeStatus(SMnode *pMnode) { SArray *pInvalidList = taosArrayInit(4, sizeof(STaskId)); for (int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { - STaskId *p = taosArrayGet(execInfo.pTaskList, i); + STaskId *p = taosArrayGet(execInfo.pTaskList, i); + if (p == NULL) { + continue; + } + STaskStatusEntry *pEntry = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); if (pEntry == NULL) { continue; @@ -1186,8 +1207,12 @@ static int32_t mndCheckTaskAndNodeStatus(SMnode *pMnode) { if (pEntry->status == TASK_STATUS__STOP) { for (int32_t j = 0; j < taosArrayGetSize(pInvalidList); ++j) { STaskId *pId = taosArrayGet(pInvalidList, j); + if (pId == NULL) { + continue; + } + if (pEntry->id.streamId == pId->streamId) { - void* px = taosArrayPush(pInvalidList, &pEntry->id); + void *px = taosArrayPush(pInvalidList, &pEntry->id); if (px == NULL) { mError("failed to put stream into invalid list, code:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); } @@ -1227,7 +1252,7 @@ int64_t getStreamTaskLastReadyState(SArray *pTaskList, int64_t streamId) { for (int32_t i = 0; i < taosArrayGetSize(pTaskList); ++i) { STaskId *p = taosArrayGet(pTaskList, i); STaskStatusEntry *pEntry = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); - if (pEntry == NULL || pEntry->id.streamId != streamId) { + if (p == NULL || pEntry == NULL || pEntry->id.streamId != streamId) { continue; } @@ -1265,11 +1290,14 @@ static int32_t mndProcessStreamCheckpoint(SRpcMsg *pReq) { int32_t numOfCheckpointTrans = 0; if ((code = mndCheckTaskAndNodeStatus(pMnode)) != 0) { - terrno = TSDB_CODE_STREAM_TASK_IVLD_STATUS; - return -1; + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } SArray *pList = taosArrayInit(4, sizeof(SCheckpointInterval)); + if (pList == NULL) { + return terrno; + } + int64_t now = taosGetTimestampMs(); while ((pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream)) != NULL) { @@ -1336,6 +1364,9 @@ static int32_t mndProcessStreamCheckpoint(SRpcMsg *pReq) { for (int32_t i = 0; i < numOfQual; ++i) { SCheckpointInterval *pCheckpointInfo = taosArrayGet(pList, i); + if (pCheckpointInfo == NULL) { + continue; + } SStreamObj *p = NULL; code = mndGetStreamObj(pMnode, pCheckpointInfo->streamId, &p); @@ -1367,8 +1398,8 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { SMDropStreamReq dropReq = {0}; if (tDeserializeSMDropStreamReq(pReq->pCont, pReq->contLen, &dropReq) < 0) { mError("invalid drop stream msg recv, discarded"); - terrno = TSDB_CODE_INVALID_MSG; - return -1; + code = TSDB_CODE_INVALID_MSG; + TAOS_RETURN(code); } mDebug("recv drop stream:%s msg", dropReq.name); @@ -1381,10 +1412,10 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { tFreeMDropStreamReq(&dropReq); return 0; } else { - terrno = TSDB_CODE_MND_STREAM_NOT_EXIST; + code = TSDB_CODE_MND_STREAM_NOT_EXIST; mError("stream:%s not exist failed to drop it", dropReq.name); tFreeMDropStreamReq(&dropReq); - return -1; + TAOS_RETURN(code); } } @@ -1401,11 +1432,11 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { sdbCancelFetch(pMnode->pSdb, pIter); tFreeMDropStreamReq(&dropReq); - terrno = TSDB_CODE_TSMA_MUST_BE_DROPPED; + code = TSDB_CODE_TSMA_MUST_BE_DROPPED; mError("try to drop sma-related stream:%s, uid:0x%" PRIx64 " code:%s only allowed to be dropped along with sma", dropReq.name, pStream->uid, tstrerror(terrno)); - return -1; + TAOS_RETURN(code); } if (pSma) { @@ -1427,7 +1458,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { if (conflict) { sdbRelease(pMnode->pSdb, pStream); tFreeMDropStreamReq(&dropReq); - return -1; + return terrno; } STrans *pTrans = NULL; @@ -1436,34 +1467,44 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { mError("stream:%s uid:0x%" PRIx64 " failed to drop since %s", dropReq.name, pStream->uid, terrstr()); sdbRelease(pMnode->pSdb, pStream); tFreeMDropStreamReq(&dropReq); - return -1; + TAOS_RETURN(code); } code = mndStreamRegisterTrans(pTrans, MND_STREAM_DROP_NAME, pStream->uid); - - // drop all tasks - if (mndStreamSetDropAction(pMnode, pTrans, pStream) < 0) { - mError("stream:%s uid:0x%" PRIx64 " failed to drop task since %s", dropReq.name, pStream->uid, terrstr()); + if (code) { + mError("failed to register drop stream trans, code:%s", tstrerror(code)); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); tFreeMDropStreamReq(&dropReq); - return -1; + TAOS_RETURN(code); + } + + // drop all tasks + code = mndStreamSetDropAction(pMnode, pTrans, pStream); + if (code) { + mError("stream:%s uid:0x%" PRIx64 " failed to drop task since %s", dropReq.name, pStream->uid, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + tFreeMDropStreamReq(&dropReq); + TAOS_RETURN(code); } // drop stream - if (mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED) < 0) { + code = mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED); + if (code) { sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); tFreeMDropStreamReq(&dropReq); - return -1; + TAOS_RETURN(code); } - if (mndTransPrepare(pMnode, pTrans) != 0) { + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); tFreeMDropStreamReq(&dropReq); - return -1; + TAOS_RETURN(code); } // kill the related checkpoint trans @@ -1489,13 +1530,14 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { if (code == 0) { return TSDB_CODE_ACTION_IN_PROGRESS; } else { - return code; + TAOS_RETURN(code); } } int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int32_t code = 0; while (1) { SStreamObj *pStream = NULL; @@ -1508,18 +1550,8 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { sdbCancelFetch(pSdb, pIter); mError("db:%s, failed to drop stream:%s since sourceDbUid:%" PRId64 " not match with targetDbUid:%" PRId64, pDb->name, pStream->name, pStream->sourceDbUid, pStream->targetDbUid); - terrno = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; - return -1; + TAOS_RETURN(TSDB_CODE_MND_STREAM_MUST_BE_DELETED); } else { -#if 0 - if (mndStreamSetDropAction(pMnode, pTrans, pStream) < 0) { - mError("stream:%s, failed to drop task since %s", pStream->name, terrstr()); - sdbRelease(pMnode->pSdb, pStream); - sdbCancelFetch(pSdb, pIter); - return -1; - } -#endif - // kill the related checkpoint trans int32_t transId = mndStreamGetRelTrans(pMnode, pStream->uid); if (transId != 0) { @@ -1530,10 +1562,11 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { // drop the stream obj in execInfo removeStreamTasksInBuf(pStream, &execInfo); - if (mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED) < 0) { + code = mndPersistTransLog(pStream, pTrans, SDB_STATUS_DROPPED); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { sdbRelease(pSdb, pStream); sdbCancelFetch(pSdb, pIter); - return -1; + return code; } } } @@ -1548,8 +1581,7 @@ int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = mndAcquireDb(pMnode, dbName); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; + TAOS_RETURN(TSDB_CODE_MND_DB_NOT_SELECTED); } int32_t numOfStreams = 0; @@ -1571,15 +1603,6 @@ int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) return 0; } -static void int64ToHexStr(int64_t id, char *pBuf, int32_t bufLen) { - memset(pBuf, 0, bufLen); - pBuf[2] = '0'; - pBuf[3] = 'x'; - - int32_t len = tintToHex(id, &pBuf[4]); - varDataSetLen(pBuf, len + 2); -} - static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -1607,379 +1630,6 @@ static void mndCancelGetNextStream(SMnode *pMnode, void *pIter) { sdbCancelFetch(pSdb, pIter); } -int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows) { - int32_t code = 0; - int32_t cols = 0; - int32_t lino = 0; - - char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName)); - SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - - code = colDataSetVal(pColInfo, numOfRows, (const char *)streamName, false); - TSDB_CHECK_CODE(code, lino, _end); - - // create time - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pStream->createTime, false); - TSDB_CHECK_CODE(code, lino, _end); - - // stream id - char buf[128] = {0}; - int64ToHexStr(pStream->uid, buf, tListLen(buf)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, buf, false); - TSDB_CHECK_CODE(code, lino, _end); - - // related fill-history stream id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - if (pStream->hTaskUid != 0) { - int64ToHexStr(pStream->hTaskUid, buf, tListLen(buf)); - code = colDataSetVal(pColInfo, numOfRows, buf, false); - } else { - code = colDataSetVal(pColInfo, numOfRows, buf, true); - } - TSDB_CHECK_CODE(code, lino, _end); - - // related fill-history stream id - char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(sql, pStream->sql, sizeof(sql)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)sql, false); - TSDB_CHECK_CODE(code, lino, _end); - - char status[20 + VARSTR_HEADER_SIZE] = {0}; - char status2[20] = {0}; - mndShowStreamStatus(status2, pStream); - STR_WITH_MAXSIZE_TO_VARSTR(status, status2, sizeof(status)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&status, false); - TSDB_CHECK_CODE(code, lino, _end); - - char sourceDB[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(sourceDB, mndGetDbStr(pStream->sourceDb), sizeof(sourceDB)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&sourceDB, false); - TSDB_CHECK_CODE(code, lino, _end); - - char targetDB[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(targetDB, mndGetDbStr(pStream->targetDb), sizeof(targetDB)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&targetDB, false); - TSDB_CHECK_CODE(code, lino, _end); - - if (pStream->targetSTbName[0] == 0) { - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, NULL, true); - } else { - char targetSTB[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(targetSTB, mndGetStbStr(pStream->targetSTbName), sizeof(targetSTB)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&targetSTB, false); - } - TSDB_CHECK_CODE(code, lino, _end); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pStream->conf.watermark, false); - TSDB_CHECK_CODE(code, lino, _end); - - char trigger[20 + VARSTR_HEADER_SIZE] = {0}; - char trigger2[20] = {0}; - mndShowStreamTrigger(trigger2, pStream); - STR_WITH_MAXSIZE_TO_VARSTR(trigger, trigger2, sizeof(trigger)); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&trigger, false); - TSDB_CHECK_CODE(code, lino, _end); - - // sink_quota - char sinkQuota[20 + VARSTR_HEADER_SIZE] = {0}; - sinkQuota[0] = '0'; - char dstStr[20] = {0}; - STR_TO_VARSTR(dstStr, sinkQuota) - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)dstStr, false); - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint interval - char tmp[20 + VARSTR_HEADER_SIZE] = {0}; - sprintf(varDataVal(tmp), "%d sec", tsStreamCheckpointInterval); - varDataSetLen(tmp, strlen(varDataVal(tmp))); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)tmp, false); - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint backup type - char backup[20 + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(backup, "none") - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)backup, false); - TSDB_CHECK_CODE(code, lino, _end); - - // history scan idle - char scanHistoryIdle[20 + VARSTR_HEADER_SIZE] = {0}; - strcpy(scanHistoryIdle, "100a"); - - memset(dstStr, 0, tListLen(dstStr)); - STR_TO_VARSTR(dstStr, scanHistoryIdle) - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)dstStr, false); - - _end: - return code; -} - -static int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t numOfRows) { - SColumnInfoData *pColInfo; - int32_t cols = 0; - int32_t code = 0; - int32_t lino = 0; - - STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId}; - - STaskStatusEntry *pe = taosHashGet(execInfo.pTaskMap, &id, sizeof(id)); - if (pe == NULL) { - mError("task:0x%" PRIx64 " not exists in any vnodes, streamName:%s, streamId:0x%" PRIx64 " createTs:%" PRId64 - " no valid status/stage info", - id.taskId, pStream->name, pStream->uid, pStream->createTime); - return TSDB_CODE_STREAM_TASK_NOT_EXIST; - } - - // stream name - char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName)); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)streamName, false); - TSDB_CHECK_CODE(code, lino, _end); - - // task id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - - char idstr[128] = {0}; - int64ToHexStr(pTask->id.taskId, idstr, tListLen(idstr)); - code = colDataSetVal(pColInfo, numOfRows, idstr, false); - TSDB_CHECK_CODE(code, lino, _end); - - // node type - char nodeType[20 + VARSTR_HEADER_SIZE] = {0}; - varDataSetLen(nodeType, 5); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - if (pTask->info.nodeId > 0) { - memcpy(varDataVal(nodeType), "vnode", 5); - } else { - memcpy(varDataVal(nodeType), "snode", 5); - } - code = colDataSetVal(pColInfo, numOfRows, nodeType, false); - TSDB_CHECK_CODE(code, lino, _end); - - // node id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - int64_t nodeId = TMAX(pTask->info.nodeId, 0); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&nodeId, false); - TSDB_CHECK_CODE(code, lino, _end); - - // level - char level[20 + VARSTR_HEADER_SIZE] = {0}; - if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { - memcpy(varDataVal(level), "source", 6); - varDataSetLen(level, 6); - } else if (pTask->info.taskLevel == TASK_LEVEL__AGG) { - memcpy(varDataVal(level), "agg", 3); - varDataSetLen(level, 3); - } else if (pTask->info.taskLevel == TASK_LEVEL__SINK) { - memcpy(varDataVal(level), "sink", 4); - varDataSetLen(level, 4); - } - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)level, false); - TSDB_CHECK_CODE(code, lino, _end); - - // status - char status[20 + VARSTR_HEADER_SIZE] = {0}; - - const char *pStatus = streamTaskGetStatusStr(pe->status); - STR_TO_VARSTR(status, pStatus); - - // status - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)status, false); - TSDB_CHECK_CODE(code, lino, _end); - - // stage - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->stage, false); - TSDB_CHECK_CODE(code, lino, _end); - - // input queue - char vbuf[40] = {0}; - char buf[38] = {0}; - const char *queueInfoStr = "%4.2f MiB (%6.2f%)"; - snprintf(buf, tListLen(buf), queueInfoStr, pe->inputQUsed, pe->inputRate); - STR_TO_VARSTR(vbuf, buf); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - - // input total - const char *formatTotalMb = "%7.2f MiB"; - const char *formatTotalGb = "%7.2f GiB"; - if (pe->procsTotal < 1024) { - snprintf(buf, tListLen(buf), formatTotalMb, pe->procsTotal); - } else { - snprintf(buf, tListLen(buf), formatTotalGb, pe->procsTotal / 1024); - } - - memset(vbuf, 0, tListLen(vbuf)); - STR_TO_VARSTR(vbuf, buf); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - - // process throughput - const char *formatKb = "%7.2f KiB/s"; - const char *formatMb = "%7.2f MiB/s"; - if (pe->procsThroughput < 1024) { - snprintf(buf, tListLen(buf), formatKb, pe->procsThroughput); - } else { - snprintf(buf, tListLen(buf), formatMb, pe->procsThroughput / 1024); - } - - memset(vbuf, 0, tListLen(vbuf)); - STR_TO_VARSTR(vbuf, buf); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - - // output total - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - - if (pTask->info.taskLevel == TASK_LEVEL__SINK) { - colDataSetNULL(pColInfo, numOfRows); - } else { - sprintf(buf, formatTotalMb, pe->outputTotal); - memset(vbuf, 0, tListLen(vbuf)); - STR_TO_VARSTR(vbuf, buf); - - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - } - - // output throughput - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - - if (pTask->info.taskLevel == TASK_LEVEL__SINK) { - colDataSetNULL(pColInfo, numOfRows); - } else { - if (pe->outputThroughput < 1024) { - snprintf(buf, tListLen(buf), formatKb, pe->outputThroughput); - } else { - snprintf(buf, tListLen(buf), formatMb, pe->outputThroughput / 1024); - } - - memset(vbuf, 0, tListLen(vbuf)); - STR_TO_VARSTR(vbuf, buf); - - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - } - - // output queue - // sprintf(buf, queueInfoStr, pe->outputQUsed, pe->outputRate); - // STR_TO_VARSTR(vbuf, buf); - - // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - // colDataSetVal(pColInfo, numOfRows, (const char*)vbuf, false); - - // info - if (pTask->info.taskLevel == TASK_LEVEL__SINK) { - const char *sinkStr = "%.2f MiB"; - snprintf(buf, tListLen(buf), sinkStr, pe->sinkDataSize); - } else if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { - // offset info - const char *offsetStr = "%" PRId64 " [%" PRId64 ", %" PRId64 "]"; - snprintf(buf, tListLen(buf), offsetStr, pe->processedVer, pe->verRange.minVer, pe->verRange.maxVer); - } else { - memset(buf, 0, tListLen(buf)); - } - - STR_TO_VARSTR(vbuf, buf); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); - TSDB_CHECK_CODE(code, lino, _end); - - // start_time - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startTime, false); - TSDB_CHECK_CODE(code, lino, _end); - - // start id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startCheckpointId, false); - TSDB_CHECK_CODE(code, lino, _end); - - // start ver - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startCheckpointVer, false); - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint time - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - if (pe->checkpointInfo.latestTime != 0) { - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestTime, false); - } else { - code = colDataSetVal(pColInfo, numOfRows, 0, true); - } - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint_id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestId, false); - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint version - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestVer, false); - TSDB_CHECK_CODE(code, lino, _end); - - // checkpoint size - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetNULL(pColInfo, numOfRows); - - // checkpoint backup status - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, 0, true); - TSDB_CHECK_CODE(code, lino, _end); - - // ds_err_info - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, 0, true); - TSDB_CHECK_CODE(code, lino, _end); - - // history_task_id - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - if (pe->hTaskId != 0) { - int64ToHexStr(pe->hTaskId, idstr, tListLen(idstr)); - code = colDataSetVal(pColInfo, numOfRows, idstr, false); - } else { - code = colDataSetVal(pColInfo, numOfRows, 0, true); - } - TSDB_CHECK_CODE(code, lino, _end); - - // history_task_status - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - code = colDataSetVal(pColInfo, numOfRows, 0, true); - TSDB_CHECK_CODE(code, lino, _end); - - _end: - return code; -} - static int32_t mndRetrieveStreamTask(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -2059,8 +1709,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { SMPauseStreamReq pauseReq = {0}; if (tDeserializeSMPauseStreamReq(pReq->pCont, pReq->contLen, &pauseReq) < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_MSG); } code = mndAcquireStream(pMnode, pauseReq.name, &pStream); @@ -2070,8 +1719,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { return 0; } else { mError("stream:%s not exist, failed to pause stream", pauseReq.name); - terrno = TSDB_CODE_MND_STREAM_NOT_EXIST; - return -1; + TAOS_RETURN(TSDB_CODE_MND_STREAM_NOT_EXIST); } } @@ -2091,14 +1739,14 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_PAUSE_NAME, true); if (conflict) { sdbRelease(pMnode->pSdb, pStream); - return -1; + TAOS_RETURN(TSDB_CODE_MND_TRANS_CONFLICT); } bool updated = taskNodeIsUpdated(pMnode); if (updated) { mError("tasks are not ready for pause, node update detected"); sdbRelease(pMnode->pSdb, pStream); - return -1; + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } { // check for tasks, if tasks are not ready, not allowed to pause @@ -2108,6 +1756,9 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { for (int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { STaskId *p = taosArrayGet(execInfo.pTaskList, i); + if (p == NULL) { + continue; + } STaskStatusEntry *pEntry = taosHashGet(execInfo.pTaskMap, p, sizeof(*p)); if (pEntry == NULL) { @@ -2131,13 +1782,13 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { if (!found) { mError("stream:%s task not report status yet, not ready for pause", pauseReq.name); sdbRelease(pMnode->pSdb, pStream); - return -1; + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } if (!readyToPause) { mError("stream:%s task not ready for pause yet", pauseReq.name); sdbRelease(pMnode->pSdb, pStream); - return -1; + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } } @@ -2179,7 +1830,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { taosWUnLockLatch(&pStream->lock); code = mndTransPrepare(pMnode, pTrans); - if (code) { + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -2198,13 +1849,12 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) { int32_t code = 0; if ((terrno = grantCheckExpire(TSDB_GRANT_STREAMS)) < 0) { - return -1; + return terrno; } SMResumeStreamReq resumeReq = {0}; if (tDeserializeSMResumeStreamReq(pReq->pCont, pReq->contLen, &resumeReq) < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; + TAOS_RETURN(TSDB_CODE_INVALID_MSG); } code = mndAcquireStream(pMnode, resumeReq.name, &pStream); @@ -2215,8 +1865,7 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) { return 0; } else { mError("stream:%s not exist, failed to resume stream", resumeReq.name); - terrno = TSDB_CODE_MND_STREAM_NOT_EXIST; - return -1; + TAOS_RETURN(TSDB_CODE_MND_STREAM_NOT_EXIST); } } @@ -2273,7 +1922,8 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) { } taosWUnLockLatch(&pStream->lock); - if (mndTransPrepare(pMnode, pTrans) != 0) { + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -2310,10 +1960,16 @@ static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pP int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); for (int32_t i = 0; i < numOfNodes; ++i) { SNodeEntry *pPrevEntry = taosArrayGet(pPrevNodeList, i); + if (pPrevEntry == NULL) { + continue; + } int32_t num = taosArrayGetSize(pNodeList); for (int32_t j = 0; j < num; ++j) { SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); + if(pCurrent == NULL) { + continue; + } if (pCurrent->nodeId == pPrevEntry->nodeId) { if (pPrevEntry->stageUpdated || isNodeEpsetChanged(&pPrevEntry->epset, &pCurrent->epset)) { @@ -2434,7 +2090,7 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange } code = mndTransPrepare(pMnode, pTrans); - if (code) { + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -2656,7 +2312,7 @@ void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode) bool exist = false; for (int32_t j = 0; j < taosArrayGetSize(pExecNode->pNodeList); ++j) { SNodeEntry *pEntry = taosArrayGet(pExecNode->pNodeList, j); - if (pEntry->nodeId == pTask->info.nodeId) { + if ((pEntry != NULL) && (pEntry->nodeId == pTask->info.nodeId)) { exist = true; break; } @@ -2683,14 +2339,17 @@ static void doAddTaskId(SArray *pList, int32_t taskId, int64_t uid, int32_t numO int32_t num = taosArrayGetSize(pList); for (int32_t i = 0; i < num; ++i) { int32_t *pId = taosArrayGet(pList, i); + if (pId == NULL) { + continue; + } + if (taskId == *pId) { return; } } - void* p = taosArrayPush(pList, &taskId); int32_t numOfTasks = taosArrayGetSize(pList); - + void *p = taosArrayPush(pList, &taskId); if (p) { mDebug("stream:0x%" PRIx64 " receive %d reqs for checkpoint, remain:%d", uid, numOfTasks, numOfTotal - numOfTasks); } else { @@ -2799,6 +2458,10 @@ static void doAddReportStreamTask(SArray* pList, const SCheckpointReport* pRepor bool existed = false; for (int32_t i = 0; i < taosArrayGetSize(pList); ++i) { STaskChkptInfo *p = taosArrayGet(pList, i); + if (p == NULL) { + continue; + } + if (p->taskId == pReport->taskId) { existed = true; break; @@ -2870,14 +2533,15 @@ int32_t mndProcessCheckpointReport(SRpcMsg *pReq) { SArray **pReqTaskList = (SArray **)taosHashGet(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId)); if (pReqTaskList == NULL) { SArray *pList = taosArrayInit(4, sizeof(STaskChkptInfo)); - doAddReportStreamTask(pList, &req); + if (pList != NULL) { + doAddReportStreamTask(pList, &req); + code = taosHashPut(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId), &pList, POINTER_BYTES); + if (code) { + mError("stream:0x%" PRIx64 " failed to put into checkpoint stream", req.streamId); + } - code = taosHashPut(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId), &pList, POINTER_BYTES); - if (code) { - mError("stream:0x%"PRIx64 " failed to put into checkpoint stream", req.streamId); + pReqTaskList = (SArray **)taosHashGet(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId)); } - - pReqTaskList = (SArray **)taosHashGet(execInfo.pChkptStreams, &req.streamId, sizeof(req.streamId)); } else { doAddReportStreamTask(*pReqTaskList, &req); } @@ -2907,6 +2571,10 @@ static int64_t getConsensusId(int64_t streamId, int32_t numOfTasks, int32_t* pEx for(int32_t i = 0; i < taosArrayGetSize(execInfo.pTaskList); ++i) { STaskId* p = taosArrayGet(execInfo.pTaskList, i); + if (p == NULL) { + continue; + } + if (p->streamId != streamId) { continue; } @@ -2943,6 +2611,9 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { SMnode *pMnode = pMsg->info.node; int64_t now = taosGetTimestampMs(); SArray *pStreamList = taosArrayInit(4, sizeof(int64_t)); + if (pStreamList == NULL) { + return terrno; + } mDebug("start to process consensus-checkpointId in tmr"); @@ -2970,6 +2641,9 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { int64_t streamId = -1; int32_t num = taosArrayGetSize(pInfo->pTaskList); SArray *pList = taosArrayInit(4, sizeof(int32_t)); + if (pList == NULL) { + continue; + } SStreamObj *pStream = NULL; code = mndGetStreamObj(pMnode, pInfo->streamId, &pStream); @@ -2981,6 +2655,10 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { for (int32_t j = 0; j < num; ++j) { SCheckpointConsensusEntry *pe = taosArrayGet(pInfo->pTaskList, j); + if (pe == NULL) { + continue; + } + streamId = pe->req.streamId; int32_t existed = 0; @@ -3017,9 +2695,13 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { if (taosArrayGetSize(pList) > 0) { for (int32_t i = 0; i < taosArrayGetSize(pList); ++i) { int32_t *taskId = taosArrayGet(pList, i); + if (taskId == NULL) { + continue; + } + for (int32_t k = 0; k < taosArrayGetSize(pInfo->pTaskList); ++k) { SCheckpointConsensusEntry *pe = taosArrayGet(pInfo->pTaskList, k); - if (pe->req.taskId == *taskId) { + if ((pe != NULL) && (pe->req.taskId == *taskId)) { taosArrayRemove(pInfo->pTaskList, k); break; } @@ -3041,6 +2723,10 @@ int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg) { for (int32_t i = 0; i < taosArrayGetSize(pStreamList); ++i) { int64_t *pStreamId = (int64_t *)taosArrayGet(pStreamList, i); + if (pStreamId == NULL) { + continue; + } + code = mndClearConsensusCheckpointId(execInfo.pStreamConsensus, *pStreamId); } @@ -3129,7 +2815,7 @@ int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, } code = mndTransPrepare(pMnode, pTrans); - if (code) { + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare update checkpoint-info meta trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -3141,3 +2827,82 @@ int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, return TSDB_CODE_ACTION_IN_PROGRESS; } + +static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + int32_t code = 0; + SOrphanTask *pTask = NULL; + int32_t i = 0; + STrans *pTrans = NULL; + int32_t numOfTasks = 0; + + SMStreamDropOrphanMsg msg = {0}; + code = tDeserializeDropOrphanTaskMsg(pReq->pCont, pReq->contLen, &msg); + if (code) { + return code; + } + + numOfTasks = taosArrayGetSize(msg.pList); + if (numOfTasks == 0) { + mDebug("no orphan tasks to drop, no need to create trans"); + goto _err; + } + + mDebug("create trans to drop %d orphan tasks", numOfTasks); + + i = 0; + while (i < numOfTasks && ((pTask = taosArrayGet(msg.pList, i)) == NULL)) { + i += 1; + } + + if (pTask == NULL) { + mError("failed to extract entry in drop orphan task list, not create trans to drop orphan-task"); + goto _err; + } + + // check if it is conflict with other trans in both sourceDb and targetDb. + bool conflict = mndStreamTransConflictCheck(pMnode, pTask->streamId, MND_STREAM_DROP_NAME, false); + if (conflict) { + TAOS_RETURN(TSDB_CODE_MND_TRANS_CONFLICT); + } + + SStreamObj dummyObj = {.uid = pTask->streamId, .sourceDb = "", .targetSTbName = ""}; + + code = doCreateTrans(pMnode, &dummyObj, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans); + if (pTrans == NULL || code != 0) { + mError("failed to create trans to drop orphan tasks since %s", terrstr()); + goto _err; + } + + code = mndStreamRegisterTrans(pTrans, MND_STREAM_DROP_NAME, pTask->streamId); + if (code) { + mndTransDrop(pTrans); + return code; + } + + // drop all tasks + if ((code = mndStreamSetDropActionFromList(pMnode, pTrans, msg.pList)) < 0) { + mError("failed to create trans to drop orphan tasks since %s", terrstr()); + goto _err; + } + + // drop stream + if ((code = mndPersistTransLog(&dummyObj, pTrans, SDB_STATUS_DROPPED)) < 0) { + goto _err; + } + + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { + mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); + goto _err; + } + +_err: + tDestroyDropOrphanTaskMsg(&msg); + mndTransDrop(pTrans); + + if (code == TSDB_CODE_SUCCESS) { + mDebug("create drop %d orphan tasks trans succ", numOfTasks); + } + return code; +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndStreamHb.c b/source/dnode/mnode/impl/src/mndStreamHb.c index 1ca46f128f..11556a212d 100644 --- a/source/dnode/mnode/impl/src/mndStreamHb.c +++ b/source/dnode/mnode/impl/src/mndStreamHb.c @@ -22,12 +22,12 @@ typedef struct SFailedCheckpointInfo { int32_t transId; } SFailedCheckpointInfo; -static void mndStreamStartUpdateCheckpointInfo(SMnode *pMnode); +static int32_t mndStreamSendUpdateChkptInfoMsg(SMnode *pMnode); +static int32_t mndSendDropOrphanTasksMsg(SMnode *pMnode, SArray *pList); +static int32_t mndSendResetFromCheckpointMsg(SMnode *pMnode, int64_t streamId, int32_t transId); static void updateStageInfo(STaskStatusEntry *pTaskEntry, int64_t stage); static void addIntoCheckpointList(SArray *pList, const SFailedCheckpointInfo *pInfo); -static int32_t mndResetStatusFromCheckpoint(SMnode *pMnode, int64_t streamId, int32_t transId); static int32_t setNodeEpsetExpiredFlag(const SArray *pNodeList); -static int32_t mndDropOrphanTasks(SMnode *pMnode, SArray *pList); static int32_t suspendAllStreams(SMnode *pMnode, SRpcHandleInfo *info); static bool validateHbMsg(const SArray *pNodeList, int32_t vgId); static void cleanupAfterProcessHbMsg(SStreamHbMsg *pReq, SArray *pFailedChkptList, SArray *pOrphanTasks); @@ -37,6 +37,10 @@ void updateStageInfo(STaskStatusEntry *pTaskEntry, int64_t stage) { int32_t numOfNodes = taosArrayGetSize(execInfo.pNodeList); for (int32_t j = 0; j < numOfNodes; ++j) { SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, j); + if (pNodeEntry == NULL) { + continue; + } + if (pNodeEntry->nodeId == pTaskEntry->nodeId) { mInfo("vgId:%d stage updated from %" PRId64 " to %" PRId64 ", nodeUpdate trigger by s-task:0x%" PRIx64, pTaskEntry->nodeId, pTaskEntry->stage, stage, pTaskEntry->id.taskId); @@ -52,7 +56,7 @@ void addIntoCheckpointList(SArray *pList, const SFailedCheckpointInfo *pInfo) { int32_t num = taosArrayGetSize(pList); for (int32_t i = 0; i < num; ++i) { SFailedCheckpointInfo *p = taosArrayGet(pList, i); - if (p->transId == pInfo->transId) { + if (p && (p->transId == pInfo->transId)) { return; } } @@ -94,7 +98,7 @@ int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream) { } code = mndTransPrepare(pMnode, pTrans); - if (code != 0) { + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -104,15 +108,110 @@ int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream) { sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); - return TSDB_CODE_ACTION_IN_PROGRESS; + return code; } -int32_t mndResetStatusFromCheckpoint(SMnode *pMnode, int64_t streamId, int32_t transId) { - int32_t code = TSDB_CODE_SUCCESS; - mndKillTransImpl(pMnode, transId, ""); +int32_t mndSendResetFromCheckpointMsg(SMnode *pMnode, int64_t streamId, int32_t transId) { + int32_t size = sizeof(SStreamTaskResetMsg); + int32_t num = taosArrayGetSize(execInfo.pKilledChkptTrans); + for(int32_t i = 0; i < num; ++i) { + SStreamTaskResetMsg* p = taosArrayGet(execInfo.pKilledChkptTrans, i); + if (p == NULL) { + continue; + } + + if (p->transId == transId && p->streamId == streamId) { + mDebug("already reset stream:0x%" PRIx64 ", not send reset-msg again for transId:%d", streamId, transId); + return TSDB_CODE_SUCCESS; + } + } + + if (num >= 10) { + taosArrayRemove(execInfo.pKilledChkptTrans, 0); // remove this first, append new reset trans in the tail + } + + SStreamTaskResetMsg p = {.streamId = streamId, .transId = transId}; + + void *px = taosArrayPush(execInfo.pKilledChkptTrans, &p); + if (px == NULL) { + mError("failed to push reset-msg trans:%d into the killed chkpt trans list, size:%d", transId, num - 1); + return terrno; + } + + SStreamTaskResetMsg *pReq = rpcMallocCont(size); + if (pReq == NULL) { + return terrno; + } + + pReq->streamId = streamId; + pReq->transId = transId; + + SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_TASK_RESET, .pCont = pReq, .contLen = size}; + int32_t code = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + if (code) { + mError("failed to put reset-task msg into write queue, code:%s", tstrerror(code)); + } else { + mDebug("send reset task status msg for transId:%d succ", transId); + } + + return code; +} + +int32_t mndStreamSendUpdateChkptInfoMsg(SMnode *pMnode) { // here reuse the doCheckpointmsg + int32_t size = sizeof(SMStreamDoCheckpointMsg); + void *pMsg = rpcMallocCont(size); + if (pMsg == NULL) { + return terrno; + } + + SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_UPDATE_CHKPT_EVT, .pCont = pMsg, .contLen = size}; + int32_t code = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + if (code) { + mError("failed to put update-checkpoint-info msg into write queue, code:%s", tstrerror(code)); + } else { + mDebug("send update checkpoint-info msg succ"); + } + + return code; +} + +int32_t mndSendDropOrphanTasksMsg(SMnode *pMnode, SArray *pList) { + SMStreamDropOrphanMsg msg = {.pList = pList}; + + int32_t num = taosArrayGetSize(pList); + int32_t contLen = tSerializeDropOrphanTaskMsg(NULL, 0, &msg); + if (contLen <= 0) { + return terrno; + } + + void *pReq = rpcMallocCont(contLen); + if (pReq == NULL) { + return terrno; + } + + (void)tSerializeDropOrphanTaskMsg(pReq, contLen, &msg); + + SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_DROP_ORPHANTASKS, .pCont = pReq, .contLen = contLen}; + int32_t code = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + if (code) { + mError("failed to put drop-orphan task msg into write queue, code:%s", tstrerror(code)); + } else { + mDebug("send drop %d orphan tasks msg succ", num); + } + + return code; +} + +int32_t mndProcessResetStatusReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + int32_t code = TSDB_CODE_SUCCESS; SStreamObj *pStream = NULL; - code = mndGetStreamObj(pMnode, streamId, &pStream); + + SStreamTaskResetMsg* pMsg = pReq->pCont; + mndKillTransImpl(pMnode, pMsg->transId, ""); + + code = mndGetStreamObj(pMnode, pMsg->streamId, &pStream); if (pStream == NULL || code != 0) { code = TSDB_CODE_STREAM_TASK_NOT_EXIST; mError("failed to acquire the streamObj:0x%" PRIx64 " to reset checkpoint, may have been dropped", pStream->uid); @@ -123,7 +222,7 @@ int32_t mndResetStatusFromCheckpoint(SMnode *pMnode, int64_t streamId, int32_t t pStream->sourceDb, pStream->targetSTbName); } else { mDebug("stream:%s (0x%" PRIx64 ") reset checkpoint procedure, transId:%d, create reset trans", pStream->name, - pStream->uid, transId); + pStream->uid, pMsg->transId); code = mndCreateStreamResetStatusTrans(pMnode, pStream); } } @@ -138,6 +237,10 @@ int32_t setNodeEpsetExpiredFlag(const SArray *pNodeList) { for (int k = 0; k < num; ++k) { int32_t *pVgId = taosArrayGet(pNodeList, k); + if (pVgId == NULL) { + continue; + } + mInfo("set node expired for nodeId:%d, total:%d", *pVgId, num); bool setFlag = false; @@ -145,8 +248,7 @@ int32_t setNodeEpsetExpiredFlag(const SArray *pNodeList) { for (int i = 0; i < numOfNodes; ++i) { SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); - - if (pNodeEntry->nodeId == *pVgId) { + if ((pNodeEntry) && (pNodeEntry->nodeId == *pVgId)) { mInfo("vgId:%d expired for some stream tasks, needs update nodeEp", *pVgId); pNodeEntry->stageUpdated = true; setFlag = true; @@ -162,51 +264,6 @@ int32_t setNodeEpsetExpiredFlag(const SArray *pNodeList) { return TSDB_CODE_SUCCESS; } -int32_t mndDropOrphanTasks(SMnode *pMnode, SArray *pList) { - SOrphanTask *pTask = taosArrayGet(pList, 0); - - // check if it is conflict with other trans in both sourceDb and targetDb. - bool conflict = mndStreamTransConflictCheck(pMnode, pTask->streamId, MND_STREAM_DROP_NAME, false); - if (conflict) { - return -1; - } - - SStreamObj dummyObj = {.uid = pTask->streamId, .sourceDb = "", .targetSTbName = ""}; - STrans *pTrans = NULL; - int32_t code = - doCreateTrans(pMnode, &dummyObj, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans); - if (pTrans == NULL || code != 0) { - mError("failed to create trans to drop orphan tasks since %s", terrstr()); - return code; - } - - code = mndStreamRegisterTrans(pTrans, MND_STREAM_DROP_NAME, pTask->streamId); - if (code) { - return code; - } - // drop all tasks - if ((code = mndStreamSetDropActionFromList(pMnode, pTrans, pList)) < 0) { - mError("failed to create trans to drop orphan tasks since %s", terrstr()); - mndTransDrop(pTrans); - return code; - } - - // drop stream - if ((code = mndPersistTransLog(&dummyObj, pTrans, SDB_STATUS_DROPPED)) < 0) { - mndTransDrop(pTrans); - return code; - } - - if ((code = mndTransPrepare(pMnode, pTrans)) != 0) { - mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return code; - } - - mndTransDrop(pTrans); - return code; -} - int32_t suspendAllStreams(SMnode *pMnode, SRpcHandleInfo *info) { SSdb *pSdb = pMnode->pSdb; SStreamObj *pStream = NULL; @@ -258,7 +315,7 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { SStreamHbMsg req = {0}; SArray *pFailedChkpt = NULL; SArray *pOrphanTasks = NULL; - int32_t code = 0; + int32_t code = 0; if ((code = grantCheckExpire(TSDB_GRANT_STREAMS)) < 0) { if (suspendAllStreams(pMnode, &pReq->info) < 0) { @@ -272,8 +329,7 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { if (tDecodeStreamHbMsg(&decoder, &req) < 0) { tCleanupStreamHbMsg(&req); tDecoderClear(&decoder); - code = terrno = TSDB_CODE_INVALID_MSG; - return code; + TAOS_RETURN(TSDB_CODE_INVALID_MSG); } tDecoderClear(&decoder); @@ -281,6 +337,11 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { pFailedChkpt = taosArrayInit(4, sizeof(SFailedCheckpointInfo)); pOrphanTasks = taosArrayInit(4, sizeof(SOrphanTask)); + if (pFailedChkpt == NULL || pOrphanTasks == NULL) { + taosArrayDestroy(pFailedChkpt); + taosArrayDestroy(pOrphanTasks); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } streamMutexLock(&execInfo.lock); @@ -288,12 +349,11 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { if (!validateHbMsg(execInfo.pNodeList, req.vgId)) { mError("vgId:%d not exists in nodeList buf, discarded", req.vgId); - code = terrno = TSDB_CODE_INVALID_MSG; doSendHbMsgRsp(terrno, &pReq->info, req.vgId, req.msgId); streamMutexUnlock(&execInfo.lock); cleanupAfterProcessHbMsg(&req, pFailedChkpt, pOrphanTasks); - return code; + TAOS_RETURN(TSDB_CODE_INVALID_MSG); } int32_t numOfUpdated = taosArrayGetSize(req.pUpdateNodes); @@ -305,15 +365,18 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { bool snodeChanged = false; for (int32_t i = 0; i < req.numOfTasks; ++i) { STaskStatusEntry *p = taosArrayGet(req.pTaskStatus, i); + if (p == NULL) { + continue; + } STaskStatusEntry *pTaskEntry = taosHashGet(execInfo.pTaskMap, &p->id, sizeof(p->id)); if (pTaskEntry == NULL) { - mError("s-task:0x%" PRIx64 " not found in mnode task list", p->id.taskId); + mError("s-task:0x%" PRIx64 " not found in mnode task list, added into orphan task list", p->id.taskId); SOrphanTask oTask = {.streamId = p->id.streamId, .taskId = p->id.taskId, .nodeId = p->nodeId}; void* px = taosArrayPush(pOrphanTasks, &oTask); if (px == NULL) { - mError("Failed to put task into list, taskId:0x%" PRIx64, p->id.taskId); + mError("failed to put task into list, taskId:0x%" PRIx64, p->id.taskId); } continue; } @@ -330,13 +393,12 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { SStreamObj *pStream = NULL; code = mndGetStreamObj(pMnode, p->id.streamId, &pStream); if (code) { - code = TSDB_CODE_STREAM_TASK_NOT_EXIST; continue; } int32_t numOfTasks = mndGetNumOfStreamTasks(pStream); - SCheckpointConsensusInfo *pInfo = NULL; + SCheckpointConsensusInfo *pInfo = NULL; code = mndGetConsensusInfo(execInfo.pStreamConsensus, p->id.streamId, numOfTasks, &pInfo); if (code == 0) { mndAddConsensusTasks(pInfo, &cp); @@ -356,7 +418,7 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { streamTaskStatusCopy(pTaskEntry, p); if ((pChkInfo->activeId != 0) && pChkInfo->failed) { - mError("stream task:0x%" PRIx64 " checkpointId:%" PRIx64 " transId:%d failed, kill it", p->id.taskId, + mError("stream task:0x%" PRIx64 " checkpointId:%" PRId64 " transId:%d failed, kill it", p->id.taskId, pChkInfo->activeId, pChkInfo->activeTransId); SFailedCheckpointInfo info = { @@ -371,13 +433,6 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { } } - if (p->status == pTaskEntry->status) { - pTaskEntry->statusLastDuration++; - } else { - pTaskEntry->status = p->status; - pTaskEntry->statusLastDuration = 0; - } - if (p->status != TASK_STATUS__READY) { mDebug("received s-task:0x%" PRIx64 " not in ready status:%s", p->id.taskId, streamTaskGetStatusStr(p->status)); } @@ -390,7 +445,6 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { if (pMnode != NULL) { SArray *p = NULL; - code = mndTakeVgroupSnapshot(pMnode, &allReady, &p); taosArrayDestroy(p); if (code) { @@ -404,10 +458,14 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { // if the execInfo.activeCheckpoint == 0, the checkpoint is restoring from wal for (int32_t i = 0; i < taosArrayGetSize(pFailedChkpt); ++i) { SFailedCheckpointInfo *pInfo = taosArrayGet(pFailedChkpt, i); + if (pInfo == NULL) { + continue; + } + mInfo("checkpointId:%" PRId64 " transId:%d failed, issue task-reset trans to reset all tasks status", pInfo->checkpointId, pInfo->transId); - code = mndResetStatusFromCheckpoint(pMnode, pInfo->streamUid, pInfo->transId); + code = mndSendResetFromCheckpointMsg(pMnode, pInfo->streamUid, pInfo->transId); if (code) { mError("failed to create reset task trans, code:%s", tstrerror(code)); } @@ -419,11 +477,14 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { // handle the orphan tasks that are invalid but not removed in some vnodes or snode due to some unknown errors. if (taosArrayGetSize(pOrphanTasks) > 0) { - code = mndDropOrphanTasks(pMnode, pOrphanTasks); + code = mndSendDropOrphanTasksMsg(pMnode, pOrphanTasks); + if (code) { + mError("failed to send drop orphan tasks msg, code:%s, try next time", tstrerror(code)); + } } if (pMnode != NULL) { // make sure that the unit test case can work - mndStreamStartUpdateCheckpointInfo(pMnode); + mndStreamSendUpdateChkptInfoMsg(pMnode); } streamMutexUnlock(&execInfo.lock); @@ -434,22 +495,10 @@ int32_t mndProcessStreamHb(SRpcMsg *pReq) { return code; } -void mndStreamStartUpdateCheckpointInfo(SMnode *pMnode) { // here reuse the doCheckpointmsg - SMStreamDoCheckpointMsg *pMsg = rpcMallocCont(sizeof(SMStreamDoCheckpointMsg)); - if (pMsg != NULL) { - int32_t size = sizeof(SMStreamDoCheckpointMsg); - SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_UPDATE_CHKPT_EVT, .pCont = pMsg, .contLen = size}; - int32_t code = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); - if (code) { - mError("failed to put into write Queue, code:%s", tstrerror(code)); - } - } -} - bool validateHbMsg(const SArray *pNodeList, int32_t vgId) { for (int32_t i = 0; i < taosArrayGetSize(pNodeList); ++i) { SNodeEntry *pEntry = taosArrayGet(pNodeList, i); - if (pEntry->nodeId == vgId) { + if ((pEntry) && (pEntry->nodeId == vgId)) { return true; } } diff --git a/source/dnode/mnode/impl/src/mndStreamTrans.c b/source/dnode/mnode/impl/src/mndStreamTrans.c index 54f4189194..414cd402ec 100644 --- a/source/dnode/mnode/impl/src/mndStreamTrans.c +++ b/source/dnode/mnode/impl/src/mndStreamTrans.c @@ -33,6 +33,10 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt) SArray *pList = taosArrayInit(4, sizeof(SKeyInfo)); int32_t num = 0; + if (pList == NULL) { + return terrno; + } + while ((pIter = taosHashIterate(execInfo.transMgmt.pDBTrans, pIter)) != NULL) { SStreamTransInfo *pEntry = (SStreamTransInfo *)pIter; @@ -59,6 +63,10 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt) int32_t size = taosArrayGetSize(pList); for (int32_t i = 0; i < size; ++i) { SKeyInfo *pKey = taosArrayGet(pList, i); + if (pKey == NULL) { + continue; + } + int32_t code = taosHashRemove(execInfo.transMgmt.pDBTrans, pKey->pKey, pKey->keyLen); if (code != 0) { taosArrayDestroy(pList); @@ -167,29 +175,28 @@ int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId) { } int32_t doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnConflct conflict, const char *name, - const char *pMsg, STrans ** pTrans1) { + const char *pMsg, STrans **pTrans1) { *pTrans1 = NULL; terrno = 0; + int32_t code = 0; STrans *p = mndTransCreate(pMnode, TRN_POLICY_RETRY, conflict, pReq, name); if (p == NULL) { - mError("failed to build trans:%s, reason: %s", name, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to build trans:%s, reason: %s", name, tstrerror(terrno)); return terrno; } mInfo("stream:0x%" PRIx64 " start to build trans %s, transId:%d", pStream->uid, pMsg, p->id); mndTransSetDbName(p, pStream->sourceDb, pStream->targetSTbName); - if (mndTransCheckConflict(pMnode, p) != 0) { - terrno = TSDB_CODE_MND_TRANS_CONFLICT; + if ((code = mndTransCheckConflict(pMnode, p)) != 0) { mError("failed to build trans:%s for stream:0x%" PRIx64 " code:%s", name, pStream->uid, tstrerror(terrno)); mndTransDrop(p); - return terrno; + return code; } *pTrans1 = p; - return 0; + return code; } SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index 5a17d659cd..38fddd8bf0 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -17,6 +17,8 @@ #include "mndTrans.h" #include "tmisce.h" #include "mndVgroup.h" +#include "mndStb.h" +#include "mndDb.h" struct SStreamTaskIter { SStreamObj *pStream; @@ -31,7 +33,6 @@ int32_t doRemoveTasks(SStreamExecInfo *pExecNode, STaskId *pRemovedId); int32_t createStreamTaskIter(SStreamObj* pStream, SStreamTaskIter** pIter) { *pIter = taosMemoryCalloc(1, sizeof(SStreamTaskIter)); if (*pIter == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } @@ -87,15 +88,46 @@ void destroyStreamTaskIter(SStreamTaskIter* pIter) { taosMemoryFree(pIter); } -int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList) { - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; - SVgObj *pVgroup = NULL; - int32_t replica = -1; // do the replica check - int32_t code = 0; +static bool checkStatusForEachReplica(SVgObj *pVgroup) { + for (int32_t i = 0; i < pVgroup->replica; ++i) { + if (!pVgroup->vnodeGid[i].syncRestore) { + mInfo("vgId:%d not restored, not ready for checkpoint or other operations", pVgroup->vgId); + return false; + } - *allReady = true; - SArray *pVgroupList = taosArrayInit(4, sizeof(SNodeEntry)); + ESyncState state = pVgroup->vnodeGid[i].syncState; + if (state == TAOS_SYNC_STATE_OFFLINE || state == TAOS_SYNC_STATE_ERROR || state == TAOS_SYNC_STATE_LEARNER || + state == TAOS_SYNC_STATE_CANDIDATE) { + mInfo("vgId:%d state:%d , not ready for checkpoint or other operations, not check other vgroups", pVgroup->vgId, + state); + return false; + } + } + + return true; +} + +int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray **pList) { + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + SVgObj *pVgroup = NULL; + int32_t code = 0; + SArray *pVgroupList = NULL; + SHashObj *pHash = NULL; + + pVgroupList = taosArrayInit(4, sizeof(SNodeEntry)); + if (pVgroupList == NULL) { + mError("failed to prepare arraylist during take vgroup snapshot, code:%s", tstrerror(terrno)); + code = terrno; + goto _err; + } + + pHash = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (pHash == NULL) { + mError("failed to prepare hashmap during take vgroup snapshot, code:%s", tstrerror(terrno)); + code = terrno; + goto _err; + } while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); @@ -106,44 +138,39 @@ int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList) { SNodeEntry entry = {.nodeId = pVgroup->vgId, .hbTimestamp = pVgroup->updateTime}; entry.epset = mndGetVgroupEpset(pMnode, pVgroup); - if (replica == -1) { - replica = pVgroup->replica; - } else { - if (replica != pVgroup->replica) { - mInfo("vgId:%d replica:%d inconsistent with other vgroups replica:%d, not ready for stream operations", - pVgroup->vgId, pVgroup->replica, replica); - *allReady = false; + int8_t *pReplica = taosHashGet(pHash, &pVgroup->dbUid, sizeof(pVgroup->dbUid)); + if (pReplica == NULL) { // not exist, add it into hash map + code = taosHashPut(pHash, &pVgroup->dbUid, sizeof(pVgroup->dbUid), &pVgroup->replica, sizeof(pVgroup->replica)); + if (code) { + mError("failed to put info into hashmap during task vgroup snapshot, code:%s", tstrerror(code)); sdbRelease(pSdb, pVgroup); - break; + sdbCancelFetch(pSdb, pIter); + goto _err; // take snapshot failed, and not all ready + } + } else { + if (*pReplica != pVgroup->replica) { + mInfo("vgId:%d replica:%d inconsistent with other vgroups replica:%d, not ready for stream operations", + pVgroup->vgId, pVgroup->replica, *pReplica); + *allReady = false; // task snap success, but not all ready } } // if not all ready till now, no need to check the remaining vgroups. + // but still we need to put the info of the existed vgroups into the snapshot list if (*allReady) { - for (int32_t i = 0; i < pVgroup->replica; ++i) { - if (!pVgroup->vnodeGid[i].syncRestore) { - mInfo("vgId:%d not restored, not ready for checkpoint or other operations", pVgroup->vgId); - *allReady = false; - break; - } - - ESyncState state = pVgroup->vnodeGid[i].syncState; - if (state == TAOS_SYNC_STATE_OFFLINE || state == TAOS_SYNC_STATE_ERROR || state == TAOS_SYNC_STATE_LEARNER || - state == TAOS_SYNC_STATE_CANDIDATE) { - mInfo("vgId:%d state:%d , not ready for checkpoint or other operations, not check other vgroups", - pVgroup->vgId, state); - *allReady = false; - break; - } - } + *allReady = checkStatusForEachReplica(pVgroup); } char buf[256] = {0}; - (void) epsetToStr(&entry.epset, buf, tListLen(buf)); + (void)epsetToStr(&entry.epset, buf, tListLen(buf)); - void* p = taosArrayPush(pVgroupList, &entry); + void *p = taosArrayPush(pVgroupList, &entry); if (p == NULL) { mError("failed to put entry in vgroup list, nodeId:%d code:out of memory", entry.nodeId); + code = terrno; + sdbRelease(pSdb, pVgroup); + sdbCancelFetch(pSdb, pIter); + goto _err; } else { mDebug("take node snapshot, nodeId:%d %s", entry.nodeId, buf); } @@ -162,15 +189,21 @@ int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList) { code = addEpIntoEpSet(&entry.epset, pObj->pDnode->fqdn, pObj->pDnode->port); if (code) { sdbRelease(pSdb, pObj); - continue; + sdbCancelFetch(pSdb, pIter); + mError("failed to extract epset for fqdn:%s during task vgroup snapshot", pObj->pDnode->fqdn); + goto _err; } char buf[256] = {0}; - (void) epsetToStr(&entry.epset, buf, tListLen(buf)); + (void)epsetToStr(&entry.epset, buf, tListLen(buf)); - void* p = taosArrayPush(pVgroupList, &entry); + void *p = taosArrayPush(pVgroupList, &entry); if (p == NULL) { - mError("failed to put entry in vgroup list, nodeId:%d code:out of memory", entry.nodeId); + code = terrno; + sdbRelease(pSdb, pObj); + sdbCancelFetch(pSdb, pIter); + mError("failed to put entry in vgroup list, nodeId:%d code:%s", entry.nodeId, tstrerror(code)); + goto _err; } else { mDebug("take snode snapshot, nodeId:%d %s", entry.nodeId, buf); } @@ -179,6 +212,14 @@ int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList) { } *pList = pVgroupList; + taosHashCleanup(pHash); + return code; + +_err: + *allReady = false; + taosArrayDestroy(pVgroupList); + taosHashCleanup(pHash); + return code; } @@ -511,6 +552,10 @@ static int32_t doSetDropActionFromId(SMnode *pMnode, STrans *pTrans, SOrphanTask int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray* pList) { for(int32_t i = 0; i < taosArrayGetSize(pList); ++i) { SOrphanTask* pTask = taosArrayGet(pList, i); + if (pTask == NULL) { + return terrno; + } + int32_t code = doSetDropActionFromId(pMnode, pTrans, pTask); if (code != 0) { return code; @@ -530,8 +575,8 @@ static void initNodeUpdateMsg(SStreamTaskNodeUpdateMsg *pMsg, const SVgroupChang pMsg->transId = transId; pMsg->pNodeList = taosArrayInit(taosArrayGetSize(pInfo->pUpdateNodeList), sizeof(SNodeUpdateInfo)); if (pMsg->pNodeList == NULL) { - mError("failed to prepare node list, code:out of memory"); - code = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to prepare node list, code:%s", tstrerror(terrno)); + code = terrno; } if (code == 0) { @@ -561,7 +606,6 @@ static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupCha void *buf = taosMemoryMalloc(tlen); if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; taosArrayDestroy(req.pNodeList); return terrno; } @@ -592,12 +636,9 @@ static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupCha static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, SVgroupChangeInfo *pInfo) { void *pBuf = NULL; int32_t len = 0; - int32_t code = streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); - if (code) { - return code; - } + (void)streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); - code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); + int32_t code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); if (code) { return code; } @@ -655,9 +696,8 @@ int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgro static int32_t doSetResetAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { SVResetStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResetStreamTaskReq)); if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVResetStreamTaskReq), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tstrerror(terrno)); return terrno; } @@ -734,6 +774,14 @@ int32_t mndInitExecInfo() { execInfo.pChkptStreams = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); execInfo.pStreamConsensus = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); execInfo.pNodeList = taosArrayInit(4, sizeof(SNodeEntry)); + execInfo.pKilledChkptTrans = taosArrayInit(4, sizeof(SStreamTaskResetMsg)); + + if (execInfo.pTaskList == NULL || execInfo.pTaskMap == NULL || execInfo.transMgmt.pDBTrans == NULL || + execInfo.pTransferStateStreams == NULL || execInfo.pChkptStreams == NULL || execInfo.pStreamConsensus == NULL || + execInfo.pNodeList == NULL || execInfo.pKilledChkptTrans == NULL) { + mError("failed to initialize the stream runtime env, code:%s", tstrerror(terrno)); + return terrno; + } taosHashSetFreeFp(execInfo.pTransferStateStreams, freeTaskList); taosHashSetFreeFp(execInfo.pChkptStreams, freeTaskList); @@ -743,14 +791,25 @@ int32_t mndInitExecInfo() { void removeExpiredNodeInfo(const SArray *pNodeSnapshot) { SArray *pValidList = taosArrayInit(4, sizeof(SNodeEntry)); + if (pValidList == NULL) { // not continue + return; + } + int32_t size = taosArrayGetSize(pNodeSnapshot); int32_t oldSize = taosArrayGetSize(execInfo.pNodeList); for (int32_t i = 0; i < oldSize; ++i) { SNodeEntry *p = taosArrayGet(execInfo.pNodeList, i); + if (p == NULL) { + continue; + } for (int32_t j = 0; j < size; ++j) { SNodeEntry *pEntry = taosArrayGet(pNodeSnapshot, j); + if (pEntry == NULL) { + continue; + } + if (pEntry->nodeId == p->nodeId) { void* px = taosArrayPush(pValidList, p); if (px == NULL) { @@ -781,6 +840,10 @@ int32_t doRemoveTasks(SStreamExecInfo *pExecNode, STaskId *pRemovedId) { for (int32_t k = 0; k < taosArrayGetSize(pExecNode->pTaskList); ++k) { STaskId *pId = taosArrayGet(pExecNode->pTaskList, k); + if (pId == NULL) { + continue; + } + if (pId->taskId == pRemovedId->taskId && pId->streamId == pRemovedId->streamId) { taosArrayRemove(pExecNode->pTaskList, k); @@ -796,6 +859,10 @@ int32_t doRemoveTasks(SStreamExecInfo *pExecNode, STaskId *pRemovedId) { void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo* pExecInfo) { for (int32_t i = 0; i < taosArrayGetSize(pTaskIds); ++i) { STaskId *pId = taosArrayGet(pTaskIds, i); + if (pId == NULL) { + continue; + } + int32_t code = doRemoveTasks(pExecInfo, pId); if (code) { mError("failed to remove task in buffer list, 0x%"PRIx64, pId->taskId); @@ -843,6 +910,10 @@ static bool taskNodeExists(SArray *pList, int32_t nodeId) { for (int32_t i = 0; i < num; ++i) { SNodeEntry *pEntry = taosArrayGet(pList, i); + if (pEntry == NULL) { + continue; + } + if (pEntry->nodeId == nodeId) { return true; } @@ -853,12 +924,22 @@ static bool taskNodeExists(SArray *pList, int32_t nodeId) { int32_t removeExpiredNodeEntryAndTaskInBuf(SArray *pNodeSnapshot) { SArray *pRemovedTasks = taosArrayInit(4, sizeof(STaskId)); + if (pRemovedTasks == NULL) { + return terrno; + } int32_t numOfTask = taosArrayGetSize(execInfo.pTaskList); for (int32_t i = 0; i < numOfTask; ++i) { STaskId *pId = taosArrayGet(execInfo.pTaskList, i); + if (pId == NULL) { + continue; + } STaskStatusEntry *pEntry = taosHashGet(execInfo.pTaskMap, pId, sizeof(*pId)); + if (pEntry == NULL) { + continue; + } + if (pEntry->nodeId == SNODE_HANDLE) { continue; } @@ -902,6 +983,10 @@ static int32_t doSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamTas int32_t size = taosArrayGetSize(*pReqTaskList); for(int32_t i = 0; i < size; ++i) { STaskChkptInfo* pInfo = taosArrayGet(*pReqTaskList, i); + if (pInfo == NULL) { + continue; + } + if (pInfo->taskId == pTask->id.taskId) { pReq->checkpointId = pInfo->checkpointId; pReq->checkpointVer = pInfo->version; @@ -965,8 +1050,11 @@ int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; void *pIter = NULL; - SArray *pDropped = taosArrayInit(4, sizeof(int64_t)); int32_t code = 0; + SArray *pDropped = taosArrayInit(4, sizeof(int64_t)); + if (pDropped == NULL) { + return terrno; + } mDebug("start to scan checkpoint report info"); @@ -974,11 +1062,15 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { SArray *pList = *(SArray **)pIter; STaskChkptInfo *pInfo = taosArrayGet(pList, 0); - SStreamObj *pStream = NULL; + if (pInfo == NULL) { + continue; + } + + SStreamObj *pStream = NULL; code = mndGetStreamObj(pMnode, pInfo->streamId, &pStream); if (pStream == NULL || code != 0) { mDebug("failed to acquire stream:0x%" PRIx64 " remove it from checkpoint-report list", pInfo->streamId); - void* p = taosArrayPush(pDropped, &pInfo->streamId); + void *p = taosArrayPush(pDropped, &pInfo->streamId); if (p == NULL) { mError("failed to put stream into drop list:0x%" PRIx64, pInfo->streamId); } @@ -1022,10 +1114,14 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { int32_t size = taosArrayGetSize(pDropped); if (size > 0) { for (int32_t i = 0; i < size; ++i) { - int64_t streamId = *(int64_t *)taosArrayGet(pDropped, i); - code = taosHashRemove(execInfo.pChkptStreams, &streamId, sizeof(streamId)); + int64_t* pStreamId = (int64_t *)taosArrayGet(pDropped, i); + if (pStreamId == NULL) { + continue; + } + + code = taosHashRemove(execInfo.pChkptStreams, pStreamId, sizeof(*pStreamId)); if (code) { - mError("failed to remove stream in buf:0x%"PRIx64, streamId); + mError("failed to remove stream in buf:0x%"PRIx64, *pStreamId); } } @@ -1051,14 +1147,14 @@ static int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStream int32_t blen; tEncodeSize(tEncodeRestoreCheckpointInfo, &req, blen, code); if (code < 0) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t tlen = sizeof(SMsgHead) + blen; void *pBuf = taosMemoryMalloc(tlen); if (pBuf == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void *abuf = POINTER_SHIFT(pBuf, sizeof(SMsgHead)); @@ -1132,7 +1228,7 @@ int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, i } code = mndTransPrepare(pMnode, pTrans); - if (code) { + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("trans:%d, failed to prepare set consensus-chkptId trans since %s", pTrans->id, terrstr()); sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); @@ -1160,6 +1256,10 @@ int32_t mndGetConsensusInfo(SHashObj* pHash, int64_t streamId, int32_t numOfTask .streamId = streamId, }; + if (p.pTaskList == NULL) { + return terrno; + } + int32_t code = taosHashPut(pHash, &streamId, sizeof(streamId), &p, sizeof(p)); if (code == 0) { void *pChkptInfo = (SCheckpointConsensusInfo *)taosHashGet(pHash, &streamId, sizeof(streamId)); @@ -1167,6 +1267,7 @@ int32_t mndGetConsensusInfo(SHashObj* pHash, int64_t streamId, int32_t numOfTask } else { *pInfo = NULL; } + return code; } @@ -1178,6 +1279,10 @@ void mndAddConsensusTasks(SCheckpointConsensusInfo *pInfo, const SRestoreCheckpo for (int32_t i = 0; i < taosArrayGetSize(pInfo->pTaskList); ++i) { SCheckpointConsensusEntry *p = taosArrayGet(pInfo->pTaskList, i); + if (p == NULL) { + continue; + } + if (p->req.taskId == info.req.taskId) { mDebug("s-task:0x%x already in consensus-checkpointId list for stream:0x%" PRIx64 ", update ts %" PRId64 "->%" PRId64 " total existed:%d", @@ -1218,5 +1323,491 @@ int64_t mndClearConsensusCheckpointId(SHashObj* pHash, int64_t streamId) { mError("failed to remove stream:0x%"PRIx64" in consensus-checkpointId list, remain:%d", streamId, numOfStreams); } + return code; +} + +static void mndShowStreamStatus(char *dst, SStreamObj *pStream) { + int8_t status = atomic_load_8(&pStream->status); + if (status == STREAM_STATUS__NORMAL) { + strcpy(dst, "ready"); + } else if (status == STREAM_STATUS__STOP) { + strcpy(dst, "stop"); + } else if (status == STREAM_STATUS__FAILED) { + strcpy(dst, "failed"); + } else if (status == STREAM_STATUS__RECOVER) { + strcpy(dst, "recover"); + } else if (status == STREAM_STATUS__PAUSE) { + strcpy(dst, "paused"); + } +} + +static void mndShowStreamTrigger(char *dst, SStreamObj *pStream) { + int8_t trigger = pStream->conf.trigger; + if (trigger == STREAM_TRIGGER_AT_ONCE) { + strcpy(dst, "at once"); + } else if (trigger == STREAM_TRIGGER_WINDOW_CLOSE) { + strcpy(dst, "window close"); + } else if (trigger == STREAM_TRIGGER_MAX_DELAY) { + strcpy(dst, "max delay"); + } +} + +static void int64ToHexStr(int64_t id, char *pBuf, int32_t bufLen) { + memset(pBuf, 0, bufLen); + pBuf[2] = '0'; + pBuf[3] = 'x'; + + int32_t len = tintToHex(id, &pBuf[4]); + varDataSetLen(pBuf, len + 2); +} + +int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows) { + int32_t code = 0; + int32_t cols = 0; + int32_t lino = 0; + + char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName)); + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)streamName, false); + TSDB_CHECK_CODE(code, lino, _end); + + // create time + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pStream->createTime, false); + TSDB_CHECK_CODE(code, lino, _end); + + // stream id + char buf[128] = {0}; + int64ToHexStr(pStream->uid, buf, tListLen(buf)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + code = colDataSetVal(pColInfo, numOfRows, buf, false); + TSDB_CHECK_CODE(code, lino, _end); + + // related fill-history stream id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + if (pStream->hTaskUid != 0) { + int64ToHexStr(pStream->hTaskUid, buf, tListLen(buf)); + code = colDataSetVal(pColInfo, numOfRows, buf, false); + } else { + code = colDataSetVal(pColInfo, numOfRows, buf, true); + } + TSDB_CHECK_CODE(code, lino, _end); + + // related fill-history stream id + char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(sql, pStream->sql, sizeof(sql)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + code = colDataSetVal(pColInfo, numOfRows, (const char *)sql, false); + TSDB_CHECK_CODE(code, lino, _end); + + char status[20 + VARSTR_HEADER_SIZE] = {0}; + char status2[20] = {0}; + mndShowStreamStatus(status2, pStream); + STR_WITH_MAXSIZE_TO_VARSTR(status, status2, sizeof(status)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&status, false); + TSDB_CHECK_CODE(code, lino, _end); + + char sourceDB[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(sourceDB, mndGetDbStr(pStream->sourceDb), sizeof(sourceDB)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&sourceDB, false); + TSDB_CHECK_CODE(code, lino, _end); + + char targetDB[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(targetDB, mndGetDbStr(pStream->targetDb), sizeof(targetDB)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&targetDB, false); + TSDB_CHECK_CODE(code, lino, _end); + + if (pStream->targetSTbName[0] == 0) { + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, NULL, true); + } else { + char targetSTB[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(targetSTB, mndGetStbStr(pStream->targetSTbName), sizeof(targetSTB)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&targetSTB, false); + } + TSDB_CHECK_CODE(code, lino, _end); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pStream->conf.watermark, false); + TSDB_CHECK_CODE(code, lino, _end); + + char trigger[20 + VARSTR_HEADER_SIZE] = {0}; + char trigger2[20] = {0}; + mndShowStreamTrigger(trigger2, pStream); + STR_WITH_MAXSIZE_TO_VARSTR(trigger, trigger2, sizeof(trigger)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&trigger, false); + TSDB_CHECK_CODE(code, lino, _end); + + // sink_quota + char sinkQuota[20 + VARSTR_HEADER_SIZE] = {0}; + sinkQuota[0] = '0'; + char dstStr[20] = {0}; + STR_TO_VARSTR(dstStr, sinkQuota) + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)dstStr, false); + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint interval + char tmp[20 + VARSTR_HEADER_SIZE] = {0}; + sprintf(varDataVal(tmp), "%d sec", tsStreamCheckpointInterval); + varDataSetLen(tmp, strlen(varDataVal(tmp))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)tmp, false); + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint backup type + char backup[20 + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(backup, "none") + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)backup, false); + TSDB_CHECK_CODE(code, lino, _end); + + // history scan idle + char scanHistoryIdle[20 + VARSTR_HEADER_SIZE] = {0}; + strcpy(scanHistoryIdle, "100a"); + + memset(dstStr, 0, tListLen(dstStr)); + STR_TO_VARSTR(dstStr, scanHistoryIdle) + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)dstStr, false); + +_end: + if (code) { + mError("error happens when build stream attr result block, lino:%d, code:%s", lino, tstrerror(code)); + } + return code; +} + +int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlock *pBlock, int32_t numOfRows) { + SColumnInfoData *pColInfo = NULL; + int32_t cols = 0; + int32_t code = 0; + int32_t lino = 0; + + STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId}; + + STaskStatusEntry *pe = taosHashGet(execInfo.pTaskMap, &id, sizeof(id)); + if (pe == NULL) { + mError("task:0x%" PRIx64 " not exists in any vnodes, streamName:%s, streamId:0x%" PRIx64 " createTs:%" PRId64 + " no valid status/stage info", + id.taskId, pStream->name, pStream->uid, pStream->createTime); + return TSDB_CODE_STREAM_TASK_NOT_EXIST; + } + + // stream name + char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName)); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)streamName, false); + TSDB_CHECK_CODE(code, lino, _end); + + // task id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + char idstr[128] = {0}; + int64ToHexStr(pTask->id.taskId, idstr, tListLen(idstr)); + code = colDataSetVal(pColInfo, numOfRows, idstr, false); + TSDB_CHECK_CODE(code, lino, _end); + + // node type + char nodeType[20 + VARSTR_HEADER_SIZE] = {0}; + varDataSetLen(nodeType, 5); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + if (pTask->info.nodeId > 0) { + memcpy(varDataVal(nodeType), "vnode", 5); + } else { + memcpy(varDataVal(nodeType), "snode", 5); + } + code = colDataSetVal(pColInfo, numOfRows, nodeType, false); + TSDB_CHECK_CODE(code, lino, _end); + + // node id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + int64_t nodeId = TMAX(pTask->info.nodeId, 0); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&nodeId, false); + TSDB_CHECK_CODE(code, lino, _end); + + // level + char level[20 + VARSTR_HEADER_SIZE] = {0}; + if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { + memcpy(varDataVal(level), "source", 6); + varDataSetLen(level, 6); + } else if (pTask->info.taskLevel == TASK_LEVEL__AGG) { + memcpy(varDataVal(level), "agg", 3); + varDataSetLen(level, 3); + } else if (pTask->info.taskLevel == TASK_LEVEL__SINK) { + memcpy(varDataVal(level), "sink", 4); + varDataSetLen(level, 4); + } + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)level, false); + TSDB_CHECK_CODE(code, lino, _end); + + // status + char status[20 + VARSTR_HEADER_SIZE] = {0}; + + const char *pStatus = streamTaskGetStatusStr(pe->status); + STR_TO_VARSTR(status, pStatus); + + // status + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)status, false); + TSDB_CHECK_CODE(code, lino, _end); + + // stage + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->stage, false); + TSDB_CHECK_CODE(code, lino, _end); + + // input queue + char vbuf[40] = {0}; + char buf[38] = {0}; + const char *queueInfoStr = "%4.2f MiB (%6.2f%)"; + snprintf(buf, tListLen(buf), queueInfoStr, pe->inputQUsed, pe->inputRate); + STR_TO_VARSTR(vbuf, buf); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + + // input total + const char *formatTotalMb = "%7.2f MiB"; + const char *formatTotalGb = "%7.2f GiB"; + if (pe->procsTotal < 1024) { + snprintf(buf, tListLen(buf), formatTotalMb, pe->procsTotal); + } else { + snprintf(buf, tListLen(buf), formatTotalGb, pe->procsTotal / 1024); + } + + memset(vbuf, 0, tListLen(vbuf)); + STR_TO_VARSTR(vbuf, buf); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + + // process throughput + const char *formatKb = "%7.2f KiB/s"; + const char *formatMb = "%7.2f MiB/s"; + if (pe->procsThroughput < 1024) { + snprintf(buf, tListLen(buf), formatKb, pe->procsThroughput); + } else { + snprintf(buf, tListLen(buf), formatMb, pe->procsThroughput / 1024); + } + + memset(vbuf, 0, tListLen(vbuf)); + STR_TO_VARSTR(vbuf, buf); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + + // output total + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + if (pTask->info.taskLevel == TASK_LEVEL__SINK) { + colDataSetNULL(pColInfo, numOfRows); + } else { + sprintf(buf, formatTotalMb, pe->outputTotal); + memset(vbuf, 0, tListLen(vbuf)); + STR_TO_VARSTR(vbuf, buf); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + } + + // output throughput + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + if (pTask->info.taskLevel == TASK_LEVEL__SINK) { + colDataSetNULL(pColInfo, numOfRows); + } else { + if (pe->outputThroughput < 1024) { + snprintf(buf, tListLen(buf), formatKb, pe->outputThroughput); + } else { + snprintf(buf, tListLen(buf), formatMb, pe->outputThroughput / 1024); + } + + memset(vbuf, 0, tListLen(vbuf)); + STR_TO_VARSTR(vbuf, buf); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + } + + // output queue + // sprintf(buf, queueInfoStr, pe->outputQUsed, pe->outputRate); + // STR_TO_VARSTR(vbuf, buf); + + // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + // colDataSetVal(pColInfo, numOfRows, (const char*)vbuf, false); + + // info + if (pTask->info.taskLevel == TASK_LEVEL__SINK) { + const char *sinkStr = "%.2f MiB"; + snprintf(buf, tListLen(buf), sinkStr, pe->sinkDataSize); + } else if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { + // offset info + const char *offsetStr = "%" PRId64 " [%" PRId64 ", %" PRId64 "]"; + snprintf(buf, tListLen(buf), offsetStr, pe->processedVer, pe->verRange.minVer, pe->verRange.maxVer); + } else { + memset(buf, 0, tListLen(buf)); + } + + STR_TO_VARSTR(vbuf, buf); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)vbuf, false); + TSDB_CHECK_CODE(code, lino, _end); + + // start_time + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startTime, false); + TSDB_CHECK_CODE(code, lino, _end); + + // start id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startCheckpointId, false); + TSDB_CHECK_CODE(code, lino, _end); + + // start ver + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->startCheckpointVer, false); + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint time + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + if (pe->checkpointInfo.latestTime != 0) { + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestTime, false); + } else { + code = colDataSetVal(pColInfo, numOfRows, 0, true); + } + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint_id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestId, false); + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint version + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pe->checkpointInfo.latestVer, false); + TSDB_CHECK_CODE(code, lino, _end); + + // checkpoint size + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + colDataSetNULL(pColInfo, numOfRows); + + // checkpoint backup status + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, 0, true); + TSDB_CHECK_CODE(code, lino, _end); + + // ds_err_info + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, 0, true); + TSDB_CHECK_CODE(code, lino, _end); + + // history_task_id + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + if (pe->hTaskId != 0) { + int64ToHexStr(pe->hTaskId, idstr, tListLen(idstr)); + code = colDataSetVal(pColInfo, numOfRows, idstr, false); + } else { + code = colDataSetVal(pColInfo, numOfRows, 0, true); + } + TSDB_CHECK_CODE(code, lino, _end); + + // history_task_status + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno); + + code = colDataSetVal(pColInfo, numOfRows, 0, true); + TSDB_CHECK_CODE(code, lino, _end); + + _end: + if (code) { + mError("error happens during build task attr result blocks, lino:%d, code:%s", lino, tstrerror(code)); + } return code; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index bb59af2808..585bf5527d 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -27,8 +27,7 @@ #define MND_SUBSCRIBE_VER_NUMBER 3 #define MND_SUBSCRIBE_RESERVE_SIZE 64 -#define MND_CONSUMER_LOST_HB_CNT 6 -#define MND_CONSUMER_LOST_CLEAR_THRESHOLD 43200 +//#define MND_CONSUMER_LOST_HB_CNT 6 static int32_t mqRebInExecCnt = 0; @@ -331,6 +330,7 @@ static int32_t processRemoveAddVgs(SMnode *pMnode, SMqRebOutputObj *pOutput) { int32_t code = 0; int32_t totalVgNum = 0; SVgObj *pVgroup = NULL; + SMqVgEp *pVgEp = NULL; void *pIter = NULL; SArray *newVgs = taosArrayInit(0, POINTER_BYTES); MND_TMQ_NULL_CHECK(newVgs); @@ -346,11 +346,12 @@ static int32_t processRemoveAddVgs(SMnode *pMnode, SMqRebOutputObj *pOutput) { } totalVgNum++; - SMqVgEp *pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); + pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); MND_TMQ_NULL_CHECK(pVgEp); pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup); pVgEp->vgId = pVgroup->vgId; MND_TMQ_NULL_CHECK(taosArrayPush(newVgs, &pVgEp)); + pVgEp = NULL; sdbRelease(pMnode->pSdb, pVgroup); } @@ -361,13 +362,13 @@ static int32_t processRemoveAddVgs(SMnode *pMnode, SMqRebOutputObj *pOutput) { SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; int32_t j = 0; while (j < taosArrayGetSize(pConsumerEp->vgs)) { - SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j); - MND_TMQ_NULL_CHECK(pVgEp); + SMqVgEp *pVgEpTmp = taosArrayGetP(pConsumerEp->vgs, j); + MND_TMQ_NULL_CHECK(pVgEpTmp); bool find = false; for (int32_t k = 0; k < taosArrayGetSize(newVgs); k++) { SMqVgEp *pnewVgEp = taosArrayGetP(newVgs, k); MND_TMQ_NULL_CHECK(pnewVgEp); - if (pVgEp->vgId == pnewVgEp->vgId) { + if (pVgEpTmp->vgId == pnewVgEp->vgId) { tDeleteSMqVgEp(pnewVgEp); taosArrayRemove(newVgs, k); find = true; @@ -375,8 +376,8 @@ static int32_t processRemoveAddVgs(SMnode *pMnode, SMqRebOutputObj *pOutput) { } } if (!find) { - mInfo("[rebalance] processRemoveAddVgs old vgId:%d", pVgEp->vgId); - tDeleteSMqVgEp(pVgEp); + mInfo("[rebalance] processRemoveAddVgs old vgId:%d", pVgEpTmp->vgId); + tDeleteSMqVgEp(pVgEpTmp); taosArrayRemove(pConsumerEp->vgs, j); continue; } @@ -387,12 +388,16 @@ static int32_t processRemoveAddVgs(SMnode *pMnode, SMqRebOutputObj *pOutput) { if (taosArrayGetSize(pOutput->pSub->unassignedVgs) == 0 && taosArrayGetSize(newVgs) != 0) { MND_TMQ_NULL_CHECK(taosArrayAddAll(pOutput->pSub->unassignedVgs, newVgs)); mInfo("[rebalance] processRemoveAddVgs add new vg num:%d", (int)taosArrayGetSize(newVgs)); - (void)taosArrayDestroy(newVgs); + taosArrayDestroy(newVgs); } else { - (void)taosArrayDestroyP(newVgs, (FDelete)tDeleteSMqVgEp); + taosArrayDestroyP(newVgs, (FDelete)tDeleteSMqVgEp); } return totalVgNum; + END: + sdbRelease(pMnode->pSdb, pVgroup); + taosMemoryFree(pVgEp); + taosArrayDestroyP(newVgs, (FDelete)tDeleteSMqVgEp); return code; } @@ -758,32 +763,32 @@ static int32_t mndCheckConsumer(SRpcMsg *pMsg, SHashObj *rebSubHash) { } int32_t hbStatus = atomic_add_fetch_32(&pConsumer->hbStatus, 1); + int32_t pollStatus = atomic_add_fetch_32(&pConsumer->pollStatus, 1); int32_t status = atomic_load_32(&pConsumer->status); mDebug("[rebalance] check for consumer:0x%" PRIx64 " status:%d(%s), sub-time:%" PRId64 ", createTime:%" PRId64 - ", hbstatus:%d", + ", hbstatus:%d, pollStatus:%d", pConsumer->consumerId, status, mndConsumerStatusName(status), pConsumer->subscribeTime, - pConsumer->createTime, hbStatus); + pConsumer->createTime, hbStatus, pollStatus); if (status == MQ_CONSUMER_STATUS_READY) { - if (taosArrayGetSize(pConsumer->assignedTopics) == 0) { // unsubscribe or close + if (taosArrayGetSize(pConsumer->currentTopics) == 0) { // unsubscribe or close MND_TMQ_RETURN_CHECK(mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, &pMsg->info)); - } else if (hbStatus > MND_CONSUMER_LOST_HB_CNT) { + } else if (hbStatus * tsMqRebalanceInterval * 1000 >= pConsumer->sessionTimeoutMs || + pollStatus * tsMqRebalanceInterval * 1000 >= pConsumer->maxPollIntervalMs) { taosRLockLatch(&pConsumer->lock); MND_TMQ_RETURN_CHECK(buildRebInfo(rebSubHash, pConsumer->currentTopics, 0, pConsumer->cgroup, pConsumer->consumerId)); taosRUnLockLatch(&pConsumer->lock); } else { checkForVgroupSplit(pMnode, pConsumer, rebSubHash); } - } else if (status == MQ_CONSUMER_STATUS_LOST) { - if (hbStatus > MND_CONSUMER_LOST_CLEAR_THRESHOLD) { // clear consumer if lost a day - MND_TMQ_RETURN_CHECK(mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, &pMsg->info)); - } - } else { + } else if (status == MQ_CONSUMER_STATUS_REBALANCE) { taosRLockLatch(&pConsumer->lock); MND_TMQ_RETURN_CHECK(buildRebInfo(rebSubHash, pConsumer->rebNewTopics, 1, pConsumer->cgroup, pConsumer->consumerId)); MND_TMQ_RETURN_CHECK(buildRebInfo(rebSubHash, pConsumer->rebRemovedTopics, 0, pConsumer->cgroup, pConsumer->consumerId)); taosRUnLockLatch(&pConsumer->lock); + } else { + MND_TMQ_RETURN_CHECK(mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, &pMsg->info)); } mndReleaseConsumer(pMnode, pConsumer); @@ -1013,37 +1018,37 @@ END: return code; } -static int32_t mndDropConsumerByGroup(SMnode *pMnode, STrans *pTrans, char *cgroup, char *topic) { - void *pIter = NULL; - SMqConsumerObj *pConsumer = NULL; - int code = 0; - while (1) { - pIter = sdbFetch(pMnode->pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); - if (pIter == NULL) { - break; - } - - // drop consumer in lost status, other consumers not in lost status already deleted by rebalance - if (pConsumer->status != MQ_CONSUMER_STATUS_LOST || strcmp(cgroup, pConsumer->cgroup) != 0) { - sdbRelease(pMnode->pSdb, pConsumer); - continue; - } - int32_t sz = taosArrayGetSize(pConsumer->assignedTopics); - for (int32_t i = 0; i < sz; i++) { - char *name = taosArrayGetP(pConsumer->assignedTopics, i); - if (name && strcmp(topic, name) == 0) { - MND_TMQ_RETURN_CHECK(mndSetConsumerDropLogs(pTrans, pConsumer)); - } - } - - sdbRelease(pMnode->pSdb, pConsumer); - } - -END: - sdbRelease(pMnode->pSdb, pConsumer); - sdbCancelFetch(pMnode->pSdb, pIter); - return code; -} +//static int32_t mndDropConsumerByGroup(SMnode *pMnode, STrans *pTrans, char *cgroup, char *topic) { +// void *pIter = NULL; +// SMqConsumerObj *pConsumer = NULL; +// int code = 0; +// while (1) { +// pIter = sdbFetch(pMnode->pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); +// if (pIter == NULL) { +// break; +// } +// +// // drop consumer in lost status, other consumers not in lost status already deleted by rebalance +// if (pConsumer->status != MQ_CONSUMER_STATUS_LOST || strcmp(cgroup, pConsumer->cgroup) != 0) { +// sdbRelease(pMnode->pSdb, pConsumer); +// continue; +// } +// int32_t sz = taosArrayGetSize(pConsumer->assignedTopics); +// for (int32_t i = 0; i < sz; i++) { +// char *name = taosArrayGetP(pConsumer->assignedTopics, i); +// if (name && strcmp(topic, name) == 0) { +// MND_TMQ_RETURN_CHECK(mndSetConsumerDropLogs(pTrans, pConsumer)); +// } +// } +// +// sdbRelease(pMnode->pSdb, pConsumer); +// } +// +//END: +// sdbRelease(pMnode->pSdb, pConsumer); +// sdbCancelFetch(pMnode->pSdb, pIter); +// return code; +//} static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) { SMnode *pMnode = pMsg->info.node; @@ -1079,7 +1084,6 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) { mInfo("trans:%d, used to drop cgroup:%s on topic %s", pTrans->id, dropReq.cgroup, dropReq.topic); mndTransSetDbName(pTrans, pSub->dbName, dropReq.cgroup); MND_TMQ_RETURN_CHECK(mndTransCheckConflict(pMnode, pTrans)); - MND_TMQ_RETURN_CHECK(mndDropConsumerByGroup(pMnode, pTrans, dropReq.cgroup, dropReq.topic)); MND_TMQ_RETURN_CHECK(sendDeleteSubToVnode(pMnode, pSub, pTrans)); MND_TMQ_RETURN_CHECK(mndSetDropSubCommitLogs(pMnode, pTrans, pSub)); MND_TMQ_RETURN_CHECK(mndTransPrepare(pMnode, pTrans)); @@ -1375,7 +1379,7 @@ static int32_t buildResult(SSDataBlock *pBlock, int32_t *numOfRows, int64_t cons if (data) { // vg id char buf[TSDB_OFFSET_LEN * 2 + VARSTR_HEADER_SIZE] = {0}; - tFormatOffset(varDataVal(buf), TSDB_OFFSET_LEN, &data->offset); + (void)tFormatOffset(varDataVal(buf), TSDB_OFFSET_LEN, &data->offset); (void)sprintf(varDataVal(buf) + strlen(varDataVal(buf)), "/%" PRId64, data->ever); varDataSetLen(buf, strlen(varDataVal(buf))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 70d0b858f6..89f3c6e253 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -212,8 +212,7 @@ int32_t mndProcessWriteMsg(SMnode *pMnode, SRpcMsg *pMsg, SFsmCbMeta *pMeta) { mndTransRefresh(pMnode, pTrans); sdbSetApplyInfo(pMnode->pSdb, pMeta->index, pMeta->term, pMeta->lastConfigIndex); - sdbWriteFile(pMnode->pSdb, tsMndSdbWriteDelta); - code = 0; + code = sdbWriteFile(pMnode->pSdb, tsMndSdbWriteDelta); _OUT: if (pTrans) mndReleaseTrans(pMnode, pTrans); @@ -222,7 +221,7 @@ _OUT: static int32_t mndPostMgmtCode(SMnode *pMnode, int32_t code) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); if (pMgmt->transId == 0) { goto _OUT; } @@ -232,7 +231,7 @@ static int32_t mndPostMgmtCode(SMnode *pMnode, int32_t code) { pMgmt->transSec = 0; pMgmt->transSeq = 0; pMgmt->errCode = code; - tsem_post(&pMgmt->syncSem); + (void)tsem_post(&pMgmt->syncSem); if (pMgmt->errCode != 0) { mError("trans:%d, failed to propose since %s, post sem", transId, tstrerror(pMgmt->errCode)); @@ -241,7 +240,7 @@ static int32_t mndPostMgmtCode(SMnode *pMnode, int32_t code) { } _OUT: - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); return 0; } @@ -304,7 +303,7 @@ void mndRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) { } else { mInfo("vgId:1, sync restore finished"); } - mndRefreshUserIpWhiteList(pMnode); + (void)mndRefreshUserIpWhiteList(pMnode); ASSERT(commitIdx == mndSyncAppliedIndex(pFsm)); } @@ -350,16 +349,16 @@ static void mndBecomeFollower(const SSyncFSM *pFsm) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; mInfo("vgId:1, become follower"); - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); if (pMgmt->transId != 0) { mInfo("vgId:1, become follower and post sem, trans:%d, failed to propose since not leader", pMgmt->transId); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->transSeq = 0; pMgmt->errCode = TSDB_CODE_SYN_NOT_LEADER; - tsem_post(&pMgmt->syncSem); + (void)tsem_post(&pMgmt->syncSem); } - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); } static void mndBecomeLearner(const SSyncFSM *pFsm) { @@ -367,16 +366,16 @@ static void mndBecomeLearner(const SSyncFSM *pFsm) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; mInfo("vgId:1, become learner"); - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); if (pMgmt->transId != 0) { mInfo("vgId:1, become learner and post sem, trans:%d, failed to propose since not leader", pMgmt->transId); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->transSeq = 0; pMgmt->errCode = TSDB_CODE_SYN_NOT_LEADER; - tsem_post(&pMgmt->syncSem); + (void)tsem_post(&pMgmt->syncSem); } - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); } static void mndBecomeLeader(const SSyncFSM *pFsm) { @@ -435,12 +434,12 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) { int32_t mndInitSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - taosThreadMutexInit(&pMgmt->lock, NULL); - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexInit(&pMgmt->lock, NULL); + (void)taosThreadMutexLock(&pMgmt->lock); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->transSeq = 0; - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); SSyncInfo syncInfo = { .snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT, @@ -477,7 +476,7 @@ int32_t mndInitSync(SMnode *pMnode) { } int32_t code = 0; - tsem_init(&pMgmt->syncSem, 0, 0); + (void)tsem_init(&pMgmt->syncSem, 0, 0); pMgmt->sync = syncOpen(&syncInfo, true); if (pMgmt->sync <= 0) { if (terrno != 0) code = terrno; @@ -495,15 +494,15 @@ void mndCleanupSync(SMnode *pMnode) { syncStop(pMgmt->sync); mInfo("mnode-sync is stopped, id:%" PRId64, pMgmt->sync); - tsem_destroy(&pMgmt->syncSem); - taosThreadMutexDestroy(&pMgmt->lock); + (void)tsem_destroy(&pMgmt->syncSem); + (void)taosThreadMutexDestroy(&pMgmt->lock); memset(pMgmt, 0, sizeof(SSyncMgmt)); } void mndSyncCheckTimeout(SMnode *pMnode) { mTrace("check sync timeout"); SSyncMgmt *pMgmt = &pMnode->syncMgmt; - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); if (pMgmt->transId != 0) { int32_t curSec = taosGetTimestampSec(); int32_t delta = curSec - pMgmt->transSec; @@ -515,7 +514,7 @@ void mndSyncCheckTimeout(SMnode *pMnode) { pMgmt->transSeq = 0; terrno = TSDB_CODE_SYN_TIMEOUT; pMgmt->errCode = TSDB_CODE_SYN_TIMEOUT; - tsem_post(&pMgmt->syncSem); + (void)tsem_post(&pMgmt->syncSem); } else { mDebug("trans:%d, waiting for sync confirm, start:%d cur:%d delta:%d seq:%" PRId64, pMgmt->transId, pMgmt->transSec, curSec, curSec - pMgmt->transSec, pMgmt->transSeq); @@ -523,7 +522,7 @@ void mndSyncCheckTimeout(SMnode *pMnode) { } else { // mTrace("check sync timeout msg, no trans waiting for confirm"); } - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); } int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { @@ -536,12 +535,12 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { if (req.pCont == NULL) return TSDB_CODE_OUT_OF_MEMORY; memcpy(req.pCont, pRaw, req.contLen); - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); pMgmt->errCode = 0; if (pMgmt->transId != 0) { mError("trans:%d, can't be proposed since trans:%d already waiting for confirm", transId, pMgmt->transId); - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); rpcFreeCont(req.pCont); TAOS_RETURN(TSDB_CODE_MND_LAST_TRANS_NOT_FINISHED); } @@ -555,23 +554,24 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { if (code == 0) { mInfo("trans:%d, is proposing and wait sem, seq:%" PRId64, transId, seq); pMgmt->transSeq = seq; - taosThreadMutexUnlock(&pMgmt->lock); - tsem_wait(&pMgmt->syncSem); + (void)taosThreadMutexUnlock(&pMgmt->lock); + (void)tsem_wait(&pMgmt->syncSem); } else if (code > 0) { mInfo("trans:%d, confirm at once since replica is 1, continue execute", transId); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->transSeq = 0; - taosThreadMutexUnlock(&pMgmt->lock); - sdbWriteWithoutFree(pMnode->pSdb, pRaw); - sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID); - code = 0; + (void)taosThreadMutexUnlock(&pMgmt->lock); + code = sdbWriteWithoutFree(pMnode->pSdb, pRaw); + if (code == 0) { + sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID); + } } else { mError("trans:%d, failed to proposed since %s", transId, terrstr()); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->transSeq = 0; - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); if (terrno == 0) { terrno = TSDB_CODE_APP_ERROR; } @@ -600,15 +600,15 @@ void mndSyncStart(SMnode *pMnode) { void mndSyncStop(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); if (pMgmt->transId != 0) { mInfo("vgId:1, is stopped and post sem, trans:%d", pMgmt->transId); pMgmt->transId = 0; pMgmt->transSec = 0; pMgmt->errCode = TSDB_CODE_APP_IS_STOPPING; - tsem_post(&pMgmt->syncSem); + (void)tsem_post(&pMgmt->syncSem); } - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); } bool mndIsLeader(SMnode *pMnode) { diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index ac379a9f94..f766c00f7d 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -70,16 +70,16 @@ static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) { SMnodeStat mstat = {0}; mndGetStat(pMnode, &mstat); - tjsonAddDoubleToObject(pJson, "numOfDnode", mstat.numOfDnode); - tjsonAddDoubleToObject(pJson, "numOfMnode", mstat.numOfMnode); - tjsonAddDoubleToObject(pJson, "numOfVgroup", mstat.numOfVgroup); - tjsonAddDoubleToObject(pJson, "numOfDatabase", mstat.numOfDatabase); - tjsonAddDoubleToObject(pJson, "numOfSuperTable", mstat.numOfSuperTable); - tjsonAddDoubleToObject(pJson, "numOfChildTable", mstat.numOfChildTable); - tjsonAddDoubleToObject(pJson, "numOfColumn", mstat.numOfColumn); - tjsonAddDoubleToObject(pJson, "numOfPoint", mstat.totalPoints); - tjsonAddDoubleToObject(pJson, "totalStorage", mstat.totalStorage); - tjsonAddDoubleToObject(pJson, "compStorage", mstat.compStorage); + (void)tjsonAddDoubleToObject(pJson, "numOfDnode", mstat.numOfDnode); + (void)tjsonAddDoubleToObject(pJson, "numOfMnode", mstat.numOfMnode); + (void)tjsonAddDoubleToObject(pJson, "numOfVgroup", mstat.numOfVgroup); + (void)tjsonAddDoubleToObject(pJson, "numOfDatabase", mstat.numOfDatabase); + (void)tjsonAddDoubleToObject(pJson, "numOfSuperTable", mstat.numOfSuperTable); + (void)tjsonAddDoubleToObject(pJson, "numOfChildTable", mstat.numOfChildTable); + (void)tjsonAddDoubleToObject(pJson, "numOfColumn", mstat.numOfColumn); + (void)tjsonAddDoubleToObject(pJson, "numOfPoint", mstat.totalPoints); + (void)tjsonAddDoubleToObject(pJson, "totalStorage", mstat.totalStorage); + (void)tjsonAddDoubleToObject(pJson, "compStorage", mstat.compStorage); } static char* mndBuildTelemetryReport(SMnode* pMnode) { @@ -90,29 +90,29 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { if (pJson == NULL) return NULL; char clusterName[64] = {0}; - mndGetClusterName(pMnode, clusterName, sizeof(clusterName)); - tjsonAddStringToObject(pJson, "instanceId", clusterName); - tjsonAddDoubleToObject(pJson, "reportVersion", 1); + if ((terrno = mndGetClusterName(pMnode, clusterName, sizeof(clusterName))) != 0) return NULL; + (void)tjsonAddStringToObject(pJson, "instanceId", clusterName); + (void)tjsonAddDoubleToObject(pJson, "reportVersion", 1); if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) { - tjsonAddStringToObject(pJson, "os", tmp); + (void)tjsonAddStringToObject(pJson, "os", tmp); } float numOfCores = 0; if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) { - tjsonAddStringToObject(pJson, "cpuModel", tmp); - tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores); + (void)tjsonAddStringToObject(pJson, "cpuModel", tmp); + (void)tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores); } else { - tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores); + (void)tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores); } snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); - tjsonAddStringToObject(pJson, "memory", tmp); + (void)tjsonAddStringToObject(pJson, "memory", tmp); - tjsonAddStringToObject(pJson, "version", version); - tjsonAddStringToObject(pJson, "buildInfo", buildinfo); - tjsonAddStringToObject(pJson, "gitInfo", gitinfo); - tjsonAddStringToObject(pJson, "email", pMgmt->email); + (void)tjsonAddStringToObject(pJson, "version", version); + (void)tjsonAddStringToObject(pJson, "buildInfo", buildinfo); + (void)tjsonAddStringToObject(pJson, "gitInfo", gitinfo); + (void)tjsonAddStringToObject(pJson, "email", pMgmt->email); mndBuildRuntimeInfo(pMnode, pJson); @@ -126,9 +126,9 @@ static int32_t mndProcessTelemTimer(SRpcMsg* pReq) { STelemMgmt* pMgmt = &pMnode->telemMgmt; if (!tsEnableTelem) return 0; - taosThreadMutexLock(&pMgmt->lock); + (void)taosThreadMutexLock(&pMgmt->lock); char* pCont = mndBuildTelemetryReport(pMnode); - taosThreadMutexUnlock(&pMgmt->lock); + (void)taosThreadMutexUnlock(&pMgmt->lock); if (pCont != NULL) { if (taosSendHttpReport(tsTelemServer, tsTelemUri, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT) != 0) { @@ -142,10 +142,12 @@ static int32_t mndProcessTelemTimer(SRpcMsg* pReq) { } int32_t mndInitTelem(SMnode* pMnode) { + int32_t code = 0; STelemMgmt* pMgmt = &pMnode->telemMgmt; - taosThreadMutexInit(&pMgmt->lock, NULL); - taosGetEmail(pMgmt->email, sizeof(pMgmt->email)); + (void)taosThreadMutexInit(&pMgmt->lock, NULL); + if ((code = taosGetEmail(pMgmt->email, sizeof(pMgmt->email))) != 0) + mWarn("failed to get email since %s", tstrerror(code)); mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer); return 0; @@ -153,5 +155,5 @@ int32_t mndInitTelem(SMnode* pMnode) { void mndCleanupTelem(SMnode* pMnode) { STelemMgmt* pMgmt = &pMnode->telemMgmt; - taosThreadMutexDestroy(&pMgmt->lock); + (void)taosThreadMutexDestroy(&pMgmt->lock); } diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 930c4d66d5..46d5afc145 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -613,44 +613,44 @@ static bool checkTopic(SArray *topics, char *topicName){ return false; } -static int32_t mndDropConsumerByTopic(SMnode *pMnode, STrans *pTrans, char *topicName){ - int32_t code = 0; - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; - SMqConsumerObj *pConsumer = NULL; - while (1) { - pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); - if (pIter == NULL) { - break; - } - - bool found = checkTopic(pConsumer->assignedTopics, topicName); - if (found){ - if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) { - MND_TMQ_RETURN_CHECK(mndSetConsumerDropLogs(pTrans, pConsumer)); - sdbRelease(pSdb, pConsumer); - continue; - } - mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s", - topicName, pConsumer->consumerId, pConsumer->cgroup); - code = TSDB_CODE_MND_TOPIC_SUBSCRIBED; - goto END; - } - - if (checkTopic(pConsumer->rebNewTopics, topicName) || checkTopic(pConsumer->rebRemovedTopics, topicName)) { - code = TSDB_CODE_MND_TOPIC_SUBSCRIBED; - mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)", - topicName, pConsumer->consumerId, pConsumer->cgroup); - goto END; - } - sdbRelease(pSdb, pConsumer); - } - -END: - sdbRelease(pSdb, pConsumer); - sdbCancelFetch(pSdb, pIter); - return code; -} +//static int32_t mndDropConsumerByTopic(SMnode *pMnode, STrans *pTrans, char *topicName){ +// int32_t code = 0; +// SSdb *pSdb = pMnode->pSdb; +// void *pIter = NULL; +// SMqConsumerObj *pConsumer = NULL; +// while (1) { +// pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); +// if (pIter == NULL) { +// break; +// } +// +// bool found = checkTopic(pConsumer->assignedTopics, topicName); +// if (found){ +// if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) { +// MND_TMQ_RETURN_CHECK(mndSetConsumerDropLogs(pTrans, pConsumer)); +// sdbRelease(pSdb, pConsumer); +// continue; +// } +// mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s", +// topicName, pConsumer->consumerId, pConsumer->cgroup); +// code = TSDB_CODE_MND_TOPIC_SUBSCRIBED; +// goto END; +// } +// +// if (checkTopic(pConsumer->rebNewTopics, topicName) || checkTopic(pConsumer->rebRemovedTopics, topicName)) { +// code = TSDB_CODE_MND_TOPIC_SUBSCRIBED; +// mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)", +// topicName, pConsumer->consumerId, pConsumer->cgroup); +// goto END; +// } +// sdbRelease(pSdb, pConsumer); +// } +// +//END: +// sdbRelease(pSdb, pConsumer); +// sdbCancelFetch(pSdb, pIter); +// return code; +//} static int32_t mndDropCheckInfoByTopic(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic){ // broadcast to all vnode @@ -722,9 +722,10 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { mndTransSetDbName(pTrans, pTopic->db, NULL); MND_TMQ_RETURN_CHECK(mndTransCheckConflict(pMnode, pTrans)); mInfo("trans:%d, used to drop topic:%s", pTrans->id, pTopic->name); + MND_TMQ_RETURN_CHECK(mndCheckTopicPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_TOPIC, pTopic)); MND_TMQ_RETURN_CHECK(mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db)); - MND_TMQ_RETURN_CHECK(mndDropConsumerByTopic(pMnode, pTrans, dropReq.name)); +// MND_TMQ_RETURN_CHECK(mndDropConsumerByTopic(pMnode, pTrans, dropReq.name)); MND_TMQ_RETURN_CHECK(mndDropSubByTopic(pMnode, pTrans, dropReq.name)); if (pTopic->ntbUid != 0) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 871c8989ff..8ed3f66009 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -376,7 +376,7 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) { for (int32_t i = 0; i < arbgroupIdNum; ++i) { int32_t arbGroupId = 0; SDB_GET_INT32(pRaw, dataPos, &arbGroupId, _OVER) - taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0); + if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER; } SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER) @@ -461,7 +461,7 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { mInfo("trans:%d, perform insert action, row:%p stage:%s, callfunc:1, startFunc:%d", pTrans->id, pTrans, mndTransStr(pTrans->stage), pTrans->startFunc); - taosThreadMutexInit(&pTrans->mutex, NULL); + (void)taosThreadMutexInit(&pTrans->mutex, NULL); if (pTrans->startFunc > 0) { TransCbFp fp = mndTransGetCbFp(pTrans->startFunc); @@ -616,7 +616,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict, pTrans->pRpcArray = taosArrayInit(1, sizeof(SRpcHandleInfo)); pTrans->mTraceId = pReq ? TRACE_GET_ROOTID(&pReq->info.traceId) : tGenIdPI64(); taosInitRWLatch(&pTrans->lockRpcArray); - taosThreadMutexInit(&pTrans->mutex, NULL); + (void)taosThreadMutexInit(&pTrans->mutex, NULL); if (pTrans->redoActions == NULL || pTrans->undoActions == NULL || pTrans->commitActions == NULL || pTrans->pRpcArray == NULL) { @@ -627,7 +627,10 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict, } if (pReq != NULL) { - taosArrayPush(pTrans->pRpcArray, &pReq->info); + if (taosArrayPush(pTrans->pRpcArray, &pReq->info) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } pTrans->originRpcType = pReq->msgType; } @@ -765,7 +768,7 @@ void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname) } void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) { - taosHashPut(pTrans->arbGroupIds, &groupId, sizeof(int32_t), NULL, 0); + (void)taosHashPut(pTrans->arbGroupIds, &groupId, sizeof(int32_t), NULL, 0); } void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; } @@ -1505,9 +1508,9 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr pTrans->actionPos++; mInfo("trans:%d, %s:%d is executed and need sync to other mnodes", pTrans->id, mndTransStr(pAction->stage), pAction->id); - taosThreadMutexUnlock(&pTrans->mutex); + (void)taosThreadMutexUnlock(&pTrans->mutex); code = mndTransSync(pMnode, pTrans); - taosThreadMutexLock(&pTrans->mutex); + (void)taosThreadMutexLock(&pTrans->mutex); if (code != 0) { pTrans->actionPos--; pTrans->code = terrno; @@ -1540,21 +1543,21 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans, bool topHalf) { int32_t code = TSDB_CODE_ACTION_IN_PROGRESS; - taosThreadMutexLock(&pTrans->mutex); + (void)taosThreadMutexLock(&pTrans->mutex); if (pTrans->stage == TRN_STAGE_REDO_ACTION) { code = mndTransExecuteActionsSerial(pMnode, pTrans, pTrans->redoActions, topHalf); } - taosThreadMutexUnlock(&pTrans->mutex); + (void)taosThreadMutexUnlock(&pTrans->mutex); return code; } static int32_t mndTransExecuteUndoActionsSerial(SMnode *pMnode, STrans *pTrans, bool topHalf) { int32_t code = TSDB_CODE_ACTION_IN_PROGRESS; - taosThreadMutexLock(&pTrans->mutex); + (void)taosThreadMutexLock(&pTrans->mutex); if (pTrans->stage == TRN_STAGE_UNDO_ACTION) { code = mndTransExecuteActionsSerial(pMnode, pTrans, pTrans->undoActions, topHalf); } - taosThreadMutexUnlock(&pTrans->mutex); + (void)taosThreadMutexUnlock(&pTrans->mutex); return code; } @@ -1894,7 +1897,7 @@ void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans); if (pIter == NULL) break; - taosArrayPush(pArray, &pTrans->id); + (void)taosArrayPush(pArray, &pTrans->id); sdbRelease(pSdb, pTrans); } @@ -1925,36 +1928,36 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->id, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->id, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->createdTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->createdTime, false); char stage[TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(stage, mndTransStr(pTrans->stage), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)stage, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)stage, false); char opername[TSDB_TRANS_OPER_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(opername, pTrans->opername, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)opername, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)opername, false); char dbname[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndGetDbStr(pTrans->dbname), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)dbname, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)dbname, false); char stbname[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(stbname, mndGetDbStr(pTrans->stbname), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false); char lastInfo[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0}; char detail[TSDB_TRANS_ERROR_LEN + 1] = {0}; @@ -1970,7 +1973,7 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false); numOfRows++; sdbRelease(pSdb, pTrans); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 945d29f7ab..1737044437 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -682,7 +682,7 @@ static void ipRangeToStr(SIpV4Range *range, char *buf) { struct in_addr addr; addr.s_addr = range->ip; - uv_inet_ntop(AF_INET, &addr, buf, 32); + (void)uv_inet_ntop(AF_INET, &addr, buf, 32); if (range->mask != 32) { (void)sprintf(buf + strlen(buf), "/%d", range->mask); } @@ -2188,7 +2188,7 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode mndReleaseDb(pMnode, pDb); TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code } - taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len); + (void)taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len); mndReleaseDb(pMnode, pDb); } else { taosHashClear(pNewUser->readDbs); @@ -2204,7 +2204,7 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode mndReleaseDb(pMnode, pDb); TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code } - taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len); + (void)taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len); mndReleaseDb(pMnode, pDb); } else { taosHashClear(pNewUser->writeDbs); @@ -2311,7 +2311,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) { TAOS_CHECK_GOTO(mndAcquireUser(pMnode, alterReq.user, &pUser), &lino, _OVER); - mndAcquireUser(pMnode, pReq->info.conn.user, &pOperUser); + (void)mndAcquireUser(pMnode, pReq->info.conn.user, &pOperUser); if (pOperUser == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_MND_NO_USER_FROM_CONN, &lino, _OVER); } @@ -2517,7 +2517,7 @@ static int32_t mndDropUser(SMnode *pMnode, SRpcMsg *pReq, SUserObj *pUser) { mndTransDrop(pTrans); TAOS_RETURN(terrno); } - ipWhiteMgtRemove(pUser->user); + (void)ipWhiteMgtRemove(pUser->user); mndTransDrop(pTrans); TAOS_RETURN(0); @@ -2830,7 +2830,10 @@ static int32_t mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, i } if (nodesStringToNode(value, &pAst) == 0) { - nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen); + if (nodesNodeToSQL(pAst, *sql, bufSz, &sqlLen) != 0) { + sqlLen = 5; + (void)sprintf(*sql, "error"); + } nodesDestroyNode(pAst); } else { sqlLen = 5; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 30c11c09ce..5cfc896a1c 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -390,7 +390,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg return NULL; } - tSerializeSCreateVnodeReq(pReq, contLen, &createReq); + (void)tSerializeSCreateVnodeReq(pReq, contLen, &createReq); *pContLen = contLen; return pReq; } @@ -436,7 +436,7 @@ static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pV pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); + (void)tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); *pContLen = contLen; return pReq; } @@ -514,7 +514,7 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq); + (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq); *pContLen = contLen; return pReq; } @@ -587,7 +587,7 @@ static void *mndBuildCheckLearnCatchupReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req); + (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req); *pContLen = contLen; return pReq; } @@ -611,7 +611,7 @@ static void *mndBuildDisableVnodeWriteReq(SMnode *pMnode, SDbObj *pDb, int32_t v return NULL; } - tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq); + (void)tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq); *pContLen = contLen; return pReq; } @@ -639,7 +639,7 @@ static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, int32_t srcVgId, SVg return NULL; } - tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq); + (void)tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq); *pContLen = contLen; return pReq; } @@ -664,7 +664,7 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb return NULL; } - tSerializeSDropVnodeReq(pReq, contLen, &dropReq); + (void)tSerializeSDropVnodeReq(pReq, contLen, &dropReq); *pContLen = contLen; return pReq; } @@ -699,7 +699,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2 } if (online && pDnode->numOfSupportVnodes > 0) { - taosArrayPush(pArray, pDnode); + if (taosArrayPush(pArray, pDnode) == NULL) return false; } return true; } @@ -877,7 +877,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { pVgroup->dbUid = pDb->uid; pVgroup->replica = pDb->cfg.replications; - if (mndGetAvailableDnode(pMnode, pDb, pVgroup, pArray) != 0) { + if ((code = mndGetAvailableDnode(pMnode, pDb, pVgroup, pArray)) != 0) { goto _OVER; } @@ -907,7 +907,7 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { epset.inUse = epset.numOfEps; } - addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); mndReleaseDnode(pMnode, pDnode); } epsetSort(&epset); @@ -930,7 +930,7 @@ SEpSet mndGetVgroupEpsetById(SMnode *pMnode, int32_t vgId) { epset.inUse = epset.numOfEps; } - addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); mndReleaseDnode(pMnode, pDnode); } @@ -965,26 +965,26 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); SName name = {0}; char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); - tNameGetDbName(&name, varDataVal(db)); + (void)tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + (void)tNameGetDbName(&name, varDataVal(db)); varDataSetLen(db, strlen(varDataVal(db))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)db, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); // default 3 replica, add 1 replica if move vnode for (int32_t i = 0; i < 4; ++i) { pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); if (i < pVgroup->replica) { int16_t dnodeId = (int16_t)pVgroup->vnodeGid[i].dnodeId; - colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); bool exist = false; bool online = false; @@ -1038,7 +1038,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); } else { colDataSetNULL(pColInfo, numOfRows); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1048,19 +1048,19 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); int32_t cacheUsage = (int32_t)pVgroup->cacheUsage; - colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); // if (pDb == NULL || pDb->compactStartTime <= 0) { // colDataSetNULL(pColInfo, numOfRows); // } else { - // colDataSetVal(pColInfo, numOfRows, (const char *)&pDb->compactStartTime, false); + // (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pDb->compactStartTime, false); // } numOfRows++; @@ -1158,10 +1158,10 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); // db_name const char *dbname = mndGetDbStr(pVgroup->dbName); @@ -1172,7 +1172,7 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB STR_WITH_MAXSIZE_TO_VARSTR(b1, "NULL", TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE); } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); // dnode is online? SDnodeObj *pDnode = mndAcquireDnode(pMnode, pGid->dnodeId); @@ -1186,18 +1186,18 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB ESyncState syncState = (isDnodeOnline) ? pGid->syncState : TAOS_SYNC_STATE_OFFLINE; STR_TO_VARSTR(buf, syncStr(syncState)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); int64_t roleTimeMs = (isDnodeOnline) ? pGid->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); int64_t startTimeMs = (isDnodeOnline) ? pGid->startTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); + (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); numOfRows++; sdbRelease(pSdb, pDnode); @@ -2452,7 +2452,7 @@ static void *mndBuildSForceBecomeFollowerReq(SMnode *pMnode, SVgObj *pVgroup, in pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq); + (void)tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq); *pContLen = contLen; return pReq; } @@ -3366,7 +3366,7 @@ static void *mndBuildCompactVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgrou pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq); + (void)tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq); *pContLen = contLen; return pReq; } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index c1d4ba7893..7244f2d7c9 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -46,7 +46,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { } for (ESdbType i = 0; i < SDB_MAX; ++i) { - taosThreadRwlockInit(&pSdb->locks[i], NULL); + (void)taosThreadRwlockInit(&pSdb->locks[i], NULL); pSdb->maxId[i] = 0; pSdb->tableVer[i] = 0; pSdb->keyTypes[i] = SDB_KEY_INT32; @@ -60,7 +60,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { pSdb->commitTerm = -1; pSdb->commitConfig = -1; pSdb->pMnode = pOption->pMnode; - taosThreadMutexInit(&pSdb->filelock, NULL); + (void)taosThreadMutexInit(&pSdb->filelock, NULL); mInfo("sdb init success"); return pSdb; } @@ -68,7 +68,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mInfo("start to cleanup sdb"); - sdbWriteFile(pSdb, 0); + (void)sdbWriteFile(pSdb, 0); if (pSdb->currDir != NULL) { taosMemoryFreeClear(pSdb->currDir); @@ -99,14 +99,14 @@ void sdbCleanup(SSdb *pSdb) { taosHashClear(hash); taosHashCleanup(hash); - taosThreadRwlockDestroy(&pSdb->locks[i]); + (void)taosThreadRwlockDestroy(&pSdb->locks[i]); pSdb->hashObjs[i] = NULL; memset(&pSdb->locks[i], 0, sizeof(pSdb->locks[i])); mInfo("sdb table:%s is cleaned up", sdbTableName(i)); } - taosThreadMutexDestroy(&pSdb->filelock); + (void)taosThreadMutexDestroy(&pSdb->filelock); taosMemoryFree(pSdb); mInfo("sdb is cleaned up"); } @@ -188,19 +188,19 @@ void sdbGetCommitInfo(SSdb *pSdb, int64_t *index, int64_t *term, int64_t *config void sdbWriteLock(SSdb *pSdb, int32_t type) { TdThreadRwlock *pLock = &pSdb->locks[type]; // mTrace("sdb table:%d start write lock:%p", type, pLock); - taosThreadRwlockWrlock(pLock); + (void)taosThreadRwlockWrlock(pLock); // mTrace("sdb table:%d stop write lock:%p", type, pLock); } void sdbReadLock(SSdb *pSdb, int32_t type) { TdThreadRwlock *pLock = &pSdb->locks[type]; // mTrace("sdb table:%d start read lock:%p", type, pLock); - taosThreadRwlockRdlock(pLock); + (void)taosThreadRwlockRdlock(pLock); // mTrace("sdb table:%d stop read lock:%p", type, pLock); } void sdbUnLock(SSdb *pSdb, int32_t type) { TdThreadRwlock *pLock = &pSdb->locks[type]; // mTrace("sdb table:%d unlock:%p", type, pLock); - taosThreadRwlockUnlock(pLock); + (void)taosThreadRwlockUnlock(pLock); } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 0952fbe7a3..6fb395e63f 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -258,7 +258,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { if (code != 0) { mError("failed to read sdb file:%s head since %s", file, tstrerror(code)); taosMemoryFree(pRaw); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return -1; } @@ -361,14 +361,14 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { pSdb->commitTerm, pSdb->commitConfig); _OVER: - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); sdbFreeRaw(pRaw); TAOS_RETURN(code); } int32_t sdbReadFile(SSdb *pSdb) { - taosThreadMutexLock(&pSdb->filelock); + (void)taosThreadMutexLock(&pSdb->filelock); sdbResetData(pSdb); int32_t code = sdbReadFileImp(pSdb); @@ -377,7 +377,7 @@ int32_t sdbReadFile(SSdb *pSdb) { sdbResetData(pSdb); } - taosThreadMutexUnlock(&pSdb->filelock); + (void)taosThreadMutexUnlock(&pSdb->filelock); return code; } @@ -404,7 +404,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) { code = sdbWriteFileHead(pSdb, pFile); if (code != 0) { mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code)); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return -1; } @@ -507,7 +507,9 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) { } } - taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + code = taosRenameFile(tmpfile, curfile); + } if (code == 0) { code = taosRenameFile(tmpfile, curfile); @@ -541,7 +543,7 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) { return 0; } - taosThreadMutexLock(&pSdb->filelock); + (void)taosThreadMutexLock(&pSdb->filelock); if (pSdb->pWal != NULL) { if (pSdb->sync > 0) { code = syncBeginSnapshot(pSdb->sync, pSdb->applyIndex); @@ -560,7 +562,7 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) { if (code != 0) { mError("failed to write sdb file since %s", tstrerror(code)); } - taosThreadMutexUnlock(&pSdb->filelock); + (void)taosThreadMutexUnlock(&pSdb->filelock); return code; } @@ -602,7 +604,7 @@ static void sdbCloseIter(SSdbIter *pIter) { if (pIter == NULL) return; if (pIter->file != NULL) { - taosCloseFile(&pIter->file); + (void)taosCloseFile(&pIter->file); pIter->file = NULL; } @@ -624,18 +626,18 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter char datafile[PATH_MAX] = {0}; snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); - taosThreadMutexLock(&pSdb->filelock); + (void)taosThreadMutexLock(&pSdb->filelock); int64_t commitIndex = pSdb->commitIndex; int64_t commitTerm = pSdb->commitTerm; int64_t commitConfig = pSdb->commitConfig; if (taosCopyFile(datafile, pIter->name) < 0) { - taosThreadMutexUnlock(&pSdb->filelock); + (void)taosThreadMutexUnlock(&pSdb->filelock); code = TAOS_SYSTEM_ERROR(errno); mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); } - taosThreadMutexUnlock(&pSdb->filelock); + (void)taosThreadMutexUnlock(&pSdb->filelock); pIter->file = taosOpenFile(pIter->name, TD_FILE_READ); if (pIter->file == NULL) { @@ -725,7 +727,10 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i goto _OVER; } - taosCloseFile(&pIter->file); + if (taosCloseFile(&pIter->file) != 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _OVER; + } pIter->file = NULL; char datafile[PATH_MAX] = {0}; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 4043ff6a12..03b45c25b4 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -176,7 +176,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * if (code != 0) { if (terrno == 0) terrno = TSDB_CODE_MND_TRANS_UNKNOW_ERROR; code = terrno; - taosHashRemove(hash, pRow->pObj, keySize); + (void)taosHashRemove(hash, pRow->pObj, keySize); sdbFreeRow(pSdb, pRow, false); terrno = code; sdbUnLock(pSdb, type); @@ -239,10 +239,10 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; - atomic_add_fetch_32(&pOldRow->refCount, 1); + (void)atomic_add_fetch_32(&pOldRow->refCount, 1); sdbPrintOper(pSdb, pOldRow, "delete"); - taosHashRemove(hash, pOldRow->pObj, keySize); + TAOS_CHECK_RETURN(taosHashRemove(hash, pOldRow->pObj, keySize)); pSdb->tableVer[pOldRow->type]++; sdbUnLock(pSdb, type); @@ -309,7 +309,7 @@ void *sdbAcquireAll(SSdb *pSdb, ESdbType type, const void *pKey, bool onlyReady) SSdbRow *pRow = *ppRow; switch (pRow->status) { case SDB_STATUS_READY: - atomic_add_fetch_32(&pRow->refCount, 1); + (void)atomic_add_fetch_32(&pRow->refCount, 1); pRet = pRow->pObj; sdbPrintOper(pSdb, pRow, "acquire"); break; @@ -327,7 +327,7 @@ void *sdbAcquireAll(SSdb *pSdb, ESdbType type, const void *pKey, bool onlyReady) if (pRet == NULL) { if (!onlyReady) { terrno = 0; - atomic_add_fetch_32(&pRow->refCount, 1); + (void)atomic_add_fetch_32(&pRow->refCount, 1); pRet = pRow->pObj; sdbPrintOper(pSdb, pRow, "acquire"); } @@ -395,7 +395,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { continue; } - atomic_add_fetch_32(&pRow->refCount, 1); + (void)atomic_add_fetch_32(&pRow->refCount, 1); sdbPrintOper(pSdb, pRow, "fetch"); *ppObj = pRow->pObj; break; @@ -423,7 +423,7 @@ void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStat continue; } - atomic_add_fetch_32(&pRow->refCount, 1); + (void)atomic_add_fetch_32(&pRow->refCount, 1); sdbPrintOper(pSdb, pRow, "fetch"); *ppObj = pRow->pObj; *status = pRow->status; diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index c078e7eb21..da5a232851 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -42,7 +42,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) { // remove attached object such as trans SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type]; if (deleteFp != NULL) { - (*deleteFp)(pSdb, pRow->pObj, callFunc); + (void)(*deleteFp)(pSdb, pRow->pObj, callFunc); } sdbPrintOper(pSdb, pRow, "free"); diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 5e536e5fbf..ce7c8aee7f 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -36,7 +36,7 @@ int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProce streamTaskOpenAllUpstreamInput(pTask); streamTaskResetUpstreamStageInfo(pTask); - streamSetupScheduleTrigger(pTask); + (void)streamSetupScheduleTrigger(pTask); SCheckpointInfo *pChkInfo = &pTask->chkInfo; tqSetRestoreVersionInfo(pTask); @@ -91,14 +91,14 @@ FAIL: } int32_t sndInit(SSnode *pSnode) { - streamTaskSchedTask(&pSnode->msgCb, pSnode->pMeta->vgId, 0, 0, STREAM_EXEC_T_START_ALL_TASKS); + (void)streamTaskSchedTask(&pSnode->msgCb, pSnode->pMeta->vgId, 0, 0, STREAM_EXEC_T_START_ALL_TASKS); return 0; } void sndClose(SSnode *pSnode) { stopRsync(); streamMetaNotifyClose(pSnode->pMeta); - streamMetaCommit(pSnode->pMeta); + (void)streamMetaCommit(pSnode->pMeta); streamMetaClose(pSnode->pMeta); taosMemoryFree(pSnode); } diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index d986d63ac7..87d7d2150e 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -39,9 +39,9 @@ typedef struct SMetaCache SMetaCache; // clang-format on // metaOpen ================== -int32_t metaRLock(SMeta* pMeta); -int32_t metaWLock(SMeta* pMeta); -int32_t metaULock(SMeta* pMeta); +void metaRLock(SMeta* pMeta); +void metaWLock(SMeta* pMeta); +void metaULock(SMeta* pMeta); // metaEntry ================== int metaEncodeEntry(SEncoder* pCoder, const SMetaEntry* pME); diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index 29eaa0509a..243f51ca0a 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -194,7 +194,7 @@ typedef enum { #define TD_SMA_LOOPS_CHECK(n, limit) \ if (++(n) > limit) { \ - sched_yield(); \ + (void)sched_yield(); \ (n) = 0; \ } diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 978821f890..f6f86850a4 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -378,7 +378,7 @@ struct STsdb { struct { SVHashTable *ht; SArray *arr; - } *commitInfo; + } * commitInfo; }; struct TSDBKEY { @@ -937,7 +937,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, TSDBROW *row, STsdb *pTsdb); int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, TSDBROW *row, bool dup); -int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); +void tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHandle **handle); int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h); @@ -945,7 +945,6 @@ int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h); int32_t tsdbCacheGetBlockS3(SLRUCache *pCache, STsdbFD *pFD, LRUHandle **handle); int32_t tsdbCacheGetPageS3(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, LRUHandle **handle); int32_t tsdbCacheSetPageS3(SLRUCache *pCache, STsdbFD *pFD, int64_t pgno, uint8_t *pPage); -int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 8af902538d..3d4067ba99 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -156,7 +156,7 @@ int32_t metaCacheOpen(SMeta* pMeta) { } taosHashSetFreeFp(pMeta->pCache->sTagFilterResCache.pTableEntry, freeCacheEntryFp); - taosThreadMutexInit(&pMeta->pCache->sTagFilterResCache.lock, NULL); + (void)taosThreadMutexInit(&pMeta->pCache->sTagFilterResCache.lock, NULL); pMeta->pCache->STbGroupResCache.pResCache = taosLRUCacheInit(5 * 1024 * 1024, -1, 0.5); if (pMeta->pCache->STbGroupResCache.pResCache == NULL) { @@ -171,7 +171,7 @@ int32_t metaCacheOpen(SMeta* pMeta) { } taosHashSetFreeFp(pMeta->pCache->STbGroupResCache.pTableEntry, freeCacheEntryFp); - taosThreadMutexInit(&pMeta->pCache->STbGroupResCache.lock, NULL); + (void)taosThreadMutexInit(&pMeta->pCache->STbGroupResCache.lock, NULL); pMeta->pCache->STbFilterCache.pStb = taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); @@ -201,11 +201,11 @@ void metaCacheClose(SMeta* pMeta) { statsCacheClose(pMeta); taosLRUCacheCleanup(pMeta->pCache->sTagFilterResCache.pUidResCache); - taosThreadMutexDestroy(&pMeta->pCache->sTagFilterResCache.lock); + (void)taosThreadMutexDestroy(&pMeta->pCache->sTagFilterResCache.lock); taosHashCleanup(pMeta->pCache->sTagFilterResCache.pTableEntry); taosLRUCacheCleanup(pMeta->pCache->STbGroupResCache.pResCache); - taosThreadMutexDestroy(&pMeta->pCache->STbGroupResCache.lock); + (void)taosThreadMutexDestroy(&pMeta->pCache->STbGroupResCache.lock); taosHashCleanup(pMeta->pCache->STbGroupResCache.pTableEntry); taosHashCleanup(pMeta->pCache->STbFilterCache.pStb); @@ -495,7 +495,7 @@ static int checkAllEntriesInCache(const STagFilterResEntry* pEntry, SArray* pInv return TSDB_CODE_OUT_OF_MEMORY; } } else { - taosLRUCacheRelease(pCache, pRes, false); + (void)taosLRUCacheRelease(pCache, pRes, false); } } @@ -552,7 +552,9 @@ int32_t metaGetCachedTableUidList(void* pVnode, tb_uid_t suid, const uint8_t* pK int32_t size = *(int32_t*)p; // set the result into the buffer - taosArrayAddBatch(pList1, p + sizeof(int32_t), size); + if (taosArrayAddBatch(pList1, p + sizeof(int32_t), size) == NULL) { + return terrno; + } (*pEntry)->hitTimes += 1; @@ -562,7 +564,7 @@ int32_t metaGetCachedTableUidList(void* pVnode, tb_uid_t suid, const uint8_t* pK ((double)(*pEntry)->hitTimes) / acc); } - taosLRUCacheRelease(pCache, pHandle, false); + (void)taosLRUCacheRelease(pCache, pHandle, false); // unlock meta (void)taosThreadMutexUnlock(pLock); @@ -618,7 +620,7 @@ static int32_t addNewEntry(SHashObj* pTableEntry, const void* pKey, int32_t keyL p->hitTimes = 0; tdListInit(&p->list, keyLen); TAOS_CHECK_RETURN(taosHashPut(pTableEntry, &suid, sizeof(uint64_t), &p, POINTER_BYTES)); - tdListAppend(&p->list, pKey); + (void)tdListAppend(&p->list, pKey); return 0; } @@ -662,7 +664,7 @@ int32_t metaUidFilterCachePut(void* pVnode, uint64_t suid, const void* pKey, int } else { // check if it exists or not size_t size = listNEles(&(*pEntry)->list); if (size == 0) { - tdListAppend(&(*pEntry)->list, pKey); + (void)tdListAppend(&(*pEntry)->list, pKey); } else { SListNode* pNode = listHead(&(*pEntry)->list); uint64_t* p = (uint64_t*)pNode->data; @@ -671,7 +673,7 @@ int32_t metaUidFilterCachePut(void* pVnode, uint64_t suid, const void* pKey, int (void)taosThreadMutexUnlock(pLock); return TSDB_CODE_SUCCESS; } else { // not equal, append it - tdListAppend(&(*pEntry)->list, pKey); + (void)tdListAppend(&(*pEntry)->list, pKey); } } } @@ -761,7 +763,7 @@ int32_t metaGetCachedTbGroup(void* pVnode, tb_uid_t suid, const uint8_t* pKey, i ((double)(*pEntry)->hitTimes) / acc); } - taosLRUCacheRelease(pCache, pHandle, false); + (void)taosLRUCacheRelease(pCache, pHandle, false); // unlock meta (void)taosThreadMutexUnlock(pLock); @@ -839,7 +841,7 @@ int32_t metaPutTbGroupToCache(void* pVnode, uint64_t suid, const void* pKey, int } else { // check if it exists or not size_t size = listNEles(&(*pEntry)->list); if (size == 0) { - tdListAppend(&(*pEntry)->list, pKey); + (void)tdListAppend(&(*pEntry)->list, pKey); } else { SListNode* pNode = listHead(&(*pEntry)->list); uint64_t* p = (uint64_t*)pNode->data; @@ -848,14 +850,14 @@ int32_t metaPutTbGroupToCache(void* pVnode, uint64_t suid, const void* pKey, int (void)taosThreadMutexUnlock(pLock); return TSDB_CODE_SUCCESS; } else { // not equal, append it - tdListAppend(&(*pEntry)->list, pKey); + (void)tdListAppend(&(*pEntry)->list, pKey); } } } // add to cache. - taosLRUCacheInsert(pCache, key, TAG_FILTER_RES_KEY_LEN, pPayload, payloadLen, freeTbGroupCachePayload, NULL, - TAOS_LRU_PRIORITY_LOW, NULL); + (void)taosLRUCacheInsert(pCache, key, TAG_FILTER_RES_KEY_LEN, pPayload, payloadLen, freeTbGroupCachePayload, NULL, + TAOS_LRU_PRIORITY_LOW, NULL); _end: (void)taosThreadMutexUnlock(pLock); metaDebug("vgId:%d, suid:%" PRIu64 " tb group added into cache, total:%d, tables:%d", vgId, suid, diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index ec26e94c5a..13163aef05 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -29,10 +29,10 @@ static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen static int32_t metaInitLock(SMeta *pMeta) { TdThreadRwlockAttr attr; - taosThreadRwlockAttrInit(&attr); - taosThreadRwlockAttrSetKindNP(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); - taosThreadRwlockInit(&pMeta->lock, &attr); - taosThreadRwlockAttrDestroy(&attr); + (void)taosThreadRwlockAttrInit(&attr); + (void)taosThreadRwlockAttrSetKindNP(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); + (void)taosThreadRwlockInit(&pMeta->lock, &attr); + (void)taosThreadRwlockAttrDestroy(&attr); return 0; } static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); } @@ -48,7 +48,7 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { char indexFullPath[128] = {0}; // create handle - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); offset = strlen(path); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR); @@ -56,16 +56,16 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); } - metaInitLock(pMeta); + (void)metaInitLock(pMeta); pMeta->path = (char *)&pMeta[1]; strcpy(pMeta->path, path); - taosRealPath(pMeta->path, NULL, strlen(path) + 1); + (void)taosRealPath(pMeta->path, NULL, strlen(path) + 1); pMeta->pVnode = pVnode; // create path if not created yet - taosMkDir(pMeta->path); + (void)taosMkDir(pMeta->path); // open env code = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback, @@ -186,31 +186,19 @@ int metaAlterCache(SMeta *pMeta, int32_t nPage) { return code; } -int32_t metaRLock(SMeta *pMeta) { +void metaRLock(SMeta *pMeta) { metaTrace("meta rlock %p", &pMeta->lock); - int32_t code = taosThreadRwlockRdlock(&pMeta->lock); - if (code) { - return TAOS_SYSTEM_ERROR(code); - } - return 0; + (void)taosThreadRwlockRdlock(&pMeta->lock); } -int32_t metaWLock(SMeta *pMeta) { +void metaWLock(SMeta *pMeta) { metaTrace("meta wlock %p", &pMeta->lock); - int32_t code = taosThreadRwlockWrlock(&pMeta->lock); - if (code) { - return TAOS_SYSTEM_ERROR(code); - } - return 0; + (void)taosThreadRwlockWrlock(&pMeta->lock); } -int32_t metaULock(SMeta *pMeta) { +void metaULock(SMeta *pMeta) { metaTrace("meta ulock %p", &pMeta->lock); - int32_t code = taosThreadRwlockUnlock(&pMeta->lock); - if (code) { - return TAOS_SYSTEM_ERROR(code); - } - return 0; + (void)taosThreadRwlockUnlock(&pMeta->lock); } static void metaCleanup(SMeta **ppMeta) { @@ -235,7 +223,7 @@ static void metaCleanup(SMeta **ppMeta) { if (pMeta->pSkmDb) tdbTbClose(pMeta->pSkmDb); if (pMeta->pTbDb) tdbTbClose(pMeta->pTbDb); if (pMeta->pEnv) tdbClose(pMeta->pEnv); - metaDestroyLock(pMeta); + (void)metaDestroyLock(pMeta); taosMemoryFreeClear(*ppMeta); } diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index ee616d7a0d..d4ff980311 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -252,7 +252,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { if (!pTbCur->paused) { metaReaderClear(&pTbCur->mr); if (pTbCur->pDbc) { - tdbTbcClose((TBC *)pTbCur->pDbc); + (void)tdbTbcClose((TBC *)pTbCur->pDbc); } } taosMemoryFree(pTbCur); @@ -262,7 +262,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { void metaPauseTbCursor(SMTbCursor *pTbCur) { if (!pTbCur->paused) { metaReaderClear(&pTbCur->mr); - tdbTbcClose((TBC *)pTbCur->pDbc); + (void)tdbTbcClose((TBC *)pTbCur->pDbc); pTbCur->paused = 1; } } @@ -270,19 +270,19 @@ void metaResumeTbCursor(SMTbCursor *pTbCur, int8_t first, int8_t move) { if (pTbCur->paused) { metaReaderDoInit(&pTbCur->mr, pTbCur->pMeta, META_READER_LOCK); - tdbTbcOpen(((SMeta *)pTbCur->pMeta)->pUidIdx, (TBC **)&pTbCur->pDbc, NULL); + (void)tdbTbcOpen(((SMeta *)pTbCur->pMeta)->pUidIdx, (TBC **)&pTbCur->pDbc, NULL); if (first) { - tdbTbcMoveToFirst((TBC *)pTbCur->pDbc); + (void)tdbTbcMoveToFirst((TBC *)pTbCur->pDbc); } else { int c = 1; - tdbTbcMoveTo(pTbCur->pDbc, pTbCur->pKey, pTbCur->kLen, &c); + (void)tdbTbcMoveTo(pTbCur->pDbc, pTbCur->pKey, pTbCur->kLen, &c); if (c == 0) { if (move) tdbTbcMoveToNext(pTbCur->pDbc); } else if (c < 0) { - tdbTbcMoveToPrev(pTbCur->pDbc); + (void)tdbTbcMoveToPrev(pTbCur->pDbc); } else { - tdbTbcMoveToNext(pTbCur->pDbc); + (void)tdbTbcMoveToNext(pTbCur->pDbc); } } @@ -303,7 +303,7 @@ int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) { tDecoderClear(&pTbCur->mr.coder); - metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); + (void)metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); if (pTbCur->mr.me.type == jumpTableType) { continue; } @@ -327,7 +327,7 @@ int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType) { tDecoderClear(&pTbCur->mr.coder); - metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); + (void)metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); if (pTbCur->mr.me.type == jumpTableType) { continue; } @@ -355,11 +355,11 @@ _query: version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &(STbDbKey){.uid = uid, .version = version}, sizeof(STbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &(STbDbKey){.uid = uid, .version = version}, sizeof(STbDbKey), &pData, &nData); SMetaEntry me = {0}; tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &me); + (void)metaDecodeEntry(&dc, &me); if (me.type == TSDB_SUPER_TABLE) { if (sver == -1 || sver == me.stbEntry.schemaRow.version) { pSchema = tCloneSSchemaWrapper(&me.stbEntry.schemaRow); @@ -385,7 +385,7 @@ _query: } tDecoderInit(&dc, pData, nData); - tDecodeSSchemaWrapperEx(&dc, &schema); + (void)tDecodeSSchemaWrapperEx(&dc, &schema); pSchema = tCloneSSchemaWrapper(&schema); tDecoderClear(&dc); @@ -433,7 +433,7 @@ void metaCloseCtbCursor(SMCtbCursor *pCtbCur) { if (!pCtbCur->paused) { if (pCtbCur->pMeta && pCtbCur->lock) metaULock(pCtbCur->pMeta); if (pCtbCur->pCur) { - tdbTbcClose(pCtbCur->pCur); + (void)tdbTbcClose(pCtbCur->pCur); } } tdbFree(pCtbCur->pKey); @@ -444,7 +444,7 @@ void metaCloseCtbCursor(SMCtbCursor *pCtbCur) { void metaPauseCtbCursor(SMCtbCursor *pCtbCur) { if (!pCtbCur->paused) { - tdbTbcClose((TBC *)pCtbCur->pCur); + (void)tdbTbcClose((TBC *)pCtbCur->pCur); if (pCtbCur->lock) { metaULock(pCtbCur->pMeta); } @@ -472,17 +472,17 @@ int32_t metaResumeCtbCursor(SMCtbCursor *pCtbCur, int8_t first) { ctbIdxKey.suid = pCtbCur->suid; ctbIdxKey.uid = INT64_MIN; int c = 0; - tdbTbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c); + (void)tdbTbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c); if (c > 0) { - tdbTbcMoveToNext(pCtbCur->pCur); + (void)tdbTbcMoveToNext(pCtbCur->pCur); } } else { int c = 0; ret = tdbTbcMoveTo(pCtbCur->pCur, pCtbCur->pKey, pCtbCur->kLen, &c); if (c < 0) { - tdbTbcMoveToPrev(pCtbCur->pCur); + (void)tdbTbcMoveToPrev(pCtbCur->pCur); } else { - tdbTbcMoveToNext(pCtbCur->pCur); + (void)tdbTbcMoveToNext(pCtbCur->pCur); } } } @@ -540,9 +540,9 @@ SMStbCursor *metaOpenStbCursor(SMeta *pMeta, tb_uid_t suid) { } // move to the suid - tdbTbcMoveTo(pStbCur->pCur, &suid, sizeof(suid), &c); + (void)tdbTbcMoveTo(pStbCur->pCur, &suid, sizeof(suid), &c); if (c > 0) { - tdbTbcMoveToNext(pStbCur->pCur); + (void)tdbTbcMoveToNext(pStbCur->pCur); } return pStbCur; @@ -552,7 +552,7 @@ void metaCloseStbCursor(SMStbCursor *pStbCur) { if (pStbCur) { if (pStbCur->pMeta) metaULock(pStbCur->pMeta); if (pStbCur->pCur) { - tdbTbcClose(pStbCur->pCur); + (void)tdbTbcClose(pStbCur->pCur); tdbFree(pStbCur->pKey); tdbFree(pStbCur->pVal); @@ -603,35 +603,35 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv skmDbKey.uid = suid ? suid : uid; skmDbKey.sver = INT32_MAX; - tdbTbcOpen(pMeta->pSkmDb, &pSkmDbC, NULL); + (void)tdbTbcOpen(pMeta->pSkmDb, &pSkmDbC, NULL); metaRLock(pMeta); if (tdbTbcMoveTo(pSkmDbC, &skmDbKey, sizeof(skmDbKey), &c) < 0) { metaULock(pMeta); - tdbTbcClose(pSkmDbC); + (void)tdbTbcClose(pSkmDbC); code = TSDB_CODE_NOT_FOUND; goto _exit; } if (c == 0) { metaULock(pMeta); - tdbTbcClose(pSkmDbC); + (void)tdbTbcClose(pSkmDbC); code = TSDB_CODE_FAILED; metaError("meta/query: incorrect c: %" PRId32 ".", c); goto _exit; } if (c < 0) { - tdbTbcMoveToPrev(pSkmDbC); + (void)tdbTbcMoveToPrev(pSkmDbC); } const void *pKey = NULL; int32_t nKey = 0; - tdbTbcGet(pSkmDbC, &pKey, &nKey, NULL, NULL); + (void)tdbTbcGet(pSkmDbC, &pKey, &nKey, NULL, NULL); if (((SSkmDbKey *)pKey)->uid != skmDbKey.uid) { metaULock(pMeta); - tdbTbcClose(pSkmDbC); + (void)tdbTbcClose(pSkmDbC); code = TSDB_CODE_NOT_FOUND; goto _exit; } @@ -639,7 +639,7 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv sver = ((SSkmDbKey *)pKey)->sver; metaULock(pMeta); - tdbTbcClose(pSkmDbC); + (void)tdbTbcClose(pSkmDbC); } } @@ -753,9 +753,9 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { // move to the suid smaIdxKey.uid = uid; smaIdxKey.smaUid = INT64_MIN; - tdbTbcMoveTo(pSmaCur->pCur, &smaIdxKey, sizeof(smaIdxKey), &c); + (void)tdbTbcMoveTo(pSmaCur->pCur, &smaIdxKey, sizeof(smaIdxKey), &c); if (c > 0) { - tdbTbcMoveToNext(pSmaCur->pCur); + (void)tdbTbcMoveToNext(pSmaCur->pCur); } return pSmaCur; @@ -765,7 +765,7 @@ void metaCloseSmaCursor(SMSmaCursor *pSmaCur) { if (pSmaCur) { if (pSmaCur->pMeta) metaULock(pSmaCur->pMeta); if (pSmaCur->pCur) { - tdbTbcClose(pSmaCur->pCur); + (void)tdbTbcClose(pSmaCur->pCur); tdbFree(pSmaCur->pKey); tdbFree(pSmaCur->pVal); @@ -863,7 +863,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { _err: metaReaderClear(&mr); taosArrayDestroy(pSmaIds); - tFreeTSmaWrapper(pSW, deepCopy); + (void)tFreeTSmaWrapper(pSW, deepCopy); return NULL; } @@ -1086,7 +1086,7 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) { END: if (pCursor->pMeta) metaULock(pCursor->pMeta); - if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + if (pCursor->pCur) (void)tdbTbcClose(pCursor->pCur); taosMemoryFree(pCursor); return ret; } @@ -1153,7 +1153,7 @@ int32_t metaFilterTableName(void *pVnode, SMetaFltParam *arg, SArray *pUids) { END: if (pCursor->pMeta) metaULock(pCursor->pMeta); - if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + if (pCursor->pCur) (void)tdbTbcClose(pCursor->pCur); taosMemoryFree(buf); taosMemoryFree(pKey); @@ -1182,7 +1182,7 @@ int32_t metaFilterTtl(void *pVnode, SMetaFltParam *arg, SArray *pUids) { END: if (pCursor->pMeta) metaULock(pCursor->pMeta); - if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + if (pCursor->pCur) (void)tdbTbcClose(pCursor->pCur); taosMemoryFree(buf); taosMemoryFree(pKey); @@ -1221,7 +1221,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) { } tbDbKey.uid = param->suid; tbDbKey.version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); ret = metaDecodeEntry(&dc, &oStbEntry); @@ -1353,7 +1353,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) { END: if (pCursor->pMeta) metaULock(pCursor->pMeta); - if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + if (pCursor->pCur) (void)tdbTbcClose(pCursor->pCur); if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); tDecoderClear(&dc); tdbFree(pData); @@ -1427,7 +1427,7 @@ int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *pUidTagInfo) { taosHashInit(numOfElems / 0.7, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); for (int i = 0; i < numOfElems; i++) { STUidTagInfo *pTagInfo = taosArrayGet(pUidTagInfo, i); - taosHashPut(pSepecifiedUidMap, &pTagInfo->uid, sizeof(uint64_t), &i, sizeof(int32_t)); + (void)taosHashPut(pSepecifiedUidMap, &pTagInfo->uid, sizeof(uint64_t), &i, sizeof(int32_t)); } } @@ -1513,7 +1513,7 @@ int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo, SMetaReader *pR } // upsert the cache metaWLock(pMeta); - metaCacheUpsert(pMeta, pInfo); + (void)metaCacheUpsert(pMeta, pInfo); metaULock(pMeta); if (lock) { @@ -1565,7 +1565,7 @@ int32_t metaGetStbStats(void *pVnode, int64_t uid, int64_t *numOfTables, int32_t // upsert the cache metaWLock(pVnodeObj->pMeta); - metaStatsCacheUpsert(pVnodeObj->pMeta, &state); + (void)metaStatsCacheUpsert(pVnodeObj->pMeta, &state); metaULock(pVnodeObj->pMeta); _exit: @@ -1578,6 +1578,6 @@ void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t deltaCtb, int32_t del if (metaStatsCacheGet(pMeta, uid, &stats) == TSDB_CODE_SUCCESS) { stats.ctbNum += deltaCtb; stats.colNum += deltaCol; - metaStatsCacheUpsert(pMeta, &stats); + (void)metaStatsCacheUpsert(pMeta, &stats); } } diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index b8043c00de..3f99bcb5b2 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -59,7 +59,7 @@ _exit: void metaSnapReaderClose(SMetaSnapReader** ppReader) { if (ppReader && *ppReader) { - tdbTbcClose((*ppReader)->pTbc); + (void)tdbTbcClose((*ppReader)->pTbc); taosMemoryFree(*ppReader); *ppReader = NULL; } @@ -87,7 +87,7 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { if (key.version < pReader->sver // || metaGetInfo(pReader->pMeta, key.uid, &info, NULL) == TSDB_CODE_NOT_FOUND) { - tdbTbcMoveToNext(pReader->pTbc); + (void)tdbTbcMoveToNext(pReader->pTbc); continue; } @@ -110,7 +110,7 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { metaDebug("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " blockLen:%d", TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData); - tdbTbcMoveToNext(pReader->pTbc); + (void)tdbTbcMoveToNext(pReader->pTbc); break; } @@ -223,17 +223,17 @@ static int32_t MoveToSnapShotVersion(SSnapContext* ctx) { int32_t code = 0; (void)tdbTbcClose((TBC*)ctx->pCur); code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } STbDbKey key = {.version = ctx->snapVersion, .uid = INT64_MAX}; int c = 0; code = tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } if (c < 0) { - tdbTbcMoveToPrev((TBC*)ctx->pCur); + (void)tdbTbcMoveToPrev((TBC*)ctx->pCur); } return 0; } @@ -241,13 +241,13 @@ static int32_t MoveToSnapShotVersion(SSnapContext* ctx) { static int32_t MoveToPosition(SSnapContext* ctx, int64_t ver, int64_t uid) { (void)tdbTbcClose((TBC*)ctx->pCur); int32_t code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } STbDbKey key = {.version = ver, .uid = uid}; int c = 0; code = tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } return c; @@ -256,11 +256,11 @@ static int32_t MoveToPosition(SSnapContext* ctx, int64_t ver, int64_t uid) { static int32_t MoveToFirst(SSnapContext* ctx) { (void)tdbTbcClose((TBC*)ctx->pCur); int32_t code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } code = tdbTbcMoveToFirst((TBC*)ctx->pCur); - if (code != 0){ + if (code != 0) { return TAOS_GET_TERRNO(code); } return 0; @@ -271,38 +271,39 @@ static int32_t saveSuperTableInfoForChildTable(SMetaEntry* me, SHashObj* suidInf if (data) { return 0; } - int32_t code = 0; + int32_t code = 0; STableInfoForChildTable dataTmp = {0}; dataTmp.tableName = taosStrdup(me->name); - if (dataTmp.tableName == NULL){ + if (dataTmp.tableName == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto END; } dataTmp.schemaRow = tCloneSSchemaWrapper(&me->stbEntry.schemaRow); - if (dataTmp.schemaRow == NULL){ + if (dataTmp.schemaRow == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto END; } dataTmp.tagRow = tCloneSSchemaWrapper(&me->stbEntry.schemaTag); - if (dataTmp.tagRow == NULL){ + if (dataTmp.tagRow == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto END; } code = taosHashPut(suidInfo, &me->uid, sizeof(tb_uid_t), &dataTmp, sizeof(STableInfoForChildTable)); - if (code != 0){ + if (code != 0) { goto END; } return 0; END: destroySTableInfoForChildTable(&dataTmp); - return TAOS_GET_TERRNO(code);; + return TAOS_GET_TERRNO(code); + ; } int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8_t subType, int8_t withMeta, SSnapContext** ctxRet) { SSnapContext* ctx = taosMemoryCalloc(1, sizeof(SSnapContext)); - if (ctx == NULL){ + if (ctx == NULL) { return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } *ctxRet = ctx; @@ -319,14 +320,16 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 ctx->suidInfo = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); if (ctx->suidInfo == NULL) { - return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);; + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + ; } taosHashSetFreeFp(ctx->suidInfo, destroySTableInfoForChildTable); ctx->index = 0; ctx->idList = taosArrayInit(100, sizeof(int64_t)); - if (ctx->idList == NULL){ - return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);; + if (ctx->idList == NULL) { + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + ; } void* pKey = NULL; void* pVal = NULL; @@ -334,7 +337,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 metaDebug("tmqsnap init snapVersion:%" PRIi64, ctx->snapVersion); int32_t code = MoveToFirst(ctx); - if (code != 0){ + if (code != 0) { return code; } while (1) { @@ -348,7 +351,8 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 continue; } - if (tdbTbGet(ctx->pMeta->pUidIdx, &tmp->uid, sizeof(tb_uid_t), NULL, NULL) < 0) { // check if table exist for now, need optimize later + if (tdbTbGet(ctx->pMeta->pUidIdx, &tmp->uid, sizeof(tb_uid_t), NULL, NULL) < + 0) { // check if table exist for now, need optimize later continue; } @@ -356,7 +360,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 SMetaEntry me = {0}; tDecoderInit(&dc, pVal, vLen); ret = metaDecodeEntry(&dc, &me); - if (ret < 0){ + if (ret < 0) { tDecoderClear(&dc); return TAOS_GET_TERRNO(ret); } @@ -368,7 +372,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 } } - if (taosArrayPush(ctx->idList, &tmp->uid) == NULL){ + if (taosArrayPush(ctx->idList, &tmp->uid) == NULL) { tDecoderClear(&dc); return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } @@ -383,7 +387,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 taosHashClear(ctx->idVersion); code = MoveToSnapShotVersion(ctx); - if (code != 0){ + if (code != 0) { return code; } while (1) { @@ -405,7 +409,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 SMetaEntry me = {0}; tDecoderInit(&dc, pVal, vLen); ret = metaDecodeEntry(&dc, &me); - if (ret < 0){ + if (ret < 0) { tDecoderClear(&dc); return TAOS_GET_TERRNO(ret); } @@ -421,7 +425,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_SUPER_TABLE) || (ctx->subType == TOPIC_SUB_TYPE__TABLE && me.uid == ctx->suid)) { ret = saveSuperTableInfoForChildTable(&me, ctx->suidInfo); - if (ret != 0){ + if (ret != 0) { tDecoderClear(&dc); return ret; } @@ -431,7 +435,7 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8 for (int i = 0; i < taosArrayGetSize(ctx->idList); i++) { int64_t* uid = taosArrayGet(ctx->idList, i); - if (uid == NULL){ + if (uid == NULL) { return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } SIdInfo* idData = (SIdInfo*)taosHashGet(ctx->idVersion, uid, sizeof(int64_t)); @@ -467,7 +471,7 @@ static int32_t buildNormalChildTableInfo(SVCreateTbReq* req, void** pBuf, int32_ ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); goto end; } - if (taosArrayPush(reqs.pArray, req) == NULL){ + if (taosArrayPush(reqs.pArray, req) == NULL) { ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); goto end; } @@ -540,10 +544,10 @@ int32_t setForSnapShot(SSnapContext* ctx, int64_t uid) { return 0; } -void taosXSetTablePrimaryKey(SSnapContext* ctx, int64_t uid){ - bool ret = false; - SSchemaWrapper *schema = metaGetTableSchema(ctx->pMeta, uid, -1, 1); - if (schema && schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY){ +void taosXSetTablePrimaryKey(SSnapContext* ctx, int64_t uid) { + bool ret = false; + SSchemaWrapper* schema = metaGetTableSchema(ctx->pMeta, uid, -1, 1); + if (schema && schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY) { ret = true; } tDeleteSchemaWrapper(schema); @@ -639,7 +643,7 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); goto END; } - STag* p = (STag*)me.ctbEntry.pTags; + STag* p = (STag*)me.ctbEntry.pTags; if (tTagIsJson(p)) { if (p->nTag != 0) { SSchema* schema = &data->tagRow->pSchema[0]; @@ -651,7 +655,7 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe } } else { SArray* pTagVals = NULL; - ret = tTagToValArray((const STag*)p, &pTagVals); + ret = tTagToValArray((const STag*)p, &pTagVals); if (ret != 0) { metaError("meta/snap: tag to val array failed."); taosArrayDestroy(pTagVals); @@ -701,9 +705,9 @@ END: } int32_t getMetaTableInfoFromSnapshot(SSnapContext* ctx, SMetaTableInfo* result) { - void* pKey = NULL; - void* pVal = NULL; - int vLen, kLen; + void* pKey = NULL; + void* pVal = NULL; + int vLen, kLen; while (1) { if (ctx->index >= taosArrayGetSize(ctx->idList)) { @@ -711,7 +715,7 @@ int32_t getMetaTableInfoFromSnapshot(SSnapContext* ctx, SMetaTableInfo* result) return 0; } int64_t* uidTmp = taosArrayGet(ctx->idList, ctx->index); - if (uidTmp == NULL){ + if (uidTmp == NULL) { return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } ctx->index++; @@ -728,21 +732,21 @@ int32_t getMetaTableInfoFromSnapshot(SSnapContext* ctx, SMetaTableInfo* result) continue; } ret = tdbTbcGet((TBC*)ctx->pCur, (const void**)&pKey, &kLen, (const void**)&pVal, &vLen); - if (ret != 0){ + if (ret != 0) { return TAOS_GET_TERRNO(ret); } SDecoder dc = {0}; SMetaEntry me = {0}; tDecoderInit(&dc, pVal, vLen); ret = metaDecodeEntry(&dc, &me); - if (ret != 0){ + if (ret != 0) { tDecoderClear(&dc); return TAOS_GET_TERRNO(ret); } metaDebug("tmqsnap get uid info uid:%" PRIi64 " name:%s index:%d", me.uid, me.name, ctx->index - 1); if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_CHILD_TABLE) || - (ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid)){ + (ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid)) { STableInfoForChildTable* data = (STableInfoForChildTable*)taosHashGet(ctx->suidInfo, &me.ctbEntry.suid, sizeof(tb_uid_t)); if (data == NULL) { @@ -763,7 +767,7 @@ int32_t getMetaTableInfoFromSnapshot(SSnapContext* ctx, SMetaTableInfo* result) result->uid = me.uid; tstrncpy(result->tbName, me.name, TSDB_TABLE_NAME_LEN); tDecoderClear(&dc); - if(result->schema == NULL){ + if (result->schema == NULL) { return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); } break; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 04447fd3ce..2badeec2c9 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -161,10 +161,10 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len); } if (term != NULL) { - indexMultiTermAdd(terms, term); + (void)indexMultiTermAdd(terms, term); } } - indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); + (void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); indexMultiTermDestroy(terms); taosArrayDestroy(pTagVals); @@ -223,10 +223,10 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len); } if (term != NULL) { - indexMultiTermAdd(terms, term); + (void)indexMultiTermAdd(terms, term); } } - indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); + (void)indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); indexMultiTermDestroy(terms); taosArrayDestroy(pTagVals); #endif @@ -239,7 +239,7 @@ static inline void metaTimeSeriesNotifyCheck(SMeta *pMeta) { int64_t deltaTS = nTimeSeries - pMeta->pVnode->config.vndStats.numOfReportedTimeSeries; if (deltaTS > tsTimeSeriesThreshold) { if (0 == atomic_val_compare_exchange_8(&dmNotifyHdl.state, 1, 2)) { - tsem_post(&dmNotifyHdl.sem); + (void)tsem_post(&dmNotifyHdl.sem); } } #endif @@ -323,10 +323,10 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb // drop all child tables TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); + (void)(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); if (rc < 0) { - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); metaWLock(pMeta); goto _drop_super_table; } @@ -344,7 +344,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb (void)taosArrayPush(tbUidList, &(((SCtbIdxKey *)pKey)->uid)); } - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); (void)tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, tbUidList, pReq->suid); @@ -352,19 +352,19 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb for (int32_t iChild = 0; iChild < taosArrayGetSize(tbUidList); iChild++) { tb_uid_t uid = *(tb_uid_t *)taosArrayGet(tbUidList, iChild); - metaDropTableByUid(pMeta, uid, NULL, NULL, NULL); + (void)metaDropTableByUid(pMeta, uid, NULL, NULL, NULL); } // drop super table _drop_super_table: tdbTbGet(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pData, &nData); - tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = ((SUidIdxVal *)pData)[0].version, .uid = pReq->suid}, - sizeof(STbDbKey), pMeta->txn); - tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, pMeta->txn); - tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); - tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); + (void)tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = ((SUidIdxVal *)pData)[0].version, .uid = pReq->suid}, + sizeof(STbDbKey), pMeta->txn); + (void)tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, pMeta->txn); + (void)tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); + (void)tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); - metaStatsCacheDrop(pMeta, pReq->suid); + (void)metaStatsCacheDrop(pMeta, pReq->suid); metaULock(pMeta); @@ -387,10 +387,10 @@ static void metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) { int nKey = 0; TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); + (void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); if (rc < 0) { - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); metaWLock(pMeta); return; } @@ -410,7 +410,7 @@ static void metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) { tdbFree(pKey); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); } int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { @@ -425,28 +425,28 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int32_t ret; int32_t c = -2; - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); + (void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); ret = tdbTbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c); if (ret < 0 || c) { - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pUidIdxc); return terrno = TSDB_CODE_TDB_STB_NOT_EXIST; } ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); if (ret < 0) { - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pUidIdxc); return terrno = TSDB_CODE_TDB_STB_NOT_EXIST; } oversion = ((SUidIdxVal *)pData)[0].version; - tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); + (void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); ret = tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = pReq->suid, .version = oversion}), sizeof(STbDbKey), &c); if (!(ret == 0 && c == 0)) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); metaError("meta/table: invalide ret: %" PRId32 " or c: %" PRId32 "alter stb failed.", ret, c); return terrno = TSDB_CODE_TDB_STB_NOT_EXIST; @@ -454,8 +454,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); if (ret < 0) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); return terrno = TSDB_CODE_TDB_STB_NOT_EXIST; } @@ -463,7 +463,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { oStbEntry.pBuf = taosMemoryMalloc(nData); memcpy(oStbEntry.pBuf, pData, nData); tDecoderInit(&dc, oStbEntry.pBuf, nData); - metaDecodeEntry(&dc, &oStbEntry); + (void)metaDecodeEntry(&dc, &oStbEntry); nStbEntry.version = version; nStbEntry.type = TSDB_SUPER_TABLE; @@ -487,7 +487,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int8_t col_type = pReq->schemaRow.pSchema[nCols - 1].type; metaGetSubtables(pMeta, pReq->suid, uids); - tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type); + (void)tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type); } else if (deltaCol == -1) { int16_t cid = -1; bool hasPrimaryKey = false; @@ -503,7 +503,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (cid != -1) { metaGetSubtables(pMeta, pReq->suid, uids); - tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey); + (void)tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey); } } if (uids) taosArrayDestroy(uids); @@ -512,25 +512,25 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { metaWLock(pMeta); // compare two entry if (oStbEntry.stbEntry.schemaRow.version != pReq->schemaRow.version) { - metaSaveToSkmDb(pMeta, &nStbEntry); + (void)metaSaveToSkmDb(pMeta, &nStbEntry); } // update table.db - metaSaveToTbDb(pMeta, &nStbEntry); + (void)metaSaveToTbDb(pMeta, &nStbEntry); // update uid index - metaUpdateUidIdx(pMeta, &nStbEntry); + (void)metaUpdateUidIdx(pMeta, &nStbEntry); // metaStatsCacheDrop(pMeta, nStbEntry.uid); if (updStat) { - metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol); + (void)metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol); } metaULock(pMeta); if (updStat) { int64_t ctbNum; - metaGetStbStats(pMeta->pVnode, pReq->suid, &ctbNum, NULL); + (void)metaGetStbStats(pMeta->pVnode, pReq->suid, &ctbNum, NULL); pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol); metaTimeSeriesNotifyCheck(pMeta); } @@ -540,8 +540,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { _exit: if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); tDecoderClear(&dc); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); return 0; } int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { @@ -568,7 +568,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); ret = metaDecodeEntry(&dc, &oStbEntry); @@ -619,10 +619,10 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { * iterator all pTdDbc by uid and version */ TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); + (void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); if (rc < 0) { - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } for (;;) { @@ -632,7 +632,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (rc < 0) { tdbFree(pKey); tdbFree(pVal); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); pCtbIdxc = NULL; break; } @@ -667,12 +667,12 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { tdbFree(pVal); if (rc < 0) { metaDestroyTagIdxKey(pTagIdxKey); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } metaWLock(pMeta); - tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); metaULock(pMeta); metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; @@ -688,16 +688,16 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { metaWLock(pMeta); // update table.db - metaSaveToTbDb(pMeta, &nStbEntry); + (void)metaSaveToTbDb(pMeta, &nStbEntry); // update uid index - metaUpdateUidIdx(pMeta, &nStbEntry); + (void)metaUpdateUidIdx(pMeta, &nStbEntry); metaULock(pMeta); if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); tDecoderClear(&dc); tdbFree(pData); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); return TSDB_CODE_SUCCESS; _err: if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); @@ -729,7 +729,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); ret = metaDecodeEntry(&dc, &oStbEntry); if (ret < 0) { @@ -756,10 +756,10 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) * iterator all pTdDbc by uid and version */ TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); + (void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); if (rc < 0) { - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } for (;;) { @@ -769,7 +769,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) if (rc < 0) { tdbFree(pKey); tdbFree(pVal); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); pCtbIdxc = NULL; break; } @@ -804,12 +804,12 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) tdbFree(pVal); if (rc < 0) { metaDestroyTagIdxKey(pTagIdxKey); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } metaWLock(pMeta); - tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + (void)tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); metaULock(pMeta); metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; @@ -836,9 +836,9 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) metaWLock(pMeta); // update table.db - metaSaveToTbDb(pMeta, &nStbEntry); + (void)metaSaveToTbDb(pMeta, &nStbEntry); // update uid index - metaUpdateUidIdx(pMeta, &nStbEntry); + (void)metaUpdateUidIdx(pMeta, &nStbEntry); metaULock(pMeta); tDeleteSchemaWrapper(tag); @@ -849,7 +849,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) tDecoderClear(&dc); tdbFree(pData); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); return TSDB_CODE_SUCCESS; _err: if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); @@ -937,18 +937,18 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs if (!sysTbl) { int32_t nCols = 0; - metaGetStbStats(pMeta->pVnode, me.ctbEntry.suid, 0, &nCols); + (void)metaGetStbStats(pMeta->pVnode, me.ctbEntry.suid, 0, &nCols); pStats->numOfTimeSeries += nCols - 1; } metaWLock(pMeta); - metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1, 0); - metaUidCacheClear(pMeta, me.ctbEntry.suid); - metaTbGroupCacheClear(pMeta, me.ctbEntry.suid); + (void)metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1, 0); + (void)metaUidCacheClear(pMeta, me.ctbEntry.suid); + (void)metaTbGroupCacheClear(pMeta, me.ctbEntry.suid); metaULock(pMeta); if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, me.ctbEntry.suid, NULL); + (void)tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, me.ctbEntry.suid, NULL); } } else { me.ntbEntry.btime = pReq->btime; @@ -964,7 +964,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs pStats->numOfNTimeSeries += me.ntbEntry.schemaRow.nCols - 1; if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, -1, &me.ntbEntry.schemaRow); + (void)tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, -1, &me.ntbEntry.schemaRow); } } @@ -982,7 +982,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs (*pMetaRsp)->suid = pReq->ctb.suid; strcpy((*pMetaRsp)->tbName, pReq->name); } else { - metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp); + (void)metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp); for (int32_t i = 0; i < pReq->colCmpr.nCols; i++) { SColCmpr *p = &pReq->colCmpr.pColCmpr[i]; (*pMetaRsp)->pSchemaExt[i].colId = p->id; @@ -1036,7 +1036,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi (void)taosArrayPush(tbUids, &uid); if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { - tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); + (void)tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL); } } @@ -1062,7 +1062,7 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) { tb_uid_t suid = 0; int8_t sysTbl = 0; int type; - metaDropTableByUid(pMeta, uid, &type, &suid, &sysTbl); + (void)metaDropTableByUid(pMeta, uid, &type, &suid, &sysTbl); if (!sysTbl && type == TSDB_CHILD_TABLE && suid != 0 && suidHash) { int64_t *pVal = tSimpleHashGet(suidHash, &suid, sizeof(tb_uid_t)); if (pVal) { @@ -1070,7 +1070,7 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) { } else { nCtbDropped = 1; } - tSimpleHashPut(suidHash, &suid, sizeof(tb_uid_t), &nCtbDropped, sizeof(int64_t)); + (void)tSimpleHashPut(suidHash, &suid, sizeof(tb_uid_t), &nCtbDropped, sizeof(int64_t)); } /* if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { @@ -1111,7 +1111,7 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { code = tdbTbcMoveToFirst(pCur); if (code) { - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return code; } @@ -1127,7 +1127,7 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { SMetaEntry me = {0}; SDecoder dc = {0}; tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &me); + (void)metaDecodeEntry(&dc, &me); if (me.type != TSDB_SUPER_TABLE) { char tbFName[TSDB_TABLE_FNAME_LEN + 1]; @@ -1142,7 +1142,7 @@ static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { } tdbFree(pData); tdbFree(pKey); - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } @@ -1237,7 +1237,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } int64_t version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); rc = metaDecodeEntry(&dc, &e); @@ -1260,7 +1260,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p SMetaEntry stbEntry = {0}; tDecoderInit(&tdc, tData, tLen); - metaDecodeEntry(&tdc, &stbEntry); + (void)metaDecodeEntry(&tdc, &stbEntry); if (pSysTbl) *pSysTbl = metaTbInFilterCache(pMeta, stbEntry.name, 1) ? 1 : 0; @@ -1268,7 +1268,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; - metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); + (void)metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); } else { for (int i = 0; i < pTagSchema->nCols; i++) { pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[i]; @@ -1296,7 +1296,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p if (metaCreateTagIdxKey(e.ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, uid, &pTagIdxKey, &nTagIdxKey) == 0) { - tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); + (void)tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn); } metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; @@ -1308,9 +1308,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } } - tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), pMeta->txn); - tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn); - tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn); + (void)tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), pMeta->txn); + (void)tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn); + (void)tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn); if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteBtimeIdx(pMeta, &e); if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e); @@ -1318,12 +1318,13 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p if (e.type != TSDB_SUPER_TABLE) metaDeleteTtl(pMeta, &e); if (e.type == TSDB_CHILD_TABLE) { - tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), pMeta->txn); + (void)tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), + pMeta->txn); --pMeta->pVnode->config.vndStats.numOfCTables; - metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1, 0); - metaUidCacheClear(pMeta, e.ctbEntry.suid); - metaTbGroupCacheClear(pMeta, e.ctbEntry.suid); + (void)metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1, 0); + (void)metaUidCacheClear(pMeta, e.ctbEntry.suid); + (void)metaTbGroupCacheClear(pMeta, e.ctbEntry.suid); /* if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { tsdbCacheDropTable(pMeta->pVnode->pTsdb, e.uid, e.ctbEntry.suid, NULL); @@ -1341,16 +1342,16 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p } */ } else if (e.type == TSDB_SUPER_TABLE) { - tdbTbDelete(pMeta->pSuidIdx, &e.uid, sizeof(tb_uid_t), pMeta->txn); + (void)tdbTbDelete(pMeta->pSuidIdx, &e.uid, sizeof(tb_uid_t), pMeta->txn); // drop schema.db (todo) - metaStatsCacheDrop(pMeta, uid); - metaUidCacheClear(pMeta, uid); - metaTbGroupCacheClear(pMeta, uid); + (void)metaStatsCacheDrop(pMeta, uid); + (void)metaUidCacheClear(pMeta, uid); + (void)metaTbGroupCacheClear(pMeta, uid); --pMeta->pVnode->config.vndStats.numOfSTables; } - metaCacheDrop(pMeta, uid); + (void)metaCacheDrop(pMeta, uid); tDecoderClear(&dc); tdbFree(pData); @@ -1423,30 +1424,30 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // search uid index TBC *pUidIdxc = NULL; - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); - tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + (void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); + (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c); return TSDB_CODE_FAILED; } - tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); oversion = ((SUidIdxVal *)pData)[0].version; // search table.db TBC *pTbDbc = NULL; - tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); - tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + (void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); + (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c); return TSDB_CODE_FAILED; } - tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); // get table entry SDecoder dc = {0}; @@ -1455,8 +1456,8 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); if (ret != 0) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); tDecoderClear(&dc); metaError("meta/table: invalide ret: %" PRId32 " alt tb column failed.", ret); return ret; @@ -1536,7 +1537,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl SSchema *pCol = &pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1]; uint32_t compress = pAlterTbReq->action == TSDB_ALTER_TABLE_ADD_COLUMN ? createDefaultColCmprByType(pCol->type) : pAlterTbReq->compress; - updataTableColCmpr(&entry.colCmpr, pCol, 1, compress); + (void)updataTableColCmpr(&entry.colCmpr, pCol, 1, compress); freeColCmpr = true; ASSERT(entry.colCmpr.nCols == pSchema->nCols); break; @@ -1574,7 +1575,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl (void)tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey); } - updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0); + (void)updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0); ASSERT(entry.colCmpr.nCols == pSchema->nCols); break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: @@ -1620,20 +1621,20 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // do actual write metaWLock(pMeta); - metaDeleteNcolIdx(pMeta, &oldEntry); - metaUpdateNcolIdx(pMeta, &entry); + (void)metaDeleteNcolIdx(pMeta, &oldEntry); + (void)metaUpdateNcolIdx(pMeta, &entry); // save to table db - metaSaveToTbDb(pMeta, &entry); + (void)metaSaveToTbDb(pMeta, &entry); - metaUpdateUidIdx(pMeta, &entry); + (void)metaUpdateUidIdx(pMeta, &entry); - metaSaveToSkmDb(pMeta, &entry); + (void)metaSaveToSkmDb(pMeta, &entry); - metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); + (void)metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); metaULock(pMeta); - metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); + (void)metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); for (int32_t i = 0; i < entry.colCmpr.nCols; i++) { SColCmpr *p = &entry.colCmpr.pColCmpr[i]; pMetaRsp->pSchemaExt[i].colId = p->id; @@ -1644,16 +1645,16 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (pNewSchema) taosMemoryFree(pNewSchema); if (freeColCmpr) taosMemoryFree(entry.colCmpr.pColCmpr); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); tDecoderClear(&dc); return 0; _err: if (entry.pBuf) taosMemoryFree(entry.pBuf); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); tDecoderClear(&dc); return TSDB_CODE_FAILED; @@ -1688,15 +1689,15 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA // search uid index TBC *pUidIdxc = NULL; - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); - tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + (void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); + (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c); return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } - tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); oversion = ((SUidIdxVal *)pData)[0].version; // search table.db @@ -1705,34 +1706,34 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA SDecoder dc2 = {0}; /* get ctbEntry */ - tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); - tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + (void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); + (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c); return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } - tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); ctbEntry.pBuf = taosMemoryMalloc(nData); memcpy(ctbEntry.pBuf, pData, nData); tDecoderInit(&dc1, ctbEntry.pBuf, nData); - metaDecodeEntry(&dc1, &ctbEntry); + (void)metaDecodeEntry(&dc1, &ctbEntry); /* get stbEntry*/ - tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal); + (void)tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal); if (!pVal) { terrno = TSDB_CODE_INVALID_MSG; goto _err; } - tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}), - sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal); + (void)tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}), + sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal); tdbFree(pVal); tDecoderInit(&dc2, stbEntry.pBuf, nVal); - metaDecodeEntry(&dc2, &stbEntry); + (void)metaDecodeEntry(&dc2, &stbEntry); SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; SSchema *pColumn = NULL; @@ -1802,12 +1803,12 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA metaWLock(pMeta); // save to table.db - metaSaveToTbDb(pMeta, &ctbEntry); + (void)metaSaveToTbDb(pMeta, &ctbEntry); // save to uid.idx - metaUpdateUidIdx(pMeta, &ctbEntry); + (void)metaUpdateUidIdx(pMeta, &ctbEntry); - metaUpdateTagIdx(pMeta, &ctbEntry); + (void)metaUpdateTagIdx(pMeta, &ctbEntry); if (NULL == ctbEntry.ctbEntry.pTags) { metaError("meta/table: null tags, update tag val failed."); @@ -1815,13 +1816,13 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid}; - tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags, - ((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn); + (void)tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags, + ((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn); - metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid); - metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid); + (void)metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid); + (void)metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid); - metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs); + (void)metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs); metaULock(pMeta); @@ -1830,8 +1831,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA taosMemoryFree((void *)ctbEntry.ctbEntry.pTags); if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); return 0; _err: @@ -1839,8 +1840,8 @@ _err: tDecoderClear(&dc2); if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); return -1; } @@ -1868,30 +1869,30 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p // search uid index TBC *pUidIdxc = NULL; - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); - tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + (void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); + (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c); return TSDB_CODE_FAILED; } - tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); oversion = ((SUidIdxVal *)pData)[0].version; // search table.db TBC *pTbDbc = NULL; - tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); - tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + (void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); + (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); if (c != 0) { - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c); return TSDB_CODE_FAILED; } - tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); // get table entry SDecoder dc = {0}; @@ -1901,8 +1902,8 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p ret = metaDecodeEntry(&dc, &entry); if (ret != 0) { tDecoderClear(&dc); - tdbTbcClose(pUidIdxc); - tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); metaError("meta/table: invalide ret: %" PRId32 " alt tb options failed.", ret); return TSDB_CODE_FAILED; } @@ -1912,9 +1913,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p // build SMetaEntry if (entry.type == TSDB_CHILD_TABLE) { if (pAlterTbReq->updateTTL) { - metaDeleteTtl(pMeta, &entry); + (void)metaDeleteTtl(pMeta, &entry); entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; - metaUpdateTtl(pMeta, &entry); + (void)metaUpdateTtl(pMeta, &entry); } if (pAlterTbReq->newCommentLen >= 0) { entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen; @@ -1922,9 +1923,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p } } else { if (pAlterTbReq->updateTTL) { - metaDeleteTtl(pMeta, &entry); + (void)metaDeleteTtl(pMeta, &entry); entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; - metaUpdateTtl(pMeta, &entry); + (void)metaUpdateTtl(pMeta, &entry); } if (pAlterTbReq->newCommentLen >= 0) { entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen; @@ -1933,14 +1934,14 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p } // save to table db - metaSaveToTbDb(pMeta, &entry); - metaUpdateUidIdx(pMeta, &entry); - metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); + (void)metaSaveToTbDb(pMeta, &entry); + (void)metaUpdateUidIdx(pMeta, &entry); + (void)metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); metaULock(pMeta); - tdbTbcClose(pTbDbc); - tdbTbcClose(pUidIdxc); + (void)tdbTbcClose(pTbDbc); + (void)tdbTbcClose(pUidIdxc); tDecoderClear(&dc); if (entry.pBuf) taosMemoryFree(entry.pBuf); return 0; @@ -1981,7 +1982,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb STbDbKey tbDbKey = {0}; tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pVal)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); tDecoderInit(&dc, pVal, nVal); ret = metaDecodeEntry(&dc, &stbEntry); if (ret < 0) { @@ -2017,10 +2018,10 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb * iterator all pTdDbc by uid and version */ TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); + (void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); if (rc < 0) { - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } for (;;) { @@ -2057,14 +2058,14 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb tdbFree(pKey); tdbFree(pVal); metaDestroyTagIdxKey(pTagIdxKey); - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); goto _err; } - tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; } - tdbTbcClose(pCtbIdxc); + (void)tdbTbcClose(pCtbIdxc); return 0; _err: @@ -2115,7 +2116,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT STbDbKey tbDbKey = {0}; tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pVal)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); tDecoderInit(&dc, pVal, nVal); ret = metaDecodeEntry(&dc, &stbEntry); @@ -2156,7 +2157,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair)); TBC *pTagIdxc = NULL; - tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL); + (void)tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL); int rc = tdbTbcMoveTo(pTagIdxc, &(STagIdxKey){.suid = suid, .cid = INT32_MIN, .type = pCol->type}, sizeof(STagIdxKey), &c); for (;;) { @@ -2173,12 +2174,12 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT SMetaPair pair = {.key = pKey, nKey = nKey}; (void)taosArrayPush(tagIdxList, &pair); } - tdbTbcClose(pTagIdxc); + (void)tdbTbcClose(pTagIdxc); metaWLock(pMeta); for (int i = 0; i < taosArrayGetSize(tagIdxList); i++) { SMetaPair *pair = taosArrayGet(tagIdxList, i); - tdbTbDelete(pMeta->pTagIdx, pair->key, pair->nkey, pMeta->txn); + (void)tdbTbDelete(pMeta->pTagIdx, pair->key, pair->nkey, pMeta->txn); } metaULock(pMeta); @@ -2265,9 +2266,9 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq * tbEntry.version = version; metaWLock(pMeta); - metaSaveToTbDb(pMeta, &tbEntry); - metaUpdateUidIdx(pMeta, &tbEntry); - metaUpdateChangeTime(pMeta, suid, pReq->ctimeMs); + (void)metaSaveToTbDb(pMeta, &tbEntry); + (void)metaUpdateUidIdx(pMeta, &tbEntry); + (void)metaUpdateChangeTime(pMeta, suid, pReq->ctimeMs); metaULock(pMeta); @@ -2362,7 +2363,7 @@ static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) { // upsert cache SMetaInfo info; metaGetEntryInfo(pME, &info); - metaCacheUpsert(pMeta, &info); + (void)metaCacheUpsert(pMeta, &info); SUidIdxVal uidIdxVal = {.suid = info.suid, .version = info.version, .skmVer = info.skmVer}; @@ -2478,7 +2479,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { } tbDbKey.uid = pCtbEntry->ctbEntry.suid; tbDbKey.version = ((SUidIdxVal *)pData)[0].version; - tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); ret = metaDecodeEntry(&dc, &stbEntry); @@ -2525,7 +2526,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { ret = -1; goto end; } - tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; } @@ -2574,7 +2575,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) { } tEncoderInit(&coder, pVal, vLen); - tEncodeSSchemaWrapper(&coder, pSW); + (void)tEncodeSSchemaWrapper(&coder, pSW); if (tdbTbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, pMeta->txn) < 0) { rcode = -1; @@ -2662,7 +2663,7 @@ int32_t colCompressDebug(SHashObj *pColCmprObj) { p = taosHashIterate(pColCmprObj, p); uint8_t l1, l2, lvl; - tcompressDebug(cmprAlg, &l1, &l2, &lvl); + (void)tcompressDebug(cmprAlg, &l1, &l2, &lvl); const char *l1str = columnEncodeStr(l1); const char *l2str = columnCompressStr(l2); @@ -2711,7 +2712,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) { SColCmprWrapper *p = &e.colCmpr; for (int32_t i = 0; i < p->nCols; i++) { SColCmpr *pCmpr = &p->pColCmpr[i]; - taosHashPut(pColCmprObj, &pCmpr->id, sizeof(pCmpr->id), &pCmpr->alg, sizeof(pCmpr->alg)); + (void)taosHashPut(pColCmprObj, &pCmpr->id, sizeof(pCmpr->id), &pCmpr->alg, sizeof(pCmpr->alg)); } } else { tDecoderClear(&dc); @@ -2725,7 +2726,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) { metaULock(pMeta); *ppColCmprObj = pColCmprObj; - colCompressDebug(pColCmprObj); + (void)colCompressDebug(pColCmprObj); return 0; } diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c index e707f2150d..75b112f42b 100644 --- a/source/dnode/vnode/src/sma/smaCommit.c +++ b/source/dnode/vnode/src/sma/smaCommit.c @@ -257,7 +257,7 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) { if (RSMA_INFO_IS_DEL(pRSmaInfo)) { int32_t refVal = T_REF_VAL_GET(pRSmaInfo); if (refVal == 0) { - taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid)); + (void)taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid)); } else { smaDebug( "vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for " diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index e7a8de17a0..a219da33db 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -46,7 +46,7 @@ int32_t smaInit() { old = atomic_val_compare_exchange_8(&smaMgmt.inited, 0, 2); if (old != 2) break; if (++nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } } @@ -69,7 +69,7 @@ int32_t smaInit() { if (!smaMgmt.refHash || !smaMgmt.tmrHandle) { code = terrno; - taosCloseRef(smaMgmt.rsetId); + (void)taosCloseRef(smaMgmt.rsetId); if (smaMgmt.refHash) { taosHashCleanup(smaMgmt.refHash); smaMgmt.refHash = NULL; @@ -97,7 +97,7 @@ void smaCleanUp() { old = atomic_val_compare_exchange_8(&smaMgmt.inited, 1, 2); if (old != 2) break; if (++nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } } @@ -130,7 +130,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) { : atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv); if ((code = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) { - tdFreeSmaEnv(pEnv); + (void)tdFreeSmaEnv(pEnv); *ppEnv = NULL; (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL) : atomic_store_ptr(&SMA_RSMA_ENV(pSma), NULL); @@ -179,7 +179,7 @@ static void tRSmaInfoHashFreeNode(void *data) { if ((pItem = RSMA_INFO_ITEM((SRSmaInfo *)pRSmaInfo, 1)) && pItem->level) { (void)taosHashRemove(smaMgmt.refHash, &pItem, POINTER_BYTES); } - tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo); + (void)tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo); } } @@ -207,7 +207,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS SRSmaStat *pRSmaStat = (SRSmaStat *)(*pSmaStat); pRSmaStat->pSma = (SSma *)pSma; atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_INIT); - tsem_init(&pRSmaStat->notEmpty, 0, 0); + (void)tsem_init(&pRSmaStat->notEmpty, 0, 0); if (!(pRSmaStat->blocks = taosArrayInit(1, sizeof(SSDataBlock)))) { code = TSDB_CODE_OUT_OF_MEMORY; TAOS_CHECK_GOTO(code, &lino, _exit); @@ -216,7 +216,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS (void)taosArrayPush(pRSmaStat->blocks, &datablock); // init smaMgmt - smaInit(); + TAOS_CHECK_GOTO(smaInit(), &lino, _exit); int64_t refId = taosAddRef(smaMgmt.rsetId, pRSmaStat); if (refId < 0) { @@ -285,20 +285,20 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { } // step 3: - tdRsmaStopExecutor(pSma); + (void)tdRsmaStopExecutor(pSma); // step 4: destroy the rsma info and associated fetch tasks taosHashCleanup(RSMA_INFO_HASH(pStat)); // step 5: free pStat - tsem_destroy(&(pStat->notEmpty)); + (void)tsem_destroy(&(pStat->notEmpty)); taosArrayDestroy(pStat->blocks); taosMemoryFreeClear(pStat); } } static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { - tdDestroySmaState(pSmaStat, smaType); + (void)tdDestroySmaState(pSmaStat, smaType); if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { taosMemoryFreeClear(pSmaStat); } @@ -438,7 +438,7 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) { pthread = (TdThread *)&pStat->data; for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) { - tsem_post(&(pRSmaStat->notEmpty)); + (void)tsem_post(&(pRSmaStat->notEmpty)); } for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) { diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index d5409cf268..ebff03ff99 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -412,7 +412,7 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con _exit: if (code != 0) { - tdFreeRSmaInfo(pSma, pRSmaInfo); + (void)tdFreeRSmaInfo(pSma, pRSmaInfo); } else { smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid); } @@ -1264,7 +1264,7 @@ _checkpoint: if (pItem && pItem->pStreamTask) { SStreamTask *pTask = pItem->pStreamTask; // atomic_store_32(&pTask->pMeta->chkptNotReadyTasks, 1); - streamTaskSetActiveCheckpointInfo(pTask, checkpointId); + (void)streamTaskSetActiveCheckpointInfo(pTask, checkpointId); pTask->chkInfo.checkpointId = checkpointId; // 1pTask->checkpointingId; pTask->chkInfo.checkpointVer = pItem->submitReqVer; @@ -1373,7 +1373,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { ", rsetId:%d refId:%" PRIi64, SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaRef->refId); if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) { - taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); + (void)taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); } tdReleaseRSmaInfo(pSma, pRSmaInfo); (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); @@ -1629,7 +1629,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { batchMax = TMAX(batchMax, 4); } while (occupied || (++batchCnt < batchMax)) { // greedy mode - taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock + (void)taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock int32_t qallItemSize = taosQallItemSize(pInfo->qall); if (qallItemSize > 0) { if ((code = tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type)) != 0) { @@ -1663,7 +1663,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { } if (qallItemSize > 0) { - atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize); + (void)atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize); continue; } if (RSMA_NEED_FETCH(pInfo)) { @@ -1673,7 +1673,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { break; } } - atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0); + (void)atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0); } } } else { diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index 918fd9e5d3..96010728c2 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -123,7 +123,7 @@ static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t ver, const char *pMsg TAOS_CHECK_EXIT(metaCreateTSma(SMA_META(pSma), ver, pCfg)); // create stable to save tsma result in dstVgId - tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + (void)tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); pReq.name = (char *)tNameGetTableName(&stbFullName); pReq.suid = pCfg->dstTbUid; pReq.schemaRow = pCfg->schemaRow; @@ -283,7 +283,7 @@ static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq * SEncoder encoder; tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len); - tEncodeSBatchDeleteReq(&encoder, pDelReq); + (void)tEncodeSBatchDeleteReq(&encoder, pDelReq); tEncoderClear(&encoder); ((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode); diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 0ab420ce63..8a4571a4af 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -169,7 +169,7 @@ void tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId) { } dataRsp.common.blockNum = 0; char buf[TSDB_OFFSET_LEN] = {0}; - tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.common.reqOffset); + (void) tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.common.reqOffset); tqInfo("tqPushEmptyDataRsp to consumer:0x%" PRIx64 " vgId:%d, offset:%s, reqId:0x%" PRIx64, req.consumerId, vgId, buf, req.reqId); @@ -187,8 +187,8 @@ int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* char buf1[TSDB_OFFSET_LEN] = {0}; char buf2[TSDB_OFFSET_LEN] = {0}; - tFormatOffset(buf1, TSDB_OFFSET_LEN, &((SMqDataRspCommon*)pRsp)->reqOffset); - tFormatOffset(buf2, TSDB_OFFSET_LEN, &((SMqDataRspCommon*)pRsp)->rspOffset); + (void) tFormatOffset(buf1, TSDB_OFFSET_LEN, &((SMqDataRspCommon*)pRsp)->reqOffset); + (void) tFormatOffset(buf2, TSDB_OFFSET_LEN, &((SMqDataRspCommon*)pRsp)->rspOffset); tqDebug("tmq poll vgId:%d consumer:0x%" PRIx64 " (epoch %d) send rsp, block num:%d, req:%s, rsp:%s, reqId:0x%" PRIx64, vgId, pReq->consumerId, pReq->epoch, ((SMqDataRspCommon*)pRsp)->blockNum, buf1, buf2, pReq->reqId); @@ -412,7 +412,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { } char buf[TSDB_OFFSET_LEN] = {0}; - tFormatOffset(buf, TSDB_OFFSET_LEN, &reqOffset); + (void) tFormatOffset(buf, TSDB_OFFSET_LEN, &reqOffset); tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, recv poll req vgId:%d, req:%s, reqId:0x%" PRIx64, consumerId, req.epoch, pHandle->subKey, vgId, buf, req.reqId); @@ -745,7 +745,7 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV } streamTaskResetUpstreamStageInfo(pTask); - streamSetupScheduleTrigger(pTask); + (void) streamSetupScheduleTrigger(pTask); SCheckpointInfo* pChkInfo = &pTask->chkInfo; tqSetRestoreVersionInfo(pTask); @@ -801,8 +801,11 @@ static void doStartFillhistoryStep2(SStreamTask* pTask, SStreamTask* pStreamTask if (done) { qDebug("s-task:%s scan wal(step 2) verRange:%" PRId64 "-%" PRId64 " ended, elapsed time:%.2fs", id, pStep2Range->minVer, pStep2Range->maxVer, 0.0); - streamTaskPutTranstateIntoInputQ(pTask); - streamExecTask(pTask); // exec directly + int32_t code = streamTaskPutTranstateIntoInputQ(pTask); // todo: msg lost. + if (code) { + qError("s-task:%s failed put trans-state into inputQ, code:%s", id, tstrerror(code)); + } + (void) streamExecTask(pTask); // exec directly } else { STimeWindow* pWindow = &pTask->dataRange.window; tqDebug("s-task:%s level:%d verRange:%" PRId64 "-%" PRId64 " window:%" PRId64 "-%" PRId64 @@ -811,7 +814,10 @@ static void doStartFillhistoryStep2(SStreamTask* pTask, SStreamTask* pStreamTask pStreamTask->id.idStr); ASSERT(pTask->status.schedStatus == TASK_SCHED_STATUS__WAITING); - streamSetParamForStreamScannerStep2(pTask, pStep2Range, pWindow); + int32_t code = streamSetParamForStreamScannerStep2(pTask, pStep2Range, pWindow); + if (code) { + tqError("s-task:%s level:%d failed to set step2 param", id, pTask->info.taskLevel); + } int64_t dstVer = pStep2Range->minVer; pTask->chkInfo.nextProcessVer = dstVer; @@ -820,12 +826,12 @@ static void doStartFillhistoryStep2(SStreamTask* pTask, SStreamTask* pStreamTask tqDebug("s-task:%s wal reader start scan WAL verRange:%" PRId64 "-%" PRId64 ", set sched-status:%d", id, dstVer, pStep2Range->maxVer, TASK_SCHED_STATUS__INACTIVE); - /*int8_t status = */ streamTaskSetSchedStatusInactive(pTask); + (void) streamTaskSetSchedStatusInactive(pTask); // now the fill-history task starts to scan data from wal files. - int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_SCANHIST_DONE); + code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_SCANHIST_DONE); if (code == TSDB_CODE_SUCCESS) { - tqScanWalAsync(pTq, false); + (void) tqScanWalAsync(pTq, false); } } } @@ -949,11 +955,11 @@ int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg) { pTask->streamTaskId.taskId, pTask->id.idStr); tqDebug("s-task:%s fill-history task set status to be dropping", id); - streamBuildAndSendDropTaskMsg(pTask->pMsgCb, pMeta->vgId, &pTask->id, 0); + code = streamBuildAndSendDropTaskMsg(pTask->pMsgCb, pMeta->vgId, &pTask->id, 0); atomic_store_32(&pTask->status.inScanHistorySentinel, 0); streamMetaReleaseTask(pMeta, pTask); - return -1; + return code; // todo: handle failure } ASSERT(pStreamTask->info.taskLevel == TASK_LEVEL__SOURCE); @@ -971,15 +977,14 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { // extracted submit data from wal files for all tasks if (pReq->reqType == STREAM_EXEC_T_EXTRACT_WAL_DATA) { - tqScanWal(pTq); - return 0; + return tqScanWal(pTq); } int32_t code = tqStreamTaskProcessRunReq(pTq->pStreamMeta, pMsg, vnodeIsRoleLeader(pTq->pVnode)); // let's continue scan data in the wal files if (code == 0 && (pReq->reqType >= 0 || pReq->reqType == STREAM_EXEC_T_RESUME_TASK)) { - tqScanWalAsync(pTq, false); + (void) tqScanWalAsync(pTq, false); // it's ok to failed } return code; @@ -1044,7 +1049,11 @@ int32_t tqStreamProgressRetrieveReq(STQ *pTq, SRpcMsg *pMsg) { pRsp->subFetchIdx = req.subFetchIdx; pRsp->vgId = req.vgId; pRsp->streamId = req.streamId; - tSerializeStreamProgressRsp(pRsp, sizeof(SStreamProgressRsp) + sizeof(SMsgHead), pRsp); + code = tSerializeStreamProgressRsp(pRsp, sizeof(SStreamProgressRsp) + sizeof(SMsgHead), pRsp); + if (code) { + goto _OVER; + } + SRpcMsg rsp = {.info = pMsg->info, .code = 0}; rsp.pCont = pRspBuf; pRspBuf = NULL; @@ -1079,18 +1088,18 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) tqError("vgId:%d failed to decode checkpoint-source msg, code:%s", vgId, tstrerror(code)); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return code; + return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode } tDecoderClear(&decoder); if (!vnodeIsRoleLeader(pTq->pVnode)) { tqDebug("vgId:%d not leader, ignore checkpoint-source msg, s-task:0x%x", vgId, req.taskId); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode } if (!pTq->pVnode->restored) { @@ -1098,9 +1107,9 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) ", transId:%d s-task:0x%x ignore it", vgId, req.checkpointId, req.transId, req.taskId); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; // always return success to mnode, , todo: handle failure of build and send msg to mnode } SStreamTask* pTask = NULL; @@ -1110,7 +1119,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) " transId:%d it may have been destroyed", vgId, req.taskId, req.checkpointId, req.transId); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs return TSDB_CODE_SUCCESS; } @@ -1123,13 +1132,13 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) streamMetaReleaseTask(pMeta, pTask); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; // todo retry handle error } // todo save the checkpoint failed info - taosThreadMutexLock(&pTask->lock); + streamMutexLock(&pTask->lock); ETaskStatus status = streamTaskGetStatus(pTask).state; if (req.mndTrigger == 1) { @@ -1137,13 +1146,12 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) tqError("s-task:%s not ready for checkpoint, since it is halt, ignore checkpointId:%" PRId64 ", set it failure", pTask->id.idStr, req.checkpointId); - taosThreadMutexUnlock(&pTask->lock); + streamMutexUnlock(&pTask->lock); streamMetaReleaseTask(pMeta, pTask); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return TSDB_CODE_SUCCESS; } } else { @@ -1162,7 +1170,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) " transId:%d already handled, ignore msg and continue process checkpoint", pTask->id.idStr, checkpointId, req.transId); - taosThreadMutexUnlock(&pTask->lock); + streamMutexUnlock(&pTask->lock); streamMetaReleaseTask(pMeta, pTask); return TSDB_CODE_SUCCESS; @@ -1171,19 +1179,24 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) tqWarn("s-task:%s repeatly recv checkpoint-source msg checkpointId:%" PRId64 " transId:%d already handled, return success", pTask->id.idStr, req.checkpointId, req.transId); - taosThreadMutexUnlock(&pTask->lock); + streamMutexUnlock(&pTask->lock); streamMetaReleaseTask(pMeta, pTask); SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs return TSDB_CODE_SUCCESS; } } - streamProcessCheckpointSourceReq(pTask, &req); - taosThreadMutexUnlock(&pTask->lock); + code = streamProcessCheckpointSourceReq(pTask, &req); + streamMutexUnlock(&pTask->lock); + + if (code) { + qError("s-task:%s (vgId:%d) failed to process checkpoint-source req, code:%s", pTask->id.idStr, vgId, tstrerror(code)); + return code; + } if (req.mndTrigger) { qInfo("s-task:%s (vgId:%d) level:%d receive checkpoint-source msg chkpt:%" PRId64 ", transId:%d, ", pTask->id.idStr, @@ -1198,13 +1211,13 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) code = streamAddCheckpointSourceRspMsg(&req, &pMsg->info, pTask); if (code != TSDB_CODE_SUCCESS) { SRpcMsg rsp = {0}; - streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); + (void) streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); tmsgSendRsp(&rsp); // error occurs - return code; + return TSDB_CODE_SUCCESS; } streamMetaReleaseTask(pMeta, pTask); - return code; + return TSDB_CODE_SUCCESS; } // downstream task has complete the stream task checkpoint procedure, let's start the handle the rsp by execute task diff --git a/source/dnode/vnode/src/tq/tqScan.c b/source/dnode/vnode/src/tq/tqScan.c index 5df8c97962..d072d7199c 100644 --- a/source/dnode/vnode/src/tq/tqScan.c +++ b/source/dnode/vnode/src/tq/tqScan.c @@ -115,14 +115,15 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* if (pDataBlock == NULL) { break; } + STqOffsetVal offset = {0}; - qStreamExtractOffset(task, &offset); + code = qStreamExtractOffset(task, &offset); + TSDB_CHECK_CODE(code, line, END); + pHandle->block = NULL; code = createOneDataBlock(pDataBlock, true, &pHandle->block); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, line, END); pHandle->blockTime = offset.ts; tOffsetDestroy(&offset); @@ -140,8 +141,11 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* } else { code = copyDataBlock(pHandle->block, pDataBlock); TSDB_CHECK_CODE(code, line, END); + STqOffsetVal offset = {0}; - qStreamExtractOffset(task, &offset); + code = qStreamExtractOffset(task, &offset); + TSDB_CHECK_CODE(code, line, END); + pRsp->sleepTime = offset.ts - pHandle->blockTime; pHandle->blockTime = offset.ts; tOffsetDestroy(&offset); @@ -164,10 +168,11 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq task executed finished, total blocks:%d, totalRows:%d", pHandle->consumerId, vgId, pRsp->common.blockNum, totalRows); - qStreamExtractOffset(task, &pRsp->common.rspOffset); + code = qStreamExtractOffset(task, &pRsp->common.rspOffset); END: - if ( code!= 0){ - tqError("consumer:0x%" PRIx64 " vgId:%d tmq task executed error, line:%d code:%d", pHandle->consumerId, vgId, line, code); + if (code != 0) { + tqError("consumer:0x%" PRIx64 " vgId:%d tmq task executed error, line:%d code:%d", pHandle->consumerId, vgId, line, + code); } return code; } @@ -241,31 +246,40 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc // get meta SMqBatchMetaRsp* tmp = qStreamExtractMetaMsg(task); if (taosArrayGetSize(tmp->batchMetaReq) > 0) { - qStreamExtractOffset(task, &tmp->rspOffset); + code = qStreamExtractOffset(task, &tmp->rspOffset); + if (code) { + return code; + } + *pBatchMetaRsp = *tmp; tqDebug("tmqsnap task get meta"); break; } if (pDataBlock == NULL) { - qStreamExtractOffset(task, pOffset); + code = qStreamExtractOffset(task, pOffset); + if (code) { + break; + } + if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { continue; } + tqDebug("tmqsnap vgId: %d, tsdb consume over, switch to wal, ver %" PRId64, TD_VID(pTq->pVnode), pHandle->snapshotVer + 1); - qStreamExtractOffset(task, &pRsp->common.rspOffset); + code = qStreamExtractOffset(task, &pRsp->common.rspOffset); break; } if (pRsp->common.blockNum > 0) { tqDebug("tmqsnap task exec exited, get data"); - qStreamExtractOffset(task, &pRsp->common.rspOffset); + code = qStreamExtractOffset(task, &pRsp->common.rspOffset); break; } } - return 0; + return code; } diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index d9e39ad6f5..bd6db483f0 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -106,10 +106,14 @@ int32_t tqBuildDeleteReq(STQ* pTq, const char* stbFullName, const SSDataBlock* p strncpy(req.tbname, name, TSDB_TABLE_NAME_LEN - 1); void* p = taosArrayPush(deleteReq->deleteReqs, &req); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } - if (originName) name = originName; + + if (originName) { + name = originName; + } + taosMemoryFreeClear(name); } @@ -190,6 +194,7 @@ int32_t initCreateTableMsg(SVCreateTbReq* pCreateTableReq, uint64_t suid, const pCreateTableReq->ctb.stbName = taosStrdup((char*)tNameGetTableName(&name)); if (pCreateTableReq->ctb.stbName == NULL) { // ignore this error code tqError("failed to duplicate the stb name:%s, failed to init create-table msg and create req table", stbFullName); + code = TSDB_CODE_OUT_OF_MEMORY; } } @@ -202,14 +207,14 @@ int32_t createDefaultTagColName(SArray** pColNameList) { SArray* pTagColNameList = taosArrayInit(1, TSDB_COL_NAME_LEN); if (pTagColNameList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } char tagNameStr[TSDB_COL_NAME_LEN] = "group_id"; void* p = taosArrayPush(pTagColNameList, tagNameStr); if (p == NULL) { taosArrayDestroy(pTagColNameList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *pColNameList = pTagColNameList; @@ -252,15 +257,14 @@ static int32_t doBuildAndSendCreateTableMsg(SVnode* pVnode, char* stbFullName, S SArray* tagArray = taosArrayInit(4, sizeof(STagVal)); const char* id = pTask->id.idStr; int32_t vgId = pTask->pMeta->vgId; + int32_t code = 0; tqDebug("s-task:%s build create %d table(s) msg", id, rows); - - int32_t code = 0; - SVCreateTbBatchReq reqs = {0}; SArray* crTblArray = reqs.pArray = taosArrayInit(1, sizeof(SVCreateTbReq)); - if (NULL == reqs.pArray) { + if ((NULL == reqs.pArray) || (tagArray == NULL)) { tqError("s-task:%s failed to init create table msg, code:%s", id, tstrerror(terrno)); + code = terrno; goto _end; } @@ -418,8 +422,8 @@ int32_t doMergeExistedRows(SSubmitTbData* pExisted, const SSubmitTbData* pNew, c int32_t j = 0, k = 0; SArray* pFinal = taosArrayInit(oldLen + newLen, POINTER_BYTES); if (pFinal == NULL) { - tqError("s-task:%s failed to prepare merge result datablock, code:%s", id, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + tqError("s-task:%s failed to prepare merge result datablock, code:%s", id, tstrerror(terrno)); + return terrno; } while (j < newLen && k < oldLen) { @@ -872,6 +876,9 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat tqDebug("s-task:%s stream write into table:%s, table auto created", id, dstTableName); SArray* pTagArray = taosArrayInit(pTSchema->numOfCols + 1, sizeof(STagVal)); + if (pTagArray == NULL) { + return terrno; + } pTableData->flags = SUBMIT_REQ_AUTO_CREATE_TABLE; code = @@ -957,6 +964,12 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) { metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK); code = metaReaderGetTableEntryByUid(&mer1, pOutputInfo->tbSink.stbUid); + if (code != TSDB_CODE_SUCCESS) { + tqError("s-task:%s vgId:%d failed to get the dst stable, failed to sink results", id, vgId); + metaReaderClear(&mer1); + return; + } + pOutputInfo->tbSink.pTagSchema = tCloneSSchemaWrapper(&mer1.me.stbEntry.schemaTag); metaReaderClear(&mer1); @@ -1161,6 +1174,9 @@ int32_t doRemoveFromCache(SSHashObj* pSinkTableMap, uint64_t groupId, const char int32_t doBuildAndSendDeleteMsg(SVnode* pVnode, char* stbFullName, SSDataBlock* pDataBlock, SStreamTask* pTask, int64_t suid) { SBatchDeleteReq deleteReq = {.suid = suid, .deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq))}; + if (deleteReq.deleteReqs == NULL) { + return terrno; + } int32_t code = tqBuildDeleteReq(pVnode->pTq, stbFullName, pDataBlock, &deleteReq, pTask->id.idStr, pTask->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER && pTask->subtableWithoutMd5 != 1); diff --git a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c index dda5173ad9..c89ad807c7 100644 --- a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c @@ -39,19 +39,21 @@ int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa // alloc pReader = (SStreamTaskReader*)taosMemoryCalloc(1, sizeof(SStreamTaskReader)); if (pReader == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY); } pReader->pTq = pTq; pReader->sver = sver; pReader->ever = ever; pReader->tdbTbList = taosArrayInit(4, sizeof(STablePair)); + if (pReader->tdbTbList == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); + } STablePair pair1 = {.tbl = pTq->pStreamMeta->pTaskDb, .type = SNAP_DATA_STREAM_TASK}; - taosArrayPush(pReader->tdbTbList, &pair1); + (void)taosArrayPush(pReader->tdbTbList, &pair1); STablePair pair2 = {.tbl = pTq->pStreamMeta->pCheckpointDb, .type = SNAP_DATA_STREAM_TASK_CHECKPOINT}; - taosArrayPush(pReader->tdbTbList, &pair2); + (void)taosArrayPush(pReader->tdbTbList, &pair2); pReader->pos = 0; @@ -60,16 +62,14 @@ int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa if (code) { tqInfo("vgId:%d, vnode stream-task snapshot reader failed to open, reason: %s", TD_VID(pTq->pVnode), tstrerror(code)); - taosMemoryFree(pReader); - goto _err; + TAOS_CHECK_GOTO(code, NULL, _err); } code = tdbTbcMoveToFirst(pReader->pCur); if (code) { tqInfo("vgId:%d, vnode stream-task snapshot reader failed to iterate, reason: %s", TD_VID(pTq->pVnode), tstrerror(code)); - taosMemoryFree(pReader); - goto _err; + TAOS_CHECK_GOTO(code, NULL, _err); } tqDebug("vgId:%d, vnode stream-task snapshot reader opened", TD_VID(pTq->pVnode)); @@ -79,15 +79,18 @@ int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa _err: tqError("vgId:%d, vnode stream-task snapshot reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + (void)streamTaskSnapReaderClose(pReader); *ppReader = NULL; return code; } int32_t streamTaskSnapReaderClose(SStreamTaskReader* pReader) { + if (pReader == NULL) return 0; + int32_t code = 0; tqInfo("vgId:%d, vnode stream-task snapshot reader closed", TD_VID(pReader->pTq->pVnode)); taosArrayDestroy(pReader->tdbTbList); - tdbTbcClose(pReader->pCur); + (void)tdbTbcClose(pReader->pCur); taosMemoryFree(pReader); return code; } @@ -116,20 +119,24 @@ NextTbl: break; } else { pVal = taosMemoryCalloc(1, tLen); + if (pVal == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } memcpy(pVal, tVal, tLen); vLen = tLen; } - tdbTbcMoveToNext(pReader->pCur); + (void)tdbTbcMoveToNext(pReader->pCur); break; } if (except == 1) { if (pReader->pos + 1 < taosArrayGetSize(pReader->tdbTbList)) { - tdbTbcClose(pReader->pCur); + (void)tdbTbcClose(pReader->pCur); pReader->pos += 1; pPair = taosArrayGet(pReader->tdbTbList, pReader->pos); code = tdbTbcOpen(pPair->tbl, &pReader->pCur, NULL); - tdbTbcMoveToFirst(pReader->pCur); + (void)tdbTbcMoveToFirst(pReader->pCur); goto NextTbl; } @@ -174,8 +181,7 @@ int32_t streamTaskSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa // alloc pWriter = (SStreamTaskWriter*)taosMemoryCalloc(1, sizeof(*pWriter)); if (pWriter == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY); } pWriter->pTq = pTq; pWriter->sver = sver; @@ -184,12 +190,6 @@ int32_t streamTaskSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa *ppWriter = pWriter; tqDebug("vgId:%d, vnode stream-task snapshot writer opened", TD_VID(pTq->pVnode)); return code; - -_err: - tqError("vgId:%d, vnode stream-task snapshot writer failed to write since %s", TD_VID(pTq->pVnode), tstrerror(code)); - *ppWriter = NULL; - return code; - return 0; } int32_t streamTaskSnapWriterClose(SStreamTaskWriter* pWriter, int8_t rollback) { @@ -199,7 +199,7 @@ int32_t streamTaskSnapWriterClose(SStreamTaskWriter* pWriter, int8_t rollback) { streamMetaWLock(pTq->pStreamMeta); tqDebug("vgId:%d, vnode stream-task snapshot writer closed", TD_VID(pTq->pVnode)); if (rollback) { - tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn); + (void)tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn); } else { code = tdbCommit(pTq->pStreamMeta->db, pTq->pStreamMeta->txn); if (code) goto _err; @@ -207,8 +207,7 @@ int32_t streamTaskSnapWriterClose(SStreamTaskWriter* pWriter, int8_t rollback) { if (code) goto _err; } - if (tdbBegin(pTq->pStreamMeta->db, &pTq->pStreamMeta->txn, tdbDefaultMalloc, tdbDefaultFree, NULL, 0) < 0) { - code = -1; + if ((code = tdbBegin(pTq->pStreamMeta->db, &pTq->pStreamMeta->txn, tdbDefaultMalloc, tdbDefaultFree, NULL, 0)) < 0) { taosMemoryFree(pWriter); goto _err; } @@ -241,10 +240,11 @@ int32_t streamTaskSnapWrite(SStreamTaskWriter* pWriter, uint8_t* pData, uint32_t int64_t key[2] = {taskId.streamId, taskId.taskId}; streamMetaWLock(pTq->pStreamMeta); - if (tdbTbUpsert(pTq->pStreamMeta->pTaskDb, key, sizeof(int64_t) << 1, (uint8_t*)pData + sizeof(SSnapDataHdr), - nData - sizeof(SSnapDataHdr), pTq->pStreamMeta->txn) < 0) { + if ((code = + tdbTbUpsert(pTq->pStreamMeta->pTaskDb, key, sizeof(int64_t) << 1, (uint8_t*)pData + sizeof(SSnapDataHdr), + nData - sizeof(SSnapDataHdr), pTq->pStreamMeta->txn)) < 0) { streamMetaWUnLock(pTq->pStreamMeta); - return -1; + return code; } streamMetaWUnLock(pTq->pStreamMeta); } else if (pHdr->type == SNAP_DATA_STREAM_TASK_CHECKPOINT) { diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 5073b3e9ee..8d5fa8b0b3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -117,7 +117,7 @@ typedef struct { static void tsdbGetRocksPath(STsdb *pTsdb, char *path) { SVnode *pVnode = pTsdb->pVnode; - vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); int32_t offset = strlen(path); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP); @@ -722,20 +722,14 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; { SLastCol *pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[0], values_list_sizes[0], &pLastCol); - if (code) { - tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } + (void)tsdbCacheDeserialize(values_list[0], values_list_sizes[0], &pLastCol); if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[0], klen); } taosMemoryFreeClear(pLastCol); pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[1], values_list_sizes[1], &pLastCol); - if (code) { - tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } + (void)tsdbCacheDeserialize(values_list[1], values_list_sizes[1], &pLastCol); if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[1], klen); } @@ -748,7 +742,7 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, LRUHandle *h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[0], klen); if (h) { erase = true; - taosLRUCacheRelease(pTsdb->lruCache, h, erase); + (void)taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { taosLRUCacheErase(pTsdb->lruCache, keys_list[0], klen); @@ -758,7 +752,7 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[1], klen); if (h) { erase = true; - taosLRUCacheRelease(pTsdb->lruCache, h, erase); + (void)taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { taosLRUCacheErase(pTsdb->lruCache, keys_list[1], klen); @@ -1066,12 +1060,12 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray if (cmp_res < 0 || (cmp_res == 0 && !COL_VAL_IS_NONE(pColVal))) { tsdbCacheUpdateLastCol(pLastCol, pRowKey, pColVal); } - taosLRUCacheRelease(pCache, h, false); + (void)taosLRUCacheRelease(pCache, h, false); } else { if (!remainCols) { remainCols = taosArrayInit(num_keys * 2, sizeof(SIdxKey)); } - taosArrayPush(remainCols, &(SIdxKey){i, *key}); + (void)taosArrayPush(remainCols, &(SIdxKey){i, *key}); } } @@ -1123,10 +1117,12 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray SColVal *pColVal = &updCtx->colVal; SLastCol *pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + /* if (code) { tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); } + */ SLastCol *PToFree = pLastCol; if (IS_LAST_KEY(idxKey->key) && !COL_VAL_IS_VALUE(pColVal)) { @@ -1242,18 +1238,18 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 tsdbRowGetKey(&lRow, &tsdbRowKey); STSDBRowIter iter = {0}; - tsdbRowIterOpen(&iter, &lRow, pTSchema); + (void)tsdbRowIterOpen(&iter, &lRow, pTSchema); int32_t iCol = 0; for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal && iCol < nCol; pColVal = tsdbRowIterNext(&iter), iCol++) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; - taosArrayPush(ctxArray, &updateCtx); + (void)taosArrayPush(ctxArray, &updateCtx); if (!COL_VAL_IS_VALUE(pColVal)) { - tSimpleHashPut(iColHash, &iCol, sizeof(iCol), NULL, 0); + (void)tSimpleHashPut(iColHash, &iCol, sizeof(iCol), NULL, 0); continue; } updateCtx.lflag = LFLAG_LAST; - taosArrayPush(ctxArray, &updateCtx); + (void)taosArrayPush(ctxArray, &updateCtx); } tsdbRowClose(&iter); @@ -1277,14 +1273,14 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 if (COL_VAL_IS_VALUE(&colVal)) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST, .tsdbRowKey = tsdbRowKey, .colVal = colVal}; - taosArrayPush(ctxArray, &updateCtx); - tSimpleHashIterateRemove(iColHash, &iCol, sizeof(iCol), &pIte, &iter); + (void)taosArrayPush(ctxArray, &updateCtx); + (void)tSimpleHashIterateRemove(iColHash, &iCol, sizeof(iCol), &pIte, &iter); } } } // 3. do update - tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + (void)tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); _exit: taosMemoryFreeClear(pTSchema); @@ -1317,7 +1313,7 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo .tsdbRowKey = tsdbRowKey, .colVal = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, ((SValue){.type = TSDB_DATA_TYPE_TIMESTAMP, .val = lRow.pBlockData->aTSKEY[lRow.iRow]}))}; - taosArrayPush(ctxArray, &updateCtx); + (void)taosArrayPush(ctxArray, &updateCtx); } TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0); @@ -1338,7 +1334,7 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo tColDataGetValue(pColData, tRow.iRow, &colVal); SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST, .tsdbRowKey = tsdbRowKey, .colVal = colVal}; - taosArrayPush(ctxArray, &updateCtx); + (void)taosArrayPush(ctxArray, &updateCtx); break; } } @@ -1346,15 +1342,15 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo // 2. prepare last row STSDBRowIter iter = {0}; - tsdbRowIterOpen(&iter, &lRow, pTSchema); + (void)tsdbRowIterOpen(&iter, &lRow, pTSchema); for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal; pColVal = tsdbRowIterNext(&iter)) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; - taosArrayPush(ctxArray, &updateCtx); + (void)taosArrayPush(ctxArray, &updateCtx); } tsdbRowClose(&iter); // 3. do update - tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + (void)tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); _exit: taosMemoryFreeClear(pTSchema); @@ -1379,7 +1375,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (idxKey->key.cid != PRIMARYKEY_TIMESTAMP_COL_ID) { SLastKey *key = &(SLastKey){.lflag = ltype, .uid = uid, .cid = PRIMARYKEY_TIMESTAMP_COL_ID}; - taosArrayInsert(remainCols, 0, &(SIdxKey){0, *key}); + (void)taosArrayInsert(remainCols, 0, &(SIdxKey){0, *key}); } int num_keys = TARRAY_SIZE(remainCols); @@ -1416,7 +1412,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (NULL == lastTmpIndexArray) { lastTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); } - taosArrayPush(lastTmpIndexArray, &(i)); + (void)taosArrayPush(lastTmpIndexArray, &(i)); lastColIds[lastIndex] = idxKey->key.cid; lastSlotIds[lastIndex] = pr->pSlotIds[idxKey->idx]; lastIndex++; @@ -1424,7 +1420,7 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr if (NULL == lastrowTmpIndexArray) { lastrowTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t)); } - taosArrayPush(lastrowTmpIndexArray, &(i)); + (void)taosArrayPush(lastrowTmpIndexArray, &(i)); lastrowColIds[lastrowIndex] = idxKey->key.cid; lastrowSlotIds[lastrowIndex] = pr->pSlotIds[idxKey->idx]; lastrowIndex++; @@ -1434,17 +1430,18 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr pTmpColArray = taosArrayInit(lastIndex + lastrowIndex, sizeof(SLastCol)); if (lastTmpIndexArray != NULL) { - mergeLastCid(uid, pTsdb, &lastTmpColArray, pr, lastColIds, lastIndex, lastSlotIds); + (void)mergeLastCid(uid, pTsdb, &lastTmpColArray, pr, lastColIds, lastIndex, lastSlotIds); for (int i = 0; i < taosArrayGetSize(lastTmpColArray); i++) { - taosArrayInsert(pTmpColArray, *(int32_t *)taosArrayGet(lastTmpIndexArray, i), taosArrayGet(lastTmpColArray, i)); + (void)taosArrayInsert(pTmpColArray, *(int32_t *)taosArrayGet(lastTmpIndexArray, i), + taosArrayGet(lastTmpColArray, i)); } } if (lastrowTmpIndexArray != NULL) { - mergeLastRowCid(uid, pTsdb, &lastrowTmpColArray, pr, lastrowColIds, lastrowIndex, lastrowSlotIds); + (void)mergeLastRowCid(uid, pTsdb, &lastrowTmpColArray, pr, lastrowColIds, lastrowIndex, lastrowSlotIds); for (int i = 0; i < taosArrayGetSize(lastrowTmpColArray); i++) { - taosArrayInsert(pTmpColArray, *(int32_t *)taosArrayGet(lastrowTmpIndexArray, i), - taosArrayGet(lastrowTmpColArray, i)); + (void)taosArrayInsert(pTmpColArray, *(int32_t *)taosArrayGet(lastrowTmpIndexArray, i), + taosArrayGet(lastrowTmpColArray, i)); } } @@ -1586,10 +1583,7 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA SLRUCache *pCache = pTsdb->lruCache; for (int i = 0, j = 0; i < num_keys && j < TARRAY_SIZE(remainCols); ++i) { SLastCol *pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); - if (code) { - tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } + (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); SLastCol *PToFree = pLastCol; SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[j]; if (pLastCol) { @@ -1682,19 +1676,19 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache TAOS_CHECK_RETURN(reallocVarDataVal(&lastCol.rowKey.pks[j])); } TAOS_CHECK_RETURN(reallocVarData(&lastCol.colVal)); - taosArrayPush(pLastArray, &lastCol); + (void)taosArrayPush(pLastArray, &lastCol); - taosLRUCacheRelease(pCache, h, false); + (void)taosLRUCacheRelease(pCache, h, false); } else { SLastCol noneCol = {.rowKey.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[pr->pSlotIds[i]].type)}; - taosArrayPush(pLastArray, &noneCol); + (void)taosArrayPush(pLastArray, &noneCol); if (!remainCols) { remainCols = taosArrayInit(num_keys, sizeof(SIdxKey)); } - taosArrayPush(remainCols, &(SIdxKey){i, key}); + (void)taosArrayPush(remainCols, &(SIdxKey){i, key}); } } @@ -1721,7 +1715,7 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache } taosArraySet(pLastArray, idxKey->idx, &lastCol); - taosLRUCacheRelease(pCache, h, false); + (void)taosLRUCacheRelease(pCache, h, false); taosArrayRemove(remainCols, i); } else { @@ -1810,10 +1804,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; for (int i = 0; i < num_keys; ++i) { SLastCol *pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); - if (code) { - tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } + (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); (void)taosThreadMutexLock(&pTsdb->rCache.rMutex); if (NULL != pLastCol && (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey)) { rocksdb_writebatch_delete(wb, keys_list[i], klen); @@ -1821,10 +1812,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE taosMemoryFreeClear(pLastCol); pLastCol = NULL; - code = tsdbCacheDeserialize(values_list[i + num_keys], values_list_sizes[i + num_keys], &pLastCol); - if (code) { - tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); - } + (void)tsdbCacheDeserialize(values_list[i + num_keys], values_list_sizes[i + num_keys], &pLastCol); if (NULL != pLastCol && (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey)) { rocksdb_writebatch_delete(wb, keys_list[num_keys + i], klen); } @@ -1846,7 +1834,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE if (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey) { erase = true; } - taosLRUCacheRelease(pTsdb->lruCache, h, erase); + (void)taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { taosLRUCacheErase(pTsdb->lruCache, keys_list[i], klen); @@ -1862,7 +1850,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE if (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey) { erase = true; } - taosLRUCacheRelease(pTsdb->lruCache, h, erase); + (void)taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { taosLRUCacheErase(pTsdb->lruCache, keys_list[num_keys + i], klen); @@ -1982,7 +1970,7 @@ static int32_t getTableDelDataFromTbData(STbData *pTbData, SArray *aDelData) { SDelData *pDelData = pTbData ? pTbData->pHead : NULL; for (; pDelData; pDelData = pDelData->pNext) { - taosArrayPush(aDelData, pDelData); + (void)taosArrayPush(aDelData, pDelData); } return code; @@ -2005,7 +1993,7 @@ static STableLoadInfo *getTableLoadInfo(SCacheRowsReader *pReader, uint64_t uid) if (!ppInfo) { pInfo = taosMemoryCalloc(1, sizeof(STableLoadInfo)); if (pInfo) { - tSimpleHashPut(pReader->pTableMap, &uid, sizeof(uint64_t), &pInfo, POINTER_BYTES); + (void)tSimpleHashPut(pReader->pTableMap, &uid, sizeof(uint64_t), &pInfo, POINTER_BYTES); } return pInfo; @@ -2117,11 +2105,11 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea TD_VID(pReader->pTsdb->pVnode), pReader->pCurFileSet->fid, record.skey, record.ekey, uid);*/ SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey}; - taosArrayPush(pInfo->pTombData, &delData); + (void)taosArrayPush(pInfo->pTombData, &delData); } } - tTombBlockDestroy(&block); + (void)tTombBlockDestroy(&block); if (finished) { TAOS_RETURN(code); @@ -2312,7 +2300,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie state->pr->pCurFileSet = state->pFileSet; - loadDataTomb(state->pr, state->pr->pFileReader); + (void)loadDataTomb(state->pr, state->pr->pFileReader); TAOS_CHECK_GOTO(tsdbDataFileReadBrinBlk(state->pr->pFileReader, &state->pr->pBlkArray), &lino, _err); } @@ -2329,7 +2317,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie SBrinBlk *pBrinBlk = &pBlkArray->data[i]; if (state->suid >= pBrinBlk->minTbid.suid && state->suid <= pBrinBlk->maxTbid.suid) { if (state->uid >= pBrinBlk->minTbid.uid && state->uid <= pBrinBlk->maxTbid.uid) { - taosArrayPush(state->pIndexList, pBrinBlk); + (void)taosArrayPush(state->pIndexList, pBrinBlk); } } else if (state->suid > pBrinBlk->maxTbid.suid || (state->suid == pBrinBlk->maxTbid.suid && state->uid > pBrinBlk->maxTbid.uid)) { @@ -2385,7 +2373,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie if (!state->pLastRow) { if (state->pLastIter) { - lastIterClose(&state->pLastIter); + (void)lastIterClose(&state->pLastIter); } clearLastFileSet(state); @@ -2493,7 +2481,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie if (!state->pLastRow) { if (state->pLastIter) { - lastIterClose(&state->pLastIter); + (void)lastIterClose(&state->pLastIter); } *ppRow = &state->row; @@ -2517,7 +2505,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie } else { // TODO: merge rows and *ppRow = mergedRow SRowMerger *pMerger = &state->rowMerger; - tsdbRowMergerInit(pMerger, state->pTSchema); + (void)tsdbRowMergerInit(pMerger, state->pTSchema); TAOS_CHECK_GOTO(tsdbRowMergerAdd(pMerger, &state->row, state->pTSchema), &lino, _err); TAOS_CHECK_GOTO(tsdbRowMergerAdd(pMerger, state->pLastRow, state->pTSchema), &lino, _err); @@ -2682,7 +2670,7 @@ int32_t clearNextRowFromFS(void *iter) { } if (state->pLastIter) { - lastIterClose(&state->pLastIter); + (void)lastIterClose(&state->pLastIter); } if (state->pBlockData) { @@ -2715,7 +2703,7 @@ int32_t clearNextRowFromFS(void *iter) { static void clearLastFileSet(SFSNextRowIter *state) { if (state->pLastIter) { - lastIterClose(&state->pLastIter); + (void)lastIterClose(&state->pLastIter); } if (state->pBlockData) { @@ -2724,7 +2712,7 @@ static void clearLastFileSet(SFSNextRowIter *state) { } if (state->pr->pFileReader) { - tsdbDataFileReaderClose(&state->pr->pFileReader); + (void)tsdbDataFileReaderClose(&state->pr->pFileReader); state->pr->pFileReader = NULL; state->pr->pCurFileSet = NULL; @@ -2814,7 +2802,7 @@ static int32_t nextRowIterClose(CacheNextRowIter *pIter) { for (int i = 0; i < 3; ++i) { if (pIter->input[i].nextRowClearFn) { - pIter->input[i].nextRowClearFn(pIter->input[i].iter); + (void)pIter->input[i].nextRowClearFn(pIter->input[i].iter); } } @@ -2898,7 +2886,7 @@ static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pI pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); } - taosArrayAddAll(pInfo->pTombData, pIter->pMemDelData); + (void)taosArrayAddAll(pInfo->pTombData, pIter->pMemDelData); size_t delSize = TARRAY_SIZE(pInfo->pTombData); if (delSize > 0) { @@ -2944,7 +2932,7 @@ static int32_t initLastColArrayPartial(STSchema *pTSchema, SArray **ppColArray, int16_t slotId = slotIds[i]; SLastCol col = {.rowKey.ts = 0, .colVal = COL_VAL_NULL(pTSchema->columns[slotId].colId, pTSchema->columns[slotId].type)}; - taosArrayPush(pColArray, &col); + (void)taosArrayPush(pColArray, &col); } *ppColArray = pColArray; @@ -2998,18 +2986,18 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC } for (int i = 0; i < nCols; ++i) { - taosArrayPush(aColArray, &aCols[i]); + (void)taosArrayPush(aColArray, &aCols[i]); } STsdbRowKey lastRowKey = {.key.ts = TSKEY_MAX}; // inverse iterator CacheNextRowIter iter = {0}; - nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr); + (void)nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr); do { TSDBROW *pRow = NULL; - nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, true, TARRAY_DATA(aColArray), TARRAY_SIZE(aColArray)); + (void)nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, true, TARRAY_DATA(aColArray), TARRAY_SIZE(aColArray)); if (!pRow) { break; @@ -3142,7 +3130,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC } *ppLastArray = pColArray; - nextRowIterClose(&iter); + (void)nextRowIterClose(&iter); taosArrayDestroy(aColArray); TAOS_RETURN(code); @@ -3184,16 +3172,16 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, } for (int i = 0; i < nCols; ++i) { - taosArrayPush(aColArray, &aCols[i]); + (void)taosArrayPush(aColArray, &aCols[i]); } // inverse iterator CacheNextRowIter iter = {0}; - nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr); + (void)nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr); do { TSDBROW *pRow = NULL; - nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, false, TARRAY_DATA(aColArray), TARRAY_SIZE(aColArray)); + (void)nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, false, TARRAY_DATA(aColArray), TARRAY_SIZE(aColArray)); if (!pRow) { break; @@ -3266,7 +3254,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, } *ppLastArray = pColArray; - nextRowIterClose(&iter); + (void)nextRowIterClose(&iter); taosArrayDestroy(aColArray); TAOS_RETURN(code); @@ -3286,13 +3274,7 @@ _err: TAOS_RETURN(code); } -int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { - int32_t code = 0; - - taosLRUCacheRelease(pCache, h, false); - - return code; -} +void tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { (void)taosLRUCacheRelease(pCache, h, false); } void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) { taosLRUCacheSetCapacity(pVnode->pTsdb->lruCache, capacity); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index 0c3fc95d6c..4467102d6f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -251,7 +251,7 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) { _exit: if (code) { - tsdbCommitCloseReader(committer); + TAOS_UNUSED(tsdbCommitCloseReader(committer)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } @@ -259,8 +259,8 @@ _exit: } static int32_t tsdbCommitCloseIter(SCommitter2 *committer) { - tsdbIterMergerClose(&committer->tombIterMerger); - tsdbIterMergerClose(&committer->dataIterMerger); + TAOS_UNUSED(tsdbIterMergerClose(&committer->tombIterMerger)); + TAOS_UNUSED(tsdbIterMergerClose(&committer->dataIterMerger)); TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose); TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose); return 0; @@ -322,7 +322,7 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) { _exit: if (code) { - tsdbCommitCloseIter(committer); + TAOS_UNUSED(tsdbCommitCloseIter(committer)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } @@ -335,7 +335,7 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) { STsdb *tsdb = committer->tsdb; // check if can commit - tsdbFSCheckCommit(tsdb, committer->ctx->info->fid); + TAOS_UNUSED(tsdbFSCheckCommit(tsdb, committer->ctx->info->fid)); committer->ctx->expLevel = tsdbFidLevel(committer->ctx->info->fid, &tsdb->keepCfg, committer->now); tsdbFidKeyRange(committer->ctx->info->fid, committer->minutes, committer->precision, &committer->ctx->minKey, @@ -344,7 +344,7 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) { TAOS_CHECK_GOTO(tfsAllocDisk(committer->tsdb->pVnode->pTfs, committer->ctx->expLevel, &committer->ctx->did), &lino, _exit); - tfsMkdirRecurAt(committer->tsdb->pVnode->pTfs, committer->tsdb->path, committer->ctx->did); + TAOS_UNUSED(tfsMkdirRecurAt(committer->tsdb->pVnode->pTfs, committer->tsdb->path, committer->ctx->did)); committer->ctx->tbid->suid = 0; committer->ctx->tbid->uid = 0; @@ -430,12 +430,12 @@ static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) { if (pTsdb->commitInfo) { for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i); - vHashDrop(pTsdb->commitInfo->ht, info); + TAOS_UNUSED(vHashDrop(pTsdb->commitInfo->ht, info)); tsdbTFileSetClear(&info->fset); taosMemoryFree(info); } - vHashDestroy(&pTsdb->commitInfo->ht); + TAOS_UNUSED(vHashDestroy(&pTsdb->commitInfo->ht)); taosArrayDestroy(pTsdb->commitInfo->arr); pTsdb->commitInfo->arr = NULL; taosMemoryFreeClear(pTsdb->commitInfo); @@ -461,7 +461,7 @@ static int32_t tsdbCommitInfoInit(STsdb *pTsdb) { _exit: if (code) { - tsdbCommitInfoDestroy(pTsdb); + TAOS_UNUSED(tsdbCommitInfoDestroy(pTsdb)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pTsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } return code; @@ -531,7 +531,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { SFileSetCommitInfo tinfo = { .fid = fid, }; - vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info); + TAOS_UNUSED(vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info)); if (info == NULL) { TAOS_CHECK_GOTO(tsdbCommitInfoAdd(tsdb, fid), &lino, _exit); } @@ -555,7 +555,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { }; // check if the file set already on the commit list - vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info); + TAOS_UNUSED(vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info)); if (info != NULL) { continue; } @@ -589,7 +589,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { // begin tasks on file set for (int i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); - tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset); + TAOS_UNUSED(tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset)); if (fset) { code = tsdbTFileSetInitCopy(tsdb, fset, &info->fset); if (code) { @@ -603,7 +603,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { _exit: if (code) { - tsdbCommitInfoDestroy(tsdb); + TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } return code; @@ -689,7 +689,7 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) { (void)taosThreadMutexLock(&tsdb->mutex); tsdb->imem = NULL; (void)taosThreadMutexUnlock(&tsdb->mutex); - tsdbUnrefMemTable(imem, NULL, true); + TAOS_UNUSED(tsdbUnrefMemTable(imem, NULL, true)); } else { SCommitter2 committer = {0}; @@ -730,14 +730,14 @@ int32_t tsdbCommitCommit(STsdb *tsdb) { for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); if (info->fset) { - tsdbFinishTaskOnFileSet(tsdb, info->fid); + TAOS_UNUSED(tsdbFinishTaskOnFileSet(tsdb, info->fid)); } } (void)taosThreadMutexUnlock(&tsdb->mutex); - tsdbCommitInfoDestroy(tsdb); - tsdbUnrefMemTable(pMemTable, NULL, true); + TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb)); + TAOS_UNUSED(tsdbUnrefMemTable(pMemTable, NULL, true)); } _exit: @@ -761,11 +761,11 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) { for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i); if (info->fset) { - tsdbFinishTaskOnFileSet(pTsdb, info->fid); + TAOS_UNUSED(tsdbFinishTaskOnFileSet(pTsdb, info->fid)); } } (void)taosThreadMutexUnlock(&pTsdb->mutex); - tsdbCommitInfoDestroy(pTsdb); + TAOS_UNUSED(tsdbCommitInfoDestroy(pTsdb)); _exit: if (code) { diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c index e358b8f87e..6469160536 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRAW.c @@ -35,7 +35,7 @@ int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderCon } } else { char fname1[TSDB_FILENAME_LEN]; - tsdbTFileName(config->tsdb, &config->file, fname1); + (void)tsdbTFileName(config->tsdb, &config->file, fname1); TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit); } @@ -159,7 +159,7 @@ static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) { flag |= (TD_FILE_CREATE | TD_FILE_TRUNC); } - tsdbTFileName(writer->config->tsdb, &writer->file, fname); + (void)tsdbTFileName(writer->config->tsdb, &writer->file, fname); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit); _exit: @@ -202,7 +202,7 @@ int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFil } else { TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit); } - tsdbDataFileRAWWriterDoClose(writer[0]); + (void)tsdbDataFileRAWWriterDoClose(writer[0]); } taosMemoryFree(writer[0]); writer[0] = NULL; diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c index 28598f23f7..2665cc1aaf 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c @@ -135,7 +135,7 @@ int32_t tsdbDataFileReaderOpen(const char *fname[], const SDataFileReaderConfig for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) { if (config->files[i].exist) { char fname1[TSDB_FILENAME_LEN]; - tsdbTFileName(config->tsdb, &config->files[i].file, fname1); + (void)tsdbTFileName(config->tsdb, &config->files[i].file, fname1); int32_t lcn = config->files[i].file.lcn; TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd[i], lcn), &lino, _exit); } @@ -667,7 +667,7 @@ static int32_t tsdbDataFileWriterCloseAbort(SDataFileWriter *writer) { static int32_t tsdbDataFileWriterDoClose(SDataFileWriter *writer) { if (writer->ctx->reader) { - tsdbDataFileReaderClose(&writer->ctx->reader); + (void)tsdbDataFileReaderClose(&writer->ctx->reader); } tTombBlockDestroy(writer->tombBlock); @@ -857,7 +857,7 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr } } - tsdbWriterUpdVerRange(range, brinBlk.minVer, brinBlk.maxVer); + (void)tsdbWriterUpdVerRange(range, brinBlk.minVer, brinBlk.maxVer); // write to file for (int32_t i = 0; i < 10; ++i) { @@ -1018,7 +1018,7 @@ static int32_t tsdbDataFileDoWriteBlockData(SDataFileWriter *writer, SBlockData } } - tsdbWriterUpdVerRange(&writer->ctx->range, record->minVer, record->maxVer); + (void)tsdbWriterUpdVerRange(&writer->ctx->range, record->minVer, record->maxVer); code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid, &cmprInfo.pColCmpr); @@ -1371,7 +1371,7 @@ int32_t tsdbFileWriteTombBlock(STsdbFD *fd, STombBlock *tombBlock, int8_t cmprAl } } - tsdbWriterUpdVerRange(range, tombBlk.minVer, tombBlk.maxVer); + (void)tsdbWriterUpdVerRange(range, tombBlk.minVer, tombBlk.maxVer); for (int32_t i = 0; i < ARRAY_SIZE(tombBlock->buffers); i++) { tBufferClear(buffer0); @@ -1640,8 +1640,8 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .fid = writer->config->fid, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, ofRange); - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, ofRange); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); // .data @@ -1652,7 +1652,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .fid = writer->config->fid, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); } else if (writer->config->files[ftype].file.size != writer->files[ftype].size) { op = (STFileOp){ @@ -1661,7 +1661,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .of = writer->config->files[ftype].file, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); } @@ -1673,7 +1673,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .fid = writer->config->fid, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); } else if (writer->config->files[ftype].file.size != writer->files[ftype].size) { op = (STFileOp){ @@ -1682,7 +1682,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .of = writer->config->files[ftype].file, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); } } @@ -1716,8 +1716,8 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr .fid = writer->config->fid, .nf = writer->files[ftype], }; - tsdbTFileUpdVerRange(&op.nf, ofRange); - tsdbTFileUpdVerRange(&op.nf, writer->ctx->tombRange); + (void)tsdbTFileUpdVerRange(&op.nf, ofRange); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->tombRange); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); } int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm; @@ -1754,7 +1754,7 @@ static int32_t tsdbDataFileWriterOpenDataFD(SDataFileWriter *writer) { } int32_t lcn = writer->files[ftype].lcn; - tsdbTFileName(writer->config->tsdb, &writer->files[ftype], fname); + (void)tsdbTFileName(writer->config->tsdb, &writer->files[ftype], fname); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit); if (writer->files[ftype].size == 0) { @@ -1804,7 +1804,7 @@ int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, TFileOpArr } else { TAOS_CHECK_GOTO(tsdbDataFileWriterCloseCommit(writer[0], opArr), &lino, _exit); } - tsdbDataFileWriterDoClose(writer[0]); + (void)tsdbDataFileWriterDoClose(writer[0]); } taosMemoryFree(writer[0]); writer[0] = NULL; @@ -1915,7 +1915,7 @@ static int32_t tsdbDataFileWriterOpenTombFD(SDataFileWriter *writer) { int32_t flag = (TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); int32_t lcn = writer->files[ftype].lcn; - tsdbTFileName(writer->config->tsdb, writer->files + ftype, fname); + (void)tsdbTFileName(writer->config->tsdb, writer->files + ftype, fname); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index b262912f9b..cc89b106da 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -102,8 +102,8 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { code = TSDB_CODE_OUT_OF_MEMORY; TSDB_CHECK_CODE(code, lino, _exit); } - tsdbFSToBinary(pData, pFS); - taosCalcChecksumAppend(0, pData, size); + (void)tsdbFSToBinary(pData, pFS); + (void)taosCalcChecksumAppend(0, pData, size); // save to file pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); @@ -125,7 +125,7 @@ _exit: tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); } taosMemoryFree(pData); - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); return code; } @@ -267,14 +267,14 @@ void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) { // CURRENT if (current) { - vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current, TSDB_FILENAME_LEN); offset = strlen(current); snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP); } // CURRENT.t if (current_t) { - vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); offset = strlen(current_t); snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP); } @@ -295,26 +295,26 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { int64_t size; if (taosFStatFile(pFD, &size, NULL) < 0) { code = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } pData = taosMemoryMalloc(size); if (pData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } if (taosReadFile(pFD, pData, size) < 0) { code = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } if (!taosCheckChecksumWhole(pData, size)) { code = TSDB_CODE_FILE_CORRUPTED; - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } @@ -326,7 +326,7 @@ _exit: tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); } taosMemoryFree(pData); - taosCloseFile(&pFD); + (void)taosCloseFile(&pFD); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 983fbc023d..cdef49a528 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -46,7 +46,7 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) { } fs[0]->tsdb = pTsdb; - tsem_init(&fs[0]->canEdit, 0, 1); + (void)tsem_init(&fs[0]->canEdit, 0, 1); fs[0]->fsstate = TSDB_FS_STATE_NORMAL; fs[0]->neid = 0; TARRAY2_INIT(fs[0]->fSetArr); @@ -60,7 +60,7 @@ static int32_t destroy_fs(STFileSystem **fs) { TARRAY2_DESTROY(fs[0]->fSetArr, NULL); TARRAY2_DESTROY(fs[0]->fSetArrTmp, NULL); - tsem_destroy(&fs[0]->canEdit); + (void)tsem_destroy(&fs[0]->canEdit); taosMemoryFree(fs[0]); fs[0] = NULL; return 0; @@ -69,7 +69,7 @@ static int32_t destroy_fs(STFileSystem **fs) { int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) { int32_t offset = 0; - vnodeGetPrimaryDir(pTsdb->path, pTsdb->pVnode->diskPrimary, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pTsdb->path, pTsdb->pVnode->diskPrimary, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); offset = strlen(fname); snprintf(fname + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, gCurrentFname[ftype]); @@ -105,7 +105,7 @@ _exit: tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code)); } taosMemoryFree(data); - taosCloseFile(&fp); + (void)taosCloseFile(&fp); return code; } @@ -144,7 +144,7 @@ _exit: tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code)); json[0] = NULL; } - taosCloseFile(&fp); + (void)taosCloseFile(&fp); taosMemoryFree(data); return code; } @@ -174,7 +174,7 @@ int32_t save_fs(const TFileSetArray *arr, const char *fname) { if (!item) { TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); } - cJSON_AddItemToArray(ajson, item); + (void)cJSON_AddItemToArray(ajson, item); code = tsdbTFileSetToJson(fset, item); TSDB_CHECK_CODE(code, lino, _exit); @@ -255,7 +255,7 @@ static int32_t apply_commit(STFileSystem *fs) { if (fset1 && fset2) { if (fset1->fid < fset2->fid) { // delete fset1 - tsdbTFileSetRemove(fset1); + (void)tsdbTFileSetRemove(fset1); i1++; } else if (fset1->fid > fset2->fid) { // create new file set with fid of fset2->fid @@ -274,7 +274,7 @@ static int32_t apply_commit(STFileSystem *fs) { } } else if (fset1) { // delete fset1 - tsdbTFileSetRemove(fset1); + (void)tsdbTFileSetRemove(fset1); i1++; } else { // create new file set with fid of fset2->fid @@ -298,11 +298,11 @@ static int32_t commit_edit(STFileSystem *fs) { char current[TSDB_FILENAME_LEN]; char current_t[TSDB_FILENAME_LEN]; - current_fname(fs->tsdb, current, TSDB_FCURRENT); + (void)current_fname(fs->tsdb, current, TSDB_FCURRENT); if (fs->etype == TSDB_FEDIT_COMMIT) { - current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); + (void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); } else { - current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); + (void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); } int32_t code; @@ -333,9 +333,9 @@ static int32_t abort_edit(STFileSystem *fs) { char fname[TSDB_FILENAME_LEN]; if (fs->etype == TSDB_FEDIT_COMMIT) { - current_fname(fs->tsdb, fname, TSDB_FCURRENT_C); + (void)current_fname(fs->tsdb, fname, TSDB_FCURRENT_C); } else { - current_fname(fs->tsdb, fname, TSDB_FCURRENT_M); + (void)current_fname(fs->tsdb, fname, TSDB_FCURRENT_M); } int32_t code; @@ -368,7 +368,7 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) { if (tsS3Enabled && fobj->f->lcn > 1) { char fname1[TSDB_FILENAME_LEN]; - tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1); + (void)tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1); if (!taosCheckExistFile(fname1)) { code = TSDB_CODE_FILE_CORRUPTED; tsdbError("vgId:%d %s failed since file:%s does not exist", TD_VID(fs->tsdb->pVnode), __func__, fname1); @@ -419,7 +419,7 @@ static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) { } // vnode.json - current_fname(fs->tsdb, fname, TSDB_FCURRENT); + (void)current_fname(fs->tsdb, fname, TSDB_FCURRENT); code = tsdbFSAddEntryToFileObjHash(hash, fname); TSDB_CHECK_CODE(code, lino, _exit); @@ -603,9 +603,9 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) { char cCurrent[TSDB_FILENAME_LEN]; char mCurrent[TSDB_FILENAME_LEN]; - current_fname(pTsdb, fCurrent, TSDB_FCURRENT); - current_fname(pTsdb, cCurrent, TSDB_FCURRENT_C); - current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M); + (void)current_fname(pTsdb, fCurrent, TSDB_FCURRENT); + (void)current_fname(pTsdb, cCurrent, TSDB_FCURRENT_C); + (void)current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M); if (taosCheckExistFile(fCurrent)) { // current.json exists code = load_fs(pTsdb, fCurrent, fs->fSetArr); @@ -744,7 +744,7 @@ int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback) { _exit: if (code) { tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); - destroy_fs(fs); + (void)destroy_fs(fs); } else { tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__); } @@ -777,7 +777,7 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { } fset->channel = (SVAChannelID){0}; fset->mergeScheduled = false; - tsdbFSSetBlockCommit(fset, false); + (void)tsdbFSSetBlockCommit(fset, false); fset->channelOpened = false; } } @@ -787,12 +787,12 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { // destroy all channels for (int32_t i = 0; i < taosArrayGetSize(channelArray); i++) { SVAChannelID *channel = taosArrayGet(channelArray, i); - vnodeAChannelDestroy(channel, true); + (void)vnodeAChannelDestroy(channel, true); } taosArrayDestroy(channelArray); #ifdef TD_ENTERPRISE - tsdbStopAllCompTask(pTsdb); + (void)tsdbStopAllCompTask(pTsdb); #endif return 0; } @@ -807,9 +807,9 @@ int32_t tsdbEnableBgTask(STsdb *pTsdb) { int32_t tsdbCloseFS(STFileSystem **fs) { if (fs[0] == NULL) return 0; - tsdbDisableAndCancelAllBgTask((*fs)->tsdb); - close_file_system(fs[0]); - destroy_fs(fs); + (void)tsdbDisableAndCancelAllBgTask((*fs)->tsdb); + (void)close_file_system(fs[0]); + (void)destroy_fs(fs); return 0; } @@ -832,12 +832,12 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e char current_t[TSDB_FILENAME_LEN]; if (etype == TSDB_FEDIT_COMMIT) { - current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); + (void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); } else { - current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); + (void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); } - tsem_wait(&fs->canEdit); + (void)tsem_wait(&fs->canEdit); fs->etype = etype; // edit @@ -864,7 +864,7 @@ static int32_t tsdbFSSetBlockCommit(STFileSet *fset, bool block) { } else { fset->blockCommit = false; if (fset->numWaitCommit > 0) { - taosThreadCondSignal(&fset->canCommit); + (void)taosThreadCondSignal(&fset->canCommit); } } return 0; @@ -873,11 +873,11 @@ static int32_t tsdbFSSetBlockCommit(STFileSet *fset, bool block) { int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) { (void)taosThreadMutexLock(&tsdb->mutex); STFileSet *fset; - tsdbFSGetFSet(tsdb->pFS, fid, &fset); + (void)tsdbFSGetFSet(tsdb->pFS, fid, &fset); if (fset) { while (fset->blockCommit) { fset->numWaitCommit++; - taosThreadCondWait(&fset->canCommit, &tsdb->mutex); + (void)taosThreadCondWait(&fset->canCommit, &tsdb->mutex); fset->numWaitCommit--; } } @@ -901,13 +901,13 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) { STFileSet *fset; TARRAY2_FOREACH_REVERSE(fs->fSetArr, fset) { if (TARRAY2_SIZE(fset->lvlArr) == 0) { - tsdbFSSetBlockCommit(fset, false); + (void)tsdbFSSetBlockCommit(fset, false); continue; } SSttLvl *lvl = TARRAY2_FIRST(fset->lvlArr); if (lvl->level != 0) { - tsdbFSSetBlockCommit(fset, false); + (void)tsdbFSSetBlockCommit(fset, false); continue; } @@ -932,9 +932,9 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) { } if (numFile >= sttTrigger * BLOCK_COMMIT_FACTOR) { - tsdbFSSetBlockCommit(fset, true); + (void)tsdbFSSetBlockCommit(fset, true); } else { - tsdbFSSetBlockCommit(fset, false); + (void)tsdbFSSetBlockCommit(fset, false); } } } @@ -945,13 +945,13 @@ _exit: } else { tsdbInfo("vgId:%d %s done, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype); } - tsem_post(&fs->canEdit); + (void)tsem_post(&fs->canEdit); return code; } int32_t tsdbFSEditAbort(STFileSystem *fs) { int32_t code = abort_edit(fs); - tsem_post(&fs->canEdit); + (void)tsem_post(&fs->canEdit); return code; } @@ -1163,7 +1163,7 @@ int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ev (void)taosThreadMutexUnlock(&fs->tsdb->mutex); if (code) { - tsdbTFileSetRangeClear(&fsr1); + (void)tsdbTFileSetRangeClear(&fsr1); TARRAY2_DESTROY(fsrArr[0], tsdbTFileSetRangeClear); fsrArr[0] = NULL; } @@ -1181,15 +1181,15 @@ int32_t tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr) { return tsd int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; - tsdbFSGetFSet(tsdb->pFS, fid, fset); + (void)tsdbFSGetFSet(tsdb->pFS, fid, fset); if (sttTrigger == 1 && (*fset)) { for (;;) { if ((*fset)->taskRunning) { (*fset)->numWaitTask++; - taosThreadCondWait(&(*fset)->beginTask, &tsdb->mutex); + (void)taosThreadCondWait(&(*fset)->beginTask, &tsdb->mutex); - tsdbFSGetFSet(tsdb->pFS, fid, fset); + (void)tsdbFSGetFSet(tsdb->pFS, fid, fset); ASSERT(fset != NULL); (*fset)->numWaitTask--; @@ -1209,11 +1209,11 @@ int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; if (sttTrigger == 1) { STFileSet *fset = NULL; - tsdbFSGetFSet(tsdb->pFS, fid, &fset); + (void)tsdbFSGetFSet(tsdb->pFS, fid, &fset); if (fset != NULL && fset->taskRunning) { fset->taskRunning = false; if (fset->numWaitTask > 0) { - taosThreadCondSignal(&fset->beginTask); + (void)taosThreadCondSignal(&fset->beginTask); } tsdbInfo("vgId:%d finish task on file set:%d", TD_VID(tsdb->pVnode), fid); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index 305ce6b56f..78e1a6a13d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -45,7 +45,7 @@ static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl STFileObj *fobj; code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj); if (code) { - tsdbSttLvlClear(lvl); + (void)tsdbSttLvlClear(lvl); return code; } @@ -61,7 +61,7 @@ static int32_t tsdbSttLvlInitRef(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lv STFileObj *fobj1; TARRAY2_FOREACH(lvl1->fobjArr, fobj1) { - tsdbTFileObjRef(fobj1); + (void)tsdbTFileObjRef(fobj1); code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj1); if (code) return code; } @@ -79,7 +79,7 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64 STFileObj *fobj; code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj); if (code) { - tsdbSttLvlClear(lvl); + (void)tsdbSttLvlClear(lvl); return code; } @@ -96,7 +96,7 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64 return 0; } -static void tsdbSttLvlRemoveFObj(void *data) { tsdbTFileObjRemove(*(STFileObj **)data); } +static void tsdbSttLvlRemoveFObj(void *data) { (void)tsdbTFileObjRemove(*(STFileObj **)data); } static void tsdbSttLvlRemove(SSttLvl **lvl) { TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj); taosMemoryFree(lvl[0]); @@ -173,7 +173,7 @@ static int32_t tsdbSttLvlToJson(const SSttLvl *lvl, cJSON *json) { TARRAY2_FOREACH(lvl->fobjArr, fobj) { cJSON *item = cJSON_CreateObject(); if (item == NULL) return TSDB_CODE_OUT_OF_MEMORY; - cJSON_AddItemToArray(ajson, item); + (void)cJSON_AddItemToArray(ajson, item); int32_t code = tsdbTFileToJson(fobj->f, item); if (code) return code; @@ -198,7 +198,7 @@ static int32_t tsdbJsonToSttLvl(STsdb *pTsdb, const cJSON *json, SSttLvl **lvl) item1 = cJSON_GetObjectItem(json, "files"); if (!cJSON_IsArray(item1)) { - tsdbSttLvlClear(lvl); + (void)tsdbSttLvlClear(lvl); return TSDB_CODE_FILE_CORRUPTED; } @@ -206,14 +206,14 @@ static int32_t tsdbJsonToSttLvl(STsdb *pTsdb, const cJSON *json, SSttLvl **lvl) STFile tf; code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &tf); if (code) { - tsdbSttLvlClear(lvl); + (void)tsdbSttLvlClear(lvl); return code; } STFileObj *fobj; code = tsdbTFileObjInit(pTsdb, &tf, &fobj); if (code) { - tsdbSttLvlClear(lvl); + (void)tsdbSttLvlClear(lvl); return code; } @@ -247,7 +247,7 @@ int32_t tsdbTFileSetToJson(const STFileSet *fset, cJSON *json) { TARRAY2_FOREACH(fset->lvlArr, lvl) { item2 = cJSON_CreateObject(); if (!item2) return TSDB_CODE_OUT_OF_MEMORY; - cJSON_AddItemToArray(item1, item2); + (void)cJSON_AddItemToArray(item1, item2); code = tsdbSttLvlToJson(lvl, item2); if (code) return code; @@ -347,7 +347,7 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) { TARRAY2_REMOVE(lvl->fobjArr, idx, tsdbSttLvlClearFObj); } else { ASSERT(tsdbIsSameTFile(&op->of, fset->farr[op->of.type]->f)); - tsdbTFileObjUnref(fset->farr[op->of.type]); + (void)tsdbTFileObjUnref(fset->farr[op->of.type]); fset->farr[op->of.type] = NULL; } } else { @@ -389,9 +389,9 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f } } else { if (fobj1->f->cid != fobj2->f->cid) { - tsdbTFileObjRemove(fobj2); + (void)tsdbTFileObjRemove(fobj2); } else { - tsdbTFileObjRemoveUpdateLC(fobj2); + (void)tsdbTFileObjRemoveUpdateLC(fobj2); } code = tsdbTFileObjInit(pTsdb, fobj1->f, &fset2->farr[ftype]); if (code) return code; @@ -402,7 +402,7 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f if (code) return code; } else { // remove the file - tsdbTFileObjRemove(fobj2); + (void)tsdbTFileObjRemove(fobj2); fset2->farr[ftype] = NULL; } } @@ -460,12 +460,12 @@ int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset) { TARRAY2_INIT(fset[0]->lvlArr); // background task queue - taosThreadCondInit(&(*fset)->beginTask, NULL); + (void)taosThreadCondInit(&(*fset)->beginTask, NULL); (*fset)->taskRunning = false; (*fset)->numWaitTask = 0; // block commit variables - taosThreadCondInit(&fset[0]->canCommit, NULL); + (void)taosThreadCondInit(&fset[0]->canCommit, NULL); (*fset)->numWaitCommit = 0; (*fset)->blockCommit = false; @@ -522,7 +522,8 @@ int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_ .fid = fobj->f->fid, .of = fobj->f[0], }; - TARRAY2_APPEND(fopArr, op); + code = TARRAY2_APPEND(fopArr, op); + if (code) return code; } } @@ -567,7 +568,7 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if (fset1->farr[ftype] == NULL) continue; - tsdbTFileObjRef(fset1->farr[ftype]); + (void)tsdbTFileObjRef(fset1->farr[ftype]); fset[0]->farr[ftype] = fset1->farr[ftype]; } @@ -609,13 +610,13 @@ void tsdbTFileSetClear(STFileSet **fset) { if (fset && *fset) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if ((*fset)->farr[ftype] == NULL) continue; - tsdbTFileObjUnref((*fset)->farr[ftype]); + (void)tsdbTFileObjUnref((*fset)->farr[ftype]); } TARRAY2_DESTROY((*fset)->lvlArr, tsdbSttLvlClear); - taosThreadCondDestroy(&(*fset)->beginTask); - taosThreadCondDestroy(&(*fset)->canCommit); + (void)taosThreadCondDestroy(&(*fset)->beginTask); + (void)taosThreadCondDestroy(&(*fset)->canCommit); taosMemoryFreeClear(*fset); } } @@ -625,7 +626,7 @@ int32_t tsdbTFileSetRemove(STFileSet *fset) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { if (fset->farr[ftype] != NULL) { - tsdbTFileObjRemove(fset->farr[ftype]); + (void)tsdbTFileObjRemove(fset->farr[ftype]); fset->farr[ftype] = NULL; } } diff --git a/source/dnode/vnode/src/tsdb/tsdbFSetRW.c b/source/dnode/vnode/src/tsdb/tsdbFSetRW.c index 77d8998aa7..3ccf833ddd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSetRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSetRW.c @@ -44,7 +44,7 @@ static int32_t tsdbFSetWriteTableDataBegin(SFSetWriter *writer, const TABLEID *t writer->ctx->tbid->uid = tbid->uid; code = tsdbUpdateSkmTb(writer->config->tsdb, writer->ctx->tbid, writer->skmTb); - TSDB_CHECK_CODE(code , lino, _exit); + TSDB_CHECK_CODE(code, lino, _exit); code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, tbid->suid ? tbid->suid : tbid->uid, &writer->pColCmprObj); // TODO: TSDB_CHECK_CODE(code, lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 243ff662f7..cf88f9a066 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -221,7 +221,7 @@ void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) { int32_t offset = 0; SVnode *pVnode = pTsdb->pVnode; - vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, fname, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, fname, TSDB_FILENAME_LEN); offset = strlen(fname); snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP, TD_VID(pTsdb->pVnode), pFile->commitID); diff --git a/source/dnode/vnode/src/tsdb/tsdbIter.c b/source/dnode/vnode/src/tsdb/tsdbIter.c index 3b5bd6d02f..0de9ba9822 100644 --- a/source/dnode/vnode/src/tsdb/tsdbIter.c +++ b/source/dnode/vnode/src/tsdb/tsdbIter.c @@ -224,7 +224,7 @@ static int32_t tsdbMemTableIterNext(STsdbIter *iter, const TABLEID *tbid) { iter->row->row = row[0]; - tsdbTbDataIterNext(iter->memtData->tbIter); + (void)tsdbTbDataIterNext(iter->memtData->tbIter); goto _exit; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 3114c0fa04..d8ec014985 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -410,7 +410,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid pMemTable->aBucket[idx] = pTbData; pMemTable->nTbData++; - tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn); + (void)tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn); taosWUnLockLatch(&pMemTable->latch); @@ -742,7 +742,7 @@ int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode) { int32_t nRef = atomic_fetch_add_32(&pMemTable->nRef, 1); ASSERT(nRef > 0); - vnodeBufPoolRegisterQuery(pMemTable->pPool, pQNode); + (void)vnodeBufPoolRegisterQuery(pMemTable->pPool, pQNode); _exit: return code; diff --git a/source/dnode/vnode/src/tsdb/tsdbMerge.c b/source/dnode/vnode/src/tsdb/tsdbMerge.c index 7b40290c05..1bbda8a249 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMerge.c +++ b/source/dnode/vnode/src/tsdb/tsdbMerge.c @@ -215,7 +215,7 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) { TAOS_CHECK_GOTO(tsdbSttFileReaderOpen(fobj->fname, &config, &reader), &lino, _exit); if ((code = TARRAY2_APPEND(merger->sttReaderArr, reader))) { - tsdbSttFileReaderClose(&reader); + (void)tsdbSttFileReaderClose(&reader); TSDB_CHECK_CODE(code, lino, _exit); } } @@ -230,7 +230,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(merger->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); - tsdbMergeFileSetEndCloseReader(merger); + (void)tsdbMergeFileSetEndCloseReader(merger); } return code; } @@ -282,7 +282,7 @@ static int32_t tsdbMergeFileSetBeginOpenWriter(SMerger *merger) { TAOS_CHECK_GOTO(tfsAllocDisk(merger->tsdb->pVnode->pTfs, level, &did), &lino, _exit); - tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did); + (void)tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did); SFSetWriterConfig config = { .tsdb = merger->tsdb, .toSttOnly = true, @@ -355,9 +355,9 @@ static int32_t tsdbMergeFileSetEndCloseWriter(SMerger *merger) { } static int32_t tsdbMergeFileSetEndCloseIter(SMerger *merger) { - tsdbIterMergerClose(&merger->tombIterMerger); + (void)tsdbIterMergerClose(&merger->tombIterMerger); TARRAY2_CLEAR(merger->tombIterArr, tsdbIterClose); - tsdbIterMergerClose(&merger->dataIterMerger); + (void)tsdbIterMergerClose(&merger->dataIterMerger); TARRAY2_CLEAR(merger->dataIterArr, tsdbIterClose); return 0; } @@ -479,7 +479,7 @@ static int32_t tsdbMergeGetFSet(SMerger *merger) { STFileSet *fset; (void)taosThreadMutexLock(&merger->tsdb->mutex); - tsdbFSGetFSet(merger->tsdb->pFS, merger->fid, &fset); + (void)tsdbFSGetFSet(merger->tsdb->pFS, merger->fid, &fset); if (fset == NULL) { (void)taosThreadMutexUnlock(&merger->tsdb->mutex); return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 198a010a77..e943ef2442 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -301,8 +301,10 @@ static int32_t binarySearchForStartRowIndex(uint64_t *uidList, int32_t num, uint static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray, SSttBlockLoadInfo *pBlockLoadInfo, uint64_t suid) { + void *px = NULL; + int32_t code = TSDB_CODE_SUCCESS; if (TARRAY2_SIZE(pArray) <= 0) { - return TSDB_CODE_SUCCESS; + return code; } SSttBlk *pStart = &pArray->data[0]; @@ -316,10 +318,17 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray return TSDB_CODE_SUCCESS; } else { // all blocks are qualified taosArrayClear(pBlockLoadInfo->aSttBlk); - taosArrayAddBatch(pBlockLoadInfo->aSttBlk, pArray->data, pArray->size); + px = taosArrayAddBatch(pBlockLoadInfo->aSttBlk, pArray->data, pArray->size); + if (px == NULL){ + return terrno; + } } } else { SArray *pTmp = taosArrayInit(TARRAY2_SIZE(pArray), sizeof(SSttBlk)); + if (pTmp == NULL) { + return terrno; + } + for (int32_t i = 0; i < TARRAY2_SIZE(pArray); ++i) { SSttBlk *p = &pArray->data[i]; if (p->suid < suid) { @@ -327,7 +336,11 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray } if (p->suid == suid) { - taosArrayPush(pTmp, p); + void* px = taosArrayPush(pTmp, p); + if (px == NULL) { + code = terrno; + break; + } } else if (p->suid > suid) { break; } @@ -337,7 +350,7 @@ static int32_t extractSttBlockInfo(SLDataIter *pIter, const TSttBlkArray *pArray pBlockLoadInfo->aSttBlk = pTmp; } - return TSDB_CODE_SUCCESS; + return code; } static int32_t tValueDupPayload(SValue *pVal) { @@ -357,9 +370,11 @@ static int32_t tValueDupPayload(SValue *pVal) { static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBlockLoadInfo *pBlockLoadInfo, TStatisBlkArray *pStatisBlkArray, uint64_t suid, const char *id) { + int32_t code = TSDB_CODE_SUCCESS; + void* px = NULL; int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray); if (numOfBlocks <= 0) { - return 0; + return code; } int32_t startIndex = 0; @@ -385,7 +400,10 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl int64_t st = taosGetTimestampUs(); for (int32_t k = startIndex; k < endIndex; ++k) { - tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block); + code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block); + if (code) { + return code; + } int32_t i = 0; int32_t rows = block.numOfRecords; @@ -409,21 +427,43 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl int32_t size = rows - i; int32_t offset = i * sizeof(int64_t); - taosArrayAddBatch(pBlockLoadInfo->info.pUid, tBufferGetDataAt(&block.uids, offset), size); - taosArrayAddBatch(pBlockLoadInfo->info.pFirstTs, tBufferGetDataAt(&block.firstKeyTimestamps, offset), size); - taosArrayAddBatch(pBlockLoadInfo->info.pLastTs, tBufferGetDataAt(&block.lastKeyTimestamps, offset), size); - taosArrayAddBatch(pBlockLoadInfo->info.pCount, tBufferGetDataAt(&block.counts, offset), size); + px = taosArrayAddBatch(pBlockLoadInfo->info.pUid, tBufferGetDataAt(&block.uids, offset), size); + if (px == NULL) { + return terrno; + } + + px = taosArrayAddBatch(pBlockLoadInfo->info.pFirstTs, tBufferGetDataAt(&block.firstKeyTimestamps, offset), size); + if (px == NULL){ + return terrno; + } + + px = taosArrayAddBatch(pBlockLoadInfo->info.pLastTs, tBufferGetDataAt(&block.lastKeyTimestamps, offset), size); + if (px == NULL){ + return terrno; + } + + px = taosArrayAddBatch(pBlockLoadInfo->info.pCount, tBufferGetDataAt(&block.counts, offset), size); + if (px == NULL){ + return terrno; + } if (block.numOfPKs > 0) { SValue vFirst = {0}, vLast = {0}; for (int32_t f = i; f < rows; ++f) { - int32_t code = tValueColumnGet(&block.firstKeyPKs[0], f, &vFirst); + code = tValueColumnGet(&block.firstKeyPKs[0], f, &vFirst); if (code) { break; } - tValueDupPayload(&vFirst); - taosArrayPush(pBlockLoadInfo->info.pFirstKey, &vFirst); + code = tValueDupPayload(&vFirst); + if (code) { + break; + } + + px = taosArrayPush(pBlockLoadInfo->info.pFirstKey, &vFirst); + if (px == NULL) { + return terrno; + } // todo add api to clone the original data code = tValueColumnGet(&block.lastKeyPKs[0], f, &vLast); @@ -431,14 +471,28 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl break; } - tValueDupPayload(&vLast); - taosArrayPush(pBlockLoadInfo->info.pLastKey, &vLast); + code = tValueDupPayload(&vLast); + if (code) { + break; + } + + px = taosArrayPush(pBlockLoadInfo->info.pLastKey, &vLast); + if (px == NULL) { + return terrno; + } } } else { SValue vFirst = {0}; for (int32_t j = 0; j < size; ++j) { - taosArrayPush(pBlockLoadInfo->info.pFirstKey, &vFirst); - taosArrayPush(pBlockLoadInfo->info.pLastKey, &vFirst); + px = taosArrayPush(pBlockLoadInfo->info.pFirstKey, &vFirst); + if (px == NULL) { + return terrno; + } + + px = taosArrayPush(pBlockLoadInfo->info.pLastKey, &vFirst); + if (px == NULL) { + return terrno; + } } } } else { @@ -450,24 +504,59 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl break; } - taosArrayPush(pBlockLoadInfo->info.pUid, &record.uid); - taosArrayPush(pBlockLoadInfo->info.pCount, &record.count); + px = taosArrayPush(pBlockLoadInfo->info.pUid, &record.uid); + if (px == NULL) { + return terrno; + } - taosArrayPush(pBlockLoadInfo->info.pFirstTs, &record.firstKey.ts); - taosArrayPush(pBlockLoadInfo->info.pLastTs, &record.lastKey.ts); + px = taosArrayPush(pBlockLoadInfo->info.pCount, &record.count); + if (px == NULL) { + return terrno; + } + + px = taosArrayPush(pBlockLoadInfo->info.pFirstTs, &record.firstKey.ts); + if (px == NULL) { + return terrno; + } + + px = taosArrayPush(pBlockLoadInfo->info.pLastTs, &record.lastKey.ts); + if (px == NULL) { + return terrno; + } if (record.firstKey.numOfPKs > 0) { SValue s = record.firstKey.pks[0]; - tValueDupPayload(&s); - taosArrayPush(pBlockLoadInfo->info.pFirstKey, &s); + code = tValueDupPayload(&s); + if (code) { + return code; + } + + px = taosArrayPush(pBlockLoadInfo->info.pFirstKey, &s); + if (px == NULL) { + return terrno; + } s = record.lastKey.pks[0]; - tValueDupPayload(&s); - taosArrayPush(pBlockLoadInfo->info.pLastKey, &s); + code = tValueDupPayload(&s); + if (code) { + return code; + } + + px = taosArrayPush(pBlockLoadInfo->info.pLastKey, &s); + if (px == NULL) { + return terrno; + } } else { SValue v = {0}; - taosArrayPush(pBlockLoadInfo->info.pFirstKey, &v); - taosArrayPush(pBlockLoadInfo->info.pLastKey, &v); + px = taosArrayPush(pBlockLoadInfo->info.pFirstKey, &v); + if (px == NULL) { + return terrno; + } + + px = taosArrayPush(pBlockLoadInfo->info.pLastKey, &v); + if (px == NULL) { + return terrno; + } } i += 1; @@ -482,7 +571,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl pBlockLoadInfo->cost.statisElapsedTime += el; tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el); - return TSDB_CODE_SUCCESS; + return code; } static int32_t doLoadSttFilesBlk(SSttBlockLoadInfo *pBlockLoadInfo, SLDataIter *pIter, int64_t suid, @@ -617,7 +706,7 @@ int32_t tLDataIterOpen2(SLDataIter *pIter, SSttFileReader *pSttFileReader, int32 } void tLDataIterClose2(SLDataIter *pIter) { - tsdbSttFileReaderClose(&pIter->pReader); + (void) tsdbSttFileReaderClose(&pIter->pReader); // always return 0 pIter->pReader = NULL; } @@ -890,7 +979,10 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF goto _end; } - adjustSttDataIters(pConf->pSttFileBlockIterArray, pConf->pCurrentFileset); + code = adjustSttDataIters(pConf->pSttFileBlockIterArray, pConf->pCurrentFileset); + if (code) { + goto _end; + } for (int32_t j = 0; j < numOfLevels; ++j) { SSttLvl *pSttLevel = ((STFileSet *)pConf->pCurrentFileset)->lvlArr->data[j]; @@ -940,7 +1032,10 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF // let's record the time window for current table of uid in the stt files if (pSttDataInfo != NULL && numOfRows > 0) { - taosArrayPush(pSttDataInfo->pKeyRangeList, &range); + void* px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); + if (px == NULL) { + return terrno; + } pSttDataInfo->numOfRows += numOfRows; } } else { @@ -958,7 +1053,7 @@ _end: return code; } -void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } +void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { (void) tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); } bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; } @@ -1035,7 +1130,7 @@ bool tMergeTreeNext(SMergeTree *pMTree) { if (pMTree->pIter && pIter) { int32_t c = pMTree->rbt.cmprFn(&pMTree->pIter->node, &pIter->node); if (c > 0) { - tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pMTree->pIter); + (void) tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pMTree->pIter); pMTree->pIter = NULL; } else { ASSERT(c); diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index 370d847a33..996b1a6425 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -57,18 +57,18 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg * snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir); // taosRealPath(pTsdb->path, NULL, slen); pTsdb->pVnode = pVnode; - taosThreadMutexInit(&pTsdb->mutex, NULL); + (void)taosThreadMutexInit(&pTsdb->mutex, NULL); if (!pKeepCfg) { - tsdbSetKeepCfg(pTsdb, &pVnode->config.tsdbCfg); + (void)tsdbSetKeepCfg(pTsdb, &pVnode->config.tsdbCfg); } else { memcpy(&pTsdb->keepCfg, pKeepCfg, sizeof(STsdbKeepCfg)); } // create dir if (pVnode->pTfs) { - tfsMkdir(pVnode->pTfs, pTsdb->path); + (void)tfsMkdir(pVnode->pTfs, pTsdb->path); } else { - taosMkDir(pTsdb->path); + (void)taosMkDir(pTsdb->path); } // open tsdb @@ -87,8 +87,8 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg * _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, lino, tstrerror(code)); - tsdbCloseFS(&pTsdb->pFS); - taosThreadMutexDestroy(&pTsdb->mutex); + (void)tsdbCloseFS(&pTsdb->pFS); + (void)taosThreadMutexDestroy(&pTsdb->mutex); taosMemoryFree(pTsdb); } else { tsdbDebug("vgId:%d, tsdb is opened at %s, days:%d, keep:%d,%d,%d, keepTimeoffset:%d", TD_VID(pVnode), pTsdb->path, @@ -110,12 +110,12 @@ int32_t tsdbClose(STsdb **pTsdb) { (*pTsdb)->mem = NULL; (void)taosThreadMutexUnlock(&(*pTsdb)->mutex); - tsdbCloseFS(&(*pTsdb)->pFS); + (void)tsdbCloseFS(&(*pTsdb)->pFS); tsdbCloseCache(*pTsdb); #ifdef TD_ENTERPRISE - tsdbCloseCompMonitor(*pTsdb); + (void)tsdbCloseCompMonitor(*pTsdb); #endif - taosThreadMutexDestroy(&(*pTsdb)->mutex); + (void)taosThreadMutexDestroy(&(*pTsdb)->mutex); taosMemoryFreeClear(*pTsdb); } return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index a3210dbfd9..5d25c0dc9d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -48,7 +48,7 @@ typedef struct { static int32_t getCurrentBlockInfo(SDataBlockIter* pBlockIter, SFileDataBlockInfo** pInfo); static int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, STsdbReader* pReader); -static int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes); +static void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes); static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, SRowKey* pKey, STsdbReader* pReader); static int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, @@ -3293,23 +3293,10 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { if ((!hasDataInSttBlock(pScanInfo)) || (asc && pBlockInfo->lastKey < keyInStt) || (!asc && pBlockInfo->firstKey > keyInStt)) { - if (pScanInfo->cleanSttBlocks && hasDataInSttBlock(pScanInfo)) { - if (asc) { // file block is located before the stt block - ASSERT(pScanInfo->sttRange.skey.ts > pBlockInfo->lastKey); - } else { // stt block is before the file block - ASSERT(pScanInfo->sttRange.ekey.ts < pBlockInfo->firstKey); - } - } - + // the stt blocks may located in the gap of different data block, but the whole sttRange may overlap with the + // data block, so the overlap check is invalid actually. buildCleanBlockFromDataFiles(pReader, pScanInfo, pBlockInfo, pBlockIter->index); } else { // clean stt block - if (asc) { - ASSERT(pScanInfo->sttRange.ekey.ts < pBlockInfo->firstKey); - } else { - ASSERT(pScanInfo->sttRange.skey.ts > pBlockInfo->lastKey); - } - - // return the stt file block ASSERT(pReader->info.execMode == READER_EXEC_ROWS && pSttBlockReader->mergeTree.pIter == NULL); code = buildCleanBlockFromSttFiles(pReader, pScanInfo); return code; @@ -3866,11 +3853,11 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t return false; } -FORCE_INLINE int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes) { +FORCE_INLINE void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes) { *pRes = NULL; if (!pIter->hasVal) { - return TSDB_CODE_SUCCESS; + return; } int32_t order = pReader->info.order; @@ -3880,20 +3867,20 @@ FORCE_INLINE int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, ST TSDBROW_INIT_KEY(pRow, key); if (outOfTimeWindow(key.ts, &pReader->info.window)) { pIter->hasVal = false; - return TSDB_CODE_SUCCESS; + return; } // it is a valid data version if (key.version <= pReader->info.verRange.maxVer && key.version >= pReader->info.verRange.minVer) { if (pDelList == NULL || TARRAY_SIZE(pDelList) == 0) { *pRes = pRow; - return TSDB_CODE_SUCCESS; + return; } else { bool dropped = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, pReader->suppInfo.numOfPks > 0); if (!dropped) { *pRes = pRow; - return TSDB_CODE_SUCCESS; + return; } } } @@ -3901,7 +3888,7 @@ FORCE_INLINE int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, ST while (1) { pIter->hasVal = tsdbTbDataIterNext(pIter->iter); if (!pIter->hasVal) { - return TSDB_CODE_SUCCESS; + return; } pRow = tsdbTbDataIterGet(pIter->iter); @@ -3909,19 +3896,19 @@ FORCE_INLINE int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, ST TSDBROW_INIT_KEY(pRow, key); if (outOfTimeWindow(key.ts, &pReader->info.window)) { pIter->hasVal = false; - return TSDB_CODE_SUCCESS; + return; } if (key.version <= pReader->info.verRange.maxVer && key.version >= pReader->info.verRange.minVer) { if (pDelList == NULL || TARRAY_SIZE(pDelList) == 0) { *pRes = pRow; - return TSDB_CODE_SUCCESS; + return; } else { bool dropped = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, pReader->suppInfo.numOfPks > 0); if (!dropped) { *pRes = pRow; - return TSDB_CODE_SUCCESS; + return; } } } diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 28abed1ce7..8e52074807 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -35,7 +35,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { int32_t vid = 0; const char *object_name = taosDirEntryBaseName((char *)path); - sscanf(object_name, "v%df%dver%" PRId64 ".data", &vid, &pFD->fid, &pFD->cid); + (void)sscanf(object_name, "v%df%dver%" PRId64 ".data", &vid, &pFD->fid, &pFD->cid); char *dot = strrchr(lc_path, '.'); if (!dot) { @@ -124,7 +124,7 @@ void tsdbCloseFile(STsdbFD **ppFD) { if (pFD) { taosMemoryFree(pFD->pBuf); // if (!pFD->s3File) { - taosCloseFile(&pFD->pFD); + (void)taosCloseFile(&pFD->pFD); //} taosMemoryFree(pFD); *ppFD = NULL; @@ -156,7 +156,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } - taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); + (void)taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); if (encryptAlgorithm == DND_CA_SM4) { // if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){ @@ -430,7 +430,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64 code = tsdbCacheGetPageS3(pFD->pTsdb->pgCache, pFD, pgno, &handle); if (code != TSDB_CODE_SUCCESS) { if (handle) { - tsdbCacheRelease(pFD->pTsdb->pgCache, handle); + (void)tsdbCacheRelease(pFD->pTsdb->pgCache, handle); } TSDB_CHECK_CODE(code, lino, _exit); } @@ -441,7 +441,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64 uint8_t *pPage = (uint8_t *)taosLRUCacheValue(pFD->pTsdb->pgCache, handle); memcpy(pFD->pBuf, pPage, pFD->szPage); - tsdbCacheRelease(pFD->pTsdb->pgCache, handle); + (void)tsdbCacheRelease(pFD->pTsdb->pgCache, handle); // check if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) { @@ -477,7 +477,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64 int nPage = pgnoEnd - pgno + 1; for (int i = 0; i < nPage; ++i) { if (pFD->szFile != pgno) { // DONOT cache last volatile page - tsdbCacheSetPageS3(pFD->pTsdb->pgCache, pFD, pgno, pBlock + i * pFD->szPage); + (void)tsdbCacheSetPageS3(pFD->pTsdb->pgCache, pFD, pgno, pBlock + i * pFD->szPage); } if (szHint > 0 && n >= size) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index a454f09e22..bdd174a8f8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -71,8 +71,8 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi char fname_from[TSDB_FILENAME_LEN]; char fname_to[TSDB_FILENAME_LEN]; - tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from); - tsdbTFileLastChunkName(rtner->tsdb, to, fname_to); + (void)tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from); + (void)tsdbTFileLastChunkName(rtner->tsdb, to, fname_to); fdFrom = taosOpenFile(fname_from, TD_FILE_READ); if (fdFrom == NULL) { @@ -99,8 +99,8 @@ _exit: tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - taosCloseFile(&fdFrom); - taosCloseFile(&fdTo); + (void)taosCloseFile(&fdFrom); + (void)taosCloseFile(&fdTo); return code; } @@ -112,7 +112,7 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile TdFilePtr fdFrom = NULL; TdFilePtr fdTo = NULL; - tsdbTFileName(rtner->tsdb, to, fname); + (void)tsdbTFileName(rtner->tsdb, to, fname); fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { @@ -136,8 +136,8 @@ _exit: tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - taosCloseFile(&fdFrom); - taosCloseFile(&fdTo); + (void)taosCloseFile(&fdFrom); + (void)taosCloseFile(&fdTo); return code; } @@ -255,7 +255,7 @@ static int32_t tsdbDoRetention(SRTNer *rtner) { SDiskID did; TAOS_CHECK_GOTO(tfsAllocDisk(rtner->tsdb->pVnode->pTfs, expLevel, &did), &lino, _exit); - tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did); + (void)tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did); // data for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX && (fobj = fset->farr[ftype], 1); ++ftype) { @@ -316,7 +316,7 @@ static int32_t tsdbRetention(void *arg) { // begin task (void)taosThreadMutexLock(&pTsdb->mutex); - tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset); + (void)tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset); if (fset && (code = tsdbTFileSetInitCopy(pTsdb, fset, &rtner.fset))) { (void)taosThreadMutexUnlock(&pTsdb->mutex); TSDB_CHECK_CODE(code, lino, _exit); @@ -337,7 +337,7 @@ static int32_t tsdbRetention(void *arg) { _exit: if (rtner.fset) { (void)taosThreadMutexLock(&pTsdb->mutex); - tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid); + (void)tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid); (void)taosThreadMutexUnlock(&pTsdb->mutex); } @@ -427,7 +427,7 @@ static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile TdFilePtr fdFrom = NULL; // TdFilePtr fdTo = NULL; - tsdbTFileName(rtner->tsdb, to, fname); + (void)tsdbTFileName(rtner->tsdb, to, fname); fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { @@ -442,7 +442,7 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - taosCloseFile(&fdFrom); + (void)taosCloseFile(&fdFrom); return code; } @@ -486,7 +486,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit); char fname[TSDB_FILENAME_LEN]; - tsdbTFileName(rtner->tsdb, &op.nf, fname); + (void)tsdbTFileName(rtner->tsdb, &op.nf, fname); char *object_name = taosDirEntryBaseName(fname); char object_name_prefix[TSDB_FILENAME_LEN]; int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode); @@ -542,8 +542,8 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - taosCloseFile(&fdFrom); - taosCloseFile(&fdTo); + (void)taosCloseFile(&fdFrom); + (void)taosCloseFile(&fdTo); return code; } @@ -587,7 +587,7 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64 TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit); char fname[TSDB_FILENAME_LEN]; - tsdbTFileName(rtner->tsdb, &op.nf, fname); + (void)tsdbTFileName(rtner->tsdb, &op.nf, fname); char *object_name = taosDirEntryBaseName(fname); char object_name_prefix[TSDB_FILENAME_LEN]; int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode); @@ -640,8 +640,8 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - taosCloseFile(&fdFrom); - taosCloseFile(&fdTo); + (void)taosCloseFile(&fdFrom); + (void)taosCloseFile(&fdTo); return code; } @@ -673,7 +673,7 @@ static int32_t tsdbDoS3Migrate(SRTNer *rtner) { if (/*lcn < 1 && */ taosCheckExistFile(fobj->fname)) { int32_t mtime = 0; int64_t size = 0; - taosStatFile(fobj->fname, &size, &mtime, NULL); + (void)taosStatFile(fobj->fname, &size, &mtime, NULL); if (size > chunksize && mtime < rtner->now - tsS3UploadDelaySec) { if (pCfg->s3Compact && lcn < 0) { extern int32_t tsdbAsyncCompact(STsdb * tsdb, const STimeWindow *tw, bool sync); @@ -695,12 +695,12 @@ static int32_t tsdbDoS3Migrate(SRTNer *rtner) { TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, &lino, _exit); } char fname1[TSDB_FILENAME_LEN]; - tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1); + (void)tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1); if (taosCheckExistFile(fname1)) { int32_t mtime = 0; int64_t size = 0; - taosStatFile(fname1, &size, &mtime, NULL); + (void)taosStatFile(fname1, &size, &mtime, NULL); if (size > chunksize && mtime < rtner->now - tsS3UploadDelaySec) { TAOS_CHECK_GOTO(tsdbMigrateDataFileLCS3(rtner, fobj, size, chunksize), &lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c index c9e02c5130..decf276bc6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapInfo.c @@ -196,7 +196,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray _err: if (pDiff) { - tsdbTFileSetRangeArrayDestroy(&pDiff); + (void)tsdbTFileSetRangeArrayDestroy(&pDiff); } return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 3edff5ebcb..2b63d5b6e6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -59,7 +59,7 @@ struct STsdbSnapReader { static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) { TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose); - tsdbDataFileReaderClose(&reader->dataReader); + TAOS_UNUSED(tsdbDataFileReaderClose(&reader->dataReader)); return 0; } @@ -107,7 +107,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) { TSDB_CHECK_CODE(code, lino, _exit); if ((code = TARRAY2_APPEND(reader->sttReaderArr, sttReader))) { - tsdbSttFileReaderClose(&sttReader); + TAOS_UNUSED(tsdbSttFileReaderClose(&sttReader)); TSDB_CHECK_CODE(code, lino, _exit); } } @@ -115,7 +115,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) { _exit: if (code) { - tsdbSnapReadFileSetCloseReader(reader); + TAOS_UNUSED(tsdbSnapReadFileSetCloseReader(reader)); TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino); } return code; @@ -199,8 +199,8 @@ _exit: } static int32_t tsdbSnapReadFileSetCloseIter(STsdbSnapReader* reader) { - tsdbIterMergerClose(&reader->dataIterMerger); - tsdbIterMergerClose(&reader->tombIterMerger); + TAOS_UNUSED(tsdbIterMergerClose(&reader->dataIterMerger)); + TAOS_UNUSED(tsdbIterMergerClose(&reader->tombIterMerger)); TARRAY2_CLEAR(reader->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(reader->tombIterArr, tsdbIterClose); return 0; @@ -232,8 +232,8 @@ _exit: } static int32_t tsdbSnapReadRangeEnd(STsdbSnapReader* reader) { - tsdbSnapReadFileSetCloseIter(reader); - tsdbSnapReadFileSetCloseReader(reader); + TAOS_UNUSED(tsdbSnapReadFileSetCloseIter(reader)); + TAOS_UNUSED(tsdbSnapReadFileSetCloseReader(reader)); reader->ctx->fsr = NULL; return 0; } @@ -384,7 +384,7 @@ static int32_t tsdbSnapReadTombData(STsdbSnapReader* reader, uint8_t** data) { int32_t lino = 0; SMetaInfo info; - tTombBlockClear(reader->tombBlock); + TAOS_UNUSED(tTombBlockClear(reader->tombBlock)); TABLEID tbid[1] = {0}; for (STombRecord* record; (record = tsdbIterMergerGetTombRecord(reader->tombIterMerger)) != NULL;) { @@ -441,7 +441,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s, sver:%" PRId64 " ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code), sver, ever, type); - tsdbTFileSetRangeArrayDestroy(&reader[0]->fsrArr); + TAOS_UNUSED(tsdbTFileSetRangeArrayDestroy(&reader[0]->fsrArr)); taosMemoryFree(reader[0]); reader[0] = NULL; } else { @@ -460,21 +460,21 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) { STsdb* tsdb = reader[0]->tsdb; - tTombBlockDestroy(reader[0]->tombBlock); + TAOS_UNUSED(tTombBlockDestroy(reader[0]->tombBlock)); tBlockDataDestroy(reader[0]->blockData); - tsdbIterMergerClose(&reader[0]->dataIterMerger); - tsdbIterMergerClose(&reader[0]->tombIterMerger); + TAOS_UNUSED(tsdbIterMergerClose(&reader[0]->dataIterMerger)); + TAOS_UNUSED(tsdbIterMergerClose(&reader[0]->tombIterMerger)); TARRAY2_DESTROY(reader[0]->dataIterArr, tsdbIterClose); TARRAY2_DESTROY(reader[0]->tombIterArr, tsdbIterClose); TARRAY2_DESTROY(reader[0]->sttReaderArr, tsdbSttFileReaderClose); - tsdbDataFileReaderClose(&reader[0]->dataReader); + TAOS_UNUSED(tsdbDataFileReaderClose(&reader[0]->dataReader)); - tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr); + TAOS_UNUSED(tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr)); tDestroyTSchema(reader[0]->skmTb->pTSchema); for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->buffers); ++i) { - tBufferDestroy(reader[0]->buffers + i); + TAOS_UNUSED(tBufferDestroy(reader[0]->buffers + i)); } taosMemoryFree(reader[0]); @@ -706,7 +706,7 @@ _exit: static int32_t tsdbSnapWriteFileSetCloseReader(STsdbSnapWriter* writer) { TARRAY2_CLEAR(writer->ctx->sttReaderArr, tsdbSttFileReaderClose); - tsdbDataFileReaderClose(&writer->ctx->dataReader); + TAOS_UNUSED(tsdbDataFileReaderClose(&writer->ctx->dataReader)); return 0; } @@ -782,8 +782,8 @@ _exit: } static int32_t tsdbSnapWriteFileSetCloseIter(STsdbSnapWriter* writer) { - tsdbIterMergerClose(&writer->ctx->dataIterMerger); - tsdbIterMergerClose(&writer->ctx->tombIterMerger); + TAOS_UNUSED(tsdbIterMergerClose(&writer->ctx->dataIterMerger)); + TAOS_UNUSED(tsdbIterMergerClose(&writer->ctx->tombIterMerger)); TARRAY2_CLEAR(writer->ctx->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(writer->ctx->tombIterArr, tsdbIterClose); return 0; @@ -838,7 +838,7 @@ static int32_t tsdbSnapWriteFileSetBegin(STsdbSnapWriter* writer, int32_t fid) { code = TSDB_CODE_NO_AVAIL_DISK; TSDB_CHECK_CODE(code, lino, _exit); } - tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did); + TAOS_UNUSED(tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did)); writer->ctx->hasData = true; writer->ctx->hasTomb = true; @@ -993,7 +993,7 @@ static int32_t tsdbSnapWriteDecmprTombBlock(SSnapDataHdr* hdr, STombBlock* tombB int32_t code = 0; int32_t lino = 0; - tTombBlockClear(tombBlock); + TAOS_UNUSED(tTombBlockClear(tombBlock)); int64_t size = hdr->size; ASSERT(size % TOMB_RECORD_ELEM_NUM == 0); @@ -1140,15 +1140,15 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** writer, int8_t rollback) { (void)taosThreadMutexUnlock(&writer[0]->tsdb->mutex); } - tsdbIterMergerClose(&writer[0]->ctx->tombIterMerger); - tsdbIterMergerClose(&writer[0]->ctx->dataIterMerger); + TAOS_UNUSED(tsdbIterMergerClose(&writer[0]->ctx->tombIterMerger)); + TAOS_UNUSED(tsdbIterMergerClose(&writer[0]->ctx->dataIterMerger)); TARRAY2_DESTROY(writer[0]->ctx->tombIterArr, tsdbIterClose); TARRAY2_DESTROY(writer[0]->ctx->dataIterArr, tsdbIterClose); TARRAY2_DESTROY(writer[0]->ctx->sttReaderArr, tsdbSttFileReaderClose); - tsdbDataFileReaderClose(&writer[0]->ctx->dataReader); + TAOS_UNUSED(tsdbDataFileReaderClose(&writer[0]->ctx->dataReader)); TARRAY2_DESTROY(writer[0]->fopArr, NULL); - tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr); + TAOS_UNUSED(tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr)); for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); ++i) { tBufferDestroy(writer[0]->buffers + i); diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c index ac6507ac7f..5b69638b36 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c @@ -65,7 +65,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at line %d since %s, sver:0, ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code), ever, type); - tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); + (void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); taosMemoryFree(reader[0]); reader[0] = NULL; } else { @@ -84,7 +84,7 @@ int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) { STsdb* tsdb = reader[0]->tsdb; TARRAY2_DESTROY(reader[0]->dataReaderArr, tsdbDataFileRAWReaderClose); - tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); + (void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); taosMemoryFree(reader[0]); reader[0] = NULL; @@ -141,7 +141,7 @@ static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) { _exit: if (code) { - tsdbSnapRAWReadFileSetCloseReader(reader); + (void)tsdbSnapRAWReadFileSetCloseReader(reader); TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino); } return code; @@ -268,8 +268,8 @@ _exit: } static int32_t tsdbSnapRAWReadEnd(STsdbSnapRAWReader* reader) { - tsdbSnapRAWReadFileSetCloseIter(reader); - tsdbSnapRAWReadFileSetCloseReader(reader); + (void)tsdbSnapRAWReadFileSetCloseIter(reader); + (void)tsdbSnapRAWReadFileSetCloseReader(reader); reader->ctx->fset = NULL; return 0; } @@ -420,7 +420,7 @@ static int32_t tsdbSnapRAWWriteFileSetBegin(STsdbSnapRAWWriter* writer, int32_t int32_t level = tsdbFidLevel(fid, &writer->tsdb->keepCfg, taosGetTimestampSec()); code = tfsAllocDisk(writer->tsdb->pVnode->pTfs, level, &writer->ctx->did); TSDB_CHECK_CODE(code, lino, _exit); - tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did); + (void)tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did); code = tsdbSnapRAWWriteFileSetOpenWriter(writer); TSDB_CHECK_CODE(code, lino, _exit); @@ -499,7 +499,7 @@ int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** writer, int8_t rollback) { } TARRAY2_DESTROY(writer[0]->fopArr, NULL); - tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr); + (void)tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr); taosMemoryFree(writer[0]); writer[0] = NULL; diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index d39adaac41..6e24311017 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -55,7 +55,7 @@ int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *con TAOS_CHECK_GOTO(tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit); } else { char fname1[TSDB_FILENAME_LEN]; - tsdbTFileName(config->tsdb, config->file, fname1); + (void)tsdbTFileName(config->tsdb, config->file, fname1); TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit); } @@ -91,7 +91,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); - tsdbSttFileReaderClose(reader); + (void)tsdbSttFileReaderClose(reader); } return code; } @@ -507,7 +507,7 @@ static int32_t tsdbFileDoWriteSttBlockData(STsdbFD *fd, SBlockData *blockData, S if (sttBlk->maxVer < blockData->aVersion[iRow]) sttBlk->maxVer = blockData->aVersion[iRow]; } - tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer); + (void)tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer); TAOS_CHECK_RETURN(tBlockDataCompress(blockData, info, buffers, buffers + 4)); sttBlk->bInfo.offset = *fileSize; @@ -790,7 +790,7 @@ static int32_t tsdbSttFWriterDoOpen(SSttFileWriter *writer) { int32_t flag = TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; char fname[TSDB_FILENAME_LEN]; - tsdbTFileName(writer->config->tsdb, writer->file, fname); + (void)tsdbTFileName(writer->config->tsdb, writer->file, fname); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, 0), &lino, _exit); uint8_t hdr[TSDB_FHDR_SIZE] = {0}; @@ -860,7 +860,7 @@ static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, TFileOpArray *o .fid = writer->config->fid, .nf = writer->file[0], }; - tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); + (void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArray, op), &lino, _exit); @@ -874,7 +874,7 @@ _exit: static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) { char fname[TSDB_FILENAME_LEN]; - tsdbTFileName(writer->config->tsdb, writer->file, fname); + (void)tsdbTFileName(writer->config->tsdb, writer->file, fname); tsdbCloseFile(&writer->fd); (void)taosRemoveFile(fname); return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c index 6d2006eaa1..9336231420 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c +++ b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c @@ -79,7 +79,7 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader * // open fd char fname[TSDB_FILENAME_LEN]; - tsdbTFileName(tsdb, &file, fname); + (void)tsdbTFileName(tsdb, &file, fname); TAOS_CHECK_GOTO(tsdbOpenFile(fname, tsdb, TD_FILE_READ | TD_FILE_WRITE, &ctx->fd, 0), &lino, _exit); @@ -321,7 +321,7 @@ static int32_t tsdbUpgradeStt(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *r if (TARRAY2_SIZE(lvl->fobjArr) > 0) { TAOS_CHECK_GOTO(TARRAY2_APPEND(fset->lvlArr, lvl), &lino, _exit); } else { - tsdbSttLvlClear(&lvl); + (void)tsdbSttLvlClear(&lvl); } _exit: @@ -358,7 +358,7 @@ static int32_t tsdbUpgradeFileSet(STsdb *tsdb, SDFileSet *pDFileSet, TFileSetArr TAOS_CHECK_GOTO(tsdbUpgradeStt(tsdb, pDFileSet, reader, fset), &lino, _exit); } - tsdbDataFReaderClose(&reader); + (void)tsdbDataFReaderClose(&reader); TAOS_CHECK_GOTO(TARRAY2_APPEND(fileSetArray, fset), &lino, _exit); @@ -570,7 +570,7 @@ _exit: if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - tsdbDelFReaderClose(&reader); + (void)tsdbDelFReaderClose(&reader); taosArrayDestroy(aDelIdx); return code; } @@ -612,7 +612,7 @@ static int32_t tsdbUpgradeFileSystem(STsdb *tsdb, int8_t rollback) { // save new file system char fname[TSDB_FILENAME_LEN]; - current_fname(tsdb, fname, TSDB_FCURRENT); + (void)current_fname(tsdb, fname, TSDB_FCURRENT); TAOS_CHECK_GOTO(save_fs(fileSetArray, fname), &lino, _exit); _exit: diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index a1ca8ccda2..667d7ffb7c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -107,7 +107,7 @@ _exit: void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { ASSERT(idx >= 0 && idx < pMapData->nItem); - tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem); + (void)tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem); } #ifdef BUILD_NO_CALL @@ -613,7 +613,7 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal * SValue value; if (pRow->type == TSDBROW_ROW_FMT) { - tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal); + (void)tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal); } else if (pRow->type == TSDBROW_COL_FMT) { if (iCol == 0) { *pColVal = diff --git a/source/dnode/vnode/src/vnd/vnodeAsync.c b/source/dnode/vnode/src/vnd/vnodeAsync.c index 06786ecca6..2ddd3c9d3e 100644 --- a/source/dnode/vnode/src/vnd/vnodeAsync.c +++ b/source/dnode/vnode/src/vnd/vnodeAsync.c @@ -171,12 +171,12 @@ static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) { async->numTasks--; if (task->numWait == 0) { - taosThreadCondDestroy(&task->waitCond); + (void)taosThreadCondDestroy(&task->waitCond); taosMemoryFree(task); } else if (task->numWait == 1) { - taosThreadCondSignal(&task->waitCond); + (void)taosThreadCondSignal(&task->waitCond); } else { - taosThreadCondBroadcast(&task->waitCond); + (void)taosThreadCondBroadcast(&task->waitCond); } return 0; } @@ -195,7 +195,7 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { .arg = task->arg, })); } - vnodeAsyncTaskDone(async, task); + (void)vnodeAsyncTaskDone(async, task); } } } @@ -217,14 +217,14 @@ static void *vnodeAsyncLoop(void *arg) { // finish last running task if (worker->runningTask != NULL) { - vnodeAsyncTaskDone(async, worker->runningTask); + (void)vnodeAsyncTaskDone(async, worker->runningTask); worker->runningTask = NULL; } for (;;) { if (async->stop || worker->workerId >= async->numWorkers) { if (async->stop) { // cancel all tasks - vnodeAsyncCancelAllTasks(async, cancelArray); + (void)vnodeAsyncCancelAllTasks(async, cancelArray); } worker->state = EVA_WORKER_STATE_STOP; async->numLaunchWorkers--; @@ -259,7 +259,7 @@ static void *vnodeAsyncLoop(void *arg) { if (worker->runningTask == NULL) { worker->state = EVA_WORKER_STATE_IDLE; async->numIdleWorkers++; - taosThreadCondWait(&async->hasTask, &async->mutex); + (void)taosThreadCondWait(&async->hasTask, &async->mutex); async->numIdleWorkers--; worker->state = EVA_WORKER_STATE_ACTIVE; } else { @@ -271,7 +271,7 @@ static void *vnodeAsyncLoop(void *arg) { (void)taosThreadMutexUnlock(&async->mutex); // do run the task - worker->runningTask->execute(worker->runningTask->arg); + (void)worker->runningTask->execute(worker->runningTask->arg); } _exit: @@ -334,8 +334,8 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) { strcpy((char *)((*async) + 1), label); (*async)->label = (const char *)((*async) + 1); - taosThreadMutexInit(&(*async)->mutex, NULL); - taosThreadCondInit(&(*async)->hasTask, NULL); + (void)taosThreadMutexInit(&(*async)->mutex, NULL); + (void)taosThreadCondInit(&(*async)->hasTask, NULL); (*async)->stop = false; // worker @@ -356,8 +356,8 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) { (*async)->chList.next = &(*async)->chList; ret = vHashInit(&(*async)->channelTable, vnodeAsyncChannelHash, vnodeAsyncChannelCompare); if (ret != 0) { - taosThreadMutexDestroy(&(*async)->mutex); - taosThreadCondDestroy(&(*async)->hasTask); + (void)taosThreadMutexDestroy(&(*async)->mutex); + (void)taosThreadCondDestroy(&(*async)->hasTask); taosMemoryFree(*async); return ret; } @@ -371,9 +371,9 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) { } ret = vHashInit(&(*async)->taskTable, vnodeAsyncTaskHash, vnodeAsyncTaskCompare); if (ret != 0) { - vHashDestroy(&(*async)->channelTable); - taosThreadMutexDestroy(&(*async)->mutex); - taosThreadCondDestroy(&(*async)->hasTask); + (void)vHashDestroy(&(*async)->channelTable); + (void)taosThreadMutexDestroy(&(*async)->mutex); + (void)taosThreadCondDestroy(&(*async)->hasTask); taosMemoryFree(*async); return ret; } @@ -389,7 +389,7 @@ static int32_t vnodeAsyncDestroy(SVAsync **async) { // set stop and broadcast (void)taosThreadMutexLock(&(*async)->mutex); (*async)->stop = true; - taosThreadCondBroadcast(&(*async)->hasTask); + (void)taosThreadCondBroadcast(&(*async)->hasTask); (void)taosThreadMutexUnlock(&(*async)->mutex); // join all workers @@ -402,7 +402,7 @@ static int32_t vnodeAsyncDestroy(SVAsync **async) { continue; } - taosThreadJoin((*async)->workers[i].thread, NULL); + (void)taosThreadJoin((*async)->workers[i].thread, NULL); ASSERT((*async)->workers[i].state == EVA_WORKER_STATE_STOP); (*async)->workers[i].state = EVA_WORKER_STATE_UINIT; } @@ -425,11 +425,11 @@ static int32_t vnodeAsyncDestroy(SVAsync **async) { ASSERT((*async)->numChannels == 0); ASSERT((*async)->numTasks == 0); - taosThreadMutexDestroy(&(*async)->mutex); - taosThreadCondDestroy(&(*async)->hasTask); + (void)taosThreadMutexDestroy(&(*async)->mutex); + (void)taosThreadCondDestroy(&(*async)->hasTask); - vHashDestroy(&(*async)->channelTable); - vHashDestroy(&(*async)->taskTable); + (void)vHashDestroy(&(*async)->channelTable); + (void)vHashDestroy(&(*async)->taskTable); taosMemoryFree(*async); *async = NULL; @@ -442,11 +442,11 @@ static int32_t vnodeAsyncLaunchWorker(SVAsync *async) { if (async->workers[i].state == EVA_WORKER_STATE_ACTIVE) { continue; } else if (async->workers[i].state == EVA_WORKER_STATE_STOP) { - taosThreadJoin(async->workers[i].thread, NULL); + (void)taosThreadJoin(async->workers[i].thread, NULL); async->workers[i].state = EVA_WORKER_STATE_UINIT; } - taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]); + (void)taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]); async->workers[i].state = EVA_WORKER_STATE_ACTIVE; async->numLaunchWorkers++; break; @@ -461,20 +461,20 @@ int32_t vnodeAsyncOpen(int32_t numOfThreads) { // vnode-commit code = vnodeAsyncInit(&vnodeAsyncs[1], "vnode-commit"); TSDB_CHECK_CODE(code, lino, _exit); - vnodeAsyncSetWorkers(1, numOfThreads); + (void)vnodeAsyncSetWorkers(1, numOfThreads); // vnode-merge code = vnodeAsyncInit(&vnodeAsyncs[2], "vnode-merge"); TSDB_CHECK_CODE(code, lino, _exit); - vnodeAsyncSetWorkers(2, numOfThreads); + (void)vnodeAsyncSetWorkers(2, numOfThreads); _exit: return code; } int32_t vnodeAsyncClose() { - vnodeAsyncDestroy(&vnodeAsyncs[1]); - vnodeAsyncDestroy(&vnodeAsyncs[2]); + (void)vnodeAsyncDestroy(&vnodeAsyncs[1]); + (void)vnodeAsyncDestroy(&vnodeAsyncs[2]); return 0; } @@ -501,7 +501,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec task->arg = arg; task->state = EVA_TASK_STATE_WAITTING; task->numWait = 0; - taosThreadCondInit(&task->waitCond, NULL); + (void)taosThreadCondInit(&task->waitCond, NULL); // schedule task (void)taosThreadMutexLock(&async->mutex); @@ -512,10 +512,10 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec SVAChannel channel = { .channelId = channelID->id, }; - vHashGet(async->channelTable, &channel, (void **)&task->channel); + (void)vHashGet(async->channelTable, &channel, (void **)&task->channel); if (task->channel == NULL) { (void)taosThreadMutexUnlock(&async->mutex); - taosThreadCondDestroy(&task->waitCond); + (void)taosThreadCondDestroy(&task->waitCond); taosMemoryFree(task); return TSDB_CODE_INVALID_PARA; } @@ -527,7 +527,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec int32_t ret = vHashPut(async->taskTable, task); if (ret != 0) { (void)taosThreadMutexUnlock(&async->mutex); - taosThreadCondDestroy(&task->waitCond); + (void)taosThreadCondDestroy(&task->waitCond); taosMemoryFree(task); return ret; } @@ -548,9 +548,9 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec // signal worker or launch new worker if (async->numIdleWorkers > 0) { - taosThreadCondSignal(&(async->hasTask)); + (void)taosThreadCondSignal(&(async->hasTask)); } else if (async->numLaunchWorkers < async->numWorkers) { - vnodeAsyncLaunchWorker(async); + (void)vnodeAsyncLaunchWorker(async); } } else if (task->channel->scheduled->state == EVA_TASK_STATE_RUNNING || priority >= VATASK_PIORITY(task->channel->scheduled)) { @@ -603,14 +603,14 @@ int32_t vnodeAWait(SVATaskID *taskID) { (void)taosThreadMutexLock(&async->mutex); - vHashGet(async->taskTable, &task2, (void **)&task); + (void)vHashGet(async->taskTable, &task2, (void **)&task); if (task) { task->numWait++; - taosThreadCondWait(&task->waitCond, &async->mutex); + (void)taosThreadCondWait(&task->waitCond, &async->mutex); task->numWait--; if (task->numWait == 0) { - taosThreadCondDestroy(&task->waitCond); + (void)taosThreadCondDestroy(&task->waitCond); taosMemoryFree(task); } } @@ -636,14 +636,14 @@ int32_t vnodeACancel(SVATaskID *taskID) { (void)taosThreadMutexLock(&async->mutex); - vHashGet(async->taskTable, &task2, (void **)&task); + (void)vHashGet(async->taskTable, &task2, (void **)&task); if (task) { if (task->state == EVA_TASK_STATE_WAITTING) { cancel = task->cancel; arg = task->arg; task->next->prev = task->prev; task->prev->next = task->next; - vnodeAsyncTaskDone(async, task); + (void)vnodeAsyncTaskDone(async, task); } else { ret = TSDB_CODE_FAILED; } @@ -666,7 +666,7 @@ int32_t vnodeAsyncSetWorkers(int64_t asyncID, int32_t numWorkers) { (void)taosThreadMutexLock(&async->mutex); async->numWorkers = numWorkers; if (async->numIdleWorkers > 0) { - taosThreadCondBroadcast(&async->hasTask); + (void)taosThreadCondBroadcast(&async->hasTask); } (void)taosThreadMutexUnlock(&async->mutex); @@ -736,12 +736,12 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { (void)taosThreadMutexLock(&async->mutex); - vHashGet(async->channelTable, &channel2, (void **)&channel); + (void)vHashGet(async->channelTable, &channel2, (void **)&channel); if (channel) { // unregister channel channel->next->prev = channel->prev; channel->prev->next = channel->next; - vHashDrop(async->channelTable, channel); + (void)vHashDrop(async->channelTable, channel); async->numChannels--; // cancel all waiting tasks @@ -756,7 +756,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { .arg = task->arg, })); } - vnodeAsyncTaskDone(async, task); + (void)vnodeAsyncTaskDone(async, task); } } @@ -771,7 +771,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { .arg = channel->scheduled->arg, })); } - vnodeAsyncTaskDone(async, channel->scheduled); + (void)vnodeAsyncTaskDone(async, channel->scheduled); } taosMemoryFree(channel); } else { @@ -779,10 +779,10 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { // wait task SVATask *task = channel->scheduled; task->numWait++; - taosThreadCondWait(&task->waitCond, &async->mutex); + (void)taosThreadCondWait(&task->waitCond, &async->mutex); task->numWait--; if (task->numWait == 0) { - taosThreadCondDestroy(&task->waitCond); + (void)taosThreadCondDestroy(&task->waitCond); taosMemoryFree(task); } diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c index f9f539b6d3..cbd6fbbe52 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c @@ -26,7 +26,7 @@ static int32_t vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBu memset(pPool, 0, sizeof(SVBufPool)); // query handle list - taosThreadMutexInit(&pPool->mutex, NULL); + (void)taosThreadMutexInit(&pPool->mutex, NULL); pPool->nQuery = 0; pPool->qList.pNext = &pPool->qList; pPool->qList.ppNext = &pPool->qList.pNext; @@ -61,10 +61,10 @@ static int32_t vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBu static int vnodeBufPoolDestroy(SVBufPool *pPool) { vnodeBufPoolReset(pPool); if (pPool->lock) { - taosThreadSpinDestroy(pPool->lock); + (void)taosThreadSpinDestroy(pPool->lock); taosMemoryFree((void *)pPool->lock); } - taosThreadMutexDestroy(&pPool->mutex); + (void)taosThreadMutexDestroy(&pPool->mutex); taosMemoryFree(pPool); return 0; } @@ -77,7 +77,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { int32_t code; if ((code = vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i]))) { vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); - vnodeCloseBufPool(pVnode); + (void)vnodeCloseBufPool(pVnode); return code; } @@ -93,7 +93,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { int vnodeCloseBufPool(SVnode *pVnode) { for (int32_t i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) { if (pVnode->aBufPool[i]) { - vnodeBufPoolDestroy(pVnode->aBufPool[i]); + (void)vnodeBufPoolDestroy(pVnode->aBufPool[i]); pVnode->aBufPool[i] = NULL; } } @@ -141,7 +141,7 @@ void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) { pNode = taosMemoryMalloc(sizeof(*pNode) + size); if (pNode == NULL) { if (pPool->lock) { - taosThreadSpinUnlock(pPool->lock); + (void)taosThreadSpinUnlock(pPool->lock); } return NULL; } @@ -155,7 +155,7 @@ void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) { pPool->size = pPool->size + sizeof(*pNode) + size; } - if (pPool->lock) taosThreadSpinUnlock(pPool->lock); + if (pPool->lock) (void)taosThreadSpinUnlock(pPool->lock); return p; } @@ -174,7 +174,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { // allocate a new node pNode = taosMemoryMalloc(sizeof(*pNode) + size); if (pNode == NULL) { - if (pPool->lock) taosThreadSpinUnlock(pPool->lock); + if (pPool->lock) (void)taosThreadSpinUnlock(pPool->lock); return NULL; } @@ -187,7 +187,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { pPool->size = pPool->size + sizeof(*pNode) + size; } - if (pPool->lock) taosThreadSpinUnlock(pPool->lock); + if (pPool->lock) (void)taosThreadSpinUnlock(pPool->lock); return p; } @@ -223,7 +223,7 @@ void vnodeBufPoolAddToFreeList(SVBufPool *pPool) { vInfo("vgId:%d, buffer pool of id %d size changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->id, pPool->node.size, size); - vnodeBufPoolDestroy(pPool); + (void)vnodeBufPoolDestroy(pPool); pPool = pNewPool; pVnode->aBufPool[pPool->id] = pPool; } @@ -234,7 +234,7 @@ void vnodeBufPoolAddToFreeList(SVBufPool *pPool) { vnodeBufPoolReset(pPool); pPool->freeNext = pVnode->freeList; pVnode->freeList = pPool; - taosThreadCondSignal(&pVnode->poolNotEmpty); + (void)taosThreadCondSignal(&pVnode->poolNotEmpty); } void vnodeBufPoolUnRef(SVBufPool *pPool, bool proactive) { diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 12e4fe7753..e2db87173d 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -127,7 +127,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (pNodeRetentions == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - tjsonAddItemToObject(pJson, "retentions", pNodeRetentions); + TAOS_CHECK_RETURN(tjsonAddItemToObject(pJson, "retentions", pNodeRetentions)); for (int32_t i = 0; i < nRetention; ++i) { SJson *pNodeRetention = tjsonCreateObject(); const SRetention *pRetention = pCfg->tsdbCfg.retentions + i; @@ -353,7 +353,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (info == NULL) return -1; tjsonGetNumberValue(info, "nodePort", pNode->nodePort, code); if (code) return code; - tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn); + (void)tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn); tjsonGetNumberValue(info, "nodeId", pNode->nodeId, code); if (code) return code; tjsonGetNumberValue(info, "clusterId", pNode->clusterId, code); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index db6b29d427..cfaf155276 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -91,7 +91,7 @@ static int32_t vnodeGetBufPoolToUse(SVnode *pVnode) { struct timeval tv; struct timespec ts; - taosGetTimeOfDay(&tv); + (void)taosGetTimeOfDay(&tv); ts.tv_nsec = tv.tv_usec * 1000 + WAIT_TIME_MILI_SEC * 1000000; if (ts.tv_nsec > 999999999l) { ts.tv_sec = tv.tv_sec + 1; @@ -199,7 +199,7 @@ _exit: vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d selfIndex:%d changeVersion:%d", pInfo->config.vgId, fname, pInfo->config.syncCfg.replicaNum, pInfo->config.syncCfg.myIndex, pInfo->config.syncCfg.changeVersion); } - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); taosMemoryFree(data); return code; } @@ -256,10 +256,12 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { _exit: if (code) { - vError("vgId:%d %s failed at %s:%d since %s", pInfo->config.vgId, __func__, __FILE__, lino, tstrerror(code)); + if (pFile) { + vError("vgId:%d %s failed at %s:%d since %s", pInfo->config.vgId, __func__, __FILE__, lino, tstrerror(code)); + } } taosMemoryFree(pData); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return code; } @@ -270,7 +272,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { int64_t lastCommitted = pInfo->info.state.committed; // wait last commit task - vnodeAWait(&pVnode->commitTask); + (void)vnodeAWait(&pVnode->commitTask); code = syncNodeGetConfig(pVnode->sync, &pVnode->config.syncCfg); TSDB_CHECK_CODE(code, lino, _exit); @@ -285,13 +287,13 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { pInfo->txn = metaGetTxn(pVnode->pMeta); // save info - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); vDebug("vgId:%d, save config while prepare commit", TD_VID(pVnode)); code = vnodeSaveInfo(dir, &pInfo->info); TSDB_CHECK_CODE(code, lino, _exit); - tsdbPreCommit(pVnode->pTsdb); + (void)tsdbPreCommit(pVnode->pTsdb); code = metaPrepareAsyncCommit(pVnode->pMeta); TSDB_CHECK_CODE(code, lino, _exit); @@ -395,8 +397,8 @@ _exit: } int vnodeSyncCommit(SVnode *pVnode) { - vnodeAsyncCommit(pVnode); - vnodeAWait(&pVnode->commitTask); + (void)vnodeAsyncCommit(pVnode); + (void)vnodeAWait(&pVnode->commitTask); return 0; } @@ -416,9 +418,9 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { return -1; } - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); - syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); + (void)syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); code = tsdbCommitBegin(pVnode->pTsdb, pInfo); TSDB_CHECK_CODE(code, lino, _exit); @@ -455,7 +457,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { return -1; } - syncEndSnapshot(pVnode->sync); + (void)syncEndSnapshot(pVnode->sync); _exit: if (code) { @@ -470,7 +472,7 @@ bool vnodeShouldRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; int32_t offset = 0; - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); offset = strlen(tFName); snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); @@ -481,7 +483,7 @@ void vnodeRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; int32_t offset = 0; - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); offset = strlen(tFName); snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); diff --git a/source/dnode/vnode/src/vnd/vnodeHash.c b/source/dnode/vnode/src/vnd/vnodeHash.c index 093b5056ed..00fc2dfc00 100644 --- a/source/dnode/vnode/src/vnd/vnodeHash.c +++ b/source/dnode/vnode/src/vnd/vnodeHash.c @@ -98,7 +98,7 @@ int32_t vHashPut(SVHashTable* ht, void* obj) { } if (ht->numEntries >= ht->numBuckets) { - vHashRehash(ht, ht->numBuckets * 2); + (void)vHashRehash(ht, ht->numBuckets * 2); bucketIndex = ht->hash(obj) % ht->numBuckets; } @@ -144,7 +144,7 @@ int32_t vHashDrop(SVHashTable* ht, const void* obj) { taosMemoryFree(tmp); ht->numEntries--; if (ht->numBuckets > VNODE_HASH_DEFAULT_NUM_BUCKETS && ht->numEntries < ht->numBuckets / 4) { - vHashRehash(ht, ht->numBuckets / 2); + (void)vHashRehash(ht, ht->numBuckets / 2); } return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c index 228cc9e0b2..8b7de7058c 100644 --- a/source/dnode/vnode/src/vnd/vnodeModule.c +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -31,7 +31,7 @@ int vnodeInit(int nthreads) { void vnodeCleanup() { if (atomic_val_compare_exchange_32(&VINIT, 1, 0) == 0) return; - vnodeAsyncClose(); + (void)vnodeAsyncClose(); walCleanUp(); smaCleanUp(); } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index fb835fd0c2..8a2b10d2ef 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -53,7 +53,7 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs vError("vgId:%d, failed to prepare vnode dir since %s, path: %s", pCfg->vgId, strerror(errno), path); return TAOS_SYSTEM_ERROR(errno); } - vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); if (pCfg) { info.config = *pCfg; @@ -88,7 +88,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t char dir[TSDB_FILENAME_LEN] = {0}; int32_t ret = 0; - vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); ret = vnodeLoadInfo(dir, &info); if (ret < 0) { @@ -221,7 +221,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod char dir[TSDB_FILENAME_LEN] = {0}; int32_t ret = 0; - vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); ret = vnodeLoadInfo(dir, &info); if (ret < 0) { @@ -283,7 +283,7 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s char dir[TSDB_FILENAME_LEN] = {0}; int32_t code = 0; - vnodeGetPrimaryDir(dstPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(dstPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &info) == 0) { if (info.config.vgId != dstVgId) { vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId); @@ -292,7 +292,7 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s return dstVgId; } - vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &info) < 0) { vError("vgId:%d, failed to read vnode config from %s since %s", srcVgId, srcPath, tstrerror(terrno)); return -1; @@ -317,7 +317,7 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s void vnodeDestroy(int32_t vgId, const char *path, STfs *pTfs, int32_t nodeId) { vInfo("path:%s is removed while destroy vnode", path); - tfsRmdir(pTfs, path); + (void)tfsRmdir(pTfs, path); // int32_t nlevel = tfsGetLevel(pTfs); if (nodeId > 0 && vgId > 0 /*&& nlevel > 1*/ && tsS3Enabled) { @@ -351,7 +351,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC vError("failed to open vnode from %s since %s. diskPrimary:%d", path, terrstr(), diskPrimary); return NULL; } - vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN); info.config = vnodeCfgDefault; @@ -401,12 +401,12 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC pVnode->pTfs = pTfs; pVnode->diskPrimary = diskPrimary; pVnode->msgCb = msgCb; - taosThreadMutexInit(&pVnode->lock, NULL); + (void)taosThreadMutexInit(&pVnode->lock, NULL); pVnode->blocked = false; - tsem_init(&pVnode->syncSem, 0, 0); - taosThreadMutexInit(&pVnode->mutex, NULL); - taosThreadCondInit(&pVnode->poolNotEmpty, NULL); + (void)tsem_init(&pVnode->syncSem, 0, 0); + (void)taosThreadMutexInit(&pVnode->mutex, NULL); + (void)taosThreadCondInit(&pVnode->poolNotEmpty, NULL); if (vnodeAChannelInit(1, &pVnode->commitChannel) != 0) { vError("vgId:%d, failed to init commit channel", TD_VID(pVnode)); @@ -439,7 +439,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC // open wal sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR); - taosRealPath(tdir, NULL, sizeof(tdir)); + (void)taosRealPath(tdir, NULL, sizeof(tdir)); pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg)); if (pVnode->pWal == NULL) { @@ -449,7 +449,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC // open tq sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR); - taosRealPath(tdir, NULL, sizeof(tdir)); + (void)taosRealPath(tdir, NULL, sizeof(tdir)); // open query if (vnodeQueryOpen(pVnode)) { @@ -502,7 +502,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", label_count, sample_labels); vInfo("vgId:%d, new metric:%p", TD_VID(pVnode), counter); if (taos_collector_registry_register_metric(counter) == 1) { - taos_counter_destroy(counter); + (void)taos_counter_destroy(counter); counter = taos_collector_registry_get_metric(VNODE_METRIC_SQL_COUNT); vInfo("vgId:%d, get metric from registry:%p", TD_VID(pVnode), counter); } @@ -516,10 +516,10 @@ _err: if (pVnode->pQuery) vnodeQueryClose(pVnode); if (pVnode->pTq) tqClose(pVnode->pTq); if (pVnode->pWal) walClose(pVnode->pWal); - if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb); - if (pVnode->pSma) smaClose(pVnode->pSma); - if (pVnode->pMeta) metaClose(&pVnode->pMeta); - if (pVnode->freeList) vnodeCloseBufPool(pVnode); + if (pVnode->pTsdb) (void)tsdbClose(&pVnode->pTsdb); + if (pVnode->pSma) (void)smaClose(pVnode->pSma); + if (pVnode->pMeta) (void)metaClose(&pVnode->pMeta); + if (pVnode->freeList) (void)vnodeCloseBufPool(pVnode); taosMemoryFree(pVnode); return NULL; @@ -534,22 +534,22 @@ void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); } void vnodeClose(SVnode *pVnode) { if (pVnode) { - vnodeAWait(&pVnode->commitTask); - vnodeAChannelDestroy(&pVnode->commitChannel, true); + (void)vnodeAWait(&pVnode->commitTask); + (void)vnodeAChannelDestroy(&pVnode->commitChannel, true); vnodeSyncClose(pVnode); vnodeQueryClose(pVnode); tqClose(pVnode->pTq); walClose(pVnode->pWal); if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb); - smaClose(pVnode->pSma); + (void)smaClose(pVnode->pSma); if (pVnode->pMeta) metaClose(&pVnode->pMeta); - vnodeCloseBufPool(pVnode); + (void)vnodeCloseBufPool(pVnode); // destroy handle - tsem_destroy(&pVnode->syncSem); - taosThreadCondDestroy(&pVnode->poolNotEmpty); - taosThreadMutexDestroy(&pVnode->mutex); - taosThreadMutexDestroy(&pVnode->lock); + (void)tsem_destroy(&pVnode->syncSem); + (void)taosThreadCondDestroy(&pVnode->poolNotEmpty); + (void)taosThreadMutexDestroy(&pVnode->mutex); + (void)taosThreadMutexDestroy(&pVnode->lock); taosMemoryFree(pVnode); } } diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index f30b2f2ada..92e2ffeb7f 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -209,7 +209,7 @@ static void vnodeSnapReaderDestroyTsdbRanges(SVSnapReader *pReader) { for (int32_t j = 0; j < TSDB_RETENTION_MAX; ++j) { TFileSetRangeArray **ppRanges = vnodeSnapReaderGetTsdbRanges(pReader, tsdbTyps[j]); if (ppRanges == NULL) continue; - tsdbTFileSetRangeArrayDestroy(ppRanges); + (void)tsdbTFileSetRangeArrayDestroy(ppRanges); } } @@ -218,15 +218,15 @@ void vnodeSnapReaderClose(SVSnapReader *pReader) { vnodeSnapReaderDestroyTsdbRanges(pReader); if (pReader->pRsmaReader) { - rsmaSnapReaderClose(&pReader->pRsmaReader); + (void)rsmaSnapReaderClose(&pReader->pRsmaReader); } if (pReader->pTsdbReader) { - tsdbSnapReaderClose(&pReader->pTsdbReader); + (void)tsdbSnapReaderClose(&pReader->pTsdbReader); } if (pReader->pTsdbRAWReader) { - tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader); + (void)tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader); } if (pReader->pMetaReader) { @@ -260,7 +260,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) char fName[TSDB_FILENAME_LEN]; int32_t offset = 0; - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, fName, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, fName, TSDB_FILENAME_LEN); offset = strlen(fName); snprintf(fName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME); @@ -272,13 +272,13 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) int64_t size; if (taosFStatFile(pFile, &size, NULL) < 0) { - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } *ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1); if (*ppData == NULL) { - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); } ((SSnapDataHdr *)(*ppData))->type = SNAP_DATA_CFG; @@ -287,11 +287,11 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) { taosMemoryFree(*ppData); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); pReader->cfgDone = 1; goto _exit; @@ -590,15 +590,15 @@ extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb); extern int32_t tsdbEnableBgTask(STsdb *pTsdb); static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) { - tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); - vnodeSyncCommit(pVnode); - vnodeAChannelDestroy(&pVnode->commitChannel, true); + (void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); + (void)vnodeSyncCommit(pVnode); + (void)vnodeAChannelDestroy(&pVnode->commitChannel, true); return 0; } static int32_t vnodeEnableBgTask(SVnode *pVnode) { - tsdbEnableBgTask(pVnode->pTsdb); - vnodeAChannelInit(1, &pVnode->commitChannel); + (void)tsdbEnableBgTask(pVnode->pTsdb); + (void)vnodeAChannelInit(1, &pVnode->commitChannel); return 0; } @@ -610,7 +610,7 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, SSnapshotParam *pParam, SVSnapWriter int64_t ever = pParam->end; // cancel and disable all bg task - vnodeCancelAndDisableAllBgTask(pVnode); + (void)vnodeCancelAndDisableAllBgTask(pVnode); // alloc pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter)); @@ -646,7 +646,7 @@ static void vnodeSnapWriterDestroyTsdbRanges(SVSnapWriter *pWriter) { for (int32_t j = 0; j < TSDB_RETENTION_MAX; ++j) { TFileSetRangeArray **ppRanges = vnodeSnapWriterGetTsdbRanges(pWriter, tsdbTyps[j]); if (ppRanges == NULL) continue; - tsdbTFileSetRangeArrayDestroy(ppRanges); + (void)tsdbTFileSetRangeArrayDestroy(ppRanges); } } @@ -658,15 +658,15 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot * // prepare if (pWriter->pTsdbSnapWriter) { - tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter); + (void)tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter); } if (pWriter->pTsdbSnapRAWWriter) { - tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter); + (void)tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter); } if (pWriter->pRsmaSnapWriter) { - rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter); + (void)rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter); } // commit json @@ -681,7 +681,7 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot * .applyTerm = pWriter->info.state.commitTerm}; pVnode->statis = pWriter->info.statis; char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); code = vnodeCommitInfo(dir); if (code) goto _exit; @@ -740,7 +740,7 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot * if (code) goto _exit; } - vnodeBegin(pVnode); + (void)vnodeBegin(pVnode); _exit: if (code) { @@ -749,7 +749,7 @@ _exit: vInfo("vgId:%d, vnode snapshot writer closed, rollback:%d", TD_VID(pVnode), rollback); taosMemoryFree(pWriter); } - vnodeEnableBgTask(pVnode); + (void)vnodeEnableBgTask(pVnode); return code; } @@ -768,7 +768,7 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_ // modify info as needed char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + (void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, dir, TSDB_FILENAME_LEN); SVnodeStats vndStats = pWriter->info.config.vndStats; pWriter->info.config = pVnode->config; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index f154b72465..62eaddad1b 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -207,7 +207,7 @@ static int32_t vnodePreProcessDropTtlMsg(SVnode *pVnode, SRpcMsg *pMsg) { TSDB_CHECK_CODE(code, lino, _exit); } - tSerializeSVDropTtlTableReq((char *)pContNew + sizeof(SMsgHead), reqLenNew, &ttlReq); + (void)tSerializeSVDropTtlTableReq((char *)pContNew + sizeof(SMsgHead), reqLenNew, &ttlReq); pContNew->contLen = htonl(reqLenNew); pContNew->vgId = pContOld->vgId; @@ -422,7 +422,7 @@ static int32_t vnodePreProcessDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) { ((SMsgHead *)pCont)->vgId = TD_VID(pVnode); tEncoderInit(pCoder, pCont + sizeof(SMsgHead), size); - tEncodeDeleteRes(pCoder, &res); + (void)tEncodeDeleteRes(pCoder, &res); tEncoderClear(pCoder); rpcFreeCont(pMsg->pCont); @@ -632,7 +632,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg } break; case TDMT_STREAM_CONSEN_CHKPT: { if (pVnode->restored) { - tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg); + (void)tqProcessTaskConsenChkptIdReq(pVnode->pTq, pMsg); } } break; case TDMT_STREAM_TASK_PAUSE: { @@ -649,7 +649,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg } break; case TDMT_VND_STREAM_TASK_RESET: { if (pVnode->restored && vnodeIsLeader(pVnode)) { - tqProcessTaskResetReq(pVnode->pTq, pMsg); + (void)tqProcessTaskResetReq(pVnode->pTq, pMsg); } } break; case TDMT_VND_ALTER_CONFIRM: @@ -699,7 +699,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code, ver); - walApplyVer(pVnode->pWal, ver); + (void)walApplyVer(pVnode->pWal, ver); code = tqPushMsg(pVnode->pTq, pMsg->msgType); if (code) { @@ -871,7 +871,7 @@ int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) } void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { - tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data); + (void)tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data); } void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) { @@ -942,7 +942,7 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int ret = 0; if (ttlReq.nUids > 0) { metaDropTables(pVnode->pMeta, ttlReq.pTbUids); - tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false); + (void)tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false); } end: @@ -1142,7 +1142,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } } else { cRsp.code = TSDB_CODE_SUCCESS; - tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid); + (void)tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid); if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; rcode = -1; @@ -1159,11 +1159,11 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids)); - tqUpdateTbUidList(pVnode->pTq, tbUids, true); + (void)tqUpdateTbUidList(pVnode->pTq, tbUids, true); if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) { goto _exit; } - tdUidStoreFree(pStore); + (void)tdUidStoreFree(pStore); // prepare rsp int32_t ret = 0; @@ -1175,13 +1175,13 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, goto _exit; } tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen); - tEncodeSVCreateTbBatchRsp(&encoder, &rsp); + (void)tEncodeSVCreateTbBatchRsp(&encoder, &rsp); if (tsEnableAudit && tsEnableAuditCreateTable) { int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId; SName name = {0}; - tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB); + (void)tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB); SStringBuilder sb = {0}; for (int32_t i = 0; i < tbNames->size; i++) { @@ -1329,7 +1329,7 @@ _exit: tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); - tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp); + (void)tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp); tEncoderClear(&ec); if (vMetaRsp.pSchemas) { taosMemoryFree(vMetaRsp.pSchemas); @@ -1384,7 +1384,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in } } else { dropTbRsp.code = TSDB_CODE_SUCCESS; - if (tbUid > 0) tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid); + if (tbUid > 0) (void)tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid); } if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) { @@ -1404,14 +1404,14 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in } } - tqUpdateTbUidList(pVnode->pTq, tbUids, false); - tdUpdateTbUidList(pVnode->pSma, pStore, false); + (void)tqUpdateTbUidList(pVnode->pTq, tbUids, false); + (void)tdUpdateTbUidList(pVnode->pSma, pStore, false); if (tsEnableAuditCreateTable) { int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId; SName name = {0}; - tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB); + (void)tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB); SStringBuilder sb = {0}; for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { @@ -1435,12 +1435,12 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in _exit: taosArrayDestroy(tbUids); - tdUidStoreFree(pStore); + (void)tdUidStoreFree(pStore); tDecoderClear(&decoder); tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen); - tEncodeSVDropTbBatchRsp(&encoder, &rsp); + (void)tEncodeSVDropTbBatchRsp(&encoder, &rsp); tEncoderClear(&encoder); taosArrayDestroy(rsp.pArray); taosArrayDestroy(tbNames); @@ -1876,7 +1876,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in if (taosArrayGetSize(newTbUids) > 0) { vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode), (int32_t)taosArrayGetSize(newTbUids)); - tqUpdateTbUidList(pVnode->pTq, newTbUids, true); + (void)tqUpdateTbUidList(pVnode->pTq, newTbUids, true); } _exit: @@ -1885,13 +1885,13 @@ _exit: tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); - tEncodeSSubmitRsp2(&ec, pSubmitRsp); + (void)tEncodeSSubmitRsp2(&ec, pSubmitRsp); tEncoderClear(&ec); // update statistics - atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows); - atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows); - atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1); + (void)atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows); + (void)atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows); + (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1); if (tsEnableMonitor && pSubmitRsp->affectedRows > 0 && strlen(pOriginalMsg->info.conn.user) > 0) { const char *sample_labels[] = {VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS, @@ -1901,11 +1901,11 @@ _exit: pVnode->monitor.strVgId, pOriginalMsg->info.conn.user, "Success"}; - taos_counter_add(pVnode->monitor.insertCounter, pSubmitRsp->affectedRows, sample_labels); + (void)taos_counter_add(pVnode->monitor.insertCounter, pSubmitRsp->affectedRows, sample_labels); } if (code == 0) { - atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1); + (void)atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1); code = tdProcessRSmaSubmit(pVnode->pSma, ver, pSubmitReq, pReq, len); } /* @@ -2125,10 +2125,10 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe if (req.sttTrigger > 1 && pVnode->config.sttTrigger > 1) { pVnode->config.sttTrigger = req.sttTrigger; } else { - vnodeAWait(&pVnode->commitTask); - tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); + (void)vnodeAWait(&pVnode->commitTask); + (void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); pVnode->config.sttTrigger = req.sttTrigger; - tsdbEnableBgTask(pVnode->pTsdb); + (void)tsdbEnableBgTask(pVnode->pTsdb); } } @@ -2144,11 +2144,11 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe } if (walChanged) { - walAlter(pVnode->pWal, &pVnode->config.walCfg); + (void)walAlter(pVnode->pWal, &pVnode->config.walCfg); } if (tsdbChanged) { - tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg); + (void)tsdbSetKeepCfg(pVnode->pTsdb, &pVnode->config.tsdbCfg); } return 0; @@ -2158,7 +2158,7 @@ static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pRe SBatchDeleteReq deleteReq; SDecoder decoder; tDecoderInit(&decoder, pReq, len); - tDecodeSBatchDeleteReq(&decoder, &deleteReq); + (void)tDecodeSBatchDeleteReq(&decoder, &deleteReq); SMetaReader mr = {0}; metaReaderDoInit(&mr, pVnode->pMeta, META_READER_NOLOCK); @@ -2220,7 +2220,8 @@ static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, in } tDecoderInit(pCoder, pReq, len); - tDecodeDeleteRes(pCoder, pRes); + code = tDecodeDeleteRes(pCoder, pRes); + if (code) goto _err; if (pRes->affectedRows > 0) { for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) { @@ -2243,7 +2244,8 @@ static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, in pRsp->pCont = rpcMallocCont(pRsp->contLen); SEncoder ec = {0}; tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); - tEncodeSVDeleteRsp(&ec, &rsp); + code = tEncodeSVDeleteRsp(&ec, &rsp); + if (code) goto _err; tEncoderClear(&ec); return code; @@ -2325,7 +2327,7 @@ static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pR } static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { - syncCheckMember(pVnode->sync); + (void)syncCheckMember(pVnode->sync); pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP; pRsp->code = TSDB_CODE_SUCCESS; diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index b7683a8698..d9630b56fd 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -28,7 +28,7 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { const STraceId *trace = &pMsg->info.traceId; vGTrace("vgId:%d, msg:%p wait block, type:%s sec:%d seq:%" PRId64, pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), pVnode->blockSec, pVnode->blockSeq); - tsem_wait(&pVnode->syncSem); + (void)tsem_wait(&pVnode->syncSem); } static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { @@ -41,7 +41,7 @@ static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { pVnode->blocked = false; pVnode->blockSec = 0; pVnode->blockSeq = 0; - tsem_post(&pVnode->syncSem); + (void)tsem_post(&pVnode->syncSem); } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -69,7 +69,7 @@ void vnodeRedirectRpcMsg(SVnode *pVnode, SRpcMsg *pMsg, int32_t code) { if (rsp.pCont == NULL) { pMsg->code = TSDB_CODE_OUT_OF_MEMORY; } else { - tSerializeSEpSet(rsp.pCont, contLen, &newEpSet); + (void)tSerializeSEpSet(rsp.pCont, contLen, &newEpSet); rsp.contLen = contLen; } @@ -161,7 +161,7 @@ void vnodeProposeCommitOnNeed(SVnode *pVnode, bool atExit) { rpcFreeCont(rpcMsg.pCont); rpcMsg.pCont = NULL; } else { - tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &rpcMsg); + (void)tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &rpcMsg); } } @@ -556,7 +556,7 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) } while (true); ASSERT(commitIdx == vnodeSyncAppliedIndex(pFsm)); - walApplyVer(pVnode->pWal, commitIdx); + (void)walApplyVer(pVnode->pWal, commitIdx); pVnode->restored = true; SStreamMeta *pMeta = pVnode->pTq->pStreamMeta; @@ -583,7 +583,7 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) streamMetaWUnLock(pMeta); tqInfo("vgId:%d stream task already loaded, start them", vgId); - streamTaskSchedTask(&pVnode->msgCb, TD_VID(pVnode), 0, 0, STREAM_EXEC_T_START_ALL_TASKS); + (void)streamTaskSchedTask(&pVnode->msgCb, TD_VID(pVnode), 0, 0, STREAM_EXEC_T_START_ALL_TASKS); return; } } @@ -602,13 +602,13 @@ static void vnodeBecomeFollower(const SSyncFSM *pFsm) { if (pVnode->blocked) { pVnode->blocked = false; vDebug("vgId:%d, become follower and post block", pVnode->config.vgId); - tsem_post(&pVnode->syncSem); + (void)tsem_post(&pVnode->syncSem); } (void)taosThreadMutexUnlock(&pVnode->lock); if (pVnode->pTq) { tqUpdateNodeStage(pVnode->pTq, false); - tqStopStreamTasksAsync(pVnode->pTq); + (void)tqStopStreamTasksAsync(pVnode->pTq); } } @@ -620,7 +620,7 @@ static void vnodeBecomeLearner(const SSyncFSM *pFsm) { if (pVnode->blocked) { pVnode->blocked = false; vDebug("vgId:%d, become learner and post block", pVnode->config.vgId); - tsem_post(&pVnode->syncSem); + (void)tsem_post(&pVnode->syncSem); } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -743,14 +743,14 @@ int32_t vnodeSyncStart(SVnode *pVnode) { void vnodeSyncPreClose(SVnode *pVnode) { vInfo("vgId:%d, sync pre close", pVnode->config.vgId); - syncLeaderTransfer(pVnode->sync); + (void)syncLeaderTransfer(pVnode->sync); syncPreStop(pVnode->sync); (void)taosThreadMutexLock(&pVnode->lock); if (pVnode->blocked) { vInfo("vgId:%d, post block after close sync", pVnode->config.vgId); pVnode->blocked = false; - tsem_post(&pVnode->syncSem); + (void)tsem_post(&pVnode->syncSem); } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -785,7 +785,7 @@ void vnodeSyncCheckTimeout(SVnode *pVnode) { pVnode->blocked = false; pVnode->blockSec = 0; pVnode->blockSeq = 0; - tsem_post(&pVnode->syncSem); + (void)tsem_post(&pVnode->syncSem); } } (void)taosThreadMutexUnlock(&pVnode->lock); diff --git a/source/libs/audit/src/auditMain.c b/source/libs/audit/src/auditMain.c index 7a8de49abe..cdc4a964c7 100644 --- a/source/libs/audit/src/auditMain.c +++ b/source/libs/audit/src/auditMain.c @@ -45,11 +45,11 @@ static FORCE_INLINE void auditDeleteRecord(SAuditRecord * record) { void auditCleanup() { tsLogFp = NULL; - taosThreadMutexLock(&tsAudit.lock); + (void)taosThreadMutexLock(&tsAudit.lock); taosArrayDestroyP(tsAudit.records, (FDelete)auditDeleteRecord); - taosThreadMutexUnlock(&tsAudit.lock); + (void)taosThreadMutexUnlock(&tsAudit.lock); tsAudit.records = NULL; - taosThreadMutexDestroy(&tsAudit.lock); + (void)taosThreadMutexDestroy(&tsAudit.lock); } extern void auditRecordImp(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, diff --git a/source/libs/executor/inc/executorInt.h b/source/libs/executor/inc/executorInt.h index 03dd0c4581..668d40dd0b 100644 --- a/source/libs/executor/inc/executorInt.h +++ b/source/libs/executor/inc/executorInt.h @@ -1002,7 +1002,7 @@ int32_t doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, S int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo, TSKEY* primaryKeys, int32_t prevPosition, int32_t order); -void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status); +int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status); #ifdef __cplusplus } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 596487f0de..853b2865bb 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1777,6 +1777,19 @@ int32_t createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCaseNode->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pNode; + } else if (type == QUERY_NODE_LOGIC_CONDITION) { + pExp->pExpr->nodeType = QUERY_NODE_OPERATOR; + SLogicConditionNode* pCond = (SLogicConditionNode*)pNode; + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + if (!pExp->base.pParam) { + code = terrno; + } + if (TSDB_CODE_SUCCESS == code) { + pExp->base.numOfParams = 1; + SDataType* pType = &pCond->node.resType; + pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCond->node.aliasName); + pExp->pExpr->_optrRoot.pRootNode = pNode; + } } else { ASSERT(0); } @@ -2300,21 +2313,29 @@ int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t } STableKeyInfo keyInfo = {.uid = uid, .groupId = gid}; - void* tmp = taosArrayPush(pTableList->pTableList, &keyInfo); + void* p = taosHashGet(pTableList->map, &uid, sizeof(uid)); + if (p != NULL) { + qInfo("table:%" PRId64 " already in tableIdList, ignore it", uid); + goto _end; + } + + void* tmp = taosArrayPush(pTableList->pTableList, &keyInfo); QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1; code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot)); - if (code == TSDB_CODE_DUP_KEY) { - code = TSDB_CODE_SUCCESS; + if (code != TSDB_CODE_SUCCESS) { + ASSERT(code != TSDB_CODE_DUP_KEY); // we have checked the existence of uid in hash map above + taosArrayPopTailBatch(pTableList->pTableList, 1); // let's pop the last element in the array list } - QUERY_CHECK_CODE(code, lino, _end); _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } else { + qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1); } - qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1); + return code; } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index be3737dc29..6dafcb1af7 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -295,7 +295,7 @@ qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int3 return NULL; } - createRawScanOperatorInfo(pReaderHandle, pTaskInfo, &pTaskInfo->pRoot); + code = createRawScanOperatorInfo(pReaderHandle, pTaskInfo, &pTaskInfo->pRoot); if (NULL == pTaskInfo->pRoot || code != 0) { taosMemoryFree(pTaskInfo); return NULL; @@ -1163,9 +1163,15 @@ SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) { return &pTaskInfo->streamInfo.btMetaRsp; } -void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) { +int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; tOffsetCopy(pOffset, &pTaskInfo->streamInfo.currentOffset); + return 0; + /*if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + }*/ } int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) { @@ -1236,7 +1242,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT } if (subType == TOPIC_SUB_TYPE__COLUMN) { - extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator); + code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator); if (pOperator == NULL || code != 0) { return code; } @@ -1437,7 +1443,6 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT end: tOffsetCopy(&pTaskInfo->streamInfo.currentOffset, pOffset); - return 0; } diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index d56b288129..bceefd2c0d 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -75,7 +75,7 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) { static int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock); static int32_t initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); -static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag); +static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag); static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol); @@ -193,7 +193,7 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR // add a new result set for a new group SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, - sizeof(SResultRowPosition)); + sizeof(SResultRowPosition)); if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); T_LONG_JMP(pTaskInfo->env, code); @@ -522,7 +522,7 @@ int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t n if (!pResInfo->initialized) { if (pCtx[i].functionId != -1) { int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo); - if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)){ + if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) { pResInfo->initialized = false; return TSDB_CODE_UDF_FUNC_EXEC_FAILURE; } @@ -567,7 +567,8 @@ int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* p code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status); QUERY_CHECK_CODE(code, lino, _err); - extractQualifiedTupleByFilterResult(pBlock, p, status); + code = extractQualifiedTupleByFilterResult(pBlock, p, status); + QUERY_CHECK_CODE(code, lino, _err); if (pColMatchInfo != NULL) { size_t size = taosArrayGetSize(pColMatchInfo->pList); @@ -591,18 +592,20 @@ _err: return code; } -void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) { +int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) { + int32_t code = TSDB_CODE_SUCCESS; int8_t* pIndicator = (int8_t*)p->pData; if (status == FILTER_RESULT_ALL_QUALIFIED) { // here nothing needs to be done } else if (status == FILTER_RESULT_NONE_QUALIFIED) { - trimDataBlock(pBlock, pBlock->info.rows, NULL); + code = trimDataBlock(pBlock, pBlock->info.rows, NULL); pBlock->info.rows = 0; } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) { - trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator); + code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator); } else { qError("unknown filter result type: %d", status); } + return code; } void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) { @@ -639,7 +642,7 @@ void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultR pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset); if (pCtx[j].fpSet.finalize) { if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 || - strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) { + strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) { // for groupkey along with functions that output multiple lines(e.g. Histogram) // need to match groupkey result for each output row of that function. if (pCtx[j].resultInfo->numOfRes != 0) { @@ -678,7 +681,7 @@ _end: // todo refactor. SResultRow has direct pointer in miainfo void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup, - SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { + SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId); if (page == NULL) { qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo)); @@ -694,7 +697,7 @@ void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPositi doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset); if (pRow->numOfRows == 0) { releaseBufPage(pBuf, page); - return ; + return; } int32_t size = pBlock->info.capacity; diff --git a/source/libs/executor/src/mergejoinoperator.c b/source/libs/executor/src/mergejoinoperator.c index 542f161a80..2c485cdd1b 100644 --- a/source/libs/executor/src/mergejoinoperator.c +++ b/source/libs/executor/src/mergejoinoperator.c @@ -308,12 +308,9 @@ int32_t mJoinFilterAndMarkHashRows(SSDataBlock* pBlock, SFilterInfo* pFilterInfo } } - extractQualifiedTupleByFilterResult(pBlock, p, status); - - code = TSDB_CODE_SUCCESS; + code = extractQualifiedTupleByFilterResult(pBlock, p, status); _err: - colDataDestroy(p); taosMemoryFree(p); @@ -375,12 +372,9 @@ int32_t mJoinFilterAndMarkRows(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SM } } - extractQualifiedTupleByFilterResult(pBlock, p, status); - - code = TSDB_CODE_SUCCESS; + code = extractQualifiedTupleByFilterResult(pBlock, p, status); _return: - colDataDestroy(p); taosMemoryFree(p); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 6755f131b6..acc3de3447 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1311,7 +1311,8 @@ static void destroyTableScanOperatorInfo(void* param) { } int32_t createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, - STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { + STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, + SOperatorInfo** pOptrInfo) { QRY_OPTR_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; @@ -1404,7 +1405,7 @@ _error: int32_t createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { QRY_OPTR_CHECK(pOptrInfo); - int32_t code = 0; + int32_t code = 0; STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -1422,7 +1423,7 @@ int32_t createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskIn *pOptrInfo = pOperator; return code; - _end: +_end: if (pInfo != NULL) { taosMemoryFree(pInfo); } @@ -2413,10 +2414,14 @@ _end: return code; } -static void doBlockDataWindowFilter(SSDataBlock* pBlock, int32_t tsIndex, STimeWindow* pWindow, const char* id) { +static int32_t doBlockDataWindowFilter(SSDataBlock* pBlock, int32_t tsIndex, STimeWindow* pWindow, const char* id) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool* p = NULL; if (pWindow->skey != INT64_MIN || pWindow->ekey != INT64_MAX) { - bool* p = taosMemoryCalloc(pBlock->info.rows, sizeof(bool)); - bool hasUnqualified = false; + p = taosMemoryCalloc(pBlock->info.rows, sizeof(bool)); + QUERY_CHECK_NULL(p, code, lino, _end, terrno); + bool hasUnqualified = false; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, tsIndex); @@ -2445,19 +2450,28 @@ static void doBlockDataWindowFilter(SSDataBlock* pBlock, int32_t tsIndex, STimeW } if (hasUnqualified) { - trimDataBlock(pBlock, pBlock->info.rows, p); + code = trimDataBlock(pBlock, pBlock->info.rows, p); + QUERY_CHECK_CODE(code, lino, _end); } - - taosMemoryFree(p); } + +_end: + taosMemoryFree(p); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -static void doBlockDataPrimaryKeyFilter(SSDataBlock* pBlock, STqOffsetVal* offset) { +static int32_t doBlockDataPrimaryKeyFilter(SSDataBlock* pBlock, STqOffsetVal* offset) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (pBlock->info.window.skey != offset->ts || offset->primaryKey.type == 0) { - return; + return code; } bool* p = taosMemoryCalloc(pBlock->info.rows, sizeof(bool)); - bool hasUnqualified = false; + QUERY_CHECK_NULL(p, code, lino, _end, terrno); + bool hasUnqualified = false; SColumnInfoData* pColTs = taosArrayGet(pBlock->pDataBlock, 0); SColumnInfoData* pColPk = taosArrayGet(pBlock->pDataBlock, 1); @@ -2485,16 +2499,26 @@ static void doBlockDataPrimaryKeyFilter(SSDataBlock* pBlock, STqOffsetVal* offse } if (hasUnqualified) { - trimDataBlock(pBlock, pBlock->info.rows, p); + code = trimDataBlock(pBlock, pBlock->info.rows, p); + QUERY_CHECK_CODE(code, lino, _end); } +_end: taosMemoryFree(p); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // re-build the delete block, ONLY according to the split timestamp -static void rebuildDeleteBlockData(SSDataBlock* pBlock, STimeWindow* pWindow, const char* id) { +static int32_t rebuildDeleteBlockData(SSDataBlock* pBlock, STimeWindow* pWindow, const char* id) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; int32_t numOfRows = pBlock->info.rows; bool* p = taosMemoryCalloc(numOfRows, sizeof(bool)); + QUERY_CHECK_NULL(p, code, lino, _end, terrno); + bool hasUnqualified = false; int64_t skey = pWindow->skey; int64_t ekey = pWindow->ekey; @@ -2531,14 +2555,20 @@ static void rebuildDeleteBlockData(SSDataBlock* pBlock, STimeWindow* pWindow, co } if (hasUnqualified) { - trimDataBlock(pBlock, pBlock->info.rows, p); + code = trimDataBlock(pBlock, pBlock->info.rows, p); qDebug("%s re-build delete datablock, start key revised to:%" PRId64 ", rows:%" PRId64, id, skey, pBlock->info.rows); + QUERY_CHECK_CODE(code, lino, _end); } else { qDebug("%s not update the delete block", id); } +_end: taosMemoryFree(p); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t colIdComparFn(const void* param1, const void* param2) { @@ -2657,7 +2687,8 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock } // filter the block extracted from WAL files, according to the time window apply additional time window filter - doBlockDataWindowFilter(pInfo->pRes, pInfo->primaryTsIndex, pTimeWindow, id); + code = doBlockDataWindowFilter(pInfo->pRes, pInfo->primaryTsIndex, pTimeWindow, id); + QUERY_CHECK_CODE(code, lino, _end); pInfo->pRes->info.dataLoad = 1; code = blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); @@ -2676,14 +2707,19 @@ _end: return code; } -static void processPrimaryKey(SSDataBlock* pBlock, bool hasPrimaryKey, STqOffsetVal* offset) { - SValue val = {0}; +static int32_t processPrimaryKey(SSDataBlock* pBlock, bool hasPrimaryKey, STqOffsetVal* offset) { + int32_t code = TSDB_CODE_SUCCESS; + SValue val = {0}; if (hasPrimaryKey) { - doBlockDataPrimaryKeyFilter(pBlock, offset); + code = doBlockDataPrimaryKeyFilter(pBlock, offset); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + return code; + } SColumnInfoData* pColPk = taosArrayGet(pBlock->pDataBlock, 1); if (pBlock->info.rows < 1) { - return; + return code; } void* tmp = colDataGetData(pColPk, pBlock->info.rows - 1); val.type = pColPk->info.type; @@ -2696,6 +2732,7 @@ static void processPrimaryKey(SSDataBlock* pBlock, bool hasPrimaryKey, STqOffset } } tqOffsetResetToData(offset, pBlock->info.id.uid, pBlock->info.window.ekey, val); + return code; } static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { @@ -2711,7 +2748,7 @@ static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (isTaskKilled(pTaskInfo)) { (*ppRes) = NULL; - return code; + return pTaskInfo->code; } if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) { @@ -2720,9 +2757,9 @@ static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (pResult && pResult->info.rows > 0) { bool hasPrimaryKey = pAPI->tqReaderFn.tqGetTablePrimaryKey(pInfo->tqReader); - processPrimaryKey(pResult, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); - qDebug("tmqsnap doQueueScan get data uid:%" PRId64 "", pResult->info.id.uid); - if (pResult->info.rows > 0) { + code = processPrimaryKey(pResult, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); + qDebug("tmqsnap doQueueScan get data utid:%" PRId64 "", pResult->info.id.uid); + if (pResult->info.rows > 0 || code != TSDB_CODE_SUCCESS) { (*ppRes) = pResult; return code; } @@ -3156,7 +3193,8 @@ FETCH_NEXT_BLOCK: code = setBlockGroupIdByUid(pInfo, pDelBlock); QUERY_CHECK_CODE(code, lino, _end); - rebuildDeleteBlockData(pDelBlock, &pStreamInfo->fillHistoryWindow, id); + code = rebuildDeleteBlockData(pDelBlock, &pStreamInfo->fillHistoryWindow, id); + QUERY_CHECK_CODE(code, lino, _end); printSpecDataBlock(pDelBlock, getStreamOpName(pOperator->operatorType), "delete recv filtered", GET_TASKID(pTaskInfo)); if (pDelBlock->info.rows == 0) { @@ -3479,7 +3517,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (pBlock && pBlock->info.rows > 0) { bool hasPrimaryKey = pAPI->snapshotFn.taosXGetTablePrimaryKey(pInfo->sContext); - processPrimaryKey(pBlock, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); + code = processPrimaryKey(pBlock, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid); (*ppRes) = pBlock; return code; @@ -3493,7 +3531,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { tDeleteSchemaWrapper(mtInfo.schema); goto _end; } - STqOffsetVal offset = {0}; + STqOffsetVal offset = {0}; if (mtInfo.uid == 0 || pInfo->sContext->withMeta == ONLY_META) { // read snapshot done, change to get data from wal qDebug("tmqsnap read snapshot done, change to get data from wal"); tqOffsetResetToLog(&offset, pInfo->sContext->snapVersion + 1); @@ -3964,7 +4002,7 @@ int32_t createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* QUERY_CHECK_CODE(code, lino, _error); pInfo->updateWin = (STimeWindow){.skey = INT64_MAX, .ekey = INT64_MAX}; - createSpecialDataBlock(STREAM_CLEAR, &pInfo->pUpdateDataRes); + code = createSpecialDataBlock(STREAM_CLEAR, &pInfo->pUpdateDataRes); QUERY_CHECK_CODE(code, lino, _error); if (hasPrimaryKeyCol(pInfo)) { @@ -4123,7 +4161,7 @@ static EDealRes tagScanRewriteTagColumn(SNode** pNode, void* pContext) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; STagScanFilterContext* pCtx = (STagScanFilterContext*)pContext; - SColumnNode* pSColumnNode = NULL; + SColumnNode* pSColumnNode = NULL; if (QUERY_NODE_COLUMN == nodeType((*pNode))) { pSColumnNode = *(SColumnNode**)pNode; } else if (QUERY_NODE_FUNCTION == nodeType((*pNode))) { @@ -4484,8 +4522,8 @@ static void destroyTagScanOperatorInfo(void* param) { } int32_t createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pTagScanNode, - STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, - SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { + STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, + SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { QRY_OPTR_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; @@ -5083,7 +5121,7 @@ _end: static SSDataBlock* doTableMergeScanParaSubTables(SOperatorInfo* pOperator) { SSDataBlock* pRes = NULL; - int32_t code = doTableMergeScanParaSubTablesNext(pOperator, &pRes); + int32_t code = doTableMergeScanParaSubTablesNext(pOperator, &pRes); return pRes; } @@ -5317,7 +5355,7 @@ int32_t startDurationForGroupTableMergeScan(SOperatorInfo* pOperator) { pInfo->pSortHandle = NULL; code = tsortCreateSortHandle(pInfo->pSortInfo, SORT_BLOCK_TS_MERGE, pInfo->bufPageSize, numOfBufPage, - pInfo->pSortInputBlock, pTaskInfo->id.str, 0, 0, 0, &pInfo->pSortHandle); + pInfo->pSortInputBlock, pTaskInfo->id.str, 0, 0, 0, &pInfo->pSortHandle); if (code) { return code; } @@ -5569,7 +5607,7 @@ _end: static SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { SSDataBlock* pRes = NULL; - int32_t code = doTableMergeScanNext(pOperator, &pRes); + int32_t code = doTableMergeScanNext(pOperator, &pRes); return pRes; } @@ -5626,10 +5664,11 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla } int32_t createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, - STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { + STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, + SOperatorInfo** pOptrInfo) { QRY_OPTR_CHECK(pOptrInfo); - int32_t code = 0; + int32_t code = 0; STableMergeScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableMergeScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -5641,7 +5680,7 @@ int32_t createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SR int32_t numOfCols = 0; code = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, - &pInfo->base.matchInfo); + &pInfo->base.matchInfo); int32_t lino = 0; if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -5867,7 +5906,7 @@ int32_t getTableCountScanSupp(SNodeList* groupTags, SName* tableName, SNodeList* } int32_t createTableCountScanOperatorInfo(SReadHandle* readHandle, STableCountScanPhysiNode* pTblCountScanNode, - SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { + SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { QRY_OPTR_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; @@ -6040,7 +6079,7 @@ _end: } static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableCountScanOperatorInfo* pInfo = pOperator->info; STableCountScanSupp* pSupp = &pInfo->supp; @@ -6062,7 +6101,7 @@ static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRe static SSDataBlock* doTableCountScan(SOperatorInfo* pOperator) { SSDataBlock* pRes = NULL; - int32_t code = doTableCountScanNext(pOperator, &pRes); + int32_t code = doTableCountScanNext(pOperator, &pRes); return pRes; } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 7dfe88fe85..a0c56df49c 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -365,6 +365,7 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { ps->onlyRef = true; code = tsortAddSource(pInfo->pSortHandle, ps); if (code) { + taosMemoryFree(ps); return code; } diff --git a/source/libs/executor/src/streameventwindowoperator.c b/source/libs/executor/src/streameventwindowoperator.c index 76eaccb4ec..17ef2fe41f 100644 --- a/source/libs/executor/src/streameventwindowoperator.c +++ b/source/libs/executor/src/streameventwindowoperator.c @@ -510,18 +510,16 @@ int32_t doStreamEventDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera int32_t mapSize = 0; buf = taosDecodeFixedI32(buf, &mapSize); for (int32_t i = 0; i < mapSize; i++) { - SSessionKey key = {0}; SResultWindowInfo winfo = {0}; - buf = decodeSSessionKey(buf, &key); + buf = decodeSSessionKey(buf, &winfo.sessionWin); int32_t winCode = TSDB_CODE_SUCCESS; code = pAggSup->stateStore.streamStateSessionAddIfNotExist( pAggSup->pState, &winfo.sessionWin, pAggSup->gap, (void**)&winfo.pStatePos, &pAggSup->resultRowSize, &winCode); QUERY_CHECK_CODE(code, lino, _end); - ASSERT(winCode == TSDB_CODE_SUCCESS); buf = decodeSResultWindowInfo(buf, &winfo, pInfo->streamAggSup.resultRowSize); code = - tSimpleHashPut(pInfo->streamAggSup.pResultRows, &key, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); + tSimpleHashPut(pInfo->streamAggSup.pResultRows, &winfo.sessionWin, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/streamfilloperator.c b/source/libs/executor/src/streamfilloperator.c index c6bf13dabd..480814f6a0 100644 --- a/source/libs/executor/src/streamfilloperator.c +++ b/source/libs/executor/src/streamfilloperator.c @@ -470,6 +470,7 @@ static int32_t checkResult(SStreamFillSupporter* pFillSup, TSKEY ts, uint64_t gr SWinKey key = {.groupId = groupId, .ts = ts}; if (tSimpleHashGet(pFillSup->pResMap, &key, sizeof(SWinKey)) != NULL) { (*pRes) = false; + goto _end; } code = tSimpleHashPut(pFillSup->pResMap, &key, sizeof(SWinKey), NULL, 0); QUERY_CHECK_CODE(code, lino, _end); diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c index aebc2d9c97..7462d71a8a 100644 --- a/source/libs/executor/src/streamtimewindowoperator.c +++ b/source/libs/executor/src/streamtimewindowoperator.c @@ -5183,7 +5183,7 @@ int32_t createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pInfo->pDelWins = taosArrayInit(4, sizeof(SWinKey)); pInfo->delIndex = 0; - createSpecialDataBlock(STREAM_DELETE_RESULT, &pInfo->pDelRes); + code = createSpecialDataBlock(STREAM_DELETE_RESULT, &pInfo->pDelRes); QUERY_CHECK_CODE(code, lino, _error); initResultRowInfo(&pInfo->binfo.resultRowInfo); diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 1f72357f9e..eed93423f0 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2372,11 +2372,12 @@ static FORCE_INLINE int optSysBinarySearch(SArray* arr, int s, int e, uint64_t k int32_t optSysIntersection(SArray* in, SArray* out) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; + MergeIndex* mi = NULL; int32_t sz = (int32_t)taosArrayGetSize(in); if (sz <= 0) { goto _end; } - MergeIndex* mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); + mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); QUERY_CHECK_NULL(mi, code, lino, _end, terrno); for (int i = 0; i < sz; i++) { SArray* t = taosArrayGetP(in, i); diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index ec897b06a9..0c70428e78 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -101,7 +101,10 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t return terrno; } - taosArrayPush(pBucket->pPageIdList, &newPageId); + void* px = taosArrayPush(pBucket->pPageIdList, &newPageId); + if (px == NULL) { + return terrno; + } doCopyObject(pNewPage->data, key, keyLen, data, size); pNewPage->num = sizeof(SFilePage) + nodeSize; @@ -127,7 +130,7 @@ static void doRemoveFromBucket(SFilePage* pPage, SLHashNode* pNode, SLHashBucket char* p = (char*)pNode + len; char* pEnd = (char*)pPage + pPage->num; - memmove(pNode, p, (pEnd - p)); + (void) memmove(pNode, p, (pEnd - p)); pPage->num -= len; if (pPage->num == 0) { @@ -189,7 +192,7 @@ static void doTrimBucketPages(SLHashObj* pHashObj, SLHashBucket* pBucket) { nodeSize = GET_LHASH_NODE_LEN(pStart); } else { // move to the front of pLast page if (pStart != pLast->data) { - memmove(pLast->data, pStart, (((char*)pLast) + pLast->num - pStart)); + (void) memmove(pLast->data, pStart, (((char*)pLast) + pLast->num - pStart)); setBufPageDirty(pLast, true); } @@ -235,7 +238,10 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { setBufPageDirty(p, true); releaseBufPage(pHashObj->pBuf, p); - taosArrayPush(pBucket->pPageIdList, &pageId); + void* px = taosArrayPush(pBucket->pPageIdList, &pageId); + if (px == NULL) { + return terrno; + } pHashObj->numOfBuckets += 1; // printf("---------------add new bucket, id:0x%x, total:%d\n", pHashObj->numOfBuckets - 1, pHashObj->numOfBuckets); @@ -251,7 +257,7 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ if (!osTempSpaceAvailable()) { terrno = TSDB_CODE_NO_DISKSPACE; - printf("tHash Init failed since %s, tempDir:%s", terrstr(), tsTempDir); + (void) printf("tHash Init failed since %s, tempDir:%s", terrstr(), tsTempDir); taosMemoryFree(pHashObj); return NULL; } @@ -301,9 +307,10 @@ void* tHashCleanup(SLHashObj* pHashObj) { } int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data, size_t size) { + int32_t code = 0; if (pHashObj->bits == 0) { SLHashBucket* pBucket = pHashObj->pBucket[0]; - doAddToBucket(pHashObj, pBucket, 0, key, keyLen, data, size); + code = doAddToBucket(pHashObj, pBucket, 0, key, keyLen, data, size); } else { int32_t hashVal = pHashObj->hashFn(key, keyLen); int32_t v = doGetBucketIdFromHashVal(hashVal, pHashObj->bits); @@ -315,10 +322,11 @@ int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data } SLHashBucket* pBucket = pHashObj->pBucket[v]; - int32_t code = doAddToBucket(pHashObj, pBucket, v, key, keyLen, data, size); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doAddToBucket(pHashObj, pBucket, v, key, keyLen, data, size); + } + + if (code) { + return code; } pHashObj->size += 1; @@ -327,7 +335,7 @@ int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data if ((pHashObj->numOfBuckets * LHASH_CAP_RATIO * pHashObj->tuplesPerPage) < pHashObj->size) { int32_t newBucketId = pHashObj->numOfBuckets; - int32_t code = doAddNewBucket(pHashObj); + code = doAddNewBucket(pHashObj); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -362,7 +370,7 @@ int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data ASSERT(v1 == newBucketId); // printf("move key:%d to 0x%x bucket, remain items:%d\n", *(int32_t*)k, v1, pBucket->size - 1); SLHashBucket* pNewBucket = pHashObj->pBucket[newBucketId]; - doAddToBucket(pHashObj, pNewBucket, newBucketId, (void*)GET_LHASH_NODE_KEY(pNode), pNode->keyLen, + code = doAddToBucket(pHashObj, pNewBucket, newBucketId, (void*)GET_LHASH_NODE_KEY(pNode), pNode->keyLen, GET_LHASH_NODE_KEY(pNode), pNode->dataLen); doRemoveFromBucket(p, pNode, pBucket); } else { @@ -377,7 +385,7 @@ int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data doTrimBucketPages(pHashObj, pBucket); } - return TSDB_CODE_SUCCESS; + return code; } char* tHashGet(SLHashObj* pHashObj, const void* key, size_t keyLen) { @@ -420,8 +428,8 @@ int32_t tHashRemove(SLHashObj* pHashObj, const void* key, size_t keyLen) { } void tHashPrint(const SLHashObj* pHashObj, int32_t type) { - printf("==================== linear hash ====================\n"); - printf("total bucket:%d, size:%" PRId64 ", ratio:%.2f\n", pHashObj->numOfBuckets, pHashObj->size, LHASH_CAP_RATIO); + (void) printf("==================== linear hash ====================\n"); + (void) printf("total bucket:%d, size:%" PRId64 ", ratio:%.2f\n", pHashObj->numOfBuckets, pHashObj->size, LHASH_CAP_RATIO); dBufSetPrintInfo(pHashObj->pBuf); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index fa7d59e137..896b4db7cd 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -1699,6 +1699,7 @@ static int32_t initRowIdSort(SSortHandle* pHandle) { taosArrayDestroy(pHandle->pSortInfo); pHandle->pSortInfo = pOrderInfoList; + pHandle->cmpParam.pPkOrder = (pHandle->bSortPk) ? taosArrayGet(pHandle->pSortInfo, 1) : NULL; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 7c0ddb6175..ad9e5ce7d4 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -229,6 +229,7 @@ static void udfWatchUdfd(void *args) { if(uv_loop_close(&pData->loop) != 0) { fnError("udfd loop close failed, lino:%d", __LINE__); } + return; _exit: if (terrno != 0) { @@ -896,14 +897,14 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo } int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { - int32_t code = 0, lino = 0; - SUdfColumnMeta* meta = &udfCol->colMeta; + int32_t code = 0, lino = 0; + SUdfColumnMeta *meta = &udfCol->colMeta; SColumnInfoData colInfoData = createColumnInfoData(meta->type, meta->bytes, 1); code = blockDataAppendColInfo(block, &colInfoData); TAOS_CHECK_GOTO(code, &lino, _exit); - code = blockDataEnsureCapacity(block, udfCol->colData.numOfRows); + code = blockDataEnsureCapacity(block, udfCol->colData.numOfRows); TAOS_CHECK_GOTO(code, &lino, _exit); SColumnInfoData *col = NULL; diff --git a/source/libs/index/inc/indexUtil.h b/source/libs/index/inc/indexUtil.h index 308e213ac9..6b016900c2 100644 --- a/source/libs/index/inc/indexUtil.h +++ b/source/libs/index/inc/indexUtil.h @@ -55,7 +55,7 @@ extern "C" { } \ } \ if (f == false) { \ - taosArrayPush(dst, &tgt); \ + (void)taosArrayPush(dst, &tgt); \ } \ } diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index fad04798a8..986693ab00 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,7 +74,7 @@ void indexCleanup() { // refacto later taosCleanUpScheduler(indexQhandle); taosMemoryFreeClear(indexQhandle); - taosCloseRef(indexRefMgt); + (void)taosCloseRef(indexRefMgt); } typedef struct SIdxColInfo { @@ -99,15 +99,15 @@ static void idxMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateV static void idxPost(void* idx) { SIndex* pIdx = idx; - tsem_post(&pIdx->sem); + (void)tsem_post(&pIdx->sem); } static void indexWait(void* idx) { SIndex* pIdx = idx; - tsem_wait(&pIdx->sem); + (void)tsem_wait(&pIdx->sem); } int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { - taosThreadOnce(&isInit, indexEnvInit); + (void)taosThreadOnce(&isInit, indexEnvInit); int code = TSDB_CODE_SUCCESS; SIndex* idx = taosMemoryCalloc(1, sizeof(SIndex)); @@ -137,8 +137,8 @@ int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, END); } - taosThreadMutexInit(&idx->mtx, NULL); - tsem_init(&idx->sem, 0, 0); + (void)taosThreadMutexInit(&idx->mtx, NULL); + (void)tsem_init(&idx->sem, 0, 0); idx->refId = idxAddRef(idx); idx->opts = *opts; @@ -158,8 +158,8 @@ END: void indexDestroy(void* handle) { if (handle == NULL) return; SIndex* idx = handle; - taosThreadMutexDestroy(&idx->mtx); - tsem_destroy(&idx->sem); + (void)taosThreadMutexDestroy(&idx->mtx); + (void)tsem_destroy(&idx->sem); idxTFileDestroy(idx->tindex); taosMemoryFree(idx->path); @@ -190,7 +190,7 @@ void indexClose(SIndex* sIdx) { } idxReleaseRef(sIdx->refId); - idxRemoveRef(sIdx->refId); + (void)idxRemoveRef(sIdx->refId); } int64_t idxAddRef(void* p) { // impl @@ -203,16 +203,16 @@ int32_t idxRemoveRef(int64_t ref) { void idxAcquireRef(int64_t ref) { // impl - taosAcquireRef(indexRefMgt, ref); + (void)taosAcquireRef(indexRefMgt, ref); } void idxReleaseRef(int64_t ref) { // impl - taosReleaseRef(indexRefMgt, ref); + (void)taosReleaseRef(indexRefMgt, ref); } int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { // TODO(yihao): reduce the lock range - taosThreadMutexLock(&index->mtx); + (void)taosThreadMutexLock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { SIndexTerm* p = taosArrayGetP(fVals, i); @@ -223,10 +223,10 @@ int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { IndexCache** cache = taosHashGet(index->colObj, buf, sz); if (cache == NULL) { IndexCache* pCache = idxCacheCreate(index, p->suid, p->colName, p->colType); - taosHashPut(index->colObj, buf, sz, &pCache, sizeof(void*)); + (void)taosHashPut(index->colObj, buf, sz, &pCache, sizeof(void*)); } } - taosThreadMutexUnlock(&index->mtx); + (void)taosThreadMutexUnlock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { SIndexTerm* p = taosArrayGetP(fVals, i); @@ -255,10 +255,10 @@ int32_t indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* re for (size_t i = 0; i < nQuery; i++) { SIndexTermQuery* qterm = taosArrayGet(multiQuerys->query, i); SArray* trslt = NULL; - idxTermSearch(index, qterm, &trslt); - taosArrayPush(iRslts, (void*)&trslt); + (void)idxTermSearch(index, qterm, &trslt); + (void)taosArrayPush(iRslts, (void*)&trslt); } - idxMergeFinalResults(iRslts, opera, result); + (void)idxMergeFinalResults(iRslts, opera, result); idxInterRsltDestroy(iRslts); return 0; } @@ -295,7 +295,7 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery) { }; int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) { SIndexTermQuery q = {.qType = qType, .term = term}; - taosArrayPush(pQuery->query, &q); + (void)taosArrayPush(pQuery->query, &q); return 0; } @@ -341,7 +341,7 @@ void indexTermDestroy(SIndexTerm* p) { SIndexMultiTerm* indexMultiTermCreate() { return taosArrayInit(4, sizeof(SIndexTerm*)); } int32_t indexMultiTermAdd(SIndexMultiTerm* terms, SIndexTerm* term) { - taosArrayPush(terms, &term); + (void)taosArrayPush(terms, &term); return 0; } void indexMultiTermDestroy(SIndexMultiTerm* terms) { @@ -374,7 +374,7 @@ void indexRebuild(SIndexJson* idx, void* iter) { schedMsg.fp = idxSchedRebuildIdx; schedMsg.ahandle = idx; idxAcquireRef(idx->refId); - taosScheduleTask(indexQhandle, &schedMsg); + (void)taosScheduleTask(indexQhandle, &schedMsg); } /* @@ -415,10 +415,10 @@ static int32_t idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** resu int32_t sz = idxSerialCacheKey(&key, buf); - taosThreadMutexLock(&sIdx->mtx); + (void)taosThreadMutexLock(&sIdx->mtx); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); cache = (pCache == NULL) ? NULL : *pCache; - taosThreadMutexUnlock(&sIdx->mtx); + (void)taosThreadMutexUnlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); if (*result == NULL) { @@ -501,7 +501,7 @@ static void idxMayMergeTempToFinalRslt(SArray* result, TFileValue* tfv, SIdxTRsl idxTRsltMergeTo(tr, lv->tableId); idxTRsltClear(tr); - taosArrayPush(result, &tfv); + (void)taosArrayPush(result, &tfv); } else if (tfv == NULL) { // handle last iterator idxTRsltMergeTo(tr, lv->tableId); @@ -509,7 +509,7 @@ static void idxMayMergeTempToFinalRslt(SArray* result, TFileValue* tfv, SIdxTRsl tfileValueDestroy(tfv); } } else { - taosArrayPush(result, &tfv); + (void)taosArrayPush(result, &tfv); } } static void idxMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue* tv, SIdxTRslt* tr) { @@ -528,7 +528,7 @@ static void idxMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue } } if (tv != NULL) { - taosArrayAddAll(tr->total, tv->val); + (void)taosArrayAddAll(tr->total, tv->val); } } static void idxDestroyFinalRslt(SArray* result) { @@ -655,9 +655,9 @@ static int64_t idxGetAvailableVer(SIndex* sIdx, IndexCache* cache) { IndexTFile* tf = (IndexTFile*)(sIdx->tindex); - taosThreadMutexLock(&tf->mtx); + (void)taosThreadMutexLock(&tf->mtx); TFileReader* rd = tfileCacheGet(tf->cache, &key); - taosThreadMutexUnlock(&tf->mtx); + (void)taosThreadMutexUnlock(&tf->mtx); if (rd != NULL) { ver = (ver > rd->header.version ? ver : rd->header.version) + 1; @@ -698,9 +698,9 @@ static int32_t idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { TFileHeader* header = &reader->header; ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)}; - taosThreadMutexLock(&tf->mtx); + (void)taosThreadMutexLock(&tf->mtx); code = tfileCachePut(tf->cache, &key, reader); - taosThreadMutexUnlock(&tf->mtx); + (void)taosThreadMutexUnlock(&tf->mtx); return code; @@ -717,7 +717,7 @@ int32_t idxSerialCacheKey(ICacheKey* key, char* buf) { char* p = buf; char tbuf[65] = {0}; - idxInt2str((int64_t)key->suid, tbuf, 0); + (void)idxInt2str((int64_t)key->suid, tbuf, 0); SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf)); SERIALIZE_VAR_TO_BUF(buf, '_', char); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index f2aefcfc41..adf555edd2 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -104,7 +104,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe } taosMemoryFree(pCt); - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); return 0; } static int32_t cacheSearchPrefix(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { @@ -162,7 +162,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* } } taosMemoryFree(pCt); - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); return TSDB_CODE_SUCCESS; } static int32_t cacheSearchLessThan(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { @@ -222,7 +222,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr taosMemoryFree(pCt); taosMemoryFree(exBuf); - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); return 0; return TSDB_CODE_SUCCESS; @@ -329,7 +329,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR taosMemoryFree(pCt); taosMemoryFree(exBuf); - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); return TSDB_CODE_SUCCESS; } @@ -356,8 +356,8 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8 cache->suid = suid; cache->occupiedMem = 0; - taosThreadMutexInit(&cache->mtx, NULL); - taosThreadCondInit(&cache->finished, NULL); + (void)taosThreadMutexInit(&cache->mtx, NULL); + (void)taosThreadCondInit(&cache->finished, NULL); idxCacheRef(cache); if (idx != NULL) { @@ -368,10 +368,10 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8 void idxCacheDebug(IndexCache* cache) { MemTable* tbl = NULL; - taosThreadMutexLock(&cache->mtx); + (void)taosThreadMutexLock(&cache->mtx); tbl = cache->mem; idxMemRef(tbl); - taosThreadMutexUnlock(&cache->mtx); + (void)taosThreadMutexUnlock(&cache->mtx); { SSkipList* slt = tbl->mem; @@ -384,16 +384,16 @@ void idxCacheDebug(IndexCache* cache) { indexInfo("{colVal: %s, version: %" PRId64 "} \t", ct->colVal, ct->version); } } - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); idxMemUnRef(tbl); } { - taosThreadMutexLock(&cache->mtx); + (void)taosThreadMutexLock(&cache->mtx); tbl = cache->imm; idxMemRef(tbl); - taosThreadMutexUnlock(&cache->mtx); + (void)taosThreadMutexUnlock(&cache->mtx); if (tbl != NULL) { SSkipList* slt = tbl->mem; SSkipListIterator* iter = tSkipListCreateIter(slt); @@ -405,7 +405,7 @@ void idxCacheDebug(IndexCache* cache) { indexInfo("{colVal: %s, version: %" PRId64 "} \t", ct->colVal, ct->version); } } - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); } idxMemUnRef(tbl); @@ -422,29 +422,29 @@ void idxCacheDestroySkiplist(SSkipList* slt) { taosMemoryFree(ct); } } - tSkipListDestroyIter(iter); + (void)tSkipListDestroyIter(iter); tSkipListDestroy(slt); } void idxCacheBroadcast(void* cache) { IndexCache* pCache = cache; - taosThreadCondBroadcast(&pCache->finished); + (void)taosThreadCondBroadcast(&pCache->finished); } void idxCacheWait(void* cache) { IndexCache* pCache = cache; - taosThreadCondWait(&pCache->finished, &pCache->mtx); + (void)taosThreadCondWait(&pCache->finished, &pCache->mtx); } void idxCacheDestroyImm(IndexCache* cache) { if (cache == NULL) { return; } MemTable* tbl = NULL; - taosThreadMutexLock(&cache->mtx); + (void)taosThreadMutexLock(&cache->mtx); tbl = cache->imm; cache->imm = NULL; // or throw int bg thread idxCacheBroadcast(cache); - taosThreadMutexUnlock(&cache->mtx); + (void)taosThreadMutexUnlock(&cache->mtx); idxMemUnRef(tbl); idxMemUnRef(tbl); @@ -459,8 +459,8 @@ void idxCacheDestroy(void* cache) { idxMemUnRef(pCache->imm); taosMemoryFree(pCache->colName); - taosThreadMutexDestroy(&pCache->mtx); - taosThreadCondDestroy(&pCache->finished); + (void)taosThreadMutexDestroy(&pCache->mtx); + (void)taosThreadCondDestroy(&pCache->finished); if (pCache->index != NULL) { idxReleaseRef(((SIndex*)pCache->index)->refId); } @@ -475,7 +475,7 @@ Iterate* idxCacheIteratorCreate(IndexCache* cache) { if (iter == NULL) { return NULL; } - taosThreadMutexLock(&cache->mtx); + (void)taosThreadMutexLock(&cache->mtx); idxMemRef(cache->imm); @@ -486,7 +486,7 @@ Iterate* idxCacheIteratorCreate(IndexCache* cache) { iter->next = idxCacheIteratorNext; iter->getValue = idxCacheIteratorGetValue; - taosThreadMutexUnlock(&cache->mtx); + (void)taosThreadMutexUnlock(&cache->mtx); return iter; } @@ -494,7 +494,7 @@ void idxCacheIteratorDestroy(Iterate* iter) { if (iter == NULL) { return; } - tSkipListDestroyIter(iter->iter); + (void)tSkipListDestroyIter(iter->iter); iterateValueDestroy(&iter->val, true); taosMemoryFree(iter); } @@ -508,7 +508,7 @@ int idxCacheSchedToMerge(IndexCache* pCache, bool notify) { } schedMsg.msg = NULL; idxAcquireRef(pCache->index->refId); - taosScheduleTask(indexQhandle, &schedMsg); + (void)taosScheduleTask(indexQhandle, &schedMsg); return 0; } @@ -533,7 +533,7 @@ static void idxCacheMakeRoomForWrite(IndexCache* cache) { } // 1. sched to merge // 2. unref cache in bgwork - idxCacheSchedToMerge(cache, quit); + (void)idxCacheSchedToMerge(cache, quit); } } } @@ -548,7 +548,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // encode data CacheTerm* ct = taosMemoryCalloc(1, sizeof(CacheTerm)); if (ct == NULL) { - return -1; + return TSDB_CODE_OUT_OF_MEMORY; } // set up key ct->colType = term->colType; @@ -556,6 +556,10 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { ct->colVal = idxPackJsonData(term); } else { ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1)); + if (ct->colVal == NULL) { + taosMemoryFree(ct); + return TSDB_CODE_OUT_OF_MEMORY; + } memcpy(ct->colVal, term->colVal, term->nColVal); } ct->version = atomic_add_fetch_64(&pCache->version, 1); @@ -565,15 +569,15 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // ugly code, refactor later int64_t estimate = sizeof(ct) + strlen(ct->colVal); - taosThreadMutexLock(&pCache->mtx); + (void)taosThreadMutexLock(&pCache->mtx); pCache->occupiedMem += estimate; idxCacheMakeRoomForWrite(pCache); MemTable* tbl = pCache->mem; idxMemRef(tbl); - tSkipListPut(tbl->mem, (char*)ct); + (void)tSkipListPut(tbl->mem, (char*)ct); idxMemUnRef(tbl); - taosThreadMutexUnlock(&pCache->mtx); + (void)taosThreadMutexUnlock(&pCache->mtx); idxCacheUnRef(pCache); return 0; } @@ -581,13 +585,13 @@ void idxCacheForceToMerge(void* cache) { IndexCache* pCache = cache; idxCacheRef(pCache); - taosThreadMutexLock(&pCache->mtx); + (void)taosThreadMutexLock(&pCache->mtx); indexInfo("%p is forced to merge into tfile", pCache); pCache->occupiedMem += MEM_SIGNAL_QUIT; idxCacheMakeRoomForWrite(pCache); - taosThreadMutexUnlock(&pCache->mtx); + (void)taosThreadMutexUnlock(&pCache->mtx); idxCacheUnRef(pCache); return; } @@ -618,12 +622,12 @@ int idxCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STerm IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; - taosThreadMutexLock(&pCache->mtx); + (void)taosThreadMutexLock(&pCache->mtx); mem = pCache->mem; imm = pCache->imm; idxMemRef(mem); idxMemRef(imm); - taosThreadMutexUnlock(&pCache->mtx); + (void)taosThreadMutexUnlock(&pCache->mtx); int64_t st = taosGetTimestampUs(); @@ -759,7 +763,7 @@ static void idxDoMergeWork(SSchedMsg* msg) { int quit = msg->thandle ? true : false; taosMemoryFree(msg->thandle); - idxFlushCacheToTFile(sidx, pCache, quit); + (void)idxFlushCacheToTFile(sidx, pCache, quit); } static bool idxCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; @@ -777,7 +781,7 @@ static bool idxCacheIteratorNext(Iterate* itera) { iv->type = ct->operaType; iv->ver = ct->version; iv->colVal = taosStrdup(ct->colVal); - taosArrayPush(iv->val, &ct->uid); + (void)taosArrayPush(iv->val, &ct->uid); } return next; } diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index b7b9f1cc9f..6337b2c556 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -378,6 +378,9 @@ int32_t idxConvertData(void* src, int8_t type, void** dst) { int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (src == NULL) { *dst = strndup(INDEX_DATA_NULL_STR, (int)strlen(INDEX_DATA_NULL_STR)); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } return (int32_t)strlen(INDEX_DATA_NULL_STR); } int tlen = tDataTypes[type].bytes; @@ -385,63 +388,96 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { switch (type) { case TSDB_DATA_TYPE_TIMESTAMP: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(int64_t*)src, *dst, -1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(int64_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_UTINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(uint8_t*)src, *dst, 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(uint8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_TINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(int8_t*)src, *dst, 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(int8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_SMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(int16_t*)src, *dst, -1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(int16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_USMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(uint16_t*)src, *dst, -1); + (void)idxInt2str(*(uint16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_INT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(int32_t*)src, *dst, -1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(int32_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(uint32_t*)src, *dst, 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(uint32_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } sprintf(*dst, "%" PRIu64, *(uint64_t*)src); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_UBIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); - idxInt2str(*(uint64_t*)src, *dst, 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (void)idxInt2str(*(uint64_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_FLOAT: *dst = taosMemoryCalloc(1, bufSize + 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } sprintf(*dst, "%.9lf", *(float*)src); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_DOUBLE: *dst = taosMemoryCalloc(1, bufSize + 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } sprintf(*dst, "%.9lf", *(double*)src); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_NCHAR: { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; break; @@ -451,6 +487,9 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { case TSDB_DATA_TYPE_GEOMETRY: { tlen = taosEncodeBinary(NULL, varDataVal(src), varDataLen(src)); *dst = taosMemoryCalloc(1, tlen + 1); + if (*dst == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } tlen = taosEncodeBinary(dst, varDataVal(src), varDataLen(src)); *dst = (char*)*dst - tlen; break; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index a7e539efc6..9563b91593 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -646,7 +646,7 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP } SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST); - indexMultiTermQueryAdd(mtm, tm, qtype); + (void)indexMultiTermQueryAdd(mtm, tm, qtype); ret = indexJsonSearch(arg->ivtIdx, mtm, output->result); indexMultiTermQueryDestroy(mtm); } else { @@ -882,9 +882,9 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou if (ctx->noExec == false) { for (int32_t m = 0; m < node->pParameterList->length; m++) { if (node->condType == LOGIC_COND_TYPE_AND) { - taosArrayAddAll(output->result, params[m].result); + (void)taosArrayAddAll(output->result, params[m].result); } else if (node->condType == LOGIC_COND_TYPE_OR) { - taosArrayAddAll(output->result, params[m].result); + (void)taosArrayAddAll(output->result, params[m].result); } else if (node->condType == LOGIC_COND_TYPE_NOT) { // taosArrayAddAll(output->result, params[m].result); } @@ -1018,12 +1018,12 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) { SIF_ERR_RET(TSDB_CODE_APP_ERROR); } if (res->result != NULL) { - taosArrayAddAll(pDst->result, res->result); + (void)taosArrayAddAll(pDst->result, res->result); } pDst->status = res->status; sifFreeParam(res); - taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + (void)taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } sifFreeRes(ctx.pRes); return code; @@ -1055,7 +1055,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status, SMetaDataFilte } *status = res->status; sifFreeParam(res); - taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + (void)taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); void *iter = taosHashIterate(ctx.pRes, NULL); while (iter != NULL) { @@ -1090,7 +1090,7 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result, *status = st; } - taosArrayAddAll(result, param.result); + (void)taosArrayAddAll(result, param.result); sifFreeParam(¶m); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index f3b7b2fbae..54d28f4784 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -62,7 +62,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes* nodes, bool isFinal) { node->trans = taosArrayInit(16, sizeof(FstTransition)); FstBuilderNodeUnfinished un = {.node = node, .last = NULL}; - taosArrayPush(nodes->stack, &un); + (void)taosArrayPush(nodes->stack, &un); } FstBuilderNode* fstUnFinishedNodesPopRoot(FstUnFinishedNodes* nodes) { FstBuilderNodeUnfinished* un = taosArrayPop(nodes->stack); @@ -120,7 +120,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output FstLastTransition* trn = fstLastTransitionCreate(data[i], 0); FstBuilderNodeUnfinished un = {.node = n, .last = trn}; - taosArrayPush(nodes->stack, &un); + (void)taosArrayPush(nodes->stack, &un); } fstUnFinishedNodesPushEmpty(nodes, true); } @@ -214,9 +214,9 @@ void fstStateCompileForOneTransNext(IdxFstFile* w, CompiledAddr addr, uint8_t in uint8_t v = fstStateCommInput(&s, &null); if (null) { // w->write_all(&[inp]) - idxFileWrite(w, &inp, 1); + (void)idxFileWrite(w, &inp, 1); } - idxFileWrite(w, &(s.val), 1); + (void)idxFileWrite(w, &(s.val), 1); // w->write_all(&[s.val]) return; } @@ -228,7 +228,7 @@ void fstStateCompileForOneTrans(IdxFstFile* w, CompiledAddr addr, FstTransition* FST_SET_OUTPUT_PACK_SIZE(packSizes, outPackSize); FST_SET_TRANSITION_PACK_SIZE(packSizes, transPackSize); - idxFileWrite(w, (char*)&packSizes, sizeof(packSizes)); + (void)idxFileWrite(w, (char*)&packSizes, sizeof(packSizes)); FstState st = fstStateCreate(OneTrans); @@ -237,9 +237,9 @@ void fstStateCompileForOneTrans(IdxFstFile* w, CompiledAddr addr, FstTransition* bool null = false; uint8_t inp = fstStateCommInput(&st, &null); if (null == true) { - idxFileWrite(w, (char*)&trn->inp, sizeof(trn->inp)); + (void)idxFileWrite(w, (char*)&trn->inp, sizeof(trn->inp)); } - idxFileWrite(w, (char*)(&(st.val)), sizeof(st.val)); + (void)idxFileWrite(w, (char*)(&(st.val)), sizeof(st.val)); return; } void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode* node) { @@ -285,7 +285,7 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode } for (int32_t i = sz - 1; i >= 0; i--) { FstTransition* t = taosArrayGet(node->trans, i); - idxFileWrite(w, (char*)&t->inp, 1); + (void)idxFileWrite(w, (char*)&t->inp, 1); } if (sz > TRANS_INDEX_THRESHOLD) { // A value of 255 indicates that no transition exists for the byte at that idx @@ -295,24 +295,24 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode FstTransition* t = taosArrayGet(node->trans, i); index[t->inp] = i; } - idxFileWrite(w, (char*)index, 256); + (void)idxFileWrite(w, (char*)index, 256); taosMemoryFree(index); } - idxFileWrite(w, (char*)&packSizes, 1); + (void)idxFileWrite(w, (char*)&packSizes, 1); bool null = false; - fstStateStateNtrans(&st, &null); + (void)fstStateStateNtrans(&st, &null); if (null == true) { // 256 can't be represented in a u8, so we abuse the fact that // the # of transitions can never be 1 here, since 1 is always // encoded in the state byte. uint8_t v = 1; if (sz == 256) { - idxFileWrite(w, (char*)&v, 1); + (void)idxFileWrite(w, (char*)&v, 1); } else { - idxFileWrite(w, (char*)&sz, 1); + (void)idxFileWrite(w, (char*)&sz, 1); } } - idxFileWrite(w, (char*)(&(st.val)), 1); + (void)idxFileWrite(w, (char*)(&(st.val)), 1); return; } @@ -342,7 +342,7 @@ uint8_t fstStateCommInput(FstState* s, bool* null) { uint64_t fstStateInputLen(FstState* s) { ASSERT(s->state == OneTransNext || s->state == OneTrans); bool null = false; - fstStateCommInput(s, &null); + (void)fstStateCommInput(s, &null); return null ? 1 : 0; } @@ -499,7 +499,7 @@ uint64_t fstStateTransIndexSize(FstState* s, uint64_t version, uint64_t nTrans) uint64_t fstStateNtransLen(FstState* s) { ASSERT(s->state == AnyTrans); bool null = false; - fstStateStateNtrans(s, &null); + (void)fstStateStateNtrans(s, &null); return null == true ? 1 : 0; } uint64_t fstStateNtrans(FstState* s, FstSlice* slice) { @@ -673,12 +673,12 @@ bool fstNodeGetTransitionAddrAt(FstNode* node, uint64_t i, CompiledAddr* res) { FstState* st = &node->state; if (st->state == OneTransNext) { ASSERT(i == 0); - fstStateTransAddr(st, node); + (void)fstStateTransAddr(st, node); } else if (st->state == OneTrans) { ASSERT(i == 0); - fstStateTransAddr(st, node); + (void)fstStateTransAddr(st, node); } else if (st->state == AnyTrans) { - fstStateTransAddrForAnyTrans(st, node, i); + (void)fstStateTransAddrForAnyTrans(st, node, i); } else if (FST_STATE_EMPTY_FINAL(node)) { s = false; } else { @@ -755,13 +755,13 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) { char buf64[8] = {0}; void* pBuf64 = buf64; - taosEncodeFixedU64(&pBuf64, VERSION); - idxFileWrite(b->wrt, buf64, sizeof(buf64)); + (void)taosEncodeFixedU64(&pBuf64, VERSION); + (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); pBuf64 = buf64; memset(buf64, 0, sizeof(buf64)); - taosEncodeFixedU64(&pBuf64, ty); - idxFileWrite(b->wrt, buf64, sizeof(buf64)); + (void)taosEncodeFixedU64(&pBuf64, ty); + (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); return b; } @@ -862,7 +862,7 @@ CompiledAddr fstBuilderCompile(FstBuilder* b, FstBuilderNode* bn) { } CompiledAddr startAddr = (CompiledAddr)(FST_WRITER_COUNT(b->wrt)); - fstBuilderNodeCompileTo(bn, b->wrt, b->lastAddr, startAddr); + (void)fstBuilderNodeCompileTo(bn, b->wrt, b->lastAddr, startAddr); b->lastAddr = (CompiledAddr)(FST_WRITER_COUNT(b->wrt) - 1); if (entry->state == NOTFOUND) { FST_REGISTRY_CELL_INSERT(entry->cell, b->lastAddr); @@ -881,23 +881,23 @@ void* fstBuilderInsertInner(FstBuilder* b) { char buf64[8] = {0}; void* pBuf64 = buf64; - taosEncodeFixedU64(&pBuf64, b->len); - idxFileWrite(b->wrt, buf64, sizeof(buf64)); + (void)taosEncodeFixedU64(&pBuf64, b->len); + (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); pBuf64 = buf64; - taosEncodeFixedU64(&pBuf64, rootAddr); - idxFileWrite(b->wrt, buf64, sizeof(buf64)); + (void)taosEncodeFixedU64(&pBuf64, rootAddr); + (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); char buf32[4] = {0}; void* pBuf32 = buf32; uint32_t sum = idxFileMaskedCheckSum(b->wrt); - taosEncodeFixedU32(&pBuf32, sum); - idxFileWrite(b->wrt, buf32, sizeof(buf32)); + (void)taosEncodeFixedU32(&pBuf32, sum); + (void)idxFileWrite(b->wrt, buf32, sizeof(buf32)); - idxFileFlush(b->wrt); + (void)idxFileFlush(b->wrt); return b->wrt; } -void fstBuilderFinish(FstBuilder* b) { fstBuilderInsertInner(b); } +void fstBuilderFinish(FstBuilder* b) { (void)fstBuilderInsertInner(b); } FstSlice fstNodeAsSlice(FstNode* node) { FstSlice* slice = &node->data; @@ -924,7 +924,7 @@ void fstBuilderNodeUnfinishedLastCompiled(FstBuilderNodeUnfinished* unNode, Comp return; } FstTransition t = {.inp = trn->inp, .out = trn->out, .addr = addr}; - taosArrayPush(unNode->node->trans, &t); + (void)taosArrayPush(unNode->node->trans, &t); fstLastTransitionDestroy(trn); unNode->last = NULL; return; @@ -955,19 +955,19 @@ Fst* fstCreate(FstSlice* slice) { uint64_t skip = 0; uint64_t version; - taosDecodeFixedU64(buf, &version); + (void)taosDecodeFixedU64(buf, &version); skip += sizeof(version); if (version == 0 || version > VERSION) { return NULL; } uint64_t type; - taosDecodeFixedU64(buf + skip, &type); + (void)taosDecodeFixedU64(buf + skip, &type); skip += sizeof(type); uint32_t checkSum = 0; len -= sizeof(checkSum); - taosDecodeFixedU32(buf + len, &checkSum); + (void)taosDecodeFixedU32(buf + len, &checkSum); if (taosCheckChecksum(buf, len, checkSum)) { indexError("index file is corrupted"); // verify fst @@ -975,11 +975,11 @@ Fst* fstCreate(FstSlice* slice) { } CompiledAddr rootAddr; len -= sizeof(rootAddr); - taosDecodeFixedU64(buf + len, &rootAddr); + (void)taosDecodeFixedU64(buf + len, &rootAddr); uint64_t fstLen; len -= sizeof(fstLen); - taosDecodeFixedU64(buf + len, &fstLen); + (void)taosDecodeFixedU64(buf + len, &fstLen); // TODO(validate root addr) Fst* fst = (Fst*)taosMemoryCalloc(1, sizeof(Fst)); if (fst == NULL) { @@ -1001,7 +1001,7 @@ Fst* fstCreate(FstSlice* slice) { *s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice) - 1); fst->data = s; - taosThreadMutexInit(&fst->mtx, NULL); + (void)taosThreadMutexInit(&fst->mtx, NULL); return fst; FST_CREAT_FAILED: @@ -1015,7 +1015,7 @@ void fstDestroy(Fst* fst) { taosMemoryFree(fst->meta); fstSliceDestroy(fst->data); taosMemoryFree(fst->data); - taosThreadMutexDestroy(&fst->mtx); + (void)taosThreadMutexDestroy(&fst->mtx); } taosMemoryFree(fst); } @@ -1029,7 +1029,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) { uint8_t* data = fstSliceData(b, &len); SArray* nodes = (SArray*)taosArrayInit(len, sizeof(FstNode*)); - taosArrayPush(nodes, &root); + (void)taosArrayPush(nodes, &root); for (uint32_t i = 0; i < len; i++) { uint8_t inp = data[i]; Output res = 0; @@ -1038,10 +1038,10 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) { } FstTransition trn; - fstNodeGetTransitionAt(root, res, &trn); + (void)fstNodeGetTransitionAt(root, res, &trn); tOut += trn.out; root = fstGetNode(fst, trn.addr); - taosArrayPush(nodes, &root); + (void)taosArrayPush(nodes, &root); } if (!FST_NODE_IS_FINAL(root)) { goto _return; @@ -1163,7 +1163,7 @@ FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBo sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState)); sws->endAt = max; - stmStSeekMin(sws, min); + (void)stmStSeekMin(sws, min); return sws; } @@ -1188,7 +1188,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { .trans = 0, .out = {.null = false, .out = 0}, .autState = automFuncs[aut->type].start(aut)}; // auto.start callback - taosArrayPush(sws->stack, &s); + (void)taosArrayPush(sws->stack, &s); return true; } FstSlice* key = NULL; @@ -1214,15 +1214,15 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { uint64_t res = 0; if (fstNodeFindInput(node, b, &res)) { FstTransition trn; - fstNodeGetTransitionAt(node, res, &trn); + (void)fstNodeGetTransitionAt(node, res, &trn); void* preState = autState; autState = automFuncs[aut->type].accept(aut, preState, b); - taosArrayPush(sws->inp, &b); + (void)taosArrayPush(sws->inp, &b); FstStreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState}; node = NULL; - taosArrayPush(sws->stack, &s); + (void)taosArrayPush(sws->stack, &s); out += trn.out; node = fstGetNode(sws->fst, trn.addr); } else { @@ -1241,7 +1241,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { } FstStreamState s = {.node = node, .trans = i, .out = {.null = false, .out = out}, .autState = autState}; - taosArrayPush(sws->stack, &s); + (void)taosArrayPush(sws->stack, &s); taosMemoryFree(trans); return true; } @@ -1254,15 +1254,15 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { FstStreamState* s = taosArrayGet(sws->stack, sz - 1); if (inclusize) { s->trans -= 1; - taosArrayPop(sws->inp); + (void)taosArrayPop(sws->inp); } else { FstNode* n = s->node; uint64_t trans = s->trans; FstTransition trn; - fstNodeGetTransitionAt(n, trans - 1, &trn); + (void)fstNodeGetTransitionAt(n, trans - 1, &trn); FstStreamState s = { .node = fstGetNode(sws->fst, trn.addr), .trans = 0, .out = {.null = false, .out = out}, .autState = autState}; - taosArrayPush(sws->stack, &s); + (void)taosArrayPush(sws->stack, &s); return true; } return false; @@ -1291,13 +1291,13 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { FstStreamState* p = (FstStreamState*)taosArrayPop(sws->stack); if (p->trans >= FST_NODE_LEN(p->node) || !automFuncs[aut->type].canMatch(aut, p->autState)) { if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { - taosArrayPop(sws->inp); + (void)taosArrayPop(sws->inp); } fstStreamStateDestroy(p); continue; } FstTransition trn; - fstNodeGetTransitionAt(p->node, p->trans, &trn); + (void)fstNodeGetTransitionAt(p->node, p->trans, &trn); Output out = p->out.out + trn.out; void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp); @@ -1305,8 +1305,8 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { bool isMatch = automFuncs[aut->type].isMatch(aut, nextState); FstNode* nextNode = fstGetNode(sws->fst, trn.addr); - taosArrayPush(nodes, &nextNode); - taosArrayPush(sws->inp, &(trn.inp)); + (void)taosArrayPush(nodes, &nextNode); + (void)taosArrayPush(sws->inp, &(trn.inp)); if (FST_NODE_IS_FINAL(nextNode)) { void* eofState = automFuncs[aut->type].acceptEof(aut, nextState); @@ -1315,10 +1315,10 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { } } FstStreamState s1 = {.node = p->node, .trans = p->trans + 1, .out = p->out, .autState = p->autState}; - taosArrayPush(sws->stack, &s1); + (void)taosArrayPush(sws->stack, &s1); FstStreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState}; - taosArrayPush(sws->stack, &s2); + (void)taosArrayPush(sws->stack, &s2); int32_t isz = taosArrayGetSize(sws->inp); uint8_t* buf = (uint8_t*)taosMemoryMalloc(isz * sizeof(uint8_t)); diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c index a3e26d8518..f552d5feba 100644 --- a/source/libs/index/src/indexFstDfa.c +++ b/source/libs/index/src/indexFstDfa.c @@ -74,7 +74,7 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) { uint32_t result; SArray *states = taosArrayInit(0, sizeof(uint32_t)); if (dfaBuilderCacheState(builder, cur, &result)) { - taosArrayPush(states, &result); + (void)taosArrayPush(states, &result); } SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); while (taosArrayGetSize(states) != 0) { @@ -83,8 +83,8 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) { uint32_t ns, dummpy = 0; if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) { if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) { - taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)); - taosArrayPush(states, &ns); + (void)taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)); + (void)taosArrayPush(states, &ns); } } if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) { @@ -108,7 +108,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet bool succ = sparSetAdd(cur, ip, NULL); if (succ == false) return false; } - dfaRun(builder->dfa, cur, next, byte); + (void)dfaRun(builder->dfa, cur, next, byte); t = taosArrayGet(builder->dfa->states, state); @@ -133,10 +133,10 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r if (inst->ty == JUMP || inst->ty == SPLIT) { continue; } else if (inst->ty == RANGE) { - taosArrayPush(tinsts, &ip); + (void)taosArrayPush(tinsts, &ip); } else if (inst->ty == MATCH) { isMatch = true; - taosArrayPush(tinsts, &ip); + (void)taosArrayPush(tinsts, &ip); } } if (taosArrayGetSize(tinsts) == 0) { @@ -149,10 +149,10 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r taosArrayDestroy(tinsts); } else { DfaState st = {.insts = tinsts, .isMatch = isMatch}; - taosArrayPush(builder->dfa->states, &st); + (void)taosArrayPush(builder->dfa->states, &st); int32_t sz = taosArrayGetSize(builder->dfa->states) - 1; - taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz)); + (void)taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz)); *result = sz; } return true; @@ -187,7 +187,7 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { if (sparSetContains(set, ip)) { return; } - bool succ = sparSetAdd(set, ip, NULL); + bool succ = sparSetAdd(set, ip, NULL); Inst *inst = taosArrayGet(dfa->insts, ip); if (inst->ty == MATCH || inst->ty == RANGE) { // do nothing diff --git a/source/libs/index/src/indexFstFile.c b/source/libs/index/src/indexFstFile.c index d86b3d476f..69fee8d29d 100644 --- a/source/libs/index/src/indexFstFile.c +++ b/source/libs/index/src/indexFstFile.c @@ -38,7 +38,7 @@ static FORCE_INLINE void idxGenLRUKey(char* buf, const char* path, int32_t block char* p = buf; SERIALIZE_STR_VAR_TO_BUF(p, path, strlen(path)); SERIALIZE_VAR_TO_BUF(p, '_', char); - idxInt2str(blockId, p, 0); + (void)idxInt2str(blockId, p, 0); return; } static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) { @@ -48,7 +48,7 @@ static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) if (len + ctx->file.wBufOffset >= cap) { int32_t nw = cap - ctx->file.wBufOffset; memcpy(ctx->file.wBuf + ctx->file.wBufOffset, buf, nw); - taosWriteFile(ctx->file.pFile, ctx->file.wBuf, cap); + (void)taosWriteFile(ctx->file.pFile, ctx->file.wBuf, cap); memset(ctx->file.wBuf, 0, cap); ctx->file.wBufOffset = 0; @@ -58,7 +58,7 @@ static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) nw = (len / cap) * cap; if (nw != 0) { - taosWriteFile(ctx->file.pFile, buf, nw); + (void)taosWriteFile(ctx->file.pFile, buf, nw); } len -= nw; @@ -112,7 +112,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of SDataBlock* blk = taosLRUCacheValue(ctx->lru, h); nread = TMIN(blkLeft, len); memcpy(buf + total, blk->buf + blkOffset, nread); - taosLRUCacheRelease(ctx->lru, h, false); + (void)taosLRUCacheRelease(ctx->lru, h, false); } else { int32_t left = ctx->file.size - offset; if (left < kBlockSize) { @@ -162,7 +162,7 @@ static FORCE_INLINE int idxFileCtxGetSize(IFileCtx* ctx) { return ctx->offset; } else { int64_t file_size = 0; - taosStatFile(ctx->file.buf, &file_size, NULL, NULL); + (void)taosStatFile(ctx->file.buf, &file_size, NULL, NULL); return (int)file_size; } } @@ -250,16 +250,16 @@ void idxFileCtxDestroy(IFileCtx* ctx, bool remove) { int32_t nw = taosWriteFile(ctx->file.pFile, ctx->file.wBuf, ctx->file.wBufOffset); ctx->file.wBufOffset = 0; } - ctx->flush(ctx); + (void)(ctx->flush(ctx)); taosMemoryFreeClear(ctx->file.wBuf); - taosCloseFile(&ctx->file.pFile); + (void)taosCloseFile(&ctx->file.pFile); if (ctx->file.readOnly) { #ifdef USE_MMAP munmap(ctx->file.ptr, ctx->file.size); #endif } if (remove) { - unlink(ctx->file.buf); + (void)unlink(ctx->file.buf); } } taosMemoryFree(ctx); @@ -275,7 +275,7 @@ IdxFstFile* idxFileCreate(void* wrt) { return cw; } void idxFileDestroy(IdxFstFile* cw) { - idxFileFlush(cw); + (void)idxFileFlush(cw); taosMemoryFree(cw); } @@ -314,7 +314,7 @@ uint32_t idxFileMaskedCheckSum(IdxFstFile* write) { int idxFileFlush(IdxFstFile* write) { IFileCtx* ctx = write->wrt; - ctx->flush(ctx); + (void)(ctx->flush(ctx)); return 1; } @@ -324,7 +324,7 @@ void idxFilePackUintIn(IdxFstFile* writer, uint64_t n, uint8_t nBytes) { buf[i] = (uint8_t)n; n = n >> 8; } - idxFileWrite(writer, buf, nBytes); + (void)idxFileWrite(writer, buf, nBytes); taosMemoryFree(buf); return; } diff --git a/source/libs/index/src/indexFstNode.c b/source/libs/index/src/indexFstNode.c index 7185e44f46..b934cb0536 100644 --- a/source/libs/index/src/indexFstNode.c +++ b/source/libs/index/src/indexFstNode.c @@ -68,7 +68,7 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { for (size_t i = 0; i < sz; i++) { FstTransition* tran = taosArrayGet(src->trans, i); - taosArrayPush(trans, tran); + (void)taosArrayPush(trans, tran); } node->trans = trans; @@ -91,7 +91,7 @@ void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { dst->trans = taosArrayInit(sz, sizeof(FstTransition)); for (size_t i = 0; i < sz; i++) { FstTransition* trn = taosArrayGet(src->trans, i); - taosArrayPush(dst->trans, trn); + (void)taosArrayPush(dst->trans, trn); } } diff --git a/source/libs/index/src/indexFstRegex.c b/source/libs/index/src/indexFstRegex.c index 7af4b17e79..c6ceb1d965 100644 --- a/source/libs/index/src/indexFstRegex.c +++ b/source/libs/index/src/indexFstRegex.c @@ -24,12 +24,22 @@ FstRegex *regexCreate(const char *str) { } regex->orig = taosStrdup(str); + if (regex->orig == NULL) { + taosMemoryFree(regex); + return NULL; + } // construct insts based on str SArray *insts = taosArrayInit(256, sizeof(uint8_t)); + if (insts == NULL) { + taosMemoryFree(regex->orig); + taosMemoryFree(regex); + return NULL; + } + for (int i = 0; i < strlen(str); i++) { uint8_t v = str[i]; - taosArrayPush(insts, &v); + (void)taosArrayPush(insts, &v); } FstDfaBuilder *builder = dfaBuilderCreate(insts); regex->dfa = dfaBuilderBuild(builder); diff --git a/source/libs/index/src/indexFstRegister.c b/source/libs/index/src/indexFstRegister.c index adafecccb1..e27ab939b3 100644 --- a/source/libs/index/src/indexFstRegister.c +++ b/source/libs/index/src/indexFstRegister.c @@ -83,7 +83,7 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { for (uint64_t i = 0; i < nCells; i++) { FstRegistryCell cell = {.addr = NONE_ADDRESS, .node = fstBuilderNodeDefault()}; - taosArrayPush(tb, &cell); + (void)taosArrayPush(tb, &cell); } registry->table = tb; diff --git a/source/libs/index/src/indexFstUtil.c b/source/libs/index/src/indexFstUtil.c index f1e8808cf5..92cece3890 100644 --- a/source/libs/index/src/indexFstUtil.c +++ b/source/libs/index/src/indexFstUtil.c @@ -81,7 +81,7 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) { str->len = len; str->data = taosMemoryMalloc(len * sizeof(uint8_t)); - if (data != NULL) { + if (data != NULL && str->data != NULL) { memcpy(str->data, data, len); } @@ -91,7 +91,7 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) { // just shallow copy FstSlice fstSliceCopy(FstSlice* s, int32_t start, int32_t end) { FstString* str = s->str; - atomic_add_fetch_32(&str->ref, 1); + (void)atomic_add_fetch_32(&str->ref, 1); FstSlice t = {.str = str, .start = start + s->start, .end = end + s->start}; return t; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index d0166ae2e5..99c7b6bc76 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -125,7 +125,7 @@ TFileCache* tfileCacheCreate(SIndex* idx, const char* path) { char buf[128] = {0}; int32_t sz = idxSerialCacheKey(&key, buf); - taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); + (void)taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); tfileReaderRef(reader); } taosArrayDestroyEx(files, tfileDestroyFileName); @@ -172,7 +172,7 @@ int32_t tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) { TFileReader** p = taosHashGet(tcache->tableCache, buf, sz); if (p != NULL && *p != NULL) { TFileReader* oldRdr = *p; - taosHashRemove(tcache->tableCache, buf, sz); + (void)taosHashRemove(tcache->tableCache, buf, sz); indexInfo("found %s, should remove file %s", buf, oldRdr->ctx->file.buf); oldRdr->remove = true; tfileReaderUnRef(oldRdr); @@ -265,7 +265,7 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { FStmSt* st = stmBuilderIntoStm(sb); FStmStRslt* rt = NULL; while ((rt = stmStNextWith(st, NULL)) != NULL) { - taosArrayPush(offsets, &(rt->out.out)); + (void)taosArrayPush(offsets, &(rt->out.out)); swsResultDestroy(rt); } stmStDestroy(st); @@ -337,7 +337,7 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, TExeCond cond = cmpFn(ch, p, tem->colType); if (MATCH == cond) { - tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); + (void)tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); } else if (CONTINUE == cond) { } else if (BREAK == cond) { swsResultDestroy(rt); @@ -474,7 +474,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt taosMemoryFree(tBuf); } if (MATCH == cond) { - tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); + (void)tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); } else if (CONTINUE == cond) { } else if (BREAK == cond) { swsResultDestroy(rt); @@ -552,7 +552,7 @@ int32_t tfileWriterCreate(IFileCtx* ctx, TFileHeader* header, TFileWriter** pWri } tw->ctx = ctx; tw->header = *header; - tfileWriteHeader(tw); + (void)tfileWriteHeader(tw); *pWriter = tw; return code; @@ -571,7 +571,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { } else { fn = getComparFunc(colType, 0); } - taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); + (void)taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); } int32_t sz = taosArrayGetSize((SArray*)data); @@ -586,7 +586,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { if (tbsz == 0) continue; fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } - tfileWriteFstOffset(tw, fstOffset); + (void)tfileWriteFstOffset(tw, fstOffset); int32_t cap = 4 * 1024; char* buf = taosMemoryCalloc(1, cap); @@ -614,7 +614,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); - tw->ctx->write(tw->ctx, buf, ttsz); + (void)(tw->ctx->write(tw->ctx, buf, ttsz)); v->offset = tw->offset; tw->offset += ttsz; memset(buf, 0, cap); @@ -642,7 +642,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { } } fstBuilderDestroy(tw->fb); - tfileWriteFooter(tw); + (void)tfileWriteFooter(tw); return 0; } void tfileWriterClose(TFileWriter* tw) { @@ -671,7 +671,7 @@ IndexTFile* idxTFileCreate(SIndex* idx, const char* path) { tfileCacheDestroy(cache); return NULL; } - taosThreadMutexInit(&tfile->mtx, NULL); + (void)taosThreadMutexInit(&tfile->mtx, NULL); tfile->cache = cache; return tfile; } @@ -679,7 +679,7 @@ void idxTFileDestroy(IndexTFile* tfile) { if (tfile == NULL) { return; } - taosThreadMutexDestroy(&tfile->mtx); + (void)taosThreadMutexDestroy(&tfile->mtx); tfileCacheDestroy(tfile->cache); taosMemoryFree(tfile); } @@ -696,9 +696,9 @@ int idxTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* result) { SIndexTerm* term = query->term; ICacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; - taosThreadMutexLock(&pTfile->mtx); + (void)taosThreadMutexLock(&pTfile->mtx); TFileReader* reader = tfileCacheGet(pTfile->cache, &key); - taosThreadMutexUnlock(&pTfile->mtx); + (void)taosThreadMutexUnlock(&pTfile->mtx); if (reader == NULL) { return 0; } @@ -802,9 +802,9 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { TFileReader* rd = NULL; ICacheKey key = {.suid = suid, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; - taosThreadMutexLock(&tf->mtx); + (void)taosThreadMutexLock(&tf->mtx); rd = tfileCacheGet(tf->cache, &key); - taosThreadMutexUnlock(&tf->mtx); + (void)taosThreadMutexUnlock(&tf->mtx); return rd; } @@ -838,7 +838,7 @@ int tfileValuePush(TFileValue* tf, uint64_t val) { if (tf == NULL) { return -1; } - taosArrayPush(tf->tableId, &val); + (void)taosArrayPush(tf->tableId, &val); return 0; } void tfileValueDestroy(TFileValue* tf) { @@ -897,7 +897,7 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) { static int tfileWriteFooter(TFileWriter* write) { char buf[sizeof(FILE_MAGIC_NUMBER) + 1] = {0}; void* pBuf = (void*)buf; - taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER); + (void)taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER); int nwrite = write->ctx->write(write->ctx, buf, (int32_t)strlen(buf)); indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx)); @@ -964,7 +964,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* while (nid > 0) { int32_t left = block + sizeof(block) - p; if (left >= sizeof(uint64_t)) { - taosArrayPush(result, (uint64_t*)p); + (void)taosArrayPush(result, (uint64_t*)p); p += sizeof(uint64_t); } else { char buf[sizeof(uint64_t)] = {0}; @@ -975,7 +975,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* nread = ctx->readFrom(ctx, block, sizeof(block), offset); memcpy(buf + left, block, sizeof(uint64_t) - left); - taosArrayPush(result, (uint64_t*)buf); + (void)taosArrayPush(result, (uint64_t*)buf); p = block + sizeof(uint64_t) - left; } nid -= 1; @@ -996,7 +996,7 @@ static int tfileReaderVerify(TFileReader* reader) { return -1; } - taosDecodeFixedU64(buf, &tMagicNumber); + (void)taosDecodeFixedU64(buf, &tMagicNumber); return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : -1; } @@ -1040,12 +1040,12 @@ static SArray* tfileGetFileList(const char* path) { size_t len = strlen(path) + 1 + strlen(file) + 1; char* buf = taosMemoryCalloc(1, len); sprintf(buf, "%s/%s", path, file); - taosArrayPush(files, &buf); + (void)taosArrayPush(files, &buf); } - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); taosArraySort(files, tfileCompare); - tfileRmExpireFile(files); + (void)tfileRmExpireFile(files); return files; } diff --git a/source/libs/index/src/indexUtil.c b/source/libs/index/src/indexUtil.c index f89944204d..0776e71180 100644 --- a/source/libs/index/src/indexUtil.c +++ b/source/libs/index/src/indexUtil.c @@ -64,7 +64,7 @@ void iIntersection(SArray *in, SArray *out) { } } if (has == true) { - taosArrayPush(out, &tgt); + (void)taosArrayPush(out, &tgt); } } taosMemoryFreeClear(mi); @@ -75,7 +75,7 @@ void iUnion(SArray *in, SArray *out) { return; } if (sz == 1) { - taosArrayAddAll(out, taosArrayGetP(in, 0)); + (void)taosArrayAddAll(out, taosArrayGetP(in, 0)); return; } @@ -108,7 +108,7 @@ void iUnion(SArray *in, SArray *out) { continue; } } - taosArrayPush(out, &mVal); + (void)taosArrayPush(out, &mVal); } else { break; } @@ -198,11 +198,11 @@ void idxTRsltMergeTo(SIdxTRslt *tr, SArray *result) { if (taosArrayGetSize(tr->total) == 0 || taosArrayGetSize(tr->add) == 0) { SArray *t = taosArrayGetSize(tr->total) == 0 ? tr->add : tr->total; - taosArrayAddAll(result, t); + (void)taosArrayAddAll(result, t); } else { SArray *arrs = taosArrayInit(2, sizeof(void *)); - taosArrayPush(arrs, &tr->total); - taosArrayPush(arrs, &tr->add); + (void)taosArrayPush(arrs, &tr->total); + (void)taosArrayPush(arrs, &tr->add); iUnion(arrs, result); taosArrayDestroy(arrs); } diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index 488b4d1d58..d5fc1b4c65 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -100,7 +100,7 @@ extern char* tsMonFwUri; #define VNODE_ROLE "taosd_vnodes_info:role" void monInitMonitorFW(){ - taos_collector_registry_default_init(); + (void)taos_collector_registry_default_init(); tsMonitor.metrics = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); taos_gauge_t *gauge = NULL; @@ -115,9 +115,9 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 25; i++){ gauge= taos_gauge_new(dnodes_gauges[i], "", dnodes_label_count, dnodes_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, dnodes_gauges[i], strlen(dnodes_gauges[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, dnodes_gauges[i], strlen(dnodes_gauges[i]), &gauge, sizeof(taos_gauge_t *)); } int32_t dnodes_data_label_count = 5; @@ -126,9 +126,10 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 3; i++){ gauge= taos_gauge_new(dnodes_data_gauges[i], "", dnodes_data_label_count, dnodes_data_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, dnodes_data_gauges[i], strlen(dnodes_data_gauges[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, dnodes_data_gauges[i], strlen(dnodes_data_gauges[i]), &gauge, + sizeof(taos_gauge_t *)); } int32_t dnodes_log_label_count = 4; @@ -137,15 +138,16 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 3; i++){ gauge= taos_gauge_new(dnodes_log_gauges[i], "", dnodes_log_label_count, dnodes_log_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, dnodes_log_gauges[i], strlen(dnodes_log_gauges[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, dnodes_log_gauges[i], strlen(dnodes_log_gauges[i]), &gauge, + sizeof(taos_gauge_t *)); } } void monCleanupMonitorFW(){ taosHashCleanup(tsMonitor.metrics); - taos_collector_registry_destroy(TAOS_COLLECTOR_REGISTRY_DEFAULT); + (void)taos_collector_registry_destroy(TAOS_COLLECTOR_REGISTRY_DEFAULT); TAOS_COLLECTOR_REGISTRY_DEFAULT = NULL; } @@ -165,7 +167,7 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", metric_names[i]); } - taosHashRemove(tsMonitor.metrics, metric_names[i], strlen(metric_names[i])); + (void)taosHashRemove(tsMonitor.metrics, metric_names[i], strlen(metric_names[i])); } if(pBasicInfo->cluster_id == 0) { @@ -182,9 +184,9 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 18; i++){ gauge= taos_gauge_new(metric_names[i], "", label_count, sample_labels1); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, metric_names[i], strlen(metric_names[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, metric_names[i], strlen(metric_names[i]), &gauge, sizeof(taos_gauge_t *)); } char buf[TSDB_CLUSTER_ID_LEN] = {0}; @@ -194,37 +196,37 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ taos_gauge_t **metric = NULL; metric = taosHashGet(tsMonitor.metrics, MASTER_UPTIME, strlen(MASTER_UPTIME)); - taos_gauge_set(*metric, pInfo->master_uptime, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->master_uptime, sample_label_values); metric = taosHashGet(tsMonitor.metrics, DBS_TOTAL, strlen(DBS_TOTAL)); - taos_gauge_set(*metric, pInfo->dbs_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->dbs_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, TBS_TOTAL, strlen(TBS_TOTAL)); - taos_gauge_set(*metric, pInfo->tbs_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->tbs_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, STBS_TOTAL, strlen(STBS_TOTAL)); - taos_gauge_set(*metric, pInfo->stbs_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->stbs_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, VGROUPS_TOTAL, strlen(VGROUPS_TOTAL)); - taos_gauge_set(*metric, pInfo->vgroups_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->vgroups_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, VGROUPS_ALIVE, strlen(VGROUPS_ALIVE)); - taos_gauge_set(*metric, pInfo->vgroups_alive, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->vgroups_alive, sample_label_values); metric = taosHashGet(tsMonitor.metrics, VNODES_TOTAL, strlen(VNODES_TOTAL)); - taos_gauge_set(*metric, pInfo->vnodes_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->vnodes_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, VNODES_ALIVE, strlen(VNODES_ALIVE)); - taos_gauge_set(*metric, pInfo->vnodes_alive, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->vnodes_alive, sample_label_values); metric = taosHashGet(tsMonitor.metrics, CONNECTIONS_TOTAL, strlen(CONNECTIONS_TOTAL)); - taos_gauge_set(*metric, pInfo->connections_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->connections_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, TOPICS_TOTAL, strlen(TOPICS_TOTAL)); - taos_gauge_set(*metric, pInfo->topics_toal, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->topics_toal, sample_label_values); metric = taosHashGet(tsMonitor.metrics, STREAMS_TOTAL, strlen(STREAMS_TOTAL)); - taos_gauge_set(*metric, pInfo->streams_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->streams_total, sample_label_values); //dnodes number int32_t dnode_total = taosArrayGetSize(pInfo->dnodes); @@ -239,10 +241,10 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ } metric = taosHashGet(tsMonitor.metrics, DNODES_TOTAL, strlen(DNODES_TOTAL)); - taos_gauge_set(*metric, dnode_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, dnode_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, DNODES_ALIVE, strlen(DNODES_ALIVE)); - taos_gauge_set(*metric, dnode_alive, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, dnode_alive, sample_label_values); //mnodes number int32_t mnode_total = taosArrayGetSize(pInfo->mnodes); @@ -271,20 +273,20 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ } metric = taosHashGet(tsMonitor.metrics, MNODES_TOTAL, strlen(MNODES_TOTAL)); - taos_gauge_set(*metric, mnode_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, mnode_total, sample_label_values); metric = taosHashGet(tsMonitor.metrics, MNODES_ALIVE, strlen(MNODES_ALIVE)); - taos_gauge_set(*metric, mnode_alive, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, mnode_alive, sample_label_values); //grant info metric = taosHashGet(tsMonitor.metrics, EXPIRE_TIME, strlen(EXPIRE_TIME)); - taos_gauge_set(*metric, pGrantInfo->expire_time, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pGrantInfo->expire_time, sample_label_values); metric = taosHashGet(tsMonitor.metrics, TIMESERIES_USED, strlen(TIMESERIES_USED)); - taos_gauge_set(*metric, pGrantInfo->timeseries_used, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pGrantInfo->timeseries_used, sample_label_values); metric = taosHashGet(tsMonitor.metrics, TIMESERIES_TOTAL, strlen(TIMESERIES_TOTAL)); - taos_gauge_set(*metric, pGrantInfo->timeseries_total, sample_label_values); + if (metric != NULL) (void)taos_gauge_set(*metric, pGrantInfo->timeseries_total, sample_label_values); } void monGenVgroupInfoTable(SMonInfo *pMonitor){ @@ -306,11 +308,11 @@ void monGenVgroupInfoTable(SMonInfo *pMonitor){ const char *vgroup_sample_labels[] = {"cluster_id", "vgroup_id", "database_name"}; taos_gauge_t *tableNumGauge = taos_gauge_new(TABLES_NUM, "", vgroup_label_count, vgroup_sample_labels); if(taos_collector_registry_register_metric(tableNumGauge) == 1){ - taos_counter_destroy(tableNumGauge); + (void)taos_counter_destroy(tableNumGauge); } taos_gauge_t *statusGauge = taos_gauge_new(STATUS, "", vgroup_label_count, vgroup_sample_labels); if(taos_collector_registry_register_metric(statusGauge) == 1){ - taos_counter_destroy(statusGauge); + (void)taos_counter_destroy(statusGauge); } char cluster_id[TSDB_CLUSTER_ID_LEN] = {0}; @@ -325,14 +327,14 @@ void monGenVgroupInfoTable(SMonInfo *pMonitor){ const char *sample_labels[] = {cluster_id, vgroup_id, pVgroupDesc->database_name}; taos_gauge_t **metric = NULL; - - taos_gauge_set(tableNumGauge, pVgroupDesc->tables_num, sample_labels); + + if (tableNumGauge != NULL) (void)taos_gauge_set(tableNumGauge, pVgroupDesc->tables_num, sample_labels); int32_t status = 0; if(strcmp(pVgroupDesc->status, "ready") == 0){ status = 1; } - taos_gauge_set(statusGauge, status, sample_labels); + if (statusGauge != NULL) (void)taos_gauge_set(statusGauge, status, sample_labels); } } @@ -401,70 +403,70 @@ void monGenDnodeInfoTable(SMonInfo *pMonitor) { double io_write_disk_rate = io_write_disk / interval; metric = taosHashGet(tsMonitor.metrics, UPTIME, strlen(UPTIME)); - taos_gauge_set(*metric, pInfo->uptime, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->uptime, sample_labels); metric = taosHashGet(tsMonitor.metrics, CPU_ENGINE, strlen(CPU_ENGINE)); - taos_gauge_set(*metric, cpu_engine, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, cpu_engine, sample_labels); metric = taosHashGet(tsMonitor.metrics, CPU_SYSTEM, strlen(CPU_SYSTEM)); - taos_gauge_set(*metric, pSys->cpu_system, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->cpu_system, sample_labels); metric = taosHashGet(tsMonitor.metrics, CPU_CORE, strlen(CPU_CORE)); - taos_gauge_set(*metric, pSys->cpu_cores, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->cpu_cores, sample_labels); metric = taosHashGet(tsMonitor.metrics, MEM_ENGINE, strlen(MEM_ENGINE)); - taos_gauge_set(*metric, mem_engine, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, mem_engine, sample_labels); metric = taosHashGet(tsMonitor.metrics, MEM_SYSTEM, strlen(MEM_SYSTEM)); - taos_gauge_set(*metric, pSys->mem_system, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->mem_system, sample_labels); metric = taosHashGet(tsMonitor.metrics, MEM_TOTAL, strlen(MEM_TOTAL)); - taos_gauge_set(*metric, pSys->mem_total, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->mem_total, sample_labels); metric = taosHashGet(tsMonitor.metrics, DISK_ENGINE, strlen(DISK_ENGINE)); - taos_gauge_set(*metric, pSys->disk_engine, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->disk_engine, sample_labels); metric = taosHashGet(tsMonitor.metrics, DISK_USED, strlen(DISK_USED)); - taos_gauge_set(*metric, pSys->disk_used, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->disk_used, sample_labels); metric = taosHashGet(tsMonitor.metrics, DISK_TOTAL, strlen(DISK_TOTAL)); - taos_gauge_set(*metric, pSys->disk_total, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pSys->disk_total, sample_labels); metric = taosHashGet(tsMonitor.metrics, NET_IN, strlen(NET_IN)); - taos_gauge_set(*metric, net_in_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, net_in_rate, sample_labels); metric = taosHashGet(tsMonitor.metrics, NET_OUT, strlen(NET_OUT)); - taos_gauge_set(*metric, net_out_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, net_out_rate, sample_labels); metric = taosHashGet(tsMonitor.metrics, IO_READ, strlen(IO_READ)); - taos_gauge_set(*metric, io_read_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, io_read_rate, sample_labels); metric = taosHashGet(tsMonitor.metrics, IO_WRITE, strlen(IO_WRITE)); - taos_gauge_set(*metric, io_write_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, io_write_rate, sample_labels); metric = taosHashGet(tsMonitor.metrics, IO_READ_DISK, strlen(IO_READ_DISK)); - taos_gauge_set(*metric, io_read_disk_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, io_read_disk_rate, sample_labels); metric = taosHashGet(tsMonitor.metrics, IO_WRITE_DISK, strlen(IO_WRITE_DISK)); - taos_gauge_set(*metric, io_write_disk_rate, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, io_write_disk_rate, sample_labels); - //metric = taosHashGet(tsMonitor.metrics, ERRORS, strlen(ERRORS)); - //taos_gauge_set(*metric, pStat->errors, sample_labels); + // metric = taosHashGet(tsMonitor.metrics, ERRORS, strlen(ERRORS)); + // if(metric != NULL) (void)taos_gauge_set(*metric, pStat->errors, sample_labels); metric = taosHashGet(tsMonitor.metrics, VNODES_NUM, strlen(VNODES_NUM)); - taos_gauge_set(*metric, pStat->totalVnodes, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pStat->totalVnodes, sample_labels); metric = taosHashGet(tsMonitor.metrics, MASTERS, strlen(MASTERS)); - taos_gauge_set(*metric, pStat->masterNum, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pStat->masterNum, sample_labels); metric = taosHashGet(tsMonitor.metrics, HAS_MNODE, strlen(HAS_MNODE)); - taos_gauge_set(*metric, pInfo->has_mnode, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->has_mnode, sample_labels); metric = taosHashGet(tsMonitor.metrics, HAS_QNODE, strlen(HAS_QNODE)); - taos_gauge_set(*metric, pInfo->has_qnode, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->has_qnode, sample_labels); metric = taosHashGet(tsMonitor.metrics, HAS_SNODE, strlen(HAS_SNODE)); - taos_gauge_set(*metric, pInfo->has_snode, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pInfo->has_snode, sample_labels); //log number SMonLogs *logs[6]; @@ -489,16 +491,16 @@ void monGenDnodeInfoTable(SMonInfo *pMonitor) { } metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_ERROR, strlen(DNODE_LOG_ERROR)); - taos_gauge_set(*metric, numOfErrorLogs, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, numOfErrorLogs, sample_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_INFO, strlen(DNODE_LOG_INFO)); - taos_gauge_set(*metric, numOfInfoLogs, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, numOfInfoLogs, sample_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_DEBUG, strlen(DNODE_LOG_DEBUG)); - taos_gauge_set(*metric, numOfDebugLogs, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, numOfDebugLogs, sample_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_TRACE, strlen(DNODE_LOG_TRACE)); - taos_gauge_set(*metric, numOfTraceLogs, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, numOfTraceLogs, sample_labels); } void monGenDnodeStatusInfoTable(SMonInfo *pMonitor){ @@ -519,7 +521,7 @@ void monGenDnodeStatusInfoTable(SMonInfo *pMonitor){ gauge= taos_gauge_new(DNODE_STATUS, "", dnodes_label_count, dnodes_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } char cluster_id[TSDB_CLUSTER_ID_LEN]; @@ -541,7 +543,7 @@ void monGenDnodeStatusInfoTable(SMonInfo *pMonitor){ if(strcmp(pDnodeDesc->status, "ready") == 0){ status = 1; } - taos_gauge_set(gauge, status, sample_labels); + if (gauge != NULL) (void)taos_gauge_set(gauge, status, sample_labels); } } @@ -567,13 +569,13 @@ void monGenDataDiskTable(SMonInfo *pMonitor){ const char *sample_labels[] = {cluster_id, dnode_id, pMonitor->dmInfo.basic.dnode_ep, pDatadirDesc->name, level}; metric = taosHashGet(tsMonitor.metrics, DNODE_DATA_AVAIL, strlen(DNODE_DATA_AVAIL)); - taos_gauge_set(*metric, pDatadirDesc->size.avail, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pDatadirDesc->size.avail, sample_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_DATA_USED, strlen(DNODE_DATA_USED)); - taos_gauge_set(*metric, pDatadirDesc->size.used, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pDatadirDesc->size.used, sample_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_DATA_TOTAL, strlen(DNODE_DATA_TOTAL)); - taos_gauge_set(*metric, pDatadirDesc->size.total, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pDatadirDesc->size.total, sample_labels); } } @@ -594,24 +596,24 @@ void monGenLogDiskTable(SMonInfo *pMonitor){ const char *sample_log_labels[] = {cluster_id, dnode_id, pMonitor->dmInfo.basic.dnode_ep, pLogDesc->name}; metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_AVAIL, strlen(DNODE_LOG_AVAIL)); - taos_gauge_set(*metric, pLogDesc->size.avail, sample_log_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pLogDesc->size.avail, sample_log_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_USED, strlen(DNODE_LOG_USED)); - taos_gauge_set(*metric, pLogDesc->size.used, sample_log_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pLogDesc->size.used, sample_log_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_TOTAL, strlen(DNODE_LOG_TOTAL)); - taos_gauge_set(*metric, pLogDesc->size.total, sample_log_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pLogDesc->size.total, sample_log_labels); const char *sample_temp_labels[] = {cluster_id, dnode_id, pMonitor->dmInfo.basic.dnode_ep, pTempDesc->name}; metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_AVAIL, strlen(DNODE_LOG_AVAIL)); - taos_gauge_set(*metric, pTempDesc->size.avail, sample_temp_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pTempDesc->size.avail, sample_temp_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_USED, strlen(DNODE_LOG_USED)); - taos_gauge_set(*metric, pTempDesc->size.used, sample_temp_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pTempDesc->size.used, sample_temp_labels); metric = taosHashGet(tsMonitor.metrics, DNODE_LOG_TOTAL, strlen(DNODE_LOG_TOTAL)); - taos_gauge_set(*metric, pTempDesc->size.total, sample_temp_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pTempDesc->size.total, sample_temp_labels); } void monGenMnodeRoleTable(SMonInfo *pMonitor){ @@ -622,7 +624,7 @@ void monGenMnodeRoleTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", mnodes_role_gauges[i]); } - taosHashRemove(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i])); + (void)taosHashRemove(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i])); } SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; @@ -636,9 +638,10 @@ void monGenMnodeRoleTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 1; i++){ gauge= taos_gauge_new(mnodes_role_gauges[i], "", mnodes_role_label_count, mnodes_role_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i]), &gauge, + sizeof(taos_gauge_t *)); } char buf[TSDB_CLUSTER_ID_LEN] = {0}; @@ -669,13 +672,13 @@ void monGenMnodeRoleTable(SMonInfo *pMonitor){ metric = taosHashGet(tsMonitor.metrics, MNODE_ROLE, strlen(MNODE_ROLE)); if(dnodeIsOnline){ - taos_gauge_set(*metric, pMnodeDesc->syncState, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pMnodeDesc->syncState, sample_labels); } else{ - taos_gauge_set(*metric, 0, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, 0, sample_labels); } - //metric = taosHashGet(tsMonitor.metrics, MNODE_ROLE, strlen(MNODE_ROLE)); - //taos_gauge_set(*metric, pMnodeDesc->syncState, sample_labels); + // metric = taosHashGet(tsMonitor.metrics, MNODE_ROLE, strlen(MNODE_ROLE)); + // if(metric != NULL) (void)taos_gauge_set(*metric, pMnodeDesc->syncState, sample_labels); } } @@ -688,7 +691,7 @@ void monGenVnodeRoleTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", vnodes_role_gauges[i]); } - taosHashRemove(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i])); + (void)taosHashRemove(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i])); } SMonVgroupInfo *pInfo = &pMonitor->mmInfo.vgroup; @@ -702,9 +705,10 @@ void monGenVnodeRoleTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 1; i++){ gauge= taos_gauge_new(vnodes_role_gauges[i], "", vnodes_role_label_count, vnodes_role_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - taos_counter_destroy(gauge); + (void)taos_counter_destroy(gauge); } - taosHashPut(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i]), &gauge, sizeof(taos_gauge_t *)); + (void)taosHashPut(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i]), &gauge, + sizeof(taos_gauge_t *)); } char buf[TSDB_CLUSTER_ID_LEN] = {0}; @@ -728,7 +732,7 @@ void monGenVnodeRoleTable(SMonInfo *pMonitor){ const char *sample_labels[] = {buf, vgroup_id, pVgroupDesc->database_name, dnode_id}; metric = taosHashGet(tsMonitor.metrics, VNODE_ROLE, strlen(VNODE_ROLE)); - taos_gauge_set(*metric, pVnodeDesc->syncState, sample_labels); + if (metric != NULL) (void)taos_gauge_set(*metric, pVnodeDesc->syncState, sample_labels); } } } @@ -753,7 +757,7 @@ void monSendPromReport() { if (taosSendHttpReport(tsMonitor.cfg.server, tsMonFwUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); }else{ - taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT); + (void)taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT); } taosMemoryFreeClear(pCont); } diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 6bc3c43d0f..9669eac508 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -110,7 +110,7 @@ int32_t monInit(const SMonCfg *pCfg) { tsMonitor.cfg = *pCfg; tsLogFp = monRecordLog; tsMonitor.lastTime = taosGetTimestampMs(); - taosThreadMutexInit(&tsMonitor.lock, NULL); + (void)taosThreadMutexInit(&tsMonitor.lock, NULL); monInitMonitorFW(); @@ -126,7 +126,7 @@ void monCleanup() { tFreeSMonSmInfo(&tsMonitor.smInfo); tFreeSMonQmInfo(&tsMonitor.qmInfo); tFreeSMonBmInfo(&tsMonitor.bmInfo); - taosThreadMutexDestroy(&tsMonitor.lock); + (void)taosThreadMutexDestroy(&tsMonitor.lock); monCleanupMonitorFW(); } @@ -151,7 +151,9 @@ static SMonInfo *monCreateMonitorInfo() { return NULL; } - monGetLogs(&pMonitor->log); + if ((terrno = monGetLogs(&pMonitor->log)) != 0) { + return NULL; + } (void)taosThreadMutexLock(&tsMonitor.lock); memcpy(&pMonitor->dmInfo, &tsMonitor.dmInfo, sizeof(SMonDmInfo)); @@ -185,14 +187,14 @@ static void monGenBasicJson(SMonInfo *pMonitor) { SJson *pJson = pMonitor->pJson; char buf[40] = {0}; - taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI); + (void)taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI); - tjsonAddStringToObject(pJson, "ts", buf); - tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); - tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); + (void)tjsonAddStringToObject(pJson, "ts", buf); + (void)tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); + (void)tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); snprintf(buf, sizeof(buf), "%" PRId64, pInfo->cluster_id); - tjsonAddStringToObject(pJson, "cluster_id", buf); - tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); + (void)tjsonAddStringToObject(pJson, "cluster_id", buf); + (void)tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); } static void monGenBasicJsonBasic(SMonInfo *pMonitor) { @@ -203,12 +205,12 @@ static void monGenBasicJsonBasic(SMonInfo *pMonitor) { char buf[40] = {0}; sprintf(buf, "%" PRId64, taosGetTimestamp(TSDB_TIME_PRECISION_MILLI)); - tjsonAddStringToObject(pJson, "ts", buf); - tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); - tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); + (void)tjsonAddStringToObject(pJson, "ts", buf); + (void)tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); + (void)tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); snprintf(buf, sizeof(buf), "%" PRId64, pInfo->cluster_id); - tjsonAddStringToObject(pJson, "cluster_id", buf); - tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); + (void)tjsonAddStringToObject(pJson, "cluster_id", buf); + (void)tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); } static void monGenClusterJson(SMonInfo *pMonitor) { @@ -222,21 +224,21 @@ static void monGenClusterJson(SMonInfo *pMonitor) { return; } - tjsonAddStringToObject(pJson, "first_ep", pInfo->first_ep); - tjsonAddDoubleToObject(pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); - tjsonAddStringToObject(pJson, "version", pInfo->version); - tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime); - tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval); - tjsonAddDoubleToObject(pJson, "dbs_total", pInfo->dbs_total); - tjsonAddDoubleToObject(pJson, "tbs_total", pInfo->tbs_total); - tjsonAddDoubleToObject(pJson, "stbs_total", pInfo->stbs_total); - tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total); - tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive); - tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total); - tjsonAddDoubleToObject(pJson, "vnodes_alive", pInfo->vnodes_alive); - tjsonAddDoubleToObject(pJson, "connections_total", pInfo->connections_total); - tjsonAddDoubleToObject(pJson, "topics_total", pInfo->topics_toal); - tjsonAddDoubleToObject(pJson, "streams_total", pInfo->streams_total); + (void)tjsonAddStringToObject(pJson, "first_ep", pInfo->first_ep); + (void)tjsonAddDoubleToObject(pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); + (void)tjsonAddStringToObject(pJson, "version", pInfo->version); + (void)tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime); + (void)tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval); + (void)tjsonAddDoubleToObject(pJson, "dbs_total", pInfo->dbs_total); + (void)tjsonAddDoubleToObject(pJson, "tbs_total", pInfo->tbs_total); + (void)tjsonAddDoubleToObject(pJson, "stbs_total", pInfo->stbs_total); + (void)tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total); + (void)tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive); + (void)tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total); + (void)tjsonAddDoubleToObject(pJson, "vnodes_alive", pInfo->vnodes_alive); + (void)tjsonAddDoubleToObject(pJson, "connections_total", pInfo->connections_total); + (void)tjsonAddDoubleToObject(pJson, "topics_total", pInfo->topics_toal); + (void)tjsonAddDoubleToObject(pJson, "streams_total", pInfo->streams_total); SJson *pDnodesJson = tjsonAddArrayToObject(pJson, "dnodes"); if (pDnodesJson == NULL) return; @@ -246,9 +248,9 @@ static void monGenClusterJson(SMonInfo *pMonitor) { if (pDnodeJson == NULL) continue; SMonDnodeDesc *pDnodeDesc = taosArrayGet(pInfo->dnodes, i); - tjsonAddDoubleToObject(pDnodeJson, "dnode_id", pDnodeDesc->dnode_id); - tjsonAddStringToObject(pDnodeJson, "dnode_ep", pDnodeDesc->dnode_ep); - tjsonAddStringToObject(pDnodeJson, "status", pDnodeDesc->status); + (void)tjsonAddDoubleToObject(pDnodeJson, "dnode_id", pDnodeDesc->dnode_id); + (void)tjsonAddStringToObject(pDnodeJson, "dnode_ep", pDnodeDesc->dnode_ep); + (void)tjsonAddStringToObject(pDnodeJson, "status", pDnodeDesc->status); if (tjsonAddItemToArray(pDnodesJson, pDnodeJson) != 0) tjsonDelete(pDnodeJson); } @@ -261,9 +263,9 @@ static void monGenClusterJson(SMonInfo *pMonitor) { if (pMnodeJson == NULL) continue; SMonMnodeDesc *pMnodeDesc = taosArrayGet(pInfo->mnodes, i); - tjsonAddDoubleToObject(pMnodeJson, "mnode_id", pMnodeDesc->mnode_id); - tjsonAddStringToObject(pMnodeJson, "mnode_ep", pMnodeDesc->mnode_ep); - tjsonAddStringToObject(pMnodeJson, "role", pMnodeDesc->role); + (void)tjsonAddDoubleToObject(pMnodeJson, "mnode_id", pMnodeDesc->mnode_id); + (void)tjsonAddStringToObject(pMnodeJson, "mnode_ep", pMnodeDesc->mnode_ep); + (void)tjsonAddStringToObject(pMnodeJson, "role", pMnodeDesc->role); if (tjsonAddItemToArray(pMnodesJson, pMnodeJson) != 0) tjsonDelete(pMnodeJson); } @@ -273,11 +275,11 @@ static void monGenClusterJsonBasic(SMonInfo *pMonitor) { SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; - // tjsonAddStringToObject(pMonitor->pJson, "first_ep", pInfo->first_ep); - tjsonAddStringToObject(pMonitor->pJson, "first_ep", tsFirst); - tjsonAddDoubleToObject(pMonitor->pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); - tjsonAddStringToObject(pMonitor->pJson, "cluster_version", pInfo->version); - // tjsonAddDoubleToObject(pMonitor->pJson, "monitor_interval", pInfo->monitor_interval); + // (void)tjsonAddStringToObject(pMonitor->pJson, "first_ep", pInfo->first_ep); + (void)tjsonAddStringToObject(pMonitor->pJson, "first_ep", tsFirst); + (void)tjsonAddDoubleToObject(pMonitor->pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); + (void)tjsonAddStringToObject(pMonitor->pJson, "cluster_version", pInfo->version); + // (void)tjsonAddDoubleToObject(pMonitor->pJson, "monitor_interval", pInfo->monitor_interval); } static void monGenVgroupJson(SMonInfo *pMonitor) { @@ -296,10 +298,10 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { } SMonVgroupDesc *pVgroupDesc = taosArrayGet(pInfo->vgroups, i); - tjsonAddDoubleToObject(pVgroupJson, "vgroup_id", pVgroupDesc->vgroup_id); - tjsonAddStringToObject(pVgroupJson, "database_name", pVgroupDesc->database_name); - tjsonAddDoubleToObject(pVgroupJson, "tables_num", pVgroupDesc->tables_num); - tjsonAddStringToObject(pVgroupJson, "status", pVgroupDesc->status); + (void)tjsonAddDoubleToObject(pVgroupJson, "vgroup_id", pVgroupDesc->vgroup_id); + (void)tjsonAddStringToObject(pVgroupJson, "database_name", pVgroupDesc->database_name); + (void)tjsonAddDoubleToObject(pVgroupJson, "tables_num", pVgroupDesc->tables_num); + (void)tjsonAddStringToObject(pVgroupJson, "status", pVgroupDesc->status); SJson *pVnodesJson = tjsonAddArrayToObject(pVgroupJson, "vnodes"); if (pVnodesJson == NULL) continue; @@ -311,8 +313,8 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { SJson *pVnodeJson = tjsonCreateObject(); if (pVnodeJson == NULL) continue; - tjsonAddDoubleToObject(pVnodeJson, "dnode_id", pVnodeDesc->dnode_id); - tjsonAddStringToObject(pVnodeJson, "vnode_role", pVnodeDesc->vnode_role); + (void)tjsonAddDoubleToObject(pVnodeJson, "dnode_id", pVnodeDesc->dnode_id); + (void)tjsonAddStringToObject(pVnodeJson, "vnode_role", pVnodeDesc->vnode_role); if (tjsonAddItemToArray(pVnodesJson, pVnodeJson) != 0) tjsonDelete(pVnodeJson); } @@ -335,8 +337,8 @@ static void monGenStbJson(SMonInfo *pMonitor) { } SMonStbDesc *pStbDesc = taosArrayGet(pInfo->stbs, i); - tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name); - tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name); + (void)tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name); + (void)tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name); } } @@ -351,9 +353,9 @@ static void monGenGrantJson(SMonInfo *pMonitor) { return; } - tjsonAddDoubleToObject(pJson, "expire_time", pInfo->expire_time); - tjsonAddDoubleToObject(pJson, "timeseries_used", pInfo->timeseries_used); - tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total); + (void)tjsonAddDoubleToObject(pJson, "expire_time", pInfo->expire_time); + (void)tjsonAddDoubleToObject(pJson, "timeseries_used", pInfo->timeseries_used); + (void)tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total); } static void monGenDnodeJson(SMonInfo *pMonitor) { @@ -410,36 +412,36 @@ static void monGenDnodeJson(SMonInfo *pMonitor) { double io_read_disk_rate = io_read_disk / interval; double io_write_disk_rate = io_write_disk / interval; - tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime); - tjsonAddDoubleToObject(pJson, "cpu_engine", cpu_engine); - tjsonAddDoubleToObject(pJson, "cpu_system", pSys->cpu_system); - tjsonAddDoubleToObject(pJson, "cpu_cores", pSys->cpu_cores); - tjsonAddDoubleToObject(pJson, "mem_engine", mem_engine); - tjsonAddDoubleToObject(pJson, "mem_system", pSys->mem_system); - tjsonAddDoubleToObject(pJson, "mem_total", pSys->mem_total); - tjsonAddDoubleToObject(pJson, "disk_engine", pSys->disk_engine); - tjsonAddDoubleToObject(pJson, "disk_used", pSys->disk_used); - tjsonAddDoubleToObject(pJson, "disk_total", pSys->disk_total); - tjsonAddDoubleToObject(pJson, "net_in", net_in_rate); - tjsonAddDoubleToObject(pJson, "net_out", net_out_rate); - tjsonAddDoubleToObject(pJson, "io_read", io_read_rate); - tjsonAddDoubleToObject(pJson, "io_write", io_write_rate); - tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate); - tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate); - tjsonAddDoubleToObject(pJson, "req_select", pStat->numOfSelectReqs); - tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate); - tjsonAddDoubleToObject(pJson, "req_insert", pStat->numOfInsertReqs); - tjsonAddDoubleToObject(pJson, "req_insert_success", pStat->numOfInsertSuccessReqs); - tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate); - tjsonAddDoubleToObject(pJson, "req_insert_batch", pStat->numOfBatchInsertReqs); - tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pStat->numOfBatchInsertSuccessReqs); - tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate); - tjsonAddDoubleToObject(pJson, "errors", pStat->errors); - tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes); - tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum); - tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode); - tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode); - tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode); + (void)tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime); + (void)tjsonAddDoubleToObject(pJson, "cpu_engine", cpu_engine); + (void)tjsonAddDoubleToObject(pJson, "cpu_system", pSys->cpu_system); + (void)tjsonAddDoubleToObject(pJson, "cpu_cores", pSys->cpu_cores); + (void)tjsonAddDoubleToObject(pJson, "mem_engine", mem_engine); + (void)tjsonAddDoubleToObject(pJson, "mem_system", pSys->mem_system); + (void)tjsonAddDoubleToObject(pJson, "mem_total", pSys->mem_total); + (void)tjsonAddDoubleToObject(pJson, "disk_engine", pSys->disk_engine); + (void)tjsonAddDoubleToObject(pJson, "disk_used", pSys->disk_used); + (void)tjsonAddDoubleToObject(pJson, "disk_total", pSys->disk_total); + (void)tjsonAddDoubleToObject(pJson, "net_in", net_in_rate); + (void)tjsonAddDoubleToObject(pJson, "net_out", net_out_rate); + (void)tjsonAddDoubleToObject(pJson, "io_read", io_read_rate); + (void)tjsonAddDoubleToObject(pJson, "io_write", io_write_rate); + (void)tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate); + (void)tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate); + (void)tjsonAddDoubleToObject(pJson, "req_select", pStat->numOfSelectReqs); + (void)tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate); + (void)tjsonAddDoubleToObject(pJson, "req_insert", pStat->numOfInsertReqs); + (void)tjsonAddDoubleToObject(pJson, "req_insert_success", pStat->numOfInsertSuccessReqs); + (void)tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate); + (void)tjsonAddDoubleToObject(pJson, "req_insert_batch", pStat->numOfBatchInsertReqs); + (void)tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pStat->numOfBatchInsertSuccessReqs); + (void)tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate); + (void)tjsonAddDoubleToObject(pJson, "errors", pStat->errors); + (void)tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes); + (void)tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum); + (void)tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode); + (void)tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode); + (void)tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode); } static void monGenDiskJson(SMonInfo *pMonitor) { @@ -474,18 +476,18 @@ static void monGenDiskJson(SMonInfo *pMonitor) { SJson *pLogdirJson = tjsonCreateObject(); if (pLogdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "logdir", pLogdirJson) != 0) return; - tjsonAddStringToObject(pLogdirJson, "name", pLogDesc->name); - tjsonAddDoubleToObject(pLogdirJson, "avail", pLogDesc->size.avail); - tjsonAddDoubleToObject(pLogdirJson, "used", pLogDesc->size.used); - tjsonAddDoubleToObject(pLogdirJson, "total", pLogDesc->size.total); + (void)tjsonAddStringToObject(pLogdirJson, "name", pLogDesc->name); + (void)tjsonAddDoubleToObject(pLogdirJson, "avail", pLogDesc->size.avail); + (void)tjsonAddDoubleToObject(pLogdirJson, "used", pLogDesc->size.used); + (void)tjsonAddDoubleToObject(pLogdirJson, "total", pLogDesc->size.total); SJson *pTempdirJson = tjsonCreateObject(); if (pTempdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "tempdir", pTempdirJson) != 0) return; - tjsonAddStringToObject(pTempdirJson, "name", pTempDesc->name); - tjsonAddDoubleToObject(pTempdirJson, "avail", pTempDesc->size.avail); - tjsonAddDoubleToObject(pTempdirJson, "used", pTempDesc->size.used); - tjsonAddDoubleToObject(pTempdirJson, "total", pTempDesc->size.total); + (void)tjsonAddStringToObject(pTempdirJson, "name", pTempDesc->name); + (void)tjsonAddDoubleToObject(pTempdirJson, "avail", pTempDesc->size.avail); + (void)tjsonAddDoubleToObject(pTempdirJson, "used", pTempDesc->size.used); + (void)tjsonAddDoubleToObject(pTempdirJson, "total", pTempDesc->size.total); } static const char *monLogLevelStr(ELogLevel level) { @@ -530,26 +532,26 @@ static void monGenLogJson(SMonInfo *pMonitor) { SJson *pLogError = tjsonCreateObject(); if (pLogError == NULL) return; - tjsonAddStringToObject(pLogError, "level", "error"); - tjsonAddDoubleToObject(pLogError, "total", numOfErrorLogs); + (void)tjsonAddStringToObject(pLogError, "level", "error"); + (void)tjsonAddDoubleToObject(pLogError, "total", numOfErrorLogs); if (tjsonAddItemToArray(pSummaryJson, pLogError) != 0) tjsonDelete(pLogError); SJson *pLogInfo = tjsonCreateObject(); if (pLogInfo == NULL) return; - tjsonAddStringToObject(pLogInfo, "level", "info"); - tjsonAddDoubleToObject(pLogInfo, "total", numOfInfoLogs); + (void)tjsonAddStringToObject(pLogInfo, "level", "info"); + (void)tjsonAddDoubleToObject(pLogInfo, "total", numOfInfoLogs); if (tjsonAddItemToArray(pSummaryJson, pLogInfo) != 0) tjsonDelete(pLogInfo); SJson *pLogDebug = tjsonCreateObject(); if (pLogDebug == NULL) return; - tjsonAddStringToObject(pLogDebug, "level", "debug"); - tjsonAddDoubleToObject(pLogDebug, "total", numOfDebugLogs); + (void)tjsonAddStringToObject(pLogDebug, "level", "debug"); + (void)tjsonAddDoubleToObject(pLogDebug, "total", numOfDebugLogs); if (tjsonAddItemToArray(pSummaryJson, pLogDebug) != 0) tjsonDelete(pLogDebug); SJson *pLogTrace = tjsonCreateObject(); if (pLogTrace == NULL) return; - tjsonAddStringToObject(pLogTrace, "level", "trace"); - tjsonAddDoubleToObject(pLogTrace, "total", numOfTraceLogs); + (void)tjsonAddStringToObject(pLogTrace, "level", "trace"); + (void)tjsonAddDoubleToObject(pLogTrace, "total", numOfTraceLogs); if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace); } diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 8be4edaef9..01e37b6d76 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -39,18 +39,18 @@ taos_collector_t *taos_collector_new(const char *name) { self->name = taos_strdup(name); self->metrics = taos_map_new(); if (self->metrics == NULL) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } r = taos_map_set_free_value_fn(self->metrics, &taos_metric_free_generic); if (r) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } self->collect_fn = &taos_collector_default_collect; self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - taos_collector_destroy(self); + (void)taos_collector_destroy(self); return NULL; } self->proc_limits_file_path = NULL; @@ -93,7 +93,7 @@ int taos_collector_destroy_generic(void *gen) { void taos_collector_free_generic(void *gen) { taos_collector_t *self = (taos_collector_t *)gen; - taos_collector_destroy(self); + (void)taos_collector_destroy(self); } int taos_collector_set_collect_fn(taos_collector_t *self, taos_collect_fn *fn) { diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index 0c8385791d..88f56549e5 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -50,8 +50,8 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) { self->name = taos_strdup(name); self->collectors = taos_map_new(); - taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic); - taos_map_set(self->collectors, "default", taos_collector_new("default")); + (void)taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic); + if (taos_map_set(self->collectors, "default", taos_collector_new("default")) != 0) return NULL; self->metric_formatter = taos_metric_formatter_new(); self->string_builder = taos_string_builder_new(); @@ -237,15 +237,15 @@ int taos_collector_registry_clear_batch(taos_collector_registry_t *self){ } const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, char *ts, char *format, char** prom_str) { - taos_metric_formatter_clear(self->metric_formatter); - + if (taos_metric_formatter_clear(self->metric_formatter) != 0) return NULL; + SJson* pJson = tjsonCreateArray(); SJson* item = tjsonCreateObject(); - tjsonAddItemToArray(pJson, item); - tjsonAddStringToObject(item, "ts", ts); - tjsonAddDoubleToObject(item, "protocol", 2); + (void)tjsonAddItemToArray(pJson, item); + (void)tjsonAddStringToObject(item, "ts", ts); + (void)tjsonAddDoubleToObject(item, "protocol", 2); SJson* array = tjsonCreateArray(); - tjsonAddItemToObject(item, "tables", array); + (void)tjsonAddItemToObject(item, "tables", array); if(taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array) != 0){ TAOS_LOG("failed to load metrics"); @@ -304,7 +304,7 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, _OVER: tjsonDelete(pJson); if(tmp_builder != NULL){ - taos_string_builder_destroy(tmp_builder); + (void)taos_string_builder_destroy(tmp_builder); } return NULL; diff --git a/source/libs/monitorfw/src/taos_map.c b/source/libs/monitorfw/src/taos_map.c index 55aaabf1a7..64d5475af2 100644 --- a/source/libs/monitorfw/src/taos_map.c +++ b/source/libs/monitorfw/src/taos_map.c @@ -59,7 +59,7 @@ int taos_map_node_destroy(taos_map_node_t *self) { void taos_map_node_free(void *item) { taos_map_node_t *map_node = (taos_map_node_t *)item; - taos_map_node_destroy(map_node); + (void)taos_map_node_destroy(map_node); } taos_linked_list_compare_t taos_map_node_compare(void *item_a, void *item_b) { @@ -87,7 +87,7 @@ taos_map_t *taos_map_new() { // we will only have to deallocate each key once. That will happen on taos_map_node_destroy. r = taos_linked_list_set_free_fn(self->keys, taos_linked_list_no_op_free); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } @@ -98,12 +98,12 @@ taos_map_t *taos_map_new() { self->addrs[i] = taos_linked_list_new(); r = taos_linked_list_set_free_fn(self->addrs[i], taos_map_node_free); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } r = taos_linked_list_set_compare_fn(self->addrs[i], taos_map_node_compare); if (r) { - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } } @@ -112,7 +112,7 @@ taos_map_t *taos_map_new() { r = pthread_rwlock_init(self->rwlock, NULL); if (r) { TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); - taos_map_destroy(self); + (void)taos_map_destroy(self); return NULL; } @@ -188,12 +188,12 @@ static void *taos_map_get_internal(const char *key, size_t *size, size_t *max_si taos_map_node_t *current_map_node = (taos_map_node_t *)current_node->item; taos_linked_list_compare_t result = taos_linked_list_compare(list, current_map_node, temp_map_node); if (result == TAOS_EQUAL) { - taos_map_node_destroy(temp_map_node); + (void)taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return current_map_node->value; } } - taos_map_node_destroy(temp_map_node); + (void)taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return NULL; } @@ -248,8 +248,8 @@ static int taos_map_set_internal(const char *key, void *value, size_t *size, siz return 0; } } - taos_linked_list_append(list, map_node); - taos_linked_list_append(keys, (char *)map_node->key); + if (taos_linked_list_append(list, map_node) != 0) return 1; + if (taos_linked_list_append(keys, (char *)map_node->key) != 0) return 1; (*size)++; return 0; } @@ -311,7 +311,8 @@ int taos_map_ensure_space(taos_map_t *self) { self->addrs[i] = NULL; } // Destroy the collection of keys in the map - taos_linked_list_destroy(self->keys); + r = taos_linked_list_destroy(self->keys); + if (r) return r; self->keys = NULL; // Deallocate the backbone of the map diff --git a/source/libs/monitorfw/src/taos_metric.c b/source/libs/monitorfw/src/taos_metric.c index 056bf131f2..f31cef79b0 100644 --- a/source/libs/monitorfw/src/taos_metric.c +++ b/source/libs/monitorfw/src/taos_metric.c @@ -49,12 +49,12 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, for (int i = 0; i < label_key_count; i++) { if (strcmp(label_keys[i], "le") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } if (strcmp(label_keys[i], "quantile") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } k[i] = taos_strdup(label_keys[i]); @@ -68,14 +68,14 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, } else { r = taos_map_set_free_value_fn(self->samples, &taos_metric_sample_free_generic); if (r) { - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } } self->formatter = taos_metric_formatter_new(); if (self->formatter == NULL) { - taos_metric_destroy(self); + (void)taos_metric_destroy(self); return NULL; } self->rwlock = (pthread_rwlock_t *)taos_malloc(sizeof(pthread_rwlock_t)); @@ -140,7 +140,7 @@ int taos_metric_destroy_generic(void *item) { void taos_metric_free_generic(void *item) { taos_metric_t *self = (taos_metric_t *)item; - taos_metric_destroy(self); + (void)taos_metric_destroy(self); } taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const char **label_values) { diff --git a/source/libs/monitorfw/src/taos_metric_formatter.c b/source/libs/monitorfw/src/taos_metric_formatter.c index 5f34edf3e6..e57c809815 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter.c +++ b/source/libs/monitorfw/src/taos_metric_formatter.c @@ -34,12 +34,12 @@ taos_metric_formatter_t *taos_metric_formatter_new() { taos_metric_formatter_t *self = (taos_metric_formatter_t *)taos_malloc(sizeof(taos_metric_formatter_t)); self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - taos_metric_formatter_destroy(self); + (void)taos_metric_formatter_destroy(self); return NULL; } self->err_builder = taos_string_builder_new(); if (self->err_builder == NULL) { - taos_metric_formatter_destroy(self); + (void)taos_metric_formatter_destroy(self); return NULL; } return self; diff --git a/source/libs/monitorfw/src/taos_metric_formatter_custom.c b/source/libs/monitorfw/src/taos_metric_formatter_custom.c index 553227c801..0287641311 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter_custom.c +++ b/source/libs/monitorfw/src/taos_metric_formatter_custom.c @@ -88,17 +88,17 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me char* value = *(pair + 1); SJson* tag = tjsonCreateObject(); - tjsonAddStringToObject(tag, "name", key); - tjsonAddStringToObject(tag, "value", value); + (void)tjsonAddStringToObject(tag, "name", key); + (void)tjsonAddStringToObject(tag, "value", value); - tjsonAddItemToArray(arrayTag, tag); + (void)tjsonAddItemToArray(arrayTag, tag); } - tjsonAddItemToObject(item, "tags", arrayTag); + (void)tjsonAddItemToObject(item, "tags", arrayTag); metrics = tjsonCreateArray(); - tjsonAddItemToObject(item, "metrics", metrics); + (void)tjsonAddItemToObject(item, "metrics", metrics); - tjsonAddItemToArray(arrayMetricGroups, item); + (void)tjsonAddItemToArray(arrayMetricGroups, item); } else{ metrics = tjsonGetObjectItem(item, "metrics"); @@ -109,20 +109,20 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me taosMemoryFreeClear(keyvalues); SJson* metric = tjsonCreateObject(); - tjsonAddStringToObject(metric, "name", metricName); - + (void)tjsonAddStringToObject(metric, "name", metricName); + double old_value = 0; #define USE_EXCHANGE #ifdef USE_EXCHANGE - taos_metric_sample_exchange(sample, 0, &old_value); + (void)taos_metric_sample_exchange(sample, 0, &old_value); #else old_value = sample->r_value; taos_metric_sample_set(sample, 0); #endif - tjsonAddDoubleToObject(metric, "value", old_value); - tjsonAddDoubleToObject(metric, "type", metric_type); - tjsonAddItemToArray(metrics, metric); + (void)tjsonAddDoubleToObject(metric, "value", old_value); + (void)tjsonAddDoubleToObject(metric, "type", metric_type); + (void)tjsonAddItemToArray(metrics, metric); return 0; } @@ -150,7 +150,7 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me SJson* table = tjsonGetArrayItem(tableArray, i); char tableName[MONITOR_TABLENAME_LEN] = {0}; - tjsonGetStringValue(table, "name", tableName); + (void)tjsonGetStringValue(table, "name", tableName); if(strcmp(tableName, arr[0]) == 0){ isFound = true; arrayMetricGroups = tjsonGetObjectItem(table, "metric_groups"); @@ -161,10 +161,10 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me if(!isFound){ table = tjsonCreateObject(); - tjsonAddStringToObject(table, "name", arr[0]); + (void)tjsonAddStringToObject(table, "name", arr[0]); arrayMetricGroups = tjsonCreateArray(); - tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups); + (void)tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups); } int32_t sample_count = 0; @@ -183,7 +183,7 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me } if(!isFound && sample_count > 0){ - tjsonAddItemToArray(tableArray, table); + (void)tjsonAddItemToArray(tableArray, table); } else{ if(table != NULL) tjsonDelete(table); diff --git a/source/libs/monitorfw/src/taos_metric_sample.c b/source/libs/monitorfw/src/taos_metric_sample.c index 4688672835..ccddefa17e 100644 --- a/source/libs/monitorfw/src/taos_metric_sample.c +++ b/source/libs/monitorfw/src/taos_metric_sample.c @@ -63,7 +63,7 @@ int taos_metric_sample_destroy_generic(void *gen) { void taos_metric_sample_free_generic(void *gen) { taos_metric_sample_t *self = (taos_metric_sample_t *)gen; - taos_metric_sample_destroy(self); + (void)taos_metric_sample_destroy(self); } int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) { diff --git a/source/libs/monitorfw/src/taos_monitor_util.c b/source/libs/monitorfw/src/taos_monitor_util.c index d338215426..2285ed9e71 100644 --- a/source/libs/monitorfw/src/taos_monitor_util.c +++ b/source/libs/monitorfw/src/taos_monitor_util.c @@ -84,10 +84,10 @@ bool taos_monitor_is_match(const SJson* tags, char** pairs, int32_t count) { SJson* item = tjsonGetArrayItem(tags, i); char item_name[MONITOR_TAG_NAME_LEN] = {0}; - tjsonGetStringValue(item, "name", item_name); + (void)tjsonGetStringValue(item, "name", item_name); char item_value[MONITOR_TAG_VALUE_LEN] = {0}; - tjsonGetStringValue(item, "value", item_value); + (void)tjsonGetStringValue(item, "value", item_value); bool isfound = false; for(int32_t j = 0; j < count; j++){ diff --git a/source/libs/monitorfw/src/taos_string_builder.c b/source/libs/monitorfw/src/taos_string_builder.c index e1bfa4142c..208f3f6d51 100644 --- a/source/libs/monitorfw/src/taos_string_builder.c +++ b/source/libs/monitorfw/src/taos_string_builder.c @@ -44,7 +44,7 @@ taos_string_builder_t *taos_string_builder_new(void) { self->init_size = TAOS_STRING_BUILDER_INIT_SIZE; r = taos_string_builder_init(self); if (r) { - taos_string_builder_destroy(self); + (void)taos_string_builder_destroy(self); return NULL; } diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 1edfa840e2..927bc6b661 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -229,6 +229,9 @@ static void checkParamIsFunc(SFunctionNode* pFunc) { if (nodeType(pPara) == QUERY_NODE_COLUMN) { ((SColumnNode*)pPara)->node.asParam = true; } + if (nodeType(pPara) == QUERY_NODE_VALUE) { + ((SValueNode*)pPara)->node.asParam = true; + } } } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c old mode 100644 new mode 100755 index 153d8bb23d..33e2241f1e --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1450,6 +1450,8 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod return DEAL_RES_CONTINUE; } +static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc); + static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** pCol, bool* pFound) { SNodeList* pProjectionList = getProjectListFromCurrStmt(pCxt->pCurrStmt); SNode* pNode; @@ -1470,6 +1472,25 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p } } if (*pFound) { + if (QUERY_NODE_FUNCTION == nodeType(pFoundNode) && (SQL_CLAUSE_GROUP_BY == pCxt->currClause || SQL_CLAUSE_PARTITION_BY == pCxt->currClause)) { + pCxt->errCode = getFuncInfo(pCxt, (SFunctionNode*)pFoundNode); + if (TSDB_CODE_SUCCESS == pCxt->errCode) { + if (fmIsVectorFunc(((SFunctionNode*)pFoundNode)->funcId)) { + pCxt->errCode = TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION; + return DEAL_RES_ERROR; + } else if (fmIsPseudoColumnFunc(((SFunctionNode*)pFoundNode)->funcId)) { + if ('\0' != (*pCol)->tableAlias[0]) { + return translateColumnWithPrefix(pCxt, pCol); + } else { + return translateColumnWithoutPrefix(pCxt, pCol); + } + } else { + /* Do nothing and replace old node with found node. */ + } + } else { + return DEAL_RES_ERROR; + } + } SNode* pNew = NULL; int32_t code = nodesCloneNode(pFoundNode, &pNew); if (NULL == pNew) { @@ -1478,6 +1499,13 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p } nodesDestroyNode(*(SNode**)pCol); *(SNode**)pCol = (SNode*)pNew; + if (QUERY_NODE_COLUMN == nodeType(pFoundNode)) { + if ('\0' != (*pCol)->tableAlias[0]) { + return translateColumnWithPrefix(pCxt, pCol); + } else { + return translateColumnWithoutPrefix(pCxt, pCol); + } + } } return DEAL_RES_CONTINUE; } @@ -1716,6 +1744,12 @@ int32_t biCheckCreateTableTbnameCol(STranslateContext* pCxt, SCreateTableStmt* p return TSDB_CODE_SUCCESS; } +static bool clauseSupportAlias(ESqlClause clause) { + return SQL_CLAUSE_GROUP_BY == clause || + SQL_CLAUSE_PARTITION_BY == clause || + SQL_CLAUSE_ORDER_BY == clause; +} + static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { if (NULL == pCxt->pCurrStmt || (isSelectStmt(pCxt->pCurrStmt) && NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) { @@ -1742,7 +1776,8 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { res = translateColumnWithPrefix(pCxt, pCol); } else { bool found = false; - if (SQL_CLAUSE_ORDER_BY == pCxt->currClause && !(*pCol)->node.asParam) { + if ((clauseSupportAlias(pCxt->currClause)) && + !(*pCol)->node.asParam) { res = translateColumnUseAlias(pCxt, pCol, &found); } if (DEAL_RES_ERROR != res && !found) { @@ -1752,7 +1787,9 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { res = translateColumnWithoutPrefix(pCxt, pCol); } } - if (SQL_CLAUSE_ORDER_BY == pCxt->currClause && !(*pCol)->node.asParam && res != DEAL_RES_CONTINUE && + if (clauseSupportAlias(pCxt->currClause) && + !(*pCol)->node.asParam && + res != DEAL_RES_CONTINUE && res != DEAL_RES_END) { res = translateColumnUseAlias(pCxt, pCol, &found); } @@ -2957,6 +2994,13 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode** pFunc } pCxt->errCode = getFuncInfo(pCxt, *pFunc); + if (TSDB_CODE_SUCCESS == pCxt->errCode) { + if ((SQL_CLAUSE_GROUP_BY == pCxt->currClause || + SQL_CLAUSE_PARTITION_BY == pCxt->currClause) && + fmIsVectorFunc((*pFunc)->funcId)) { + pCxt->errCode = TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION; + } + } if (TSDB_CODE_SUCCESS == pCxt->errCode) { pCxt->errCode = translateFunctionImpl(pCxt, pFunc); } @@ -3442,7 +3486,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { bool partionByTbname = hasTbnameFunction(pSelect->pPartitionByList); FOREACH(pPartKey, pSelect->pPartitionByList) { if (nodesEqualNode(pPartKey, *pNode)) { - return rewriteExprToGroupKeyFunc(pCxt, pNode); + return pCxt->currClause == SQL_CLAUSE_HAVING ? DEAL_RES_IGNORE_CHILD : rewriteExprToGroupKeyFunc(pCxt, pNode); } if ((partionByTbname) && QUERY_NODE_COLUMN == nodeType(*pNode) && ((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) { @@ -3661,6 +3705,7 @@ static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) return code; } if (NULL != pSelect->pHaving) { + pCxt->currClause = SQL_CLAUSE_HAVING; code = checkExprForGroupBy(pCxt, &pSelect->pHaving); } /* @@ -4942,7 +4987,7 @@ static int32_t getPositionValue(const SValueNode* pVal) { case TSDB_DATA_TYPE_GEOMETRY: return -1; case TSDB_DATA_TYPE_BOOL: - return (pVal->datum.b ? 1 : 0); + return -1; case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_INT: @@ -4950,7 +4995,7 @@ static int32_t getPositionValue(const SValueNode* pVal) { return pVal->datum.i; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: - return pVal->datum.d; + return -1; case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: @@ -4962,25 +5007,36 @@ static int32_t getPositionValue(const SValueNode* pVal) { return -1; } -static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList, +static int32_t translateClausePosition(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pClauseList, bool* pOther) { *pOther = false; SNode* pNode = NULL; - WHERE_EACH(pNode, pOrderByList) { - SNode* pExpr = ((SOrderByExprNode*)pNode)->pExpr; + WHERE_EACH(pNode, pClauseList) { + SNode* pExpr = NULL; + switch (pNode->type) { + case QUERY_NODE_GROUPING_SET: + pExpr = getGroupByNode(pNode); + break; + case QUERY_NODE_ORDER_BY_EXPR: + pExpr = ((SOrderByExprNode*)pNode)->pExpr; + break; + default: + pExpr = pNode; + break; + } if (QUERY_NODE_VALUE == nodeType(pExpr)) { SValueNode* pVal = (SValueNode*)pExpr; + pVal->node.asPosition = false; if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } int32_t pos = getPositionValue(pVal); if (pos < 0) { - ERASE_NODE(pOrderByList); - continue; + pVal->node.asPosition = false; } else if (0 == pos || pos > LIST_LENGTH(pProjectionList)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); } else { - // No longer using SColumnRefNode, processing in replaceOrderByAliasImpl function + pVal->node.asPosition = true; } } else { *pOther = true; @@ -4992,7 +5048,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) { bool other; - int32_t code = translateOrderByPosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other); + int32_t code = translateClausePosition(pCxt, pSelect->pProjectionList, pSelect->pOrderByList, &other); if (TSDB_CODE_SUCCESS == code) { if (0 == LIST_LENGTH(pSelect->pOrderByList)) { NODES_DESTORY_LIST(pSelect->pOrderByList); @@ -5123,6 +5179,68 @@ static int32_t translateProjectionList(STranslateContext* pCxt, SSelectStmt* pSe } } +typedef struct SReplaceGroupByAliasCxt { + STranslateContext* pTranslateCxt; + SNodeList* pProjectionList; +} SReplaceGroupByAliasCxt; + +static EDealRes replaceGroupByAliasImpl(SNode** pNode, void* pContext) { + SReplaceGroupByAliasCxt* pCxt = pContext; + SNodeList* pProjectionList = pCxt->pProjectionList; + SNode* pProject = NULL; + if (QUERY_NODE_VALUE == nodeType(*pNode)) { + STranslateContext* pTransCxt = pCxt->pTranslateCxt; + SValueNode* pVal = (SValueNode*) *pNode; + if (DEAL_RES_ERROR == translateValue(pTransCxt, pVal)) { + return DEAL_RES_CONTINUE; + } + if (!pVal->node.asPosition) { + return DEAL_RES_CONTINUE; + } + int32_t pos = getPositionValue(pVal); + if (0 < pos && pos <= LIST_LENGTH(pProjectionList)) { + SNode* pNew = NULL; + int32_t code = nodesCloneNode(nodesListGetNode(pProjectionList, pos - 1), (SNode**)&pNew); + if (TSDB_CODE_SUCCESS != code) { + pCxt->pTranslateCxt->errCode = code; + return DEAL_RES_ERROR; + } + nodesDestroyNode(*pNode); + *pNode = pNew; + return DEAL_RES_CONTINUE; + } else { + return DEAL_RES_CONTINUE; + } + } else if (QUERY_NODE_COLUMN == nodeType(*pNode)) { + STranslateContext* pTransCxt = pCxt->pTranslateCxt; + return translateColumn(pTransCxt, (SColumnNode**)pNode); + } + + return DEAL_RES_CONTINUE; +} + +static int32_t replaceGroupByAlias(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (NULL == pSelect->pGroupByList) { + return TSDB_CODE_SUCCESS; + } + SReplaceGroupByAliasCxt cxt = { + .pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; + nodesRewriteExprsPostOrder(pSelect->pGroupByList, replaceGroupByAliasImpl, &cxt); + + return pCxt->errCode; +} + +static int32_t replacePartitionByAlias(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (NULL == pSelect->pPartitionByList) { + return TSDB_CODE_SUCCESS; + } + SReplaceGroupByAliasCxt cxt = { + .pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList}; + nodesRewriteExprsPostOrder(pSelect->pPartitionByList, replaceGroupByAliasImpl, &cxt); + + return pCxt->errCode; +} + static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->currClause = SQL_CLAUSE_SELECT; int32_t code = translateExprList(pCxt, pSelect->pProjectionList); @@ -5174,9 +5292,21 @@ static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL != pSelect->pWindow) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST); } - pCxt->currClause = SQL_CLAUSE_GROUP_BY; - pSelect->timeLineResMode = TIME_LINE_NONE; - return translateExprList(pCxt, pSelect->pGroupByList); + bool other; + int32_t code = translateClausePosition(pCxt, pSelect->pProjectionList, pSelect->pGroupByList, &other); + if (TSDB_CODE_SUCCESS == code) { + if (0 == LIST_LENGTH(pSelect->pGroupByList)) { + NODES_DESTORY_LIST(pSelect->pGroupByList); + return TSDB_CODE_SUCCESS; + } + code = replaceGroupByAlias(pCxt, pSelect); + } + if (TSDB_CODE_SUCCESS == code) { + pCxt->currClause = SQL_CLAUSE_GROUP_BY; + pSelect->timeLineResMode = TIME_LINE_NONE; + code = translateExprList(pCxt, pSelect->pGroupByList); + } + return code; } static int32_t getTimeRange(SNode** pPrimaryKeyCond, STimeWindow* pTimeRange, bool* pIsStrict) { @@ -5783,7 +5913,8 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SSelectStmt* pSelec int32_t code = TSDB_CODE_SUCCESS; if (pSelect->pPartitionByList) { - code = removeConstantValueFromList(&pSelect->pPartitionByList); + bool other; + code = translateClausePosition(pCxt, pSelect->pProjectionList, pSelect->pPartitionByList, &other); } if (TSDB_CODE_SUCCESS == code && pSelect->pPartitionByList) { @@ -5793,8 +5924,10 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SSelectStmt* pSelec (QUERY_NODE_FUNCTION == nodeType(pPar) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPar)->funcType))) { pSelect->timeLineResMode = TIME_LINE_MULTI; } - - code = translateExprList(pCxt, pSelect->pPartitionByList); + code = replacePartitionByAlias(pCxt, pSelect); + if (TSDB_CODE_SUCCESS == code) { + code = translateExprList(pCxt, pSelect->pPartitionByList); + } } if (TSDB_CODE_SUCCESS == code) { code = translateExprList(pCxt, pSelect->pTags); @@ -6521,7 +6654,11 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect code = removeConstantValueFromList(&pSelect->pPartitionByList); } } - + if (TSDB_CODE_SUCCESS == code) { + if (pSelect->pGroupByList) { + code = removeConstantValueFromList(&pSelect->pGroupByList); + } + } return code; } @@ -6608,7 +6745,7 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS } bool other; - int32_t code = translateOrderByPosition(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, &other); + int32_t code = translateClausePosition(pCxt, pSetOperator->pProjectionList, pSetOperator->pOrderByList, &other); /* if (TSDB_CODE_SUCCESS == code) { if (other) { @@ -12980,7 +13117,11 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* } SNode* pCol; col_id_t index = 0; - tInitDefaultSColCmprWrapperByCols(&req.colCmpr, req.ntb.schemaRow.nCols); + int32_t code = tInitDefaultSColCmprWrapperByCols(&req.colCmpr, req.ntb.schemaRow.nCols); + if (TSDB_CODE_SUCCESS != code) { + tdDestroySVCreateTbReq(&req); + return code; + } FOREACH(pCol, pStmt->pCols) { SColumnDefNode* pColDef = (SColumnDefNode*)pCol; SSchema* pScheam = req.ntb.schemaRow.pSchema + index; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 35d54ad43c..6a36ea7b85 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -44,7 +44,7 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION: return "There mustn't be aggregation"; case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT: - return "ORDER BY item must be the number of a SELECT-list expression"; + return "ORDER BY / GROUP BY item must be the number of a SELECT-list expression"; case TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION: return "Not a GROUP BY expression"; case TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION: diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 3d344a8a20..bce8cda125 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -128,7 +128,7 @@ static STaskQueue taskQueue = {0}; static void processTaskQueue(SQueueInfo *pInfo, SSchedMsg *pSchedMsg) { __async_exec_fn_t execFn = (__async_exec_fn_t)pSchedMsg->ahandle; - execFn(pSchedMsg->thandle); + (void)execFn(pSchedMsg->thandle); taosFreeQitem(pSchedMsg); } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 5e9c61eac6..d08f358ce0 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1176,27 +1176,6 @@ EDealRes sclRewriteNonConstOperator(SNode **pNode, SScalarCtx *ctx) { } } - if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) { - SNodeListNode *listNode = (SNodeListNode *)node->pRight; - SNode *tnode = NULL; - WHERE_EACH(tnode, listNode->pNodeList) { - if (SCL_IS_NULL_VALUE_NODE(tnode)) { - if (node->opType == OP_TYPE_IN) { - ERASE_NODE(listNode->pNodeList); - continue; - } else { // OP_TYPE_NOT_IN - return sclRewriteNullInOptr(pNode, ctx, node->opType); - } - } - - WHERE_NEXT; - } - - if (listNode->pNodeList->length <= 0) { - return sclRewriteNullInOptr(pNode, ctx, node->opType); - } - } - return DEAL_RES_CONTINUE; } @@ -1334,6 +1313,27 @@ EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } + if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) { + SNodeListNode *listNode = (SNodeListNode *)node->pRight; + SNode *tnode = NULL; + WHERE_EACH(tnode, listNode->pNodeList) { + if (SCL_IS_NULL_VALUE_NODE(tnode)) { + if (node->opType == OP_TYPE_IN) { + ERASE_NODE(listNode->pNodeList); + continue; + } else { // OP_TYPE_NOT_IN + return sclRewriteNullInOptr(pNode, ctx, node->opType); + } + } + + WHERE_NEXT; + } + + if (listNode->pNodeList->length <= 0) { + return sclRewriteNullInOptr(pNode, ctx, node->opType); + } + } + if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) { return sclRewriteNonConstOperator(pNode, ctx); } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 3e5471700c..23cc7324f0 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -262,7 +262,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP colDataSetNULL(pOutputData, i); continue; } - out[i] = f1(in[i]); + out[i] = f1(in[i]) + 0; } break; } @@ -276,7 +276,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP colDataSetNULL(pOutputData, i); continue; } - out[i] = d1(in[i]); + out[i] = d1(in[i]) + 0; } break; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index cbc671a73a..376a8a11d8 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -793,7 +793,7 @@ int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut, return vectorConvertFromVarData(&cCtx, overflow); } - if (overflow) { + if (overflow && TSDB_DATA_TYPE_NULL != cCtx.inType) { if (1 != pIn->numOfRows) { sclError("invalid numOfRows %d", pIn->numOfRows); return TSDB_CODE_APP_ERROR; diff --git a/source/libs/stream/inc/streamBackendRocksdb.h b/source/libs/stream/inc/streamBackendRocksdb.h index c3eeb12209..0f158591b4 100644 --- a/source/libs/stream/inc/streamBackendRocksdb.h +++ b/source/libs/stream/inc/streamBackendRocksdb.h @@ -143,9 +143,9 @@ SListNode* streamBackendAddCompare(void* backend, void* arg); void streamBackendDelCompare(void* backend, void* arg); int32_t streamStateCvtDataFormat(char* path, char* key, void* cfInst); -STaskDbWrapper* taskDbOpen(const char* path, const char* key, int64_t chkptId, int64_t* processVer); -void taskDbDestroy(void* pBackend, bool flush); -void taskDbDestroy2(void* pBackend); +int32_t taskDbOpen(const char* path, const char* key, int64_t chkptId, int64_t* processVer, STaskDbWrapper** ppTaskDb); +void taskDbDestroy(void* pBackend, bool flush); +void taskDbDestroy2(void* pBackend); void taskDbUpdateChkpId(void* pTaskDb, int64_t chkpId); @@ -252,7 +252,7 @@ int32_t taskDbDestroySnap(void* arg, SArray* pSnapInfo); int32_t taskDbDoCheckpoint(void* arg, int64_t chkpId, int64_t processId); -SBkdMgt* bkdMgtCreate(char* path); +int32_t bkdMgtCreate(char* path, SBkdMgt **bm); int32_t bkdMgtAddChkp(SBkdMgt* bm, char* task, char* path); int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, char* name); int32_t bkdMgtDumpTo(SBkdMgt* bm, char* taskId, char* dname); diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index c3e779cf5f..552767bb16 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -424,7 +424,7 @@ void cleanDir(const char* pPath, const char* id) { if (taosIsDir(pPath)) { taosRemoveDir(pPath); - taosMkDir(pPath); + (void)taosMkDir(pPath); stInfo("%s clear dir:%s, succ", id, pPath); } } @@ -531,7 +531,7 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId _EXIT: if (code != 0) { if (rename) { - taosRenameFile(defaultTmp, defaultPath); + (void)taosRenameFile(defaultTmp, defaultPath); } } @@ -652,13 +652,13 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { taosMemoryFreeClear(srcName); taosMemoryFreeClear(dstName); - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); return code; _ERROR: taosMemoryFreeClear(srcName); taosMemoryFreeClear(dstName); - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); return code; } @@ -820,8 +820,8 @@ void* streamBackendInit(const char* streamPath, int64_t chkpId, int32_t vgId) { uint32_t dbMemLimit = nextPow2(tsMaxStreamBackendCache) << 20; SBackendWrapper* pHandle = taosMemoryCalloc(1, sizeof(SBackendWrapper)); pHandle->list = tdListNew(sizeof(SCfComparator)); - taosThreadMutexInit(&pHandle->mutex, NULL); - taosThreadMutexInit(&pHandle->cfMutex, NULL); + (void)taosThreadMutexInit(&pHandle->mutex, NULL); + (void)taosThreadMutexInit(&pHandle->cfMutex, NULL); pHandle->cfInst = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); rocksdb_env_t* env = rocksdb_create_default_env(); // rocksdb_envoptions_create(); @@ -890,7 +890,7 @@ _EXIT: streamMutexDestroy(&pHandle->mutex); streamMutexDestroy(&pHandle->cfMutex); taosHashCleanup(pHandle->cfInst); - tdListFree(pHandle->list); + (void)tdListFree(pHandle->list); taosMemoryFree(pHandle); stDebug("failed to init stream backend at %s", backendPath); taosMemoryFree(backendPath); @@ -922,7 +922,7 @@ void streamBackendCleanup(void* arg) { head = tdListPopHead(pHandle->list); } - tdListFree(pHandle->list); + (void)tdListFree(pHandle->list); streamMutexDestroy(&pHandle->mutex); streamMutexDestroy(&pHandle->cfMutex); @@ -933,11 +933,11 @@ void streamBackendCleanup(void* arg) { void streamBackendHandleCleanup(void* arg) { SBackendCfWrapper* wrapper = arg; bool remove = wrapper->remove; - taosThreadRwlockWrlock(&wrapper->rwLock); + (void)taosThreadRwlockWrlock(&wrapper->rwLock); stDebug("start to do-close backendwrapper %p, %s", wrapper, wrapper->idstr); if (wrapper->rocksdb == NULL) { - taosThreadRwlockUnlock(&wrapper->rwLock); + (void)taosThreadRwlockUnlock(&wrapper->rwLock); return; } @@ -988,9 +988,9 @@ void streamBackendHandleCleanup(void* arg) { wrapper->readOpts = NULL; taosMemoryFreeClear(wrapper->cfOpts); taosMemoryFreeClear(wrapper->param); - taosThreadRwlockUnlock(&wrapper->rwLock); + (void)taosThreadRwlockUnlock(&wrapper->rwLock); - taosThreadRwlockDestroy(&wrapper->rwLock); + (void)taosThreadRwlockDestroy(&wrapper->rwLock); wrapper->rocksdb = NULL; // taosReleaseRef(streamBackendId, wrapper->backendId); @@ -1083,12 +1083,20 @@ int32_t delObsoleteCheckpoint(void* arg, const char* path) { int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { STaskDbWrapper* pBackend = arg; - taosThreadRwlockWrlock(&pBackend->chkpDirLock); + (void)taosThreadRwlockWrlock(&pBackend->chkpDirLock); - taosArrayPush(pBackend->chkpSaved, &chkpId); + (void)taosArrayPush(pBackend->chkpSaved, &chkpId); SArray* chkpDel = taosArrayInit(8, sizeof(int64_t)); + if (chkpDel == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SArray* chkpDup = taosArrayInit(8, sizeof(int64_t)); + if (chkpDup == NULL) { + taosArrayDestroy(chkpDel); + return TSDB_CODE_OUT_OF_MEMORY; + } int64_t firsId = 0; if (taosArrayGetSize(pBackend->chkpInUse) >= 1) { @@ -1097,9 +1105,9 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { for (int i = 0; i < taosArrayGetSize(pBackend->chkpSaved); i++) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); if (id >= firsId) { - taosArrayPush(chkpDup, &id); + (void)taosArrayPush(chkpDup, &id); } else { - taosArrayPush(chkpDel, &id); + (void)taosArrayPush(chkpDel, &id); } } } else { @@ -1108,17 +1116,17 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { for (int i = 0; i < dsz; i++) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); - taosArrayPush(chkpDel, &id); + (void)taosArrayPush(chkpDel, &id); } for (int i = dsz < 0 ? 0 : dsz; i < sz; i++) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); - taosArrayPush(chkpDup, &id); + (void)taosArrayPush(chkpDup, &id); } } taosArrayDestroy(pBackend->chkpSaved); pBackend->chkpSaved = chkpDup; - taosThreadRwlockUnlock(&pBackend->chkpDirLock); + (void)taosThreadRwlockUnlock(&pBackend->chkpDirLock); for (int i = 0; i < taosArrayGetSize(chkpDel); i++) { int64_t id = *(int64_t*)taosArrayGet(chkpDel, i); @@ -1263,7 +1271,7 @@ int32_t taskDbLoadChkpInfo(STaskDbWrapper* pBackend) { int ret = sscanf(taosGetDirEntryName(de), "checkpoint%" PRId64 "", &checkpointId); if (ret == 1) { - taosArrayPush(pBackend->chkpSaved, &checkpointId); + (void)taosArrayPush(pBackend->chkpSaved, &checkpointId); } } else { continue; @@ -1272,7 +1280,7 @@ int32_t taskDbLoadChkpInfo(STaskDbWrapper* pBackend) { taosArraySort(pBackend->chkpSaved, chkpIdComp); taosMemoryFree(pChkpDir); - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); return 0; } @@ -1281,7 +1289,7 @@ int32_t chkpGetAllDbCfHandle2(STaskDbWrapper* pBackend, rocksdb_column_family_ha for (int i = 0; i < sizeof(ginitDict) / sizeof(ginitDict[0]); i++) { if (pBackend->pCf[i]) { rocksdb_column_family_handle_t* p = pBackend->pCf[i]; - taosArrayPush(pHandle, &p); + (void)taosArrayPush(pHandle, &p); } } int32_t nCf = taosArrayGetSize(pHandle); @@ -1430,7 +1438,7 @@ int32_t taskDbBuildSnap(void* arg, SArray* pSnap) { code = TSDB_CODE_OUT_OF_MEMORY; break; } - taosArrayPush(pSnap, &snap); + (void)taosArrayPush(pSnap, &snap); pIter = taosHashIterate(pMeta->pTaskDbUnique, pIter); } @@ -1497,7 +1505,7 @@ void* taskAcquireDb(int64_t refId) { } void taskReleaseDb(int64_t refId) { // release - taosReleaseRef(taskDbWrapperId, refId); + (void)taosReleaseRef(taskDbWrapperId, refId); } int64_t taskGetDBRef(void* arg) { @@ -1558,7 +1566,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) code = 0; _EXIT: taosMemoryFree(pDst); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return code; } int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { @@ -1613,7 +1621,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { code = 0; _EXIT: - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); taosMemoryFree(pDst); return code; } @@ -1671,7 +1679,7 @@ int32_t taskDbDoCheckpoint(void* arg, int64_t chkpId, int64_t processId) { goto _EXIT; } - atomic_store_64(&pTaskDb->dataWritten, 0); + (void)atomic_store_64(&pTaskDb->dataWritten, 0); pTaskDb->chkpId = chkpId; _EXIT: @@ -1679,13 +1687,13 @@ _EXIT: // clear checkpoint dir if failed if (code != 0 && pChkpDir != NULL) { if (taosDirExist(pChkpIdDir)) { - taosRemoveDir(pChkpIdDir); + (void)taosRemoveDir(pChkpIdDir); } } taosMemoryFree(pChkpIdDir); taosMemoryFree(pChkpDir); - taosReleaseRef(taskDbWrapperId, refId); + (void)taosReleaseRef(taskDbWrapperId, refId); taosMemoryFree(ppCf); return code; } @@ -1758,7 +1766,7 @@ int defaultKeyComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, } int streamStateValueIsStale(char* v) { int64_t ts = 0; - taosDecodeFixedI64(v, &ts); + (void)taosDecodeFixedI64(v, &ts); return (ts != 0 && ts < taosGetTimestampMs()) ? 1 : 0; } int iterValueIsStale(rocksdb_iterator_t* iter) { @@ -1801,8 +1809,8 @@ int stateKeyDBComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, p1 = taosDecodeFixedI64(p1, &key1.key.ts); p2 = taosDecodeFixedI64(p2, &key2.key.ts); - taosDecodeFixedI64(p1, &key1.opNum); - taosDecodeFixedI64(p2, &key2.opNum); + (void)taosDecodeFixedI64(p1, &key1.opNum); + (void)taosDecodeFixedI64(p2, &key2.opNum); return stateKeyCmpr(&key1, sizeof(key1), &key2, sizeof(key2)); } @@ -1998,8 +2006,8 @@ int parKeyDBComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, s char* p1 = (char*)aBuf; char* p2 = (char*)bBuf; - taosDecodeFixedI64(p1, &w1); - taosDecodeFixedI64(p2, &w2); + (void)taosDecodeFixedI64(p1, &w1); + (void)taosDecodeFixedI64(p2, &w2); if (w1 == w2) { return 0; } else { @@ -2320,7 +2328,7 @@ void taskDbRemoveRef(void* pTaskDb) { } STaskDbWrapper* pBackend = pTaskDb; - taosReleaseRef(taskDbWrapperId, pBackend->refId); + (void)taosReleaseRef(taskDbWrapperId, pBackend->refId); } void taskDbInitOpt(STaskDbWrapper* pTaskDb) { @@ -2386,22 +2394,22 @@ void taskDbInitChkpOpt(STaskDbWrapper* pTaskDb) { pTaskDb->chkpId = -1; pTaskDb->chkpCap = 4; pTaskDb->chkpSaved = taosArrayInit(4, sizeof(int64_t)); - taskDbLoadChkpInfo(pTaskDb); + (void)taskDbLoadChkpInfo(pTaskDb); pTaskDb->chkpInUse = taosArrayInit(4, sizeof(int64_t)); - taosThreadRwlockInit(&pTaskDb->chkpDirLock, NULL); + (void)taosThreadRwlockInit(&pTaskDb->chkpDirLock, NULL); } void taskDbRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { - taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); - taosArrayPush(pTaskDb->chkpInUse, &chkp); + (void)taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); + (void)taosArrayPush(pTaskDb->chkpInUse, &chkp); taosArraySort(pTaskDb->chkpInUse, chkpIdComp); - taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); + (void)taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); } void taskDbUnRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { - taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); + (void)taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); int32_t size = taosArrayGetSize(pTaskDb->chkpInUse); for (int i = 0; i < size; i++) { int64_t* p = taosArrayGet(pTaskDb->chkpInUse, i); @@ -2410,13 +2418,13 @@ void taskDbUnRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { break; } } - taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); + (void)taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); } void taskDbDestroyChkpOpt(STaskDbWrapper* pTaskDb) { taosArrayDestroy(pTaskDb->chkpSaved); taosArrayDestroy(pTaskDb->chkpInUse); - taosThreadRwlockDestroy(&pTaskDb->chkpDirLock); + (void)taosThreadRwlockDestroy(&pTaskDb->chkpDirLock); } int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** stateFullPath) { @@ -2462,9 +2470,9 @@ int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** sta void taskDbUpdateChkpId(void* pTaskDb, int64_t chkpId) { STaskDbWrapper* p = pTaskDb; - streamMutexLock(&p->mutex); + (void)streamMutexLock(&p->mutex); p->chkpId = chkpId; - streamMutexUnlock(&p->mutex); + (void)streamMutexUnlock(&p->mutex); } STaskDbWrapper* taskDbOpenImpl(const char* key, char* statePath, char* dbPath) { @@ -2476,7 +2484,7 @@ STaskDbWrapper* taskDbOpenImpl(const char* key, char* statePath, char* dbPath) { pTaskDb->idstr = key ? taosStrdup(key) : NULL; pTaskDb->path = statePath ? taosStrdup(statePath) : NULL; - taosThreadMutexInit(&pTaskDb->mutex, NULL); + (void)taosThreadMutexInit(&pTaskDb->mutex, NULL); taskDbInitChkpOpt(pTaskDb); taskDbInitOpt(pTaskDb); @@ -2525,35 +2533,35 @@ _EXIT: return NULL; } -STaskDbWrapper* taskDbOpen(const char* path, const char* key, int64_t chkptId, int64_t* processVer) { +int32_t taskDbOpen(const char* path, const char* key, int64_t chkptId, int64_t* processVer, STaskDbWrapper** ppTaskDb) { char* statePath = NULL; char* dbPath = NULL; int code = 0; - terrno = 0; if ((code = restoreCheckpointData(path, key, chkptId, &statePath, &dbPath, processVer)) < 0) { - terrno = code; stError("failed to restore checkpoint data, path:%s, key:%s, checkpointId: %" PRId64 "reason:%s", path, key, - chkptId, tstrerror(terrno)); - return NULL; + chkptId, tstrerror(code)); + return code; } STaskDbWrapper* pTaskDb = taskDbOpenImpl(key, statePath, dbPath); if (pTaskDb != NULL) { int64_t chkpId = -1, ver = -1; - if ((code = chkpLoadExtraInfo(dbPath, &chkpId, &ver) == 0)) { + if ((code = chkpLoadExtraInfo(dbPath, &chkpId, &ver)) == 0) { *processVer = ver; } else { - terrno = code; stError("failed to load extra info, path:%s, key:%s, checkpointId: %" PRId64 "reason:%s", path, key, chkptId, - tstrerror(terrno)); + tstrerror(code)); taskDbDestroy(pTaskDb, false); - return NULL; + return code; } + } else { + code = TSDB_CODE_INVALID_PARA; } taosMemoryFree(dbPath); taosMemoryFree(statePath); - return pTaskDb; + *ppTaskDb = pTaskDb; + return code; } void taskDbDestroy(void* pDb, bool flush) { @@ -2650,7 +2658,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { - taosReleaseRef(taskDbWrapperId, refId); + (void)taosReleaseRef(taskDbWrapperId, refId); return TSDB_CODE_OUT_OF_MEMORY; } @@ -2658,7 +2666,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char snprintf(buf, cap, "%s%s%s%s%s%" PRId64 "", pDb->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, "checkpoint", chkpId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(buf); - taosReleaseRef(taskDbWrapperId, refId); + (void)taosReleaseRef(taskDbWrapperId, refId); return TSDB_CODE_OUT_OF_RANGE; } @@ -2669,7 +2677,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char taosMemoryFree(buf); } - taosReleaseRef(taskDbWrapperId, refId); + (void)taosReleaseRef(taskDbWrapperId, refId); return code; } @@ -2794,8 +2802,10 @@ int32_t streamStateCvtDataFormat(char* path, char* key, void* pCfInst) { int32_t code = 0; int64_t processVer = -1; - STaskDbWrapper* pTaskDb = taskDbOpen(path, key, 0, &processVer); - RocksdbCfInst* pSrcBackend = pCfInst; + STaskDbWrapper* pTaskDb = NULL; + + code = taskDbOpen(path, key, 0, &processVer, &pTaskDb); + RocksdbCfInst* pSrcBackend = pCfInst; for (int i = 0; i < nCf; i++) { rocksdb_column_family_handle_t* pSrcCf = pSrcBackend->pHandle[i]; @@ -2904,7 +2914,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t inst->dbOpt = handle->dbOpt; rocksdb_writeoptions_disable_WAL(inst->wOpt, 1); - taosHashPut(handle->cfInst, idstr, strlen(idstr) + 1, &inst, sizeof(void*)); + (void)taosHashPut(handle->cfInst, idstr, strlen(idstr) + 1, &inst, sizeof(void*)); } else { inst = *pInst; } @@ -3144,9 +3154,9 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe break; \ } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ - atomic_add_fetch_64(&wrapper->dataWritten, 1); \ + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \ + if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_writeoptions_t* opts = wrapper->writeOpt; \ @@ -3178,7 +3188,7 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \ + if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_t* db = wrapper->db; \ @@ -3221,9 +3231,9 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe break; \ } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ - atomic_add_fetch_64(&wrapper->dataWritten, 1); \ + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \ + if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_t* db = wrapper->db; \ @@ -3262,7 +3272,7 @@ int32_t streamStateClear_rocksdb(SStreamState* pState) { stDebug("streamStateClear_rocksdb"); STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - atomic_add_fetch_64(&wrapper->dataWritten, 1); + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); char sKeyStr[128] = {0}; char eKeyStr[128] = {0}; @@ -3278,8 +3288,8 @@ int32_t streamStateClear_rocksdb(SStreamState* pState) { if (err != NULL) { char toStringStart[128] = {0}; char toStringEnd[128] = {0}; - stateKeyToString(&sKey, toStringStart); - stateKeyToString(&eKey, toStringEnd); + (void)stateKeyToString(&sKey, toStringStart); + (void)stateKeyToString(&eKey, toStringEnd); stWarn("failed to delete range cf(state) start: %s, end:%s, reason:%s", toStringStart, toStringEnd, err); taosMemoryFree(err); @@ -3296,15 +3306,21 @@ void streamStateCurNext_rocksdb(SStreamStateCur* pCur) { } } int32_t streamStateGetFirst_rocksdb(SStreamState* pState, SWinKey* key) { + int code = 0; stDebug("streamStateGetFirst_rocksdb"); SWinKey tmp = {.ts = 0, .groupId = 0}; - streamStatePut_rocksdb(pState, &tmp, NULL, 0); + code = streamStatePut_rocksdb(pState, &tmp, NULL, 0); + if (code != 0) { + return code; + } SStreamStateCur* pCur = streamStateSeekKeyNext_rocksdb(pState, &tmp); - int32_t code = streamStateGetKVByCur_rocksdb(pCur, key, NULL, 0); + code = streamStateGetKVByCur_rocksdb(pCur, key, NULL, 0); + if (code != 0) { + return code; + } streamStateFreeCur(pCur); - streamStateDel_rocksdb(pState, &tmp); - return code; + return streamStateDel_rocksdb(pState, &tmp); } int32_t streamStateGetGroupKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen) { @@ -3333,6 +3349,9 @@ int32_t streamStateAddIfNotExist_rocksdb(SStreamState* pState, const SWinKey* ke return 0; } *pVal = taosMemoryMalloc(size); + if (*pVal == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } memset(*pVal, 0, size); return 0; } @@ -3349,7 +3368,7 @@ int32_t streamStateGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, cons if (rocksdb_iter_valid(pCur->iter) && !iterValueIsStale(pCur->iter)) { size_t tlen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &tlen); - stateKeyDecode((void*)pKtmp, keyStr); + (void)stateKeyDecode((void*)pKtmp, keyStr); if (pKtmp->opNum != pCur->number) { return -1; } @@ -3402,7 +3421,7 @@ SStreamStateCur* streamStateSeekKeyNext_rocksdb(SStreamState* pState, const SWin SStateKey curKey; size_t kLen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - stateKeyDecode((void*)&curKey, keyStr); + (void)stateKeyDecode((void*)&curKey, keyStr); if (stateKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) > 0) { return pCur; } @@ -3424,7 +3443,7 @@ SStreamStateCur* streamStateSeekToLast_rocksdb(SStreamState* pState) { { char tbuf[256] = {0}; - stateKeyToString((void*)&maxStateKey, tbuf); + (void)stateKeyToString((void*)&maxStateKey, tbuf); stDebug("seek to last:%s", tbuf); } @@ -3474,7 +3493,7 @@ SStreamStateCur* streamStateGetCur_rocksdb(SStreamState* pState, const SWinKey* SStateKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - stateKeyDecode((void*)&curKey, keyStr); + (void)stateKeyDecode((void*)&curKey, keyStr); if (stateKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) == 0) { pCur->number = pState->number; @@ -3622,7 +3641,7 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev_rocksdb(SStreamState* pSta size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - stateSessionKeyDecode(&curKey, (char*)iKey); + (void)stateSessionKeyDecode(&curKey, (char*)iKey); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) >= 0) return pCur; rocksdb_iter_prev(pCur->iter); @@ -3659,7 +3678,7 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext_rocksdb(SStreamState* pSta size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - stateSessionKeyDecode(&curKey, (char*)iKey); + (void)stateSessionKeyDecode(&curKey, (char*)iKey); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) <= 0) return pCur; rocksdb_iter_next(pCur->iter); @@ -3699,7 +3718,7 @@ SStreamStateCur* streamStateSessionSeekKeyNext_rocksdb(SStreamState* pState, con size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - stateSessionKeyDecode(&curKey, (char*)iKey); + (void)stateSessionKeyDecode(&curKey, (char*)iKey); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) < 0) return pCur; rocksdb_iter_next(pCur->iter); @@ -3739,7 +3758,7 @@ SStreamStateCur* streamStateSessionSeekKeyPrev_rocksdb(SStreamState* pState, con size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - stateSessionKeyDecode(&curKey, (char*)iKey); + (void)stateSessionKeyDecode(&curKey, (char*)iKey); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) > 0) return pCur; rocksdb_iter_prev(pCur->iter); @@ -3762,7 +3781,7 @@ int32_t streamStateSessionGetKVByCur_rocksdb(SStreamStateCur* pCur, SSessionKey* return -1; } const char* curKey = rocksdb_iter_key(pCur->iter, (size_t*)&kLen); - stateSessionKeyDecode((void*)&ktmp, (char*)curKey); + (void)stateSessionKeyDecode((void*)&ktmp, (char*)curKey); if (pVal != NULL) *pVal = NULL; if (pVLen != NULL) *pVLen = 0; @@ -3841,7 +3860,7 @@ SStreamStateCur* streamStateFillGetCur_rocksdb(SStreamState* pState, const SWinK size_t kLen; SWinKey curKey; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - winKeyDecode((void*)&curKey, keyStr); + (void)winKeyDecode((void*)&curKey, keyStr); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) == 0) { return pCur; } @@ -3861,7 +3880,7 @@ int32_t streamStateFillGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, } size_t klen, vlen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &klen); - winKeyDecode(&winKey, keyStr); + (void)winKeyDecode(&winKey, keyStr); const char* valStr = rocksdb_iter_value(pCur->iter, &vlen); int32_t len = valueDecode((void*)valStr, vlen, NULL, (char**)pVal); @@ -3902,7 +3921,7 @@ SStreamStateCur* streamStateFillSeekKeyNext_rocksdb(SStreamState* pState, const SWinKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - winKeyDecode((void*)&curKey, keyStr); + (void)winKeyDecode((void*)&curKey, keyStr); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) < 0) { return pCur; } @@ -3939,7 +3958,7 @@ SStreamStateCur* streamStateFillSeekKeyPrev_rocksdb(SStreamState* pState, const SWinKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - winKeyDecode((void*)&curKey, keyStr); + (void)winKeyDecode((void*)&curKey, keyStr); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) > 0) { return pCur; } @@ -4022,11 +4041,12 @@ int32_t streamStateSessionAddIfNotExist_rocksdb(SStreamState* pState, SSessionKe int32_t valSize = *pVLen; void* tmp = taosMemoryMalloc(valSize); + if (tmp == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev_rocksdb(pState, key); - if (pCur == NULL) { - } - int32_t code = streamStateSessionGetKVByCur_rocksdb(pCur, key, pVal, pVLen); + int32_t code = streamStateSessionGetKVByCur_rocksdb(pCur, key, pVal, pVLen); if (code == 0) { if (sessionRangeKeyCmpr(&searchKey, key) == 0) { @@ -4074,7 +4094,7 @@ void streamStateSessionClear_rocksdb(SStreamState* pState) { if (code == 0 && size > 0) { memset(buf, 0, size); // refactor later - streamStateSessionPut_rocksdb(pState, &delKey, buf, size); + (void)streamStateSessionPut_rocksdb(pState, &delKey, buf, size); } else { taosMemoryFreeClear(buf); break; @@ -4212,7 +4232,7 @@ int32_t streamDefaultIterGet_rocksdb(SStreamState* pState, const void* start, co if (strncmp(key, start, strlen(start)) == 0 && strlen(key) >= strlen(start) + 1) { int64_t checkPoint = 0; if (sscanf(key + strlen(key), ":%" PRId64 "", &checkPoint) == 1) { - taosArrayPush(result, &checkPoint); + (void)taosArrayPush(result, &checkPoint); } } else { break; @@ -4284,7 +4304,7 @@ void streamStateDestroyBatch(void* pBatch) { rocksdb_writebatch_destroy((rock int32_t streamStatePutBatch(SStreamState* pState, const char* cfKeyName, rocksdb_writebatch_t* pBatch, void* key, void* val, int32_t vlen, int64_t ttl) { STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - atomic_add_fetch_64(&wrapper->dataWritten, 1); + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); int i = streamStateGetCfIdx(pState, cfKeyName); if (i < 0) { @@ -4304,7 +4324,7 @@ int32_t streamStatePutBatch(SStreamState* pState, const char* cfKeyName, rocksdb { char tbuf[256] = {0}; - ginitDict[i].toStrFunc((void*)key, tbuf); + (void)(ginitDict[i].toStrFunc((void*)key, tbuf)); stTrace("streamState str: %s succ to write to %s_%s, len: %d", tbuf, wrapper->idstr, ginitDict[i].key, vlen); } return 0; @@ -4319,7 +4339,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - atomic_add_fetch_64(&wrapper->dataWritten, 1); + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); rocksdb_column_family_handle_t* pCf = wrapper->pCf[ginitDict[cfIdx].idx]; rocksdb_writebatch_put_cf((rocksdb_writebatch_t*)pBatch, pCf, buf, (size_t)klen, ttlV, (size_t)ttlVLen); @@ -4330,7 +4350,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb { char tbuf[256] = {0}; - ginitDict[cfIdx].toStrFunc((void*)key, tbuf); + (void)(ginitDict[cfIdx].toStrFunc((void*)key, tbuf)); stTrace("streamState str: %s succ to write to %s_%s", tbuf, wrapper->idstr, ginitDict[cfIdx].key); } return 0; @@ -4338,7 +4358,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb int32_t streamStatePutBatch_rocksdb(SStreamState* pState, void* pBatch) { char* err = NULL; STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - atomic_add_fetch_64(&wrapper->dataWritten, 1); + (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); rocksdb_write(wrapper->db, wrapper->writeOpt, (rocksdb_writebatch_t*)pBatch, &err); if (err != NULL) { stError("streamState failed to write batch, err:%s", err); @@ -4427,8 +4447,8 @@ int32_t compareHashTableImpl(SHashObj* p1, SHashObj* p2, SArray* diff) { if (fname == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - strncpy(fname, name, len); - taosArrayPush(diff, &fname); + (void)strncpy(fname, name, len); + (void)taosArrayPush(diff, &fname); } pIter = taosHashIterate(p2, pIter); } @@ -4504,7 +4524,7 @@ void dbChkpDebugInfo(SDbChkp* pDb) { int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { int32_t code = 0; int32_t nBytes; - taosThreadRwlockWrlock(&p->rwLock); + (void)taosThreadRwlockWrlock(&p->rwLock); p->preCkptId = p->curChkpId; p->curChkpId = chkpId; @@ -4522,7 +4542,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { nBytes = snprintf(p->buf, p->len, "%s%s%s%scheckpoint%" PRId64 "", p->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, chkpId); if (nBytes <= 0 || nBytes >= p->len) { - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return TSDB_CODE_OUT_OF_RANGE; } @@ -4532,7 +4552,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { TdDirPtr pDir = taosOpenDir(p->buf); if (pDir == NULL) { - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return TAOS_SYSTEM_ERROR(errno); } @@ -4568,9 +4588,9 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { continue; } } - taosCloseDir(&pDir); + (void)taosCloseDir(&pDir); if (code != 0) { - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return code; } @@ -4582,12 +4602,12 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { if (name != NULL && !isBkdDataMeta(name, len)) { char* fname = taosMemoryCalloc(1, len + 1); if (fname == NULL) { - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return TSDB_CODE_OUT_OF_MEMORY; } - strncpy(fname, name, len); - taosArrayPush(p->pAdd, &fname); + (void)strncpy(fname, name, len); + (void)taosArrayPush(p->pAdd, &fname); } pIter = taosHashIterate(p->pSstTbl[1 - p->idx], pIter); } @@ -4619,17 +4639,18 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { p->idx = 1 - p->idx; - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return code; } void dbChkpDestroy(SDbChkp* pChkp); -SDbChkp* dbChkpCreate(char* path, int64_t initChkpId) { +int32_t dbChkpCreate(char* path, int64_t initChkpId, SDbChkp** ppChkp) { + int32_t code = 0; SDbChkp* p = taosMemoryCalloc(1, sizeof(SDbChkp)); if (p == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } @@ -4637,57 +4658,57 @@ SDbChkp* dbChkpCreate(char* path, int64_t initChkpId) { p->preCkptId = -1; p->pSST = taosArrayInit(64, sizeof(void*)); if (p->pSST == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; dbChkpDestroy(p); - return NULL; + return code; } p->path = path; p->len = strlen(path) + 128; p->buf = taosMemoryCalloc(1, p->len); if (p->buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } p->idx = 0; p->pSstTbl[0] = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (p->pSstTbl[0] == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } p->pSstTbl[1] = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (p->pSstTbl[1] == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } p->pAdd = taosArrayInit(64, sizeof(void*)); if (p->pAdd == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } p->pDel = taosArrayInit(64, sizeof(void*)); if (p->pDel == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; goto _EXIT; } p->update = 0; - taosThreadRwlockInit(&p->rwLock, NULL); + (void)taosThreadRwlockInit(&p->rwLock, NULL); SArray* list = NULL; - int32_t code = dbChkpGetDelta(p, initChkpId, list); + code = dbChkpGetDelta(p, initChkpId, list); if (code != 0) { goto _EXIT; } - - return p; + *ppChkp = p; + return code; _EXIT: dbChkpDestroy(p); - return NULL; + return code; } void dbChkpDestroy(SDbChkp* pChkp) { @@ -4717,7 +4738,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { static char* chkpMeta = "META"; int32_t code = 0; - taosThreadRwlockRdlock(&p->rwLock); + (void)taosThreadRwlockRdlock(&p->rwLock); int32_t cap = p->len + 128; @@ -4790,7 +4811,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { code = TSDB_CODE_OUT_OF_MEMORY; goto _ERROR; } - taosArrayPush(list, &p); + (void)taosArrayPush(list, &p); } // copy current file to dst dir @@ -4856,7 +4877,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { if (nBytes <= 0 || nBytes >= sizeof(content)) { code = TSDB_CODE_OUT_OF_RANGE; stError("chkp failed to format meta file: %s, reason: invalid msg", dstDir); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); goto _ERROR; } @@ -4864,10 +4885,10 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { if (nBytes != strlen(content)) { code = TAOS_SYSTEM_ERROR(errno); stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code)); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); goto _ERROR; } - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); // clear delta data buf taosArrayClearP(p->pAdd, NULL); @@ -4876,39 +4897,40 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { _ERROR: taosMemoryFree(buffer); - taosThreadRwlockUnlock(&p->rwLock); + (void)taosThreadRwlockUnlock(&p->rwLock); return code; } -SBkdMgt* bkdMgtCreate(char* path) { - terrno = 0; +int32_t bkdMgtCreate(char* path, SBkdMgt** mgt) { + int32_t code = 0; SBkdMgt* p = taosMemoryCalloc(1, sizeof(SBkdMgt)); if (p == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + code = TSDB_CODE_OUT_OF_MEMORY; + return code; } p->pDbChkpTbl = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (p->pDbChkpTbl == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; bkdMgtDestroy(p); - return NULL; + return code; } p->path = taosStrdup(path); if (p->path == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; bkdMgtDestroy(p); - return NULL; + return code; } if (taosThreadRwlockInit(&p->rwLock, NULL) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); + code = TAOS_SYSTEM_ERROR(errno); bkdMgtDestroy(p); - return NULL; + return code; } + *mgt = p; - return p; + return code; } void bkdMgtDestroy(SBkdMgt* bm) { @@ -4921,7 +4943,7 @@ void bkdMgtDestroy(SBkdMgt* bm) { pIter = taosHashIterate(bm->pDbChkpTbl, pIter); } - taosThreadRwlockDestroy(&bm->rwLock); + (void)taosThreadRwlockDestroy(&bm->rwLock); taosMemoryFree(bm->path); taosHashCleanup(bm->pDbChkpTbl); @@ -4929,7 +4951,7 @@ void bkdMgtDestroy(SBkdMgt* bm) { } int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, char* dname) { int32_t code = 0; - taosThreadRwlockWrlock(&bm->rwLock); + (void)taosThreadRwlockWrlock(&bm->rwLock); SDbChkp** ppChkp = taosHashGet(bm->pDbChkpTbl, taskId, strlen(taskId)); SDbChkp* pChkp = ppChkp != NULL ? *ppChkp : NULL; @@ -4937,36 +4959,36 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, int32_t cap = strlen(bm->path) + 64; char* path = taosMemoryCalloc(1, cap); if (path == NULL) { - taosThreadRwlockUnlock(&bm->rwLock); + (void)taosThreadRwlockUnlock(&bm->rwLock); return TSDB_CODE_OUT_OF_MEMORY; } int32_t nBytes = snprintf(path, cap, "%s%s%s", bm->path, TD_DIRSEP, taskId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(path); - taosThreadRwlockUnlock(&bm->rwLock); + (void)taosThreadRwlockUnlock(&bm->rwLock); code = TSDB_CODE_OUT_OF_RANGE; return code; } - SDbChkp* p = dbChkpCreate(path, chkpId); - if (p == NULL) { + SDbChkp* p = NULL; + code = dbChkpCreate(path, chkpId, &p); + if (code != 0) { taosMemoryFree(path); - taosThreadRwlockUnlock(&bm->rwLock); - code = terrno; + (void)taosThreadRwlockUnlock(&bm->rwLock); return code; } if (taosHashPut(bm->pDbChkpTbl, taskId, strlen(taskId), &p, sizeof(void*)) != 0) { dbChkpDestroy(p); - taosThreadRwlockUnlock(&bm->rwLock); + (void)taosThreadRwlockUnlock(&bm->rwLock); code = terrno; return code; } pChkp = p; code = dbChkpDumpTo(pChkp, dname, list); - taosThreadRwlockUnlock(&bm->rwLock); + (void)taosThreadRwlockUnlock(&bm->rwLock); return code; } else { code = dbChkpGetDelta(pChkp, chkpId, NULL); @@ -4975,7 +4997,7 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, } } - taosThreadRwlockUnlock(&bm->rwLock); + (void)taosThreadRwlockUnlock(&bm->rwLock); return code; } @@ -4986,8 +5008,9 @@ int32_t bkdMgtAddChkp(SBkdMgt* bm, char* task, char* path) { taosThreadRwlockWrlock(&bm->rwLock); SDbChkp** pp = taosHashGet(bm->pDbChkpTbl, task, strlen(task)); if (pp == NULL) { - SDbChkp* p = dbChkpCreate(path, 0); - if (p != NULL) { + SDbChkp* p = NULL; + code = dbChkpCreate(path, 0, &p); + if (code != 0) { taosHashPut(bm->pDbChkpTbl, task, strlen(task), &p, sizeof(void*)); code = 0; } diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index 625305da03..c9ba6ffcfe 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -283,6 +283,8 @@ void streamTaskStartMonitorCheckRsp(SStreamTask* pTask) { // drop procedure already started, not start check downstream now ETaskStatus s = streamTaskGetStatus(pTask).state; if (s == TASK_STATUS__DROPPING) { + stDebug("s-task:%s task not in uninit status, status:%s not start monitor check-rsp", pTask->id.idStr, + streamTaskGetStatusStr(s)); streamMutexUnlock(&pInfo->checkInfoLock); return; } diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index f2c2416ab9..c606857a65 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -253,6 +253,7 @@ int32_t streamProcessCheckpointTriggerBlock(SStreamTask* pTask, SStreamDataBlock for (int32_t i = 0; i < taosArrayGetSize(pActiveInfo->pReadyMsgList); ++i) { STaskCheckpointReadyInfo* p = taosArrayGet(pActiveInfo->pReadyMsgList, i); if (p == NULL) { + streamMutexUnlock(&pTask->lock); return TSDB_CODE_INVALID_PARA; } @@ -390,6 +391,7 @@ int32_t streamProcessCheckpointReadyMsg(SStreamTask* pTask, int64_t checkpointId for (int32_t i = 0; i < size; ++i) { STaskDownstreamReadyInfo* p = taosArrayGet(pInfo->pCheckpointReadyRecvList, i); if (p == NULL) { + streamMutexUnlock(&pInfo->lock); return TSDB_CODE_INVALID_PARA; } @@ -433,6 +435,7 @@ int32_t streamTaskProcessCheckpointReadyRsp(SStreamTask* pTask, int32_t upstream for (int32_t i = 0; i < taosArrayGetSize(pInfo->pReadyMsgList); ++i) { STaskCheckpointReadyInfo* pReadyInfo = taosArrayGet(pInfo->pReadyMsgList, i); if (pReadyInfo == NULL) { + streamMutexUnlock(&pInfo->lock); return TSDB_CODE_INVALID_PARA; } @@ -447,6 +450,7 @@ int32_t streamTaskProcessCheckpointReadyRsp(SStreamTask* pTask, int32_t upstream for (int32_t i = 0; i < taosArrayGetSize(pInfo->pReadyMsgList); ++i) { STaskCheckpointReadyInfo* pReadyInfo = taosArrayGet(pInfo->pReadyMsgList, i); if (pReadyInfo == NULL) { + streamMutexUnlock(&pInfo->lock); return TSDB_CODE_INVALID_PARA; } @@ -830,6 +834,7 @@ void checkpointTriggerMonitorFn(void* param, void* tmrId) { if (pNotSendList == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; stDebug("s-task:%s start to triggerMonitor, reason:%s", id, tstrerror(terrno)); + streamMutexUnlock(&pActiveInfo->lock); return; } @@ -938,13 +943,14 @@ bool streamTaskAlreadySendTrigger(SStreamTask* pTask, int32_t downstreamNodeId) streamMutexLock(&pInfo->lock); if (!pInfo->dispatchTrigger) { - streamMutexUnlock(&pTask->lock); + streamMutexUnlock(&pInfo->lock); return false; } for (int32_t i = 0; i < taosArrayGetSize(pInfo->pDispatchTriggerList); ++i) { STaskTriggerSendInfo* pSendInfo = taosArrayGet(pInfo->pDispatchTriggerList, i); if (pSendInfo == NULL) { + streamMutexUnlock(&pInfo->lock); return TSDB_CODE_INVALID_PARA; } @@ -964,11 +970,11 @@ bool streamTaskAlreadySendTrigger(SStreamTask* pTask, int32_t downstreamNodeId) id, pSendInfo->sendTs, before, pInfo->activeId, pInfo->transId); } - streamMutexUnlock(&pTask->lock); + streamMutexUnlock(&pInfo->lock); return true; } - ASSERT(0); + streamMutexUnlock(&pInfo->lock); return false; } @@ -1028,6 +1034,7 @@ int32_t streamTaskGetNumOfConfirmed(SStreamTask* pTask) { for (int32_t i = 0; i < taosArrayGetSize(pInfo->pDispatchTriggerList); ++i) { STaskTriggerSendInfo* p = taosArrayGet(pInfo->pDispatchTriggerList, i); if (p == NULL) { + streamMutexUnlock(&pInfo->lock); return num; } diff --git a/source/libs/stream/src/streamData.c b/source/libs/stream/src/streamData.c index 00a62d4773..57e5322e38 100644 --- a/source/libs/stream/src/streamData.c +++ b/source/libs/stream/src/streamData.c @@ -219,13 +219,17 @@ int32_t streamQueueMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* pElem if (dst->type == STREAM_INPUT__DATA_BLOCK && pElem->type == STREAM_INPUT__DATA_BLOCK) { SStreamDataBlock* pBlock = (SStreamDataBlock*)dst; SStreamDataBlock* pBlockSrc = (SStreamDataBlock*)pElem; - (void) taosArrayAddAll(pBlock->blocks, pBlockSrc->blocks); + void* px = taosArrayAddAll(pBlock->blocks, pBlockSrc->blocks); + if (px == NULL) { + return terrno; + } + taosArrayDestroy(pBlockSrc->blocks); streamQueueItemIncSize(dst, streamQueueItemGetSize(pElem)); taosFreeQitem(pElem); *pRes = dst; - return TSDB_CODE_SUCCESS; + return code; } else if (dst->type == STREAM_INPUT__MERGED_SUBMIT && pElem->type == STREAM_INPUT__DATA_SUBMIT) { SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)dst; SStreamDataSubmit* pBlockSrc = (SStreamDataSubmit*)pElem; diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 94772f0e15..41276f449b 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -907,8 +907,8 @@ int32_t streamTaskSendCheckpointReadyMsg(SStreamTask* pTask) { STaskCheckpointReadyInfo* pInfo = taosArrayGet(pList, i); SRpcMsg msg = {0}; - int32_t code = initCheckpointReadyMsg(pTask, pInfo->upstreamNodeId, pInfo->upstreamTaskId, pInfo->childId, pInfo->checkpointId, - &msg); + int32_t code = initCheckpointReadyMsg(pTask, pInfo->upstreamNodeId, pInfo->upstreamTaskId, pInfo->childId, + pInfo->checkpointId, &msg); if (code == TSDB_CODE_SUCCESS) { code = tmsgSendReq(&pInfo->upstreamNodeEpset, &msg); if (code == TSDB_CODE_SUCCESS) { diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 7b410501ca..08cf490b94 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -68,12 +68,12 @@ static void streamMetaEnvInit() { } } -void streamMetaInit() { (void) taosThreadOnce(&streamMetaModuleInit, streamMetaEnvInit); } +void streamMetaInit() { (void)taosThreadOnce(&streamMetaModuleInit, streamMetaEnvInit); } void streamMetaCleanup() { - (void) taosCloseRef(streamBackendId); - (void) taosCloseRef(streamBackendCfWrapperId); - (void) taosCloseRef(streamMetaId); + (void)taosCloseRef(streamBackendId); + (void)taosCloseRef(streamBackendCfWrapperId); + (void)taosCloseRef(streamMetaId); metaRefMgtCleanup(); streamTimerCleanUp(); @@ -128,12 +128,12 @@ int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid) { code = taosHashPut(gMetaRefMgt.pTable, &vgId, sizeof(vgId), &list, sizeof(void*)); if (code) { - stError("vgId:%d failed to put into metaRef table, rid:%" PRId64, (int32_t) vgId, *rid); + stError("vgId:%d failed to put into metaRef table, rid:%" PRId64, (int32_t)vgId, *rid); return code; } } else { SArray* list = *(SArray**)p; - void* px = taosArrayPush(list, &rid); + void* px = taosArrayPush(list, &rid); if (px == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; } @@ -186,7 +186,7 @@ int32_t streamMetaCheckBackendCompatible(SStreamMeta* pMeta) { code = tdbTbcMoveToFirst(pCur); if (code) { - (void) tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); stError("vgId:%d failed to open stream meta file cursor, not perform compatible check", pMeta->vgId); return ret; } @@ -215,7 +215,7 @@ int32_t streamMetaCheckBackendCompatible(SStreamMeta* pMeta) { tdbFree(pKey); tdbFree(pVal); - (void) tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return ret; } @@ -276,6 +276,7 @@ int32_t streamMetaMayCvtDbFormat(SStreamMeta* pMeta) { } int32_t streamTaskSetDb(SStreamMeta* pMeta, SStreamTask* pTask, const char* key) { + int32_t code = 0; int64_t chkpId = pTask->chkInfo.checkpointId; streamMutexLock(&pMeta->backendMutex); @@ -299,8 +300,8 @@ int32_t streamTaskSetDb(SStreamMeta* pMeta, SStreamTask* pTask, const char* key) STaskDbWrapper* pBackend = NULL; int64_t processVer = -1; while (1) { - pBackend = taskDbOpen(pMeta->path, key, chkpId, &processVer); - if (pBackend != NULL) { + code = taskDbOpen(pMeta->path, key, chkpId, &processVer, &pBackend); + if (code == 0) { break; } @@ -319,7 +320,7 @@ int32_t streamTaskSetDb(SStreamMeta* pMeta, SStreamTask* pTask, const char* key) if (processVer != -1) pTask->chkInfo.processedVer = processVer; - int32_t code = taosHashPut(pMeta->pTaskDbUnique, key, strlen(key), &pBackend, sizeof(void*)); + code = taosHashPut(pMeta->pTaskDbUnique, key, strlen(key), &pBackend, sizeof(void*)); if (code) { stError("s-task:0x%x failed to put taskDb backend, code:out of memory", pTask->id.taskId); } @@ -469,8 +470,8 @@ int32_t streamMetaOpen(const char* path, void* ahandle, FTaskBuild buildTaskFn, pMeta->qHandle = taosInitScheduler(32, 1, "stream-chkp", NULL); - pMeta->bkdChkptMgt = bkdMgtCreate(tpath); - if (pMeta->bkdChkptMgt == NULL) { + code = bkdMgtCreate(tpath, (SBkdMgt**)&pMeta->bkdChkptMgt); + if (code != 0) { goto _err; } @@ -485,7 +486,7 @@ _err: if (pMeta->pTaskList) taosArrayDestroy(pMeta->pTaskList); if (pMeta->pTaskDb) (void)tdbTbClose(pMeta->pTaskDb); if (pMeta->pCheckpointDb) (void)tdbTbClose(pMeta->pCheckpointDb); - if (pMeta->db) (void) tdbClose(pMeta->db); + if (pMeta->db) (void)tdbClose(pMeta->db); if (pMeta->pHbInfo) taosMemoryFreeClear(pMeta->pHbInfo); if (pMeta->updateInfo.pTasks) taosHashCleanup(pMeta->updateInfo.pTasks); if (pMeta->startInfo.pReadyTaskSet) taosHashCleanup(pMeta->startInfo.pReadyTaskSet); @@ -531,7 +532,7 @@ void streamMetaClear(SStreamMeta* pMeta) { // release the ref by timer if (p->info.delaySchedParam != 0 && p->info.fillHistory == 0) { // one more ref in timer stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", p->id.idStr, p->refCnt); - (void) taosTmrStop(p->schedInfo.pDelayTimer); + (void)taosTmrStop(p->schedInfo.pDelayTimer); p->info.delaySchedParam = 0; streamMetaReleaseTask(pMeta, p); } @@ -566,7 +567,7 @@ void streamMetaClose(SStreamMeta* pMeta) { if (pMeta == NULL) { return; } - (void) taosRemoveRef(streamMetaId, pMeta->rid); + (void)taosRemoveRef(streamMetaId, pMeta->rid); } void streamMetaCloseImpl(void* arg) { @@ -583,10 +584,10 @@ void streamMetaCloseImpl(void* arg) { streamMetaWUnLock(pMeta); // already log the error, ignore here - (void) tdbAbort(pMeta->db, pMeta->txn); - (void) tdbTbClose(pMeta->pTaskDb); - (void) tdbTbClose(pMeta->pCheckpointDb); - (void) tdbClose(pMeta->db); + (void)tdbAbort(pMeta->db, pMeta->txn); + (void)tdbTbClose(pMeta->pTaskDb); + (void)tdbTbClose(pMeta->pCheckpointDb); + (void)tdbClose(pMeta->db); taosArrayDestroy(pMeta->pTaskList); taosArrayDestroy(pMeta->chkpSaved); @@ -610,7 +611,7 @@ void streamMetaCloseImpl(void* arg) { bkdMgtDestroy(pMeta->bkdChkptMgt); pMeta->role = NODE_ROLE_UNINIT; - (void) taosThreadRwlockDestroy(&pMeta->lock); + (void)taosThreadRwlockDestroy(&pMeta->lock); taosMemoryFree(pMeta); stDebug("vgId:%d end to close stream meta", vgId); @@ -691,13 +692,13 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa p = taosArrayPush(pMeta->pTaskList, &pTask->id); if (p == NULL) { - stError("s-task:0x%"PRIx64" failed to register task into meta-list, code: out of memory", id.taskId); + stError("s-task:0x%" PRIx64 " failed to register task into meta-list, code: out of memory", id.taskId); return TSDB_CODE_OUT_OF_MEMORY; } code = taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask, POINTER_BYTES); if (code) { - stError("s-task:0x%"PRIx64" failed to register task into meta-list, code: out of memory", id.taskId); + stError("s-task:0x%" PRIx64 " failed to register task into meta-list, code: out of memory", id.taskId); return code; } @@ -710,7 +711,7 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa } if (pTask->info.fillHistory == 0) { - (void) atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); + (void)atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); } *pAdded = true; @@ -779,7 +780,7 @@ static void doRemoveIdFromList(SArray* pTaskList, int32_t num, SStreamTaskId* id static int32_t streamTaskSendTransSuccessMsg(SStreamTask* pTask, void* param) { if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { - (void) streamTaskSendCheckpointSourceRsp(pTask); + (void)streamTaskSendCheckpointSourceRsp(pTask); } return 0; } @@ -802,7 +803,7 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t } // handle the dropping event - (void) streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_DROPPING, streamTaskSendTransSuccessMsg, NULL); + (void)streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_DROPPING, streamTaskSendTransSuccessMsg, NULL); } else { stDebug("vgId:%d failed to find the task:0x%x, it may be dropped already", pMeta->vgId, taskId); streamMetaWUnLock(pMeta); @@ -841,12 +842,12 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t pTask = *ppTask; // it is an fill-history task, remove the related stream task's id that points to it if (pTask->info.fillHistory == 0) { - (void) atomic_sub_fetch_32(&pMeta->numOfStreamTasks, 1); + (void)atomic_sub_fetch_32(&pMeta->numOfStreamTasks, 1); } - (void) taosHashRemove(pMeta->pTasksMap, &id, sizeof(id)); + (void)taosHashRemove(pMeta->pTasksMap, &id, sizeof(id)); doRemoveIdFromList(pMeta->pTaskList, (int32_t)taosArrayGetSize(pMeta->pTaskList), &pTask->id); - (void) streamMetaRemoveTask(pMeta, &id); + (void)streamMetaRemoveTask(pMeta, &id); ASSERT(taosHashGetSize(pMeta->pTasksMap) == taosArrayGetSize(pMeta->pTaskList)); streamMetaWUnLock(pMeta); @@ -854,7 +855,7 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t ASSERT(pTask->status.timerActive == 0); if (pTask->info.delaySchedParam != 0 && pTask->info.fillHistory == 0) { stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", pTask->id.idStr, pTask->refCnt); - (void) taosTmrStop(pTask->schedInfo.pDelayTimer); + (void)taosTmrStop(pTask->schedInfo.pDelayTimer); pTask->info.delaySchedParam = 0; streamMetaReleaseTask(pMeta, pTask); } @@ -915,7 +916,7 @@ int64_t streamMetaGetLatestCheckpointId(SStreamMeta* pMeta) { code = tdbTbcMoveToFirst(pCur); if (code) { - (void) tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); stError("failed to open stream meta file cursor, the latest checkpointId is 0, vgId:%d", pMeta->vgId); return checkpointId; } @@ -953,7 +954,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { SDecoder decoder; int32_t vgId = 0; int32_t code = 0; - SArray* pRecycleList = NULL; + SArray* pRecycleList = NULL; if (pMeta == NULL) { return; @@ -975,7 +976,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { if (code) { stError("vgId:%d failed to open stream meta cursor, code:%s, not load any stream tasks", vgId, tstrerror(terrno)); taosArrayDestroy(pRecycleList); - (void) tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return; } @@ -1008,7 +1009,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { tFreeStreamTask(pTask); STaskId id = streamTaskGetTaskId(pTask); - (void) taosArrayPush(pRecycleList, &id); + (void)taosArrayPush(pRecycleList, &id); int32_t total = taosArrayGetSize(pRecycleList); stDebug("s-task:0x%x is already dropped, add into recycle list, total:%d", taskId, total); @@ -1029,7 +1030,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { continue; } - (void) taosArrayPush(pMeta->pTaskList, &pTask->id); + (void)taosArrayPush(pMeta->pTaskList, &pTask->id); } else { // todo this should replace the existed object put by replay creating stream task msg from mnode stError("s-task:0x%x already added into table meta by replaying WAL, need check", pTask->id.taskId); @@ -1039,17 +1040,17 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { if (taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask, POINTER_BYTES) != 0) { stError("s-task:0x%x failed to put into hashTable, code:%s, continue", pTask->id.taskId, tstrerror(terrno)); - (void) taosArrayPop(pMeta->pTaskList); + (void)taosArrayPop(pMeta->pTaskList); tFreeStreamTask(pTask); continue; } if (pTask->info.fillHistory == 0) { - (void) atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); + (void)atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1); } if (streamTaskShouldPause(pTask)) { - (void) atomic_add_fetch_32(&pMeta->numOfPausedTasks, 1); + (void)atomic_add_fetch_32(&pMeta->numOfPausedTasks, 1); } ASSERT(pTask->status.downstreamReady == 0); @@ -1065,7 +1066,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) { if (taosArrayGetSize(pRecycleList) > 0) { for (int32_t i = 0; i < taosArrayGetSize(pRecycleList); ++i) { STaskId* pId = taosArrayGet(pRecycleList, i); - (void) streamMetaRemoveTask(pMeta, pId); + (void)streamMetaRemoveTask(pMeta, pId); } } @@ -1093,7 +1094,7 @@ bool streamMetaTaskInTimer(SStreamMeta* pMeta) { SStreamTask* pTask = *(SStreamTask**)pIter; if (pTask->status.timerActive >= 1) { stDebug("s-task:%s in timer, blocking tasks in vgId:%d restart, set closing again", pTask->id.idStr, pMeta->vgId); - (void) streamTaskStop(pTask); + (void)streamTaskStop(pTask); inTimer = true; } } @@ -1126,7 +1127,7 @@ void streamMetaNotifyClose(SStreamMeta* pMeta) { SStreamTask* pTask = *(SStreamTask**)pIter; stDebug("vgId:%d s-task:%s set task closing flag", vgId, pTask->id.idStr); - (void) streamTaskStop(pTask); + (void)streamTaskStop(pTask); } streamMetaWUnLock(pMeta); @@ -1173,7 +1174,7 @@ void streamMetaResetStartInfo(STaskStartInfo* pStartInfo, int32_t vgId) { void streamMetaRLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-rlock", pMeta->vgId); - (void) taosThreadRwlockRdlock(&pMeta->lock); + (void)taosThreadRwlockRdlock(&pMeta->lock); } void streamMetaRUnLock(SStreamMeta* pMeta) { @@ -1188,24 +1189,27 @@ void streamMetaRUnLock(SStreamMeta* pMeta) { void streamMetaWLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-wlock", pMeta->vgId); - (void) taosThreadRwlockWrlock(&pMeta->lock); + (void)taosThreadRwlockWrlock(&pMeta->lock); // stTrace("vgId:%d meta-wlock completed", pMeta->vgId); } void streamMetaWUnLock(SStreamMeta* pMeta) { // stTrace("vgId:%d meta-wunlock", pMeta->vgId); - (void) taosThreadRwlockUnlock(&pMeta->lock); + (void)taosThreadRwlockUnlock(&pMeta->lock); } int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { - *pList = NULL; + QRY_OPTR_CHECK(pList); + int32_t code = 0; SArray* pTaskList = taosArrayDup(pMeta->pTaskList, NULL); if (pTaskList == NULL) { stError("failed to generate the task list during send hbMsg to mnode, vgId:%d, code: out of memory", pMeta->vgId); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } + *pList = pTaskList; + bool sendMsg = pMeta->sendMsgBeforeClosing; if (!sendMsg) { stDebug("vgId:%d no need to send msg to mnode before closing tasks", pMeta->vgId); @@ -1238,9 +1242,9 @@ int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { streamMetaReleaseTask(pMeta, pTask); } - code = streamMetaSendHbHelper(pMeta); + (void)streamMetaSendHbHelper(pMeta); pMeta->sendMsgBeforeClosing = false; - return code; + return TSDB_CODE_SUCCESS; // always return true } void streamMetaUpdateStageRole(SStreamMeta* pMeta, int64_t stage, bool isLeader) { @@ -1320,7 +1324,7 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { code = streamMetaAcquireTask(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask); if (pTask == NULL) { stError("vgId:%d failed to acquire task:0x%x during start tasks", pMeta->vgId, pTaskId->taskId); - (void) streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + (void)streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); continue; } @@ -1343,7 +1347,7 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { code = streamMetaAcquireTask(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask); if (pTask == NULL) { stError("vgId:%d failed to acquire task:0x%x during start tasks", pMeta->vgId, pTaskId->taskId); - (void) streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); + (void)streamMetaAddFailedTask(pMeta, pTaskId->streamId, pTaskId->taskId); continue; } @@ -1361,10 +1365,11 @@ int32_t streamMetaStartAllTasks(SStreamMeta* pMeta) { if (HAS_RELATED_FILLHISTORY_TASK(pTask)) { stDebug("s-task:%s downstream ready, no need to check downstream, check only related fill-history task", pTask->id.idStr); - (void) streamLaunchFillHistoryTask(pTask); // todo: how about retry launch fill-history task? + (void)streamLaunchFillHistoryTask(pTask); // todo: how about retry launch fill-history task? } - (void) streamMetaAddTaskLaunchResult(pMeta, pTaskId->streamId, pTaskId->taskId, pInfo->checkTs, pInfo->readyTs, true); + (void)streamMetaAddTaskLaunchResult(pMeta, pTaskId->streamId, pTaskId->taskId, pInfo->checkTs, pInfo->readyTs, + true); streamMetaReleaseTask(pMeta, pTask); continue; } @@ -1420,14 +1425,14 @@ int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) { for (int32_t i = 0; i < numOfTasks; ++i) { SStreamTaskId* pTaskId = taosArrayGet(pTaskList, i); - SStreamTask* pTask = NULL; + SStreamTask* pTask = NULL; code = streamMetaAcquireTaskNoLock(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask); if (code != TSDB_CODE_SUCCESS) { continue; } - (void) streamTaskStop(pTask); + (void)streamTaskStop(pTask); streamMetaReleaseTask(pMeta, pTask); } @@ -1467,7 +1472,7 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas code = streamMetaAcquireTask(pMeta, streamId, taskId, &pTask); if (pTask == NULL) { stError("vgId:%d failed to acquire task:0x%x when starting task", pMeta->vgId, taskId); - (void) streamMetaAddFailedTask(pMeta, streamId, taskId); + (void)streamMetaAddFailedTask(pMeta, streamId, taskId); return TSDB_CODE_STREAM_TASK_IVLD_STATUS; } @@ -1558,9 +1563,8 @@ int32_t streamMetaAddTaskLaunchResult(SStreamMeta* pMeta, int64_t streamId, int3 SHashObj* pDst = ready ? pStartInfo->pReadyTaskSet : pStartInfo->pFailedTaskSet; STaskInitTs initTs = {.start = startTs, .end = endTs, .success = ready}; - int32_t code = taosHashPut(pDst, &id, sizeof(id), &initTs, sizeof(STaskInitTs)); + int32_t code = taosHashPut(pDst, &id, sizeof(id), &initTs, sizeof(STaskInitTs)); if (code) { - } int32_t numOfTotal = streamMetaGetNumOfTasks(pMeta); @@ -1632,9 +1636,9 @@ int32_t streamMetaAddFailedTask(SStreamMeta* pMeta, int64_t streamId, int32_t ta streamMetaRUnLock(pMeta); // add the failed task info, along with the related fill-history task info into tasks list. - (void) streamMetaAddTaskLaunchResult(pMeta, streamId, taskId, startTs, now, false); + (void)streamMetaAddTaskLaunchResult(pMeta, streamId, taskId, startTs, now, false); if (hasFillhistoryTask) { - (void) streamMetaAddTaskLaunchResult(pMeta, hId.streamId, hId.taskId, startTs, now, false); + (void)streamMetaAddTaskLaunchResult(pMeta, hId.streamId, hId.taskId, startTs, now, false); } } else { streamMetaRUnLock(pMeta); @@ -1649,12 +1653,12 @@ int32_t streamMetaAddFailedTask(SStreamMeta* pMeta, int64_t streamId, int32_t ta void streamMetaAddFailedTaskSelf(SStreamTask* pTask, int64_t failedTs) { int32_t startTs = pTask->execInfo.checkTs; - (void) streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, startTs, failedTs, false); + (void)streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, startTs, failedTs, false); // automatically set the related fill-history task to be failed. if (HAS_RELATED_FILLHISTORY_TASK(pTask)) { STaskId* pId = &pTask->hTaskInfo.id; - (void) streamMetaAddTaskLaunchResult(pTask->pMeta, pId->streamId, pId->taskId, startTs, failedTs, false); + (void)streamMetaAddTaskLaunchResult(pTask->pMeta, pId->streamId, pId->taskId, startTs, failedTs, false); } } @@ -1662,7 +1666,7 @@ void streamMetaAddIntoUpdateTaskList(SStreamMeta* pMeta, SStreamTask* pTask, SSt int64_t startTs) { const char* id = pTask->id.idStr; int32_t vgId = pTask->pMeta->vgId; - int32_t code = 0; + int32_t code = 0; // keep the already updated info STaskUpdateEntry entry = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId, .transId = transId}; diff --git a/source/libs/stream/src/streamQueue.c b/source/libs/stream/src/streamQueue.c index 537062b04e..5e538c1e42 100644 --- a/source/libs/stream/src/streamQueue.c +++ b/source/libs/stream/src/streamQueue.c @@ -231,13 +231,14 @@ EExtractDataCode streamTaskGetDataFromInputQ(SStreamTask* pTask, SStreamQueueIte if (*pInput == NULL) { ASSERT((*numOfBlocks) == 0); *pInput = qItem; - } else { - // merge current block failed, let's handle the already merged blocks. + } else { // merge current block failed, let's handle the already merged blocks. void* newRet = NULL; int32_t code = streamQueueMergeQueueItem(*pInput, qItem, (SStreamQueueItem**)&newRet); - if (code != TSDB_CODE_SUCCESS) { - stError("s-task:%s failed to merge blocks from inputQ, numOfBlocks:%d, code:%s", id, *numOfBlocks, - tstrerror(terrno)); + if (newRet == NULL) { + if (code) { + stError("s-task:%s failed to merge blocks from inputQ, numOfBlocks:%d, code:%s", id, *numOfBlocks, + tstrerror(code)); + } *blockSize = streamQueueItemGetSize(*pInput); if (taskLevel == TASK_LEVEL__SINK) { diff --git a/source/libs/stream/src/streamStartHistory.c b/source/libs/stream/src/streamStartHistory.c index db0784d572..0dbb6ed454 100644 --- a/source/libs/stream/src/streamStartHistory.c +++ b/source/libs/stream/src/streamStartHistory.c @@ -80,7 +80,7 @@ int32_t streamStartScanHistoryAsync(SStreamTask* pTask, int8_t igUntreated) { return tmsgPutToQueue(pTask->pMsgCb, STREAM_QUEUE, &rpcMsg); } -int32_t streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration) { +void streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration) { int32_t numOfTicks = idleDuration / SCANHISTORY_IDLE_TIME_SLICE; if (numOfTicks <= 0) { numOfTicks = 1; @@ -91,10 +91,10 @@ int32_t streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration) // add ref for task SStreamTask* p = NULL; int32_t code = streamMetaAcquireTask(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, &p); - if (p == NULL) { + if (p == NULL || code != 0) { stError("s-task:0x%x failed to acquire task, status:%s, not exec scan-history data", pTask->id.taskId, streamTaskGetStatus(pTask).name); - return TSDB_CODE_SUCCESS; + return; } pTask->schedHistoryInfo.numOfTicks = numOfTicks; @@ -109,8 +109,6 @@ int32_t streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration) streamTmrReset(doExecScanhistoryInFuture, SCANHISTORY_IDLE_TIME_SLICE, pTask, streamTimer, &pTask->schedHistoryInfo.pTimer, pTask->pMeta->vgId, " start-history-task-tmr"); } - - return TSDB_CODE_SUCCESS; } int32_t streamTaskStartScanHistory(SStreamTask* pTask) { diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 141bd8fc3e..a249bad724 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -602,9 +602,9 @@ int32_t streamTaskStop(SStreamTask* pTask) { stError("failed to handle STOP event, s-task:%s", id); } - if (pTask->info.taskLevel != TASK_LEVEL__SINK) { + if (pTask->info.taskLevel != TASK_LEVEL__SINK && pTask->exec.pExecutor != NULL) { code = qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS); - if (code) { + if (code != TSDB_CODE_SUCCESS) { stError("s-task:%s failed to kill task related query handle", id); } } @@ -766,8 +766,7 @@ int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t resetRelHalt) { int32_t streamBuildAndSendDropTaskMsg(SMsgCb* pMsgCb, int32_t vgId, SStreamTaskId* pTaskId, int64_t resetRelHalt) { SVDropStreamTaskReq* pReq = rpcMallocCont(sizeof(SVDropStreamTaskReq)); if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + return terrno; } pReq->head.vgId = vgId; @@ -873,6 +872,7 @@ void streamTaskStatusCopy(STaskStatusEntry* pDst, const STaskStatusEntry* pSrc) pDst->checkpointInfo = pSrc->checkpointInfo; pDst->startCheckpointId = pSrc->startCheckpointId; pDst->startCheckpointVer = pSrc->startCheckpointVer; + pDst->status = pSrc->status; pDst->startTime = pSrc->startTime; pDst->hTaskId = pSrc->hTaskId; @@ -1089,11 +1089,10 @@ int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeChec return TSDB_CODE_SUCCESS; } -int32_t streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId) { +void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId) { pTask->chkInfo.pActiveInfo->transId = transId; pTask->chkInfo.pActiveInfo->activeId = checkpointId; pTask->chkInfo.pActiveInfo->failedId = checkpointId; - return TSDB_CODE_SUCCESS; } int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) { diff --git a/source/libs/stream/src/streamTaskSm.c b/source/libs/stream/src/streamTaskSm.c index c3e0df52d4..275c9255d2 100644 --- a/source/libs/stream/src/streamTaskSm.c +++ b/source/libs/stream/src/streamTaskSm.c @@ -270,7 +270,7 @@ int32_t streamTaskRestoreStatus(SStreamTask* pTask) { code = TSDB_CODE_FAILED; // failed to restore the status, since it is not in pause status } - (void)taosThreadMutexUnlock(&pTask->lock); + streamMutexUnlock(&pTask->lock); return code; } diff --git a/source/libs/stream/test/backendTest.cpp b/source/libs/stream/test/backendTest.cpp index 1b2f961726..2b21510e45 100644 --- a/source/libs/stream/test/backendTest.cpp +++ b/source/libs/stream/test/backendTest.cpp @@ -69,7 +69,7 @@ void *backendOpen() { key.ts = ts; const char *val = "value data"; int32_t vlen = strlen(val); - int32_t code = streamStatePut_rocksdb(p, &key, (char *)val, vlen); + int32_t code = streamStatePut_rocksdb(p, &key, (char *)val, vlen); ASSERT(code == 0); tsArray.push_back(ts); @@ -83,7 +83,7 @@ void *backendOpen() { const char *val = "value data"; int32_t len = 0; char *newVal = NULL; - int32_t code = streamStateGet_rocksdb(p, &key, (void **)&newVal, &len); + int32_t code = streamStateGet_rocksdb(p, &key, (void **)&newVal, &len); ASSERT(code == 0); ASSERT(len == strlen(val)); @@ -377,7 +377,7 @@ TEST_F(BackendEnv, checkOpen) { char val[128] = {0}; sprintf(val, "val_%d", i); int32_t code = streamStatePutBatch(p, "default", (rocksdb_writebatch_t *)pBatch, (void *)key, (void *)val, - (int32_t)(strlen(val)), tsStart + 100000); + (int32_t)(strlen(val)), tsStart + 100000); ASSERT(code == 0); } @@ -396,7 +396,7 @@ TEST_F(BackendEnv, checkOpen) { char val[128] = {0}; sprintf(val, "val_%d", i); int32_t code = streamStatePutBatchOptimize(p, 0, (rocksdb_writebatch_t *)pBatch, (void *)key, (void *)val, - (int32_t)(strlen(val)), tsStart + 100000, (void *)valBuf); + (int32_t)(strlen(val)), tsStart + 100000, (void *)valBuf); ASSERT(code == 0); } int32_t code = streamStatePutBatch_rocksdb(p, pBatch); @@ -417,7 +417,7 @@ TEST_F(BackendEnv, checkOpen) { char val[128] = {0}; sprintf(val, "val_%d", i); int32_t code = streamStatePutBatchOptimize(p, 0, (rocksdb_writebatch_t *)pBatch, (void *)key, (void *)val, - (int32_t)(strlen(val)), tsStart + 100000, (void *)valBuf); + (int32_t)(strlen(val)), tsStart + 100000, (void *)valBuf); ASSERT(code == 0); } code = streamStatePutBatch_rocksdb(p, pBatch); @@ -432,13 +432,12 @@ TEST_F(BackendEnv, checkOpen) { const char *path = "/tmp/backend/stream"; const char *dump = "/tmp/backend/stream/dump"; // taosMkDir(dump); - code = taosMulMkDir(dump); - ASSERT(code == 0); + taosMulMkDir(dump); + SBkdMgt *mgt = NULL; - SBkdMgt *mgt = bkdMgtCreate((char *)path); - SArray *result = taosArrayInit(4, sizeof(void *)); - code = bkdMgtGetDelta(mgt, p->pTdbState->idstr, 3, result, (char *)dump); - ASSERT(code == 0); + code = bkdMgtCreate((char *)path, &mgt); + SArray *result = taosArrayInit(4, sizeof(void *)); + bkdMgtGetDelta(mgt, p->pTdbState->idstr, 3, result, (char *)dump); code = taskDbDoCheckpoint(p->pTdbState->pOwner->pBackend, 4, 0); ASSERT(code == 0); @@ -475,7 +474,7 @@ TEST_F(BackendEnv, backendUtil) { } TEST_F(BackendEnv, oldBackendInit) { const char *path = "/tmp/backend1"; - int32_t code = taosMulMkDir(path); + int32_t code = taosMulMkDir(path); ASSERT(code == 0); { diff --git a/source/libs/stream/test/tstreamUpdateTest.cpp b/source/libs/stream/test/tstreamUpdateTest.cpp index 59171876ff..4360fc7d54 100644 --- a/source/libs/stream/test/tstreamUpdateTest.cpp +++ b/source/libs/stream/test/tstreamUpdateTest.cpp @@ -53,7 +53,7 @@ TEST(TD_STREAM_UPDATE_TEST, update) { void *p = NULL; // SBackendWrapper *p = streamBackendInit(streamPath, -1, 2); // p = taskDbOpen((char *)streamPath, (char *)"test", -1); - p = bkdMgtCreate((char *)streamPath); + int32_t code = bkdMgtCreate((char *)streamPath, (SBkdMgt **)&p); // const int64_t interval = 20 * 1000; // const int64_t watermark = 10 * 60 * 1000; diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index b55267a0e7..3e2b98c35b 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -76,10 +76,8 @@ int64_t syncNodeUpdateCommitIndex(SSyncNode* ths, SyncIndex commitIndex) { SyncIndex lastVer = ths->pLogStore->syncLogLastIndex(ths->pLogStore); commitIndex = TMAX(commitIndex, ths->commitIndex); ths->commitIndex = TMIN(commitIndex, lastVer); - if ((code = ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->commitIndex)) != 0) { - // TODO add return when error - sError("failed to update commit index since %s", tstrerror(code)); - } + // TODO add return when error + (void)ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->commitIndex); return ths->commitIndex; } @@ -87,10 +85,8 @@ int64_t syncNodeCheckCommitIndex(SSyncNode* ths, SyncIndex indexLikely) { int32_t code = 0; if (indexLikely > ths->commitIndex && syncNodeAgreedUpon(ths, indexLikely)) { SyncIndex commitIndex = indexLikely; - if ((code = syncNodeUpdateCommitIndex(ths, commitIndex)) != 0) { - // TODO add return when error - sError("failed to update commit index since %s", tstrerror(code)); - } + // TODO add return when error + (void)syncNodeUpdateCommitIndex(ths, commitIndex); sTrace("vgId:%d, agreed upon. role:%d, term:%" PRId64 ", index:%" PRId64 "", ths->vgId, ths->state, raftStoreGetTerm(ths), commitIndex); } @@ -102,9 +98,7 @@ int64_t syncNodeUpdateAssignedCommitIndex(SSyncNode* ths, SyncIndex assignedComm SyncIndex lastVer = ths->pLogStore->syncLogLastIndex(ths->pLogStore); assignedCommitIndex = TMAX(assignedCommitIndex, ths->assignedCommitIndex); ths->assignedCommitIndex = TMIN(assignedCommitIndex, lastVer); - if ((code = ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->assignedCommitIndex)) != 0) { - // TODO add return when error - sError("failed to update commit index since %s", tstrerror(code)); - } + // TODO add return when error + (void)ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->assignedCommitIndex); return ths->commitIndex; } diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index cce8149037..8d1e2cfebd 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -69,13 +69,13 @@ void syncCleanUp() { if (gNodeRefId != -1) { sDebug("sync rsetId:%d is closed", gNodeRefId); - taosCloseRef(gNodeRefId); + (void)taosCloseRef(gNodeRefId); gNodeRefId = -1; } if (gHbDataRefId != -1) { sDebug("sync rsetId:%d is closed", gHbDataRefId); - taosCloseRef(gHbDataRefId); + (void)taosCloseRef(gHbDataRefId); gHbDataRefId = -1; } } @@ -88,7 +88,7 @@ int64_t syncNodeAdd(SSyncNode *pNode) { return pNode->rid; } -void syncNodeRemove(int64_t rid) { taosRemoveRef(gNodeRefId, rid); } +void syncNodeRemove(int64_t rid) { (void)taosRemoveRef(gNodeRefId, rid); } SSyncNode *syncNodeAcquire(int64_t rid) { SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid); @@ -101,7 +101,7 @@ SSyncNode *syncNodeAcquire(int64_t rid) { } void syncNodeRelease(SSyncNode *pNode) { - if (pNode) taosReleaseRef(gNodeRefId, pNode->rid); + if (pNode) (void)taosReleaseRef(gNodeRefId, pNode->rid); } int64_t syncHbTimerDataAdd(SSyncHbTimerData *pData) { @@ -110,7 +110,7 @@ int64_t syncHbTimerDataAdd(SSyncHbTimerData *pData) { return pData->rid; } -void syncHbTimerDataRemove(int64_t rid) { taosRemoveRef(gHbDataRefId, rid); } +void syncHbTimerDataRemove(int64_t rid) { (void)taosRemoveRef(gHbDataRefId, rid); } SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) { SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid); @@ -122,7 +122,7 @@ SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) { return pData; } -void syncHbTimerDataRelease(SSyncHbTimerData *pData) { taosReleaseRef(gHbDataRefId, pData->rid); } +void syncHbTimerDataRelease(SSyncHbTimerData *pData) { (void)taosReleaseRef(gHbDataRefId, pData->rid); } #if 0 void syncEnvStartTimer() { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index f93b52dd2a..171b73eba7 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -181,17 +181,18 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { TAOS_RETURN(code); } - syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg); + TAOS_CHECK_RETURN(syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg)); syncNodeDoConfigChange(pSyncNode, pNewCfg, pNewCfg->lastIndex); if (pSyncNode->state == TAOS_SYNC_STATE_LEADER || pSyncNode->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) { - syncNodeStopHeartbeatTimer(pSyncNode); + // TODO check return value + (void)syncNodeStopHeartbeatTimer(pSyncNode); for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) { - syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i]); + (void)syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i]); } - syncNodeStartHeartbeatTimer(pSyncNode); + (void)syncNodeStartHeartbeatTimer(pSyncNode); // syncNodeReplicate(pSyncNode); } @@ -394,7 +395,8 @@ int32_t syncSendTimeoutRsp(int64_t rid, int64_t seq) { syncNodeRelease(pNode); if (ret == 1) { sInfo("send timeout response, seq:%" PRId64 " handle:%p ahandle:%p", seq, rpcMsg.info.handle, rpcMsg.info.ahandle); - rpcSendResponse(&rpcMsg); + // TODO check return value + (void)rpcSendResponse(&rpcMsg); return 0; } else { sError("no message handle to send timeout response, seq:%" PRId64, seq); @@ -674,9 +676,9 @@ int32_t syncGetArbToken(int64_t rid, char* outToken) { } memset(outToken, 0, TSDB_ARB_TOKEN_SIZE); - taosThreadMutexLock(&pSyncNode->arbTokenMutex); + (void)taosThreadMutexLock(&pSyncNode->arbTokenMutex); strncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE); - taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); + (void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); syncNodeRelease(pSyncNode); TAOS_RETURN(code); @@ -956,8 +958,8 @@ static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { sTrace("vgId:%d, start hb timer, rid:%" PRId64 " addr:%" PRId64, pSyncNode->vgId, pData->rid, pData->destId.addr); - taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)(pData->rid), - syncEnv()->pTimerManager, &pSyncTimer->pTimer); + (void)taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)(pData->rid), + syncEnv()->pTimerManager, &pSyncTimer->pTimer); } else { ret = TSDB_CODE_SYN_INTERNAL_ERROR; sError("vgId:%d, start ctrl hb timer error, sync env is stop", pSyncNode->vgId); @@ -967,7 +969,7 @@ static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { int32_t ret = 0; - atomic_add_fetch_64(&pSyncTimer->logicClock, 1); + (void)atomic_add_fetch_64(&pSyncTimer->logicClock, 1); if (!taosTmrStop(pSyncTimer->pTimer)) { return TSDB_CODE_SYN_INTERNAL_ERROR; } @@ -983,7 +985,8 @@ int32_t syncNodeLogStoreRestoreOnNeed(SSyncNode* pNode) { ASSERTS(pNode->pFsm != NULL, "pFsm not registered"); ASSERTS(pNode->pFsm->FpGetSnapshotInfo != NULL, "FpGetSnapshotInfo not registered"); SSnapshot snapshot = {0}; - pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + // TODO check return value + (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); SyncIndex commitIndex = snapshot.lastApplyIndex; SyncIndex firstVer = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore); @@ -1112,7 +1115,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) { } pSyncNode->arbTerm = -1; - taosThreadMutexInit(&pSyncNode->arbTokenMutex, NULL); + (void)taosThreadMutexInit(&pSyncNode->arbTokenMutex, NULL); syncUtilGenerateArbToken(pSyncNode->myNodeInfo.nodeId, pSyncInfo->vgId, pSyncNode->arbToken); sInfo("vgId:%d, arb token:%s", pSyncNode->vgId, pSyncNode->arbToken); @@ -1220,7 +1223,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) { SyncIndex commitIndex = SYNC_INDEX_INVALID; if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot = {0}; - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // TODO check return value + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex > commitIndex) { commitIndex = snapshot.lastApplyIndex; sNTrace(pSyncNode, "reset commit index by snapshot"); @@ -1373,7 +1377,7 @@ _error: void syncNodeMaybeUpdateCommitBySnapshot(SSyncNode* pSyncNode) { if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot = {0}; - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex > pSyncNode->commitIndex) { pSyncNode->commitIndex = snapshot.lastApplyIndex; } @@ -1386,11 +1390,11 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) { ASSERTS(pSyncNode->pLogStore != NULL, "log store not created"); ASSERTS(pSyncNode->pLogBuf != NULL, "ring log buffer not created"); - taosThreadMutexLock(&pSyncNode->pLogBuf->mutex); + (void)taosThreadMutexLock(&pSyncNode->pLogBuf->mutex); SyncIndex lastVer = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); SyncIndex commitIndex = pSyncNode->pLogStore->syncLogCommitIndex(pSyncNode->pLogStore); SyncIndex endIndex = pSyncNode->pLogBuf->endIndex; - taosThreadMutexUnlock(&pSyncNode->pLogBuf->mutex); + (void)taosThreadMutexUnlock(&pSyncNode->pLogBuf->mutex); if (lastVer != -1 && endIndex != lastVer + 1) { code = TSDB_CODE_WAL_LOG_INCOMPLETE; @@ -1439,7 +1443,8 @@ int32_t syncNodeStartStandBy(SSyncNode* pSyncNode) { // state change pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; pSyncNode->roleTimeMs = taosGetTimestampMs(); - syncNodeStopHeartbeatTimer(pSyncNode); + // TODO check return value + (void)syncNodeStopHeartbeatTimer(pSyncNode); // reset elect timer, long enough int32_t electMS = TIMER_MAX_MS; @@ -1464,13 +1469,13 @@ void syncNodePreClose(SSyncNode* pSyncNode) { ASSERT(pSyncNode->pFsm->FpApplyQueueItems != NULL); // stop elect timer - syncNodeStopElectTimer(pSyncNode); + (void)syncNodeStopElectTimer(pSyncNode); // stop heartbeat timer - syncNodeStopHeartbeatTimer(pSyncNode); + (void)syncNodeStopHeartbeatTimer(pSyncNode); // stop ping timer - syncNodeStopPingTimer(pSyncNode); + (void)syncNodeStopPingTimer(pSyncNode); // clean rsp syncRespCleanRsp(pSyncNode->pSyncRespMgr); @@ -1497,9 +1502,9 @@ void syncNodeClose(SSyncNode* pSyncNode) { syncRespCleanRsp(pSyncNode->pSyncRespMgr); - syncNodeStopPingTimer(pSyncNode); - syncNodeStopElectTimer(pSyncNode); - syncNodeStopHeartbeatTimer(pSyncNode); + (void)syncNodeStopPingTimer(pSyncNode); + (void)syncNodeStopElectTimer(pSyncNode); + (void)syncNodeStopHeartbeatTimer(pSyncNode); syncNodeLogReplDestroy(pSyncNode); syncRespMgrDestroy(pSyncNode->pSyncRespMgr); @@ -1517,7 +1522,7 @@ void syncNodeClose(SSyncNode* pSyncNode) { syncLogBufferDestroy(pSyncNode->pLogBuf); pSyncNode->pLogBuf = NULL; - taosThreadMutexDestroy(&pSyncNode->arbTokenMutex); + (void)taosThreadMutexDestroy(&pSyncNode->arbTokenMutex); for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) { if (pSyncNode->senders[i] != NULL) { @@ -1557,8 +1562,8 @@ ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->raftCfg int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) { int32_t ret = 0; if (syncIsInit()) { - taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, (void*)pSyncNode->rid, syncEnv()->pTimerManager, - &pSyncNode->pPingTimer); + (void)taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, (void*)pSyncNode->rid, + syncEnv()->pTimerManager, &pSyncNode->pPingTimer); atomic_store_64(&pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } else { sError("vgId:%d, start ping timer error, sync env is stop", pSyncNode->vgId); @@ -1568,8 +1573,9 @@ int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) { int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) { int32_t ret = 0; - atomic_add_fetch_64(&pSyncNode->pingTimerLogicClockUser, 1); - taosTmrStop(pSyncNode->pPingTimer); + (void)atomic_add_fetch_64(&pSyncNode->pingTimerLogicClockUser, 1); + // TODO check return value + (void)taosTmrStop(pSyncNode->pPingTimer); pSyncNode->pPingTimer = NULL; return ret; } @@ -1585,11 +1591,8 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { pSyncNode->electTimerParam.pSyncNode = pSyncNode; pSyncNode->electTimerParam.pData = NULL; - if (!taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, (void*)(pSyncNode->rid), - syncEnv()->pTimerManager, &pSyncNode->pElectTimer)) { - ret = TSDB_CODE_SYN_INTERNAL_ERROR; - } - + (void)taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, (void*)(pSyncNode->rid), + syncEnv()->pTimerManager, &pSyncNode->pElectTimer); } else { sError("vgId:%d, start elect timer error, sync env is stop", pSyncNode->vgId); } @@ -1598,8 +1601,9 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode) { int32_t ret = 0; - atomic_add_fetch_64(&pSyncNode->electTimerLogicClock, 1); - taosTmrStop(pSyncNode->pElectTimer); + (void)atomic_add_fetch_64(&pSyncNode->electTimerLogicClock, 1); + // TODO check return value + (void)taosTmrStop(pSyncNode->pElectTimer); pSyncNode->pElectTimer = NULL; return ret; @@ -1622,9 +1626,8 @@ void syncNodeResetElectTimer(SSyncNode* pSyncNode) { electMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine); } - if ((code = syncNodeRestartElectTimer(pSyncNode, electMS)) != 0) { - sError("failed to restart elect timer since %s", tstrerror(code)); - } + // TODO check return value + (void)syncNodeRestartElectTimer(pSyncNode, electMS); sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine, electMS); @@ -1634,8 +1637,8 @@ void syncNodeResetElectTimer(SSyncNode* pSyncNode) { static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) { int32_t ret = 0; if (syncIsInit()) { - taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, (void*)pSyncNode->rid, - syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer); + (void)taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, (void*)pSyncNode->rid, + syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer); atomic_store_64(&pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser); } else { sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId); @@ -1668,8 +1671,9 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { int32_t ret = 0; #if 0 - atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1); - taosTmrStop(pSyncNode->pHeartbeatTimer); + //TODO check return value + (void)atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1); + (void)taosTmrStop(pSyncNode->pHeartbeatTimer); pSyncNode->pHeartbeatTimer = NULL; #endif @@ -1685,8 +1689,9 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { #ifdef BUILD_NO_CALL int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) { - syncNodeStopHeartbeatTimer(pSyncNode); - syncNodeStartHeartbeatTimer(pSyncNode); + // TODO check return value + (void)syncNodeStopHeartbeatTimer(pSyncNode); + (void)syncNodeStartHeartbeatTimer(pSyncNode); return 0; } #endif @@ -1801,7 +1806,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } // add last config index - syncAddCfgIndex(pSyncNode, lastConfigChangeIndex); + (void)syncAddCfgIndex(pSyncNode, lastConfigChangeIndex); if (IamInNew) { //----------------------------------------- @@ -1818,7 +1823,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde // init internal pSyncNode->myNodeInfo = pSyncNode->raftCfg.cfg.nodeInfo[pSyncNode->raftCfg.cfg.myIndex]; - syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId); + (void)syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId); // init peersNum, peers, peersId pSyncNode->peersNum = pSyncNode->raftCfg.cfg.totalReplicaNum - 1; @@ -1831,14 +1836,14 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } } for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { - syncUtilNodeInfo2RaftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); + (void)syncUtilNodeInfo2RaftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); } // init replicaNum, replicasId pSyncNode->replicaNum = pSyncNode->raftCfg.cfg.replicaNum; pSyncNode->totalReplicaNum = pSyncNode->raftCfg.cfg.totalReplicaNum; for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.totalReplicaNum; ++i) { - syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); + (void)syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); } // update quorum first @@ -1884,7 +1889,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde // create new for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) { if (pSyncNode->senders[i] == NULL) { - snapshotSenderCreate(pSyncNode, i, &pSyncNode->senders[i]); + (void)snapshotSenderCreate(pSyncNode, i, &pSyncNode->senders[i]); if (pSyncNode->senders[i] == NULL) { // will be created later while send snapshot sSError(pSyncNode->senders[i], "snapshot sender create failed while reconfig"); @@ -1906,10 +1911,10 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } // persist cfg - syncWriteCfgFile(pSyncNode); + (void)syncWriteCfgFile(pSyncNode); } else { // persist cfg - syncWriteCfgFile(pSyncNode); + (void)syncWriteCfgFile(pSyncNode); sNInfo(pSyncNode, "do not config change from %d to %d", oldConfig.totalReplicaNum, pNewConfig->totalReplicaNum); } @@ -1937,10 +1942,10 @@ void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) { } while (0); if (pSyncNode->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) { - taosThreadMutexLock(&pSyncNode->arbTokenMutex); + (void)taosThreadMutexLock(&pSyncNode->arbTokenMutex); syncUtilGenerateArbToken(pSyncNode->myNodeInfo.nodeId, pSyncNode->vgId, pSyncNode->arbToken); sInfo("vgId:%d, step down as assigned leader, new arbToken:%s", pSyncNode->vgId, pSyncNode->arbToken); - taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); + (void)taosThreadMutexUnlock(&pSyncNode->arbTokenMutex); } if (currentTerm < newTerm) { @@ -1969,7 +1974,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { // state change pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; pSyncNode->roleTimeMs = taosGetTimestampMs(); - syncNodeStopHeartbeatTimer(pSyncNode); + (void)syncNodeStopHeartbeatTimer(pSyncNode); // trace log sNTrace(pSyncNode, "become follower %s", debugStr); @@ -1986,7 +1991,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); // reset elect timer syncNodeResetElectTimer(pSyncNode); @@ -2011,7 +2016,7 @@ void syncNodeBecomeLearner(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); } // TLA+ Spec @@ -2061,7 +2066,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { } // init peer mgr - syncNodePeerStateInit(pSyncNode); + (void)syncNodePeerStateInit(pSyncNode); #if 0 // update sender private term @@ -2082,13 +2087,13 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { } // stop elect timer - syncNodeStopElectTimer(pSyncNode); + (void)syncNodeStopElectTimer(pSyncNode); // start heartbeat timer - syncNodeStartHeartbeatTimer(pSyncNode); + (void)syncNodeStartHeartbeatTimer(pSyncNode); // send heartbeat right now - syncNodeHeartbeatPeers(pSyncNode); + (void)syncNodeHeartbeatPeers(pSyncNode); // call back if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeLeaderCb != NULL) { @@ -2099,7 +2104,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); // trace log sNInfo(pSyncNode, "become leader %s", debugStr); @@ -2134,7 +2139,7 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { } // init peer mgr - syncNodePeerStateInit(pSyncNode); + (void)syncNodePeerStateInit(pSyncNode); // close receiver if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) { @@ -2142,13 +2147,13 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { } // stop elect timer - syncNodeStopElectTimer(pSyncNode); + (void)syncNodeStopElectTimer(pSyncNode); // start heartbeat timer - syncNodeStartHeartbeatTimer(pSyncNode); + (void)syncNodeStartHeartbeatTimer(pSyncNode); // send heartbeat right now - syncNodeHeartbeatPeers(pSyncNode); + (void)syncNodeHeartbeatPeers(pSyncNode); // call back if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeAssignedLeaderCb != NULL) { @@ -2159,7 +2164,7 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); // trace log sNInfo(pSyncNode, "become assigned leader"); @@ -2262,7 +2267,8 @@ bool syncNodeHasSnapshot(SSyncNode* pSyncNode) { bool ret = false; SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1}; if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // TODO check return value + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex >= SYNC_INDEX_BEGIN) { ret = true; } @@ -2275,7 +2281,8 @@ bool syncNodeHasSnapshot(SSyncNode* pSyncNode) { SyncIndex syncNodeGetLastIndex(const SSyncNode* pSyncNode) { SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1}; if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // TODO check return value + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); } SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); @@ -2291,7 +2298,8 @@ SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode) { // has snapshot SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1}; if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // TODO check return value + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); } SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); @@ -2386,7 +2394,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { return preTerm; } else { if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // TODO check return value + (void)pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex == preIndex) { return snapshot.lastApplyTerm; } @@ -2433,8 +2442,8 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { } _out: - taosTmrReset(syncNodeEqPingTimer, pNode->pingTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, - &pNode->pPingTimer); + (void)taosTmrReset(syncNodeEqPingTimer, pNode->pingTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, + &pNode->pPingTimer); } } @@ -2510,8 +2519,8 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { } _out: - taosTmrReset(syncNodeEqHeartbeatTimer, pNode->heartbeatTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, - &pNode->pHeartbeatTimer); + (void)taosTmrReset(syncNodeEqHeartbeatTimer, pNode->heartbeatTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, + &pNode->pHeartbeatTimer); } else { sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64, @@ -2585,14 +2594,14 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { // send msg sTrace("vgId:%d, send heartbeat to dnode:%d", pSyncNode->vgId, DID(&(pSyncMsg->destId))); syncLogSendHeartbeat(pSyncNode, pSyncMsg, false, timerElapsed, pData->execTime); - syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + (void)syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); } else { } if (syncIsInit()) { // sTrace("vgId:%d, reset peer hb timer", pSyncNode->vgId); - taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)hbDataRid, - syncEnv()->pTimerManager, &pSyncTimer->pTimer); + (void)taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)hbDataRid, + syncEnv()->pTimerManager, &pSyncTimer->pTimer); } else { sError("sync env is stop, reset peer hb timer error"); } diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c index 8b6092e839..ef2cbece79 100644 --- a/source/libs/sync/src/syncPipeline.c +++ b/source/libs/sync/src/syncPipeline.c @@ -134,7 +134,7 @@ int32_t syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncI } SSnapshot snapshot = {0}; - (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); // TODO: check the return code + (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); if (prevIndex == snapshot.lastApplyIndex) { *pSyncTerm = snapshot.lastApplyTerm; return 0; @@ -184,7 +184,7 @@ int32_t syncLogBufferInitWithoutLock(SSyncLogBuffer* pBuf, SSyncNode* pNode) { int32_t code = 0, lino = 0; SSnapshot snapshot = {0}; - pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + TAOS_CHECK_EXIT(pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot)); SyncIndex commitIndex = snapshot.lastApplyIndex; SyncTerm commitTerm = TMAX(snapshot.lastApplyTerm, 0); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index cb07a63eed..cc2aa7d91e 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -134,7 +134,7 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); code = 0; diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 40a359379a..8644ba6bb9 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -84,7 +84,7 @@ int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) { int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) { SyncAppendEntries* pMsg = pRpcMsg->pCont; pMsg->destId = *destRaftId; - syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg); + (void)syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg); TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -113,7 +113,7 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) { // send msg syncLogSendHeartbeat(pSyncNode, pSyncMsg, true, 0, 0); - syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + (void)syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); } TAOS_RETURN(TSDB_CODE_SUCCESS); diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index 0e50cca94c..a30b9a4930 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -135,7 +135,7 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) { // trace log syncLogRecvRequestVote(ths, pMsg, pReply->voteGranted, ""); syncLogSendRequestVoteReply(ths, pReply, ""); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + (void)syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); if (resetElect) syncNodeResetElectTimer(ths); diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 450d22528d..8a2c53997b 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -86,14 +86,17 @@ int32_t snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex, SSyncSn pSender->replicaIndex = replicaIndex; pSender->term = raftStoreGetTerm(pSyncNode); pSender->startTime = -1; - pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot); pSender->finish = false; + code = pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot); + if (code != 0) { + taosMemoryFreeClear(pSender); + TAOS_RETURN(code); + } SSyncSnapBuffer *pSndBuf = NULL; code = syncSnapBufferCreate(&pSndBuf); if (pSndBuf == NULL) { - taosMemoryFree(pSender); - pSender = NULL; + taosMemoryFreeClear(pSender); TAOS_RETURN(code); } pSndBuf->entryDeleteCb = syncSnapBlockDestroy; @@ -472,7 +475,7 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) { syncSnapBufferDestroy(&pReceiver->pRcvBuf); } - snapshotReceiverClearInfoData(pReceiver); + (void)snapshotReceiverClearInfoData(pReceiver); // free receiver taosMemoryFree(pReceiver); @@ -592,7 +595,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true, &pReceiver->snapshot); if (code != 0) { - sRError(pReceiver, "snapshot receiver apply failed since %s", tstrerror(code)); + sRError(pReceiver, "snapshot receiver apply failed since %s", tstrerror(code)); TAOS_RETURN(code); } pReceiver->pWriter = NULL; @@ -603,7 +606,11 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap // get fsmState SSnapshot snapshot = {0}; - pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot); + code = pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot); + if (code != 0) { + sRError(pReceiver, "snapshot receiver get snapshot info failed since %s", tstrerror(code)); + TAOS_RETURN(code); + } pReceiver->pSyncNode->fsmState = snapshot.state; // reset wal @@ -1276,13 +1283,13 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, SRpcMsg *pRpcMsg) { if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) { sSInfo(pSender, "process end rsp"); snapshotSenderStop(pSender, true); - syncNodeReplicateReset(pSyncNode, &pMsg->srcId); + (void)syncNodeReplicateReset(pSyncNode, &pMsg->srcId); } return 0; _ERROR: snapshotSenderStop(pSender, false); - syncNodeReplicateReset(pSyncNode, &pMsg->srcId); + (void)syncNodeReplicateReset(pSyncNode, &pMsg->srcId); TAOS_RETURN(code); } diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 2076de6ec7..49737b9045 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -183,7 +183,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { - pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); } SyncIndex logLastIndex = SYNC_INDEX_INVALID; @@ -253,7 +253,7 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { - pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); } SyncIndex logLastIndex = SYNC_INDEX_INVALID; @@ -302,7 +302,7 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { - pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + (void)pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); } SyncIndex logLastIndex = SYNC_INDEX_INVALID; diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index d3a5711352..0935e87ab0 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -48,7 +48,7 @@ int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyC int8_t rollback); int32_t tdbTbClose(TTB *pTb); bool tdbTbExist(const char *tbname, TDB *pEnv); -int tdbTbDropByName(const char *tbname, TDB *pEnv, TXN* pTxn); +int tdbTbDropByName(const char *tbname, TDB *pEnv, TXN *pTxn); int32_t tdbTbDrop(TTB *pTb); int32_t tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn); int32_t tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn); @@ -80,10 +80,10 @@ int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, i int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg, int flags); int32_t tdbTxnCloseImpl(TXN *pTxn); -#define tdbTxnClose(pTxn) \ - do { \ - tdbTxnCloseImpl(pTxn); \ - (pTxn) = NULL; \ +#define tdbTxnClose(pTxn) \ + do { \ + (void)tdbTxnCloseImpl(pTxn); \ + (pTxn) = NULL; \ } while (0) // other diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index f86ed69fc3..c07f442c4a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -122,7 +122,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg zArg.pBt = pBt; ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, txn); if (ret < 0) { - tdbAbort(pEnv, txn); + (void)tdbAbort(pEnv, txn); tdbOsFree(pBt); return ret; } @@ -130,7 +130,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg ret = tdbPagerWrite(pPager, pPage); if (ret < 0) { tdbError("failed to write page since %s", terrstr()); - tdbAbort(pEnv, txn); + (void)tdbAbort(pEnv, txn); tdbOsFree(pBt); return ret; } @@ -143,7 +143,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg ret = tdbTbInsert(pPager->pEnv->pMainDb, tbname, strlen(tbname) + 1, &pBt->info, sizeof(pBt->info), txn); if (ret < 0) { - tdbAbort(pEnv, txn); + (void)tdbAbort(pEnv, txn); tdbOsFree(pBt); return ret; } @@ -194,14 +194,14 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in int idx; int c; - tdbBtcOpen(&btc, pBt, pTxn); + (void)tdbBtcOpen(&btc, pBt, pTxn); tdbTrace("tdb insert, btc: %p, pTxn: %p", &btc, pTxn); // move to the position to insert ret = tdbBtcMoveTo(&btc, pKey, kLen, &c); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-insert: btc move to failed with ret: %d.", ret); return ret; } @@ -213,7 +213,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in btc.idx++; } else if (c == 0) { // dup key not allowed with insert - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-insert: dup key. pKey: %p, kLen: %d, btc: %p, pTxn: %p", pKey, kLen, &btc, pTxn); return TSDB_CODE_DUP_KEY; } @@ -221,12 +221,12 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in ret = tdbBtcUpsert(&btc, pKey, kLen, pVal, vLen, 1); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-insert: btc upsert failed with ret: %d.", ret); return ret; } - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return 0; } @@ -235,7 +235,7 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) { int c; int ret; - tdbBtcOpen(&btc, pBt, pTxn); + (void)tdbBtcOpen(&btc, pBt, pTxn); /* btc.coder.ofps = taosArrayInit(8, sizeof(SPage *)); // btc.coder.ofps = taosArrayInit(8, sizeof(SPgno)); @@ -246,20 +246,20 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) { // move the cursor ret = tdbBtcMoveTo(&btc, pKey, kLen, &c); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-delete: btc move to failed with ret: %d.", ret); return ret; } if (btc.idx < 0 || c != 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return TSDB_CODE_NOT_FOUND; } // delete the key ret = tdbBtcDelete(&btc); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return ret; } /* @@ -274,7 +274,7 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) { btc.coder.ofps = NULL; } */ - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return 0; } @@ -337,26 +337,26 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL void *pTVal = NULL; SCellDecoder cd = {0}; - tdbBtcOpen(&btc, pBt, NULL); + (void)tdbBtcOpen(&btc, pBt, NULL); tdbTrace("tdb pget, btc: %p", &btc); ret = tdbBtcMoveTo(&btc, pKey, kLen, &cret); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-pget: btc move to failed with ret: %d.", ret); return ret; } if (btc.idx < 0 || cret) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return TSDB_CODE_NOT_FOUND; } pCell = tdbPageGetCell(btc.pPage, btc.idx); ret = tdbBtreeDecodeCell(btc.pPage, pCell, &cd, btc.pTxn, pBt); if (ret < 0) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-pget: decode cell failed with ret: %d.", ret); return ret; } @@ -364,7 +364,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL if (ppKey) { pTKey = tdbRealloc(*ppKey, cd.kLen); if (pTKey == NULL) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-pget: realloc pTKey failed."); return terrno; } @@ -376,7 +376,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL if (ppVal) { pTVal = tdbRealloc(*ppVal, cd.vLen); if (pTVal == NULL) { - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); tdbError("tdb/btree-pget: realloc pTVal failed."); return terrno; } @@ -397,7 +397,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL tdbTrace("tdb pget end, btc decoder: %p/0x%x, local decoder:%p", &btc.coder, btc.coder.freeKV, &cd); - tdbBtcClose(&btc); + (void)tdbBtcClose(&btc); return 0; } @@ -512,7 +512,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN } // Copy the root page content to the child page - tdbPageCopy(pRoot, pChild, 0); + (void)tdbPageCopy(pRoot, pChild, 0); // Reinitialize the root page zArg.flags = TDB_BTREE_ROOT; @@ -602,7 +602,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx if (i < nOlds - 1) { ((SPgno *)pDivCell[i])[0] = ((SIntHdr *)pOlds[i]->pData)->pgno; ((SIntHdr *)pOlds[i]->pData)->pgno = 0; - tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); + (void)tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } } rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno; @@ -626,14 +626,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx } } - tdbPageDropCell(pParent, sIdx, pTxn, pBt); + (void)tdbPageDropCell(pParent, sIdx, pTxn, pBt); if (!childNotLeaf) { SArray *ofps = pParent->pPager->ofps; if (ofps) { for (int i = 0; i < TARRAY_SIZE(ofps); ++i) { SPage *ofp = *(SPage **)taosArrayGet(ofps, i); - tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn); + (void)tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn); } if (destroyOfps) { @@ -791,15 +791,15 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx iarg.pBt = pBt; iarg.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]); for (int i = 0; i < nOlds; i++) { - tdbPageCreate(pOlds[0]->pageSize, &pOldsCopy[i], tdbDefaultMalloc, NULL); - tdbBtreeInitPage(pOldsCopy[i], &iarg, 0); - tdbPageCopy(pOlds[i], pOldsCopy[i], 0); + (void)tdbPageCreate(pOlds[0]->pageSize, &pOldsCopy[i], tdbDefaultMalloc, NULL); + (void)tdbBtreeInitPage(pOldsCopy[i], &iarg, 0); + (void)tdbPageCopy(pOlds[i], pOldsCopy[i], 0); pOlds[i]->nOverflow = 0; } iNew = 0; nNewCells = 0; - tdbBtreeInitPage(pNews[iNew], &iarg, 0); + (void)tdbBtreeInitPage(pNews[iNew], &iarg, 0); for (int iOld = 0; iOld < nOlds; iOld++) { SPage *pPage; @@ -818,7 +818,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx } if (nNewCells < infoNews[iNew].cnt) { - tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); + (void)tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); nNewCells++; // insert parent page @@ -828,16 +828,16 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx if (iNew == nNews - 1 && pIntHdr->pgno == 0) { pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); } else { - tdbBtreeDecodeCell(pPage, pCell, &cd, pTxn, pBt); + (void)tdbBtreeDecodeCell(pPage, pCell, &cd, pTxn, pBt); // TODO: pCell here may be inserted as an overflow cell, handle it SCell *pNewCell = tdbOsMalloc(cd.kLen + 9); int szNewCell; SPgno pgno; pgno = TDB_PAGE_PGNO(pNews[iNew]); - tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn, - pBt); - tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); + (void)tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, + pTxn, pBt); + (void)tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); tdbOsFree(pNewCell); if (TDB_CELLDECODER_FREE_VAL(&cd)) { @@ -850,7 +850,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx iNew++; nNewCells = 0; if (iNew < nNews) { - tdbBtreeInitPage(pNews[iNew], &iarg, 0); + (void)tdbBtreeInitPage(pNews[iNew], &iarg, 0); } } } else { @@ -869,13 +869,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx return TSDB_CODE_FAILED; } ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); - tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); + (void)tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); // move to next new page iNew++; nNewCells = 0; if (iNew < nNews) { - tdbBtreeInitPage(pNews[iNew], &iarg, 0); + (void)tdbBtreeInitPage(pNews[iNew], &iarg, 0); } } } @@ -892,26 +892,26 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx pIntHdr->pgno = TDB_PAGE_PGNO(pNews[nNews - 1]); } else { ((SPgno *)pDivCell[nOlds - 1])[0] = TDB_PAGE_PGNO(pNews[nNews - 1]); - tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0); + (void)tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0); } } for (int i = 0; i < nOlds; i++) { - tdbPageDestroy(pOldsCopy[i], tdbDefaultFree, NULL); + (void)tdbPageDestroy(pOldsCopy[i], tdbDefaultFree, NULL); } } if (TDB_BTREE_PAGE_IS_ROOT(pParent) && TDB_PAGE_TOTAL_CELLS(pParent) == 0) { i8 flags = TDB_BTREE_ROOT | TDB_BTREE_PAGE_IS_LEAF(pNews[0]); // copy content to the parent page - tdbBtreeInitPage(pParent, &(SBtreeInitPageArg){.flags = flags, .pBt = pBt}, 0); - tdbPageCopy(pNews[0], pParent, 1); + (void)tdbBtreeInitPage(pParent, &(SBtreeInitPageArg){.flags = flags, .pBt = pBt}, 0); + (void)tdbPageCopy(pNews[0], pParent, 1); if (!TDB_BTREE_PAGE_IS_LEAF(pNews[0])) { ((SIntHdr *)(pParent->pData))->pgno = ((SIntHdr *)(pNews[0]->pData))->pgno; } - tdbPagerInsertFreePage(pBt->pPager, pNews[0], pTxn); + (void)tdbPagerInsertFreePage(pBt->pPager, pNews[0], pTxn); } for (int i = 0; i < 3; i++) { @@ -922,7 +922,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx for (pageIdx = 0; pageIdx < nOlds; ++pageIdx) { if (pageIdx >= nNews) { - tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn); + (void)tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn); } tdbPagerReturnPage(pBt->pPager, pOlds[pageIdx], pTxn); } @@ -1986,7 +1986,7 @@ int tdbBtcMoveToNext(SBTC *pBtc) { return 0; } - tdbBtcMoveUpward(pBtc); + (void)tdbBtcMoveUpward(pBtc); pBtc->idx++; if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { @@ -2029,7 +2029,7 @@ int tdbBtcMoveToPrev(SBTC *pBtc) { return 0; } - tdbBtcMoveUpward(pBtc); + (void)tdbBtcMoveUpward(pBtc); pBtc->idx--; if (pBtc->idx >= 0) { break; @@ -2040,7 +2040,7 @@ int tdbBtcMoveToPrev(SBTC *pBtc) { for (;;) { if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; - tdbBtcMoveDownward(pBtc); + (void)tdbBtcMoveDownward(pBtc); if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; } else { @@ -2119,7 +2119,7 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int } pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); - tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt); + (void)tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt); if (ppKey) { *ppKey = (void *)pBtc->coder.pKey; @@ -2165,13 +2165,13 @@ int tdbBtcDelete(SBTC *pBtc) { destroyOfps = true; } - tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); + (void)tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); SArray *ofps = pBtc->pPage->pPager->ofps; if (ofps) { for (int i = 0; i < TARRAY_SIZE(ofps); ++i) { SPage *ofp = *(SPage **)taosArrayGet(ofps, i); - tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn); + (void)tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn); } if (destroyOfps) { @@ -2184,7 +2184,7 @@ int tdbBtcDelete(SBTC *pBtc) { if (idx == nCells - 1) { if (idx) { pBtc->idx--; - tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL); + (void)tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL); // loop to update the interial page pgno = TDB_PAGE_PGNO(pBtc->pPage); @@ -2202,7 +2202,7 @@ int tdbBtcDelete(SBTC *pBtc) { // update the cell with new key pCell = tdbOsMalloc(nKey + 9); - tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt); + (void)tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt); ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt); if (ret < 0) { @@ -2429,7 +2429,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // compare first cell pBtc->idx = lidx; - tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + (void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c <= 0) { ridx = lidx - 1; @@ -2439,7 +2439,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // compare last cell if (lidx <= ridx) { pBtc->idx = ridx; - tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + (void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c >= 0) { lidx = ridx + 1; @@ -2454,7 +2454,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { if (lidx > ridx) break; pBtc->idx = (lidx + ridx) >> 1; - tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + (void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c < 0) { // pKey < cd.pKey @@ -2476,7 +2476,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { if (c > 0) { pBtc->idx += 1; } - tdbBtcMoveDownward(pBtc); + (void)tdbBtcMoveDownward(pBtc); } } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 47a7b6fe7a..825a6e2b94 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -101,10 +101,10 @@ int tdbClose(TDB *pDb) { for (pPager = pDb->pgrList; pPager; pPager = pDb->pgrList) { pDb->pgrList = pPager->pNext; - tdbPagerClose(pPager); + (void)tdbPagerClose(pPager); } - tdbPCacheClose(pDb->pCache); + (void)tdbPCacheClose(pDb->pCache); tdbOsFree(pDb->pgrHash); tdbOsFree(pDb); } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 6cb5f89758..c1a2943bee 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -44,10 +44,10 @@ static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage); static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage); static int tdbPCacheCloseImpl(SPCache *pCache); -static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } -static void tdbPCacheDestroyLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } -static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } -static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); } +static void tdbPCacheInitLock(SPCache *pCache) { (void)tdbMutexInit(&(pCache->mutex), NULL); } +static void tdbPCacheDestroyLock(SPCache *pCache) { (void)tdbMutexDestroy(&(pCache->mutex)); } +static void tdbPCacheLock(SPCache *pCache) { (void)tdbMutexLock(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { (void)tdbMutexUnlock(&(pCache->mutex)); } int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { int32_t code = 0; @@ -74,7 +74,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { _exit: if (code) { tdbError("%s failed at %s:%d since %s", __func__, __FILE__, __LINE__, tstrerror(code)); - tdbPCacheClose(pCache); + (void)tdbPCacheClose(pCache); *ppCache = NULL; } else { *ppCache = pCache; @@ -84,7 +84,7 @@ _exit: int tdbPCacheClose(SPCache *pCache) { if (pCache) { - tdbPCacheCloseImpl(pCache); + (void)tdbPCacheCloseImpl(pCache); tdbOsFree(pCache->aPage); tdbOsFree(pCache); } @@ -149,7 +149,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) { SPage *pPage = *ppPage; *ppPage = pPage->pFreeNext; pCache->aPage[pPage->id] = NULL; - tdbPageDestroy(pPage, tdbDefaultFree, NULL); + (void)tdbPageDestroy(pPage, tdbDefaultFree, NULL); pCache->nFree--; } else { ppPage = &(*ppPage)->pFreeNext; @@ -209,7 +209,7 @@ static void tdbPCacheFreePage(SPCache *pCache, SPage *pPage) { tdbTrace("pcache/free2 page: %p/%d, pgno:%d, ", pPage, pPage->id, TDB_PAGE_PGNO(pPage)); tdbPCacheRemovePageFromHash(pCache, pPage); - tdbPageDestroy(pPage, tdbDefaultFree, NULL); + (void)tdbPageDestroy(pPage, tdbDefaultFree, NULL); } } @@ -268,7 +268,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) { tdbPCacheRemovePageFromHash(pCache, pPage); } - tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg); + (void)tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg); } // } } @@ -349,7 +349,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) for (int nLoops = 0;;) { if (pPageH->pPager) break; if (++nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } } @@ -432,7 +432,7 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { tdbTrace("pcache destroy page: %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id); tdbPCacheRemovePageFromHash(pCache, pPage); - tdbPageDestroy(pPage, tdbDefaultFree, NULL); + (void)tdbPageDestroy(pPage, tdbDefaultFree, NULL); } } @@ -518,14 +518,14 @@ static int tdbPCacheCloseImpl(SPCache *pCache) { // free free page for (SPage *pPage = pCache->pFree; pPage;) { SPage *pPageT = pPage->pFreeNext; - tdbPageDestroy(pPage, tdbDefaultFree, NULL); + (void)tdbPageDestroy(pPage, tdbDefaultFree, NULL); pPage = pPageT; } for (int32_t iBucket = 0; iBucket < pCache->nHash; iBucket++) { for (SPage *pPage = pCache->pgHash[iBucket]; pPage;) { SPage *pPageT = pPage->pHashNext; - tdbPageDestroy(pPage, tdbDefaultFree, NULL); + (void)tdbPageDestroy(pPage, tdbDefaultFree, NULL); pPage = pPageT; } } diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 322b735163..26c1c108d2 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -64,7 +64,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) memset(ptr, 0, size); pPage = (SPage *)(ptr + pageSize); - TDB_INIT_PAGE_LOCK(pPage); + (void)TDB_INIT_PAGE_LOCK(pPage); pPage->pageSize = pageSize; pPage->pData = ptr; if (pageSize < 65536) { @@ -194,7 +194,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl iOvfl++; } else { // page must has enough space to hold the cell locally - tdbPageAllocate(pPage, szCell, &pNewCell); + (void)tdbPageAllocate(pPage, szCell, &pNewCell); memcpy(pNewCell, pCell, szCell); @@ -220,7 +220,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl } int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt) { - tdbPageDropCell(pPage, idx, pTxn, pBt); + (void)tdbPageDropCell(pPage, idx, pTxn, pBt); return tdbPageInsertCell(pPage, idx, pCell, szCell, 0); } @@ -259,7 +259,7 @@ int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt) { lidx = idx - iOvfl; pCell = TDB_PAGE_CELL_AT(pPage, lidx); szCell = (*pPage->xCellSize)(pPage, pCell, 1, pTxn, pBt); - tdbPageFree(pPage, lidx, pCell, szCell); + (void)tdbPageFree(pPage, lidx, pCell, szCell); TDB_PAGE_NCELLS_SET(pPage, nCells - 1); for (; iOvfl < pPage->nOverflow; iOvfl++) { diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 414ca42a02..01dd0ac766 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -107,7 +107,7 @@ static int hashset_add(hashset_t set, void *item) { set->nitems = 0; for (size_t i = 0; i < old_capacity; ++i) { - hashset_add_member(set, (void *)old_items[i]); + (void)hashset_add_member(set, (void *)old_items[i]); } tdbOsFree(old_items); } @@ -223,7 +223,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { int tdbPagerClose(SPager *pPager) { if (pPager) { - tdbOsClose(pPager->fd); + (void)tdbOsClose(pPager->fd); tdbOsFree(pPager); } return 0; @@ -236,14 +236,14 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { if (pPage->isDirty) return 0; // ref page one more time so the page will not be release - tdbRefPage(pPage); + (void)tdbRefPage(pPage); tdbTrace("pager/mdirty page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id); // Set page as dirty pPage->isDirty = 1; tdbTrace("tdb/pager-write: put page: %p %d to dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt); - tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage); + (void)tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage); // Write page to journal if neccessary if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize && @@ -256,7 +256,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { } if (pPager->pActiveTxn->jPageSet) { - hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); + (void)hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); } } @@ -352,7 +352,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage); if (pTxn->jPageSet) { - hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); + (void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); } tdbTrace("tdb/pager-commit: remove page: %p %d from dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt); @@ -590,7 +590,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) { pPage->isDirty = 0; tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage); - hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); + (void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage))); tdbPCacheMarkFree(pPager->pCache, pPage); tdbPCacheRelease(pPager->pCache, pPage, pTxn); } @@ -712,7 +712,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN); pgid.pgno = pgno; while ((pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn)) == NULL) { - tdbPagerFlushPage(pPager, pTxn); + (void)tdbPagerFlushPage(pPager, pTxn); } tdbTrace("tdbttl fetch pager:%p", pPage->pPager); @@ -815,7 +815,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) { code = tdbTbcMoveToFirst(pCur); if (code) { tdbError("tdb/remove-free-page: moveto first failed with ret: %d.", code); - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } @@ -825,7 +825,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) { code = tdbTbcGet(pCur, (const void **)&pKey, &nKey, NULL, NULL); if (code < 0) { // tdbError("tdb/remove-free-page: tbc get failed with ret: %d.", code); - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } @@ -836,10 +836,10 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) { code = tdbTbcDelete(pCur); if (code < 0) { tdbError("tdb/remove-free-page: tbc delete failed with ret: %d.", code); - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } @@ -892,7 +892,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage lcode = TDB_TRY_LOCK_PAGE(pPage); if (lcode == P_LOCK_SUCC) { if (TDB_PAGE_INITIALIZED(pPage)) { - TDB_UNLOCK_PAGE(pPage); + (void)TDB_UNLOCK_PAGE(pPage); return 0; } @@ -906,7 +906,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage tdbTrace("tdb/pager:%p, pgno:%d, nRead:%" PRId64, pPager, pgno, nRead); if (nRead < pPage->pageSize) { tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32, pPager, pgno, nRead, pPage->pageSize); - TDB_UNLOCK_PAGE(pPage); + (void)TDB_UNLOCK_PAGE(pPage); return TAOS_SYSTEM_ERROR(errno); } @@ -953,7 +953,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage if (ret < 0) { tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", pPager, pgno, nRead, pPage->pageSize); - TDB_UNLOCK_PAGE(pPage); + (void)TDB_UNLOCK_PAGE(pPage); return ret; } @@ -961,14 +961,14 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage pPage->pPager = pPager; - TDB_UNLOCK_PAGE(pPage); + (void)TDB_UNLOCK_PAGE(pPage); } else if (lcode == P_LOCK_BUSY) { nLoops = 0; for (;;) { if (TDB_PAGE_INITIALIZED(pPage)) break; nLoops++; if (nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } } @@ -1162,7 +1162,7 @@ int tdbPagerRestoreJournals(SPager *pPager) { char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry)); if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) { int64_t txnId = -1; - sscanf(name, TDB_MAINDB_NAME "-journal.%" PRId64, &txnId); + (void)sscanf(name, TDB_MAINDB_NAME "-journal.%" PRId64, &txnId); if (taosArrayPush(pTxnList, &txnId) == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1179,14 +1179,14 @@ int tdbPagerRestoreJournals(SPager *pPager) { code = tdbPagerRestore(pPager, jname); if (code) { taosArrayDestroy(pTxnList); - tdbCloseDir(&pDir); + (void)tdbCloseDir(&pDir); tdbError("failed to restore file due to %s. jFileName:%s", strerror(code), jname); return code; } } taosArrayDestroy(pTxnList); - tdbCloseDir(&pDir); + (void)tdbCloseDir(&pDir); return 0; } @@ -1209,7 +1209,7 @@ int tdbPagerRollback(SPager *pPager) { jname[dirLen] = '/'; memcpy(jname + dirLen + 1, name, strlen(name)); if (tdbOsRemove(jname) < 0 && errno != ENOENT) { - tdbCloseDir(&pDir); + (void)tdbCloseDir(&pDir); tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name); return terrno = TAOS_SYSTEM_ERROR(errno); @@ -1217,7 +1217,7 @@ int tdbPagerRollback(SPager *pPager) { } } - tdbCloseDir(&pDir); + (void)tdbCloseDir(&pDir); return 0; } diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c index 365be222ef..d885c38864 100644 --- a/source/libs/tdb/src/db/tdbTable.c +++ b/source/libs/tdb/src/db/tdbTable.c @@ -112,7 +112,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF return ret; } } else { - tdbPagerRollback(pPager); + (void)tdbPagerRollback(pPager); } // pTb->pBt @@ -128,7 +128,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF int tdbTbClose(TTB *pTb) { if (pTb) { - tdbBtreeClose(pTb->pBt); + (void)tdbBtreeClose(pTb->pBt); tdbOsFree(pTb); } return 0; @@ -202,7 +202,7 @@ int tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int va int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); } int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) { - tdbTbDelete(pTb, pKey, kLen, pTxn); + (void)tdbTbDelete(pTb, pKey, kLen, pTxn); return tdbTbInsert(pTb, pKey, kLen, pVal, vLen, pTxn); } @@ -224,7 +224,7 @@ int tdbTbcOpen(TTB *pTb, TBC **ppTbc, TXN *pTxn) { return -1; } - tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn); + (void)tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn); *ppTbc = pTbc; return 0; @@ -238,7 +238,7 @@ int32_t tdbTbTraversal(TTB *pTb, void *data, return ret; } - tdbTbcMoveToFirst(pCur); + (void)tdbTbcMoveToFirst(pCur); void *pKey = NULL; int kLen = 0; @@ -257,7 +257,7 @@ int32_t tdbTbTraversal(TTB *pTb, void *data, } tdbFree(pKey); tdbFree(pValue); - tdbTbcClose(pCur); + (void)tdbTbcClose(pCur); return 0; } @@ -292,7 +292,7 @@ int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int n int tdbTbcClose(TBC *pTbc) { if (pTbc) { - tdbBtcClose(&pTbc->btc); + (void)tdbBtcClose(&pTbc->btc); tdbOsFree(pTbc); } diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index fe97f9c986..4382513f73 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -13,6 +13,8 @@ * along with this program. If not, see . */ +#include "tdbInt.h" + #ifndef _TDB_UTIL_H_ #define _TDB_UTIL_H_ @@ -56,8 +58,6 @@ static inline int tdbPutVarInt(u8 *p, int v) { v >>= 7; } - ASSERT(n < 6); - return n; } @@ -79,8 +79,6 @@ static inline int tdbGetVarInt(const u8 *p, int *v) { n++; } - ASSERT(n < 6); - *v = tv; return n; } diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index ede7636011..f81bbbdeb7 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -483,7 +483,7 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) { void tfsClosedir(STfsDir *pTfsDir) { if (pTfsDir) { if (pTfsDir->pDir != NULL) { - taosCloseDir(&pTfsDir->pDir); + (void)taosCloseDir(&pTfsDir->pDir); pTfsDir->pDir = NULL; } taosMemoryFree(pTfsDir); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index acb9bd20f3..e66941244c 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -103,11 +103,11 @@ typedef void* queue[2]; #define TRANS_MAGIC_NUM 0x5f375a86 #define TRANS_NOVALID_PACKET(src) ((src) != TRANS_MAGIC_NUM ? 1 : 0) -typedef struct SRpcMsg STransMsg; -typedef SRpcCtx STransCtx; -typedef SRpcCtxVal STransCtxVal; -typedef SRpcInfo STrans; -typedef SRpcConnInfo STransHandleInfo; +typedef struct SRpcMsg STransMsg; +typedef SRpcCtx STransCtx; +typedef SRpcCtxVal STransCtxVal; +typedef SRpcInfo STrans; +typedef SRpcConnInfo STransHandleInfo; // ref mgt handle typedef struct SExHandle { @@ -250,10 +250,10 @@ typedef struct { int8_t stop; } SAsyncPool; -SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb); -void transAsyncPoolDestroy(SAsyncPool* pool); -int transAsyncSend(SAsyncPool* pool, queue* mq); -bool transAsyncPoolIsEmpty(SAsyncPool* pool); +int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAsyncPool** pPool); +void transAsyncPoolDestroy(SAsyncPool* pool); +int transAsyncSend(SAsyncPool* pool, queue* mq); +bool transAsyncPoolIsEmpty(SAsyncPool* pool); #define TRANS_DESTROY_ASYNC_POOL_MSG(pool, msgType, freeFunc, param) \ do { \ @@ -279,6 +279,7 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); if (exh2 == NULL || id != exh2->refId) { \ tTrace("handle %p except, may already freed, ignore msg, ref1:%" PRIu64 ", ref2:%" PRIu64, exh1, \ exh2 ? exh2->refId : 0, id); \ + code = terrno; \ goto _return1; \ } \ } else if (id == 0) { \ @@ -287,6 +288,7 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); if (exh2 == NULL || id == exh2->refId) { \ tTrace("handle %p except, may already freed, ignore msg, ref1:%" PRIu64 ", ref2:%" PRIu64, exh1, id, \ exh2 ? exh2->refId : 0); \ + code = terrno; \ goto _return1; \ } else { \ id = exh1->refId; \ @@ -297,13 +299,13 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); } \ } while (0) -int transInitBuffer(SConnBuffer* buf); -int transClearBuffer(SConnBuffer* buf); -int transDestroyBuffer(SConnBuffer* buf); -int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf); -bool transReadComplete(SConnBuffer* connBuf); -int transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf); -int transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf); +int32_t transInitBuffer(SConnBuffer* buf); +int32_t transClearBuffer(SConnBuffer* buf); +int32_t transDestroyBuffer(SConnBuffer* buf); +int32_t transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf); +bool transReadComplete(SConnBuffer* connBuf); +int transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf); +int transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf); int transSetConnOption(uv_tcp_t* stream, int keepalive); @@ -316,14 +318,14 @@ void transUnrefCliHandle(void* handle); int transReleaseCliHandle(void* handle); int transReleaseSrvHandle(void* handle); -int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx); -int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp); -int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp, int8_t* epUpdated, - int32_t timeoutMs); -int transSendResponse(const STransMsg* msg); -int transRegisterMsg(const STransMsg* msg); -int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn); -void transSetIpWhiteList(void* shandle, void* arg, FilteFunc* func); +int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx); +int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp); +int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp, int8_t* epUpdated, + int32_t timeoutMs); +int transSendResponse(const STransMsg* msg); +int transRegisterMsg(const STransMsg* msg); +int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn); +int32_t transSetIpWhiteList(void* shandle, void* arg, FilteFunc* func); int transSockInfo2Str(struct sockaddr* sockname, char* dst); @@ -363,7 +365,7 @@ typedef struct { * init queue * note: queue'size is small, default 1 */ -void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); +int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); /* * put arg into queue @@ -420,7 +422,7 @@ typedef struct SDelayQueue { uv_loop_t* loop; } SDelayQueue; -int transDQCreate(uv_loop_t* loop, SDelayQueue** queue); +int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue); void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)); SDelayTask* transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs); void transDQCancel(SDelayQueue* queue, SDelayTask* task); @@ -433,9 +435,9 @@ bool transEpSetIsEqual2(SEpSet* a, SEpSet* b); */ void transThreadOnce(); -void transInit(); -void transCleanup(); -void transPrintEpSet(SEpSet* pEpSet); +int32_t transInit(); +void transCleanup(); +void transPrintEpSet(SEpSet* pEpSet); void transFreeMsg(void* msg); int32_t transCompressMsg(char* msg, int32_t len); diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 28c1c15ea3..908468f094 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -209,7 +209,7 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, static void* httpThread(void* arg) { SHttpModule* http = (SHttpModule*)arg; setThreadName("http-cli-send-thread"); - uv_run(http->loop, UV_RUN_DEFAULT); + (void)uv_run(http->loop, UV_RUN_DEFAULT); return NULL; } @@ -332,7 +332,7 @@ static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) { SHttpModule* http = taosAcquireRef(httpRefMgt, cli->chanId); if (http != NULL) { http->connNum -= 1; - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); } destroyHttpClient(cli); @@ -389,7 +389,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } http->connNum += 1; @@ -404,7 +404,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } } - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); } int32_t httpSendQuit(SHttpModule* http, int64_t chanId) { @@ -449,7 +449,7 @@ static void httpHandleQuit(SHttpMsg* msg) { SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); if (http == NULL) return; uv_walk(http->loop, httpWalkCb, NULL); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); } static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t port) { @@ -474,10 +474,10 @@ static void httpFailFastMayUpdate(SHashObj* pTable, char* server, int16_t port, sprintf(buf, "%s:%d", server, port); if (succ) { - taosHashRemove(pTable, buf, strlen(buf)); + (void)taosHashRemove(pTable, buf, strlen(buf)); } else { int32_t st = taosGetTimestampSec(); - taosHashPut(pTable, buf, strlen(buf), &st, sizeof(st)); + (void)taosHashPut(pTable, buf, strlen(buf), &st, sizeof(st)); } return; } @@ -559,7 +559,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to alloc read buf, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); destroyHttpClient(cli); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } @@ -568,7 +568,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to init socket handle, dst:%s:%d,chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, uv_strerror(err)); destroyHttpClient(cli); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } @@ -578,7 +578,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, tstrerror(TAOS_SYSTEM_ERROR(errno))); destroyHttpClient(cli); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } @@ -587,7 +587,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to open socket, reason:%s, dst:%s:%d, chanId:%" PRId64 ",reason:%s", uv_strerror(ret), cli->addr, cli->port, chanId, uv_strerror(ret)); destroyHttpClient(cli); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } @@ -598,7 +598,7 @@ static void httpHandleReq(SHttpMsg* msg) { httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); destroyHttpClient(cli); } - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; END: @@ -608,7 +608,7 @@ END: } httpDestroyMsg(msg); taosMemoryFree(header); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); } static void httpModuleDestroy(SHttpModule* http) { @@ -619,7 +619,7 @@ static void httpModuleDestroy(SHttpModule* http) { transAsyncPoolDestroy(http->asyncPool); } if (http->loop) { - uv_loop_close(http->loop); + (void)uv_loop_close(http->loop); taosMemoryFree(http->loop); } @@ -673,7 +673,7 @@ int32_t taosSendHttpReportByChan(const char* server, const char* uri, uint16_t p int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) { - taosThreadOnce(&transHttpInit, transHttpEnvInit); + (void)taosThreadOnce(&transHttpInit, transHttpEnvInit); return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, httpDefaultChanId); } @@ -719,9 +719,8 @@ int64_t transInitHttpChanImpl() { goto _ERROR; } - http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb); - if (http->asyncPool == NULL) { - code = terrno; + code = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb, &http->asyncPool); + if (code != 0) { goto _ERROR; } @@ -744,7 +743,7 @@ _ERROR: return code; } int64_t taosInitHttpChan() { - taosThreadOnce(&transHttpInit, transHttpEnvInit); + (void)taosThreadOnce(&transHttpInit, transHttpEnvInit); return transInitHttpChanImpl(); } @@ -763,14 +762,14 @@ void taosDestroyHttpChan(int64_t chanId) { ret = httpSendQuit(load, chanId); if (ret != 0) { tDebug("http-report already destroyed, chanId %" PRId64 ",reason:%s", chanId, tstrerror(ret)); - taosReleaseRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); return; } - taosThreadJoin(load->thread, NULL); + (void)taosThreadJoin(load->thread, NULL); httpModuleDestroy(load); - taosReleaseRef(httpRefMgt, chanId); - taosRemoveRef(httpRefMgt, chanId); + (void)taosReleaseRef(httpRefMgt, chanId); + (void)taosRemoveRef(httpRefMgt, chanId); } \ No newline at end of file diff --git a/source/libs/transport/src/tmsgcb.c b/source/libs/transport/src/tmsgcb.c index e44328c683..619592c82c 100644 --- a/source/libs/transport/src/tmsgcb.c +++ b/source/libs/transport/src/tmsgcb.c @@ -59,7 +59,7 @@ int32_t tmsgSendSyncReq(const SEpSet* epSet, SRpcMsg* pMsg) { void tmsgSendRsp(SRpcMsg* pMsg) { #if 1 - rpcSendResponse(pMsg); + (void)rpcSendResponse(pMsg); #else return (*defaultMsgCb.sendRspFp)(pMsg); #endif @@ -81,6 +81,6 @@ bool tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint1 void tmsgUpdateDnodeEpSet(SEpSet* epset) { for (int32_t i = 0; i < epset->numOfEps; ++i) { - tmsgUpdateDnodeInfo(NULL, NULL, epset->eps[i].fqdn, &epset->eps[i].port); + (void)tmsgUpdateDnodeInfo(NULL, NULL, epset->eps[i].fqdn, &epset->eps[i].port); } } diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index c35f147fc5..fbcc74e8e1 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -27,18 +27,20 @@ int (*transReleaseHandle[])(void* handle) = {transReleaseSrvHandle, transRelease static int32_t transValidLocalFqdn(const char* localFqdn, uint32_t* ip) { int32_t code = taosGetIpv4FromFqdn(localFqdn, ip); - if (code) { - terrno = TSDB_CODE_RPC_FQDN_ERROR; - return -1; + if (code != 0) { + return TSDB_CODE_RPC_FQDN_ERROR; } return 0; } void* rpcOpen(const SRpcInit* pInit) { - rpcInit(); + int32_t code = rpcInit(); + if (code != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } SRpcInfo* pRpc = taosMemoryCalloc(1, sizeof(SRpcInfo)); if (pRpc == NULL) { - return NULL; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } if (pInit->label) { int len = strlen(pInit->label) > sizeof(pRpc->label) ? sizeof(pRpc->label) : strlen(pInit->label); @@ -84,10 +86,9 @@ void* rpcOpen(const SRpcInit* pInit) { uint32_t ip = 0; if (pInit->connType == TAOS_CONN_SERVER) { - if (transValidLocalFqdn(pInit->localFqdn, &ip) != 0) { - tError("invalid fqdn:%s, errmsg:%s", pInit->localFqdn, terrstr()); - taosMemoryFree(pRpc); - return NULL; + if ((code = transValidLocalFqdn(pInit->localFqdn, &ip)) != 0) { + tError("invalid fqdn:%s, errmsg:%s", pInit->localFqdn, tstrerror(code)); + TAOS_CHECK_GOTO(code, NULL, _end); } } @@ -105,19 +106,24 @@ void* rpcOpen(const SRpcInit* pInit) { (*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc); if (pRpc->tcphandle == NULL) { - taosMemoryFree(pRpc); - return NULL; + tError("failed to init rpc handle"); + TAOS_CHECK_GOTO(terrno, NULL, _end); } int64_t refId = transAddExHandle(transGetInstMgt(), pRpc); - transAcquireExHandle(transGetInstMgt(), refId); + (void)transAcquireExHandle(transGetInstMgt(), refId); pRpc->refId = refId; return (void*)refId; +_end: + taosMemoryFree(pRpc); + terrno = code; + + return NULL; } void rpcClose(void* arg) { tInfo("start to close rpc"); - transRemoveExHandle(transGetInstMgt(), (int64_t)arg); - transReleaseExHandle(transGetInstMgt(), (int64_t)arg); + (void)transRemoveExHandle(transGetInstMgt(), (int64_t)arg); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)arg); tInfo("end to close rpc"); return; } @@ -186,7 +192,7 @@ int rpcSetDefaultAddr(void* thandle, const char* ip, const char* fqdn) { return transSetDefaultAddr(thandle, ip, fqdn); } // server only -void rpcSetIpWhite(void* thandle, void* arg) { transSetIpWhiteList(thandle, arg, NULL); } +int32_t rpcSetIpWhite(void* thandle, void* arg) { return transSetIpWhiteList(thandle, arg, NULL); } void* rpcAllocHandle() { return (void*)transAllocHandle(); } @@ -202,10 +208,8 @@ int32_t rpcCvtErrCode(int32_t code) { return code; } -int32_t rpcInit() { - transInit(); - return 0; -} +int32_t rpcInit() { return transInit(); } + void rpcCleanup(void) { transCleanup(); transHttpEnvDestroy(); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 19af63b24f..2e61f19af8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -114,7 +114,7 @@ typedef struct SCliThrd { SDelayQueue* timeoutQueue; SDelayQueue* waitConnQueue; uint64_t nextTimeout; // next timeout - void* pTransInst; // + STrans* pTransInst; // int connCount; void (*destroyAhandleFp)(void* ahandle); @@ -180,12 +180,12 @@ static int32_t allocConnRef(SCliConn* conn, bool update); static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); -static SCliConn* cliCreateConn(SCliThrd* thrd); -static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); -static void cliDestroy(uv_handle_t* handle); -static void cliSend(SCliConn* pConn); -static void cliSendBatch(SCliConn* pConn); -static void cliDestroyConnMsgs(SCliConn* conn, bool destroy); +static int32_t cliCreateConn(SCliThrd* thrd, SCliConn** pCliConn); +static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); +static void cliDestroy(uv_handle_t* handle); +static void cliSend(SCliConn* pConn); +static void cliSendBatch(SCliConn* pConn); +static void cliDestroyConnMsgs(SCliConn* conn, bool destroy); static void doFreeTimeoutMsg(void* param); static int32_t cliPreCheckSessionLimitForMsg(SCliThrd* pThrd, char* addr, SCliMsg** pMsg); @@ -196,8 +196,8 @@ static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr); static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp); -static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip); -static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn); +static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); +static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); static FORCE_INLINE void cliMayUpdateFqdnCache(SHashObj* cache, char* dst); // process data read from server, add decompress etc later @@ -226,16 +226,15 @@ static FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst); static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); // thread obj -static SCliThrd* createThrdObj(void* trans); -static void destroyThrdObj(SCliThrd* pThrd); +static int32_t createThrdObj(void* trans, SCliThrd** pThrd); +static void destroyThrdObj(SCliThrd* pThrd); +static void cliWalkCb(uv_handle_t* handle, void* arg); -static void cliWalkCb(uv_handle_t* handle, void* arg); - -#define CLI_RELEASE_UV(loop) \ - do { \ - uv_walk(loop, cliWalkCb, NULL); \ - uv_run(loop, UV_RUN_DEFAULT); \ - uv_loop_close(loop); \ +#define CLI_RELEASE_UV(loop) \ + do { \ + (void)uv_walk(loop, cliWalkCb, NULL); \ + (void)uv_run(loop, UV_RUN_DEFAULT); \ + (void)uv_loop_close(loop); \ } while (0); // snprintf may cause performance problem @@ -245,7 +244,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); int16_t len = strlen(ip); \ if (ip != NULL) memcpy(t, ip, len); \ t[len] = ':'; \ - titoa(port, 10, &t[len + 1]); \ + (void)titoa(port, 10, &t[len + 1]); \ } while (0) #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) @@ -358,15 +357,15 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { taosWUnLockLatch(&exh->latch); SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); transCtxMerge(&conn->ctx, &t->ctx->appCtx); - transQueuePush(&conn->cliMsgs, t); + (void)transQueuePush(&conn->cliMsgs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); cliSend(conn); return true; } taosWUnLockLatch(&exh->latch); tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); return false; } @@ -377,9 +376,9 @@ void cliHandleResp(SCliConn* conn) { if (conn->timer) { if (uv_is_active((uv_handle_t*)conn->timer)) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); - uv_timer_stop(conn->timer); + (void)uv_timer_stop(conn->timer); } - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer->data = NULL; conn->timer = NULL; } @@ -487,7 +486,7 @@ void cliHandleResp(SCliConn* conn) { return addConnToPool(pThrd->pool, conn); } - uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } static void cliDestroyMsgInExhandle(int64_t refId) { if (refId == 0) return; @@ -501,7 +500,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { destroyCmsg(t); } taosWUnLockLatch(&exh->latch); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); } } @@ -589,9 +588,9 @@ void cliConnTimeout(uv_timer_t* handle) { tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - uv_timer_stop(handle); + (void)uv_timer_stop(handle); handle->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer = NULL; cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); @@ -601,7 +600,7 @@ void cliReadTimeoutCb(uv_timer_t* handle) { // set up timeout cb SCliConn* conn = handle->data; tTrace("%s conn %p timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - uv_read_stop(conn->stream); + (void)uv_read_stop(conn->stream); cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); } @@ -647,7 +646,7 @@ static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); if (plist == NULL) { SConnList list = {0}; - taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); + (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); plist = taosHashGet(pool, key, klen); SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); @@ -688,7 +687,7 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); if (plist == NULL) { SConnList list = {0}; - taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); + (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); plist = taosHashGet(pool, key, klen); SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); @@ -714,10 +713,22 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { } STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + if (arg == NULL) { + doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pMsg = NULL; + return NULL; + } arg->param1 = *pMsg; arg->param2 = pThrd; - (*pMsg)->ctx->task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); + SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); + if (task == NULL) { + taosMemoryFree(arg); + doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pMsg = NULL; + return NULL; + } + (*pMsg)->ctx->task = task; tGTrace("%s msg %s delay to send, wait for avaiable connect", pTransInst->label, TMSG_INFO((*pMsg)->msg.msgType)); QUEUE_PUSH(&(list)->msgQ, &(*pMsg)->q); *pMsg = NULL; @@ -725,9 +736,23 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { // send msg in delay queue if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + if (arg == NULL) { + doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pMsg = NULL; + return NULL; + } arg->param1 = *pMsg; arg->param2 = pThrd; - (*pMsg)->ctx->task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); + + SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pTransInst->timeToGetConn); + if (task == NULL) { + taosMemoryFree(arg); + doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pMsg = NULL; + return NULL; + } + + (*pMsg)->ctx->task = task; tGTrace("%s msg %s delay to send, wait for avaiable connect", pTransInst->label, TMSG_INFO((*pMsg)->msg.msgType)); @@ -767,12 +792,16 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } - allocConnRef(conn, true); + int32_t code = allocConnRef(conn, true); + if (code != 0) { + cliDestroyConn(conn, true); + return; + } SCliThrd* thrd = conn->hostThrd; if (conn->timer != NULL) { - uv_timer_stop(conn->timer); - taosArrayPush(thrd->timerList, &conn->timer); + (void)uv_timer_stop(conn->timer); + (void)taosArrayPush(thrd->timerList, &conn->timer); conn->timer->data = NULL; conn->timer = NULL; } @@ -798,7 +827,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { pMsg->ctx->task = NULL; transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - transQueuePush(&conn->cliMsgs, pMsg); + (void)transQueuePush(&conn->cliMsgs, pMsg); conn->status = ConnNormal; cliSend(conn); @@ -812,6 +841,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->list->size >= 10) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); + if (arg == NULL) return; arg->param1 = conn; arg->param2 = thrd; @@ -821,15 +851,18 @@ static void addConnToPool(void* pool, SCliConn* conn) { } static int32_t allocConnRef(SCliConn* conn, bool update) { if (update) { - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); conn->refId = -1; } SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); + if (exh == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + exh->refId = transAddExHandle(transGetRefMgt(), exh); - SExHandle* self = transAcquireExHandle(transGetRefMgt(), exh->refId); - if (self != exh) { + if (exh->refId < 0) { taosMemoryFree(exh); return TSDB_CODE_REF_INVALID_ID; } @@ -839,8 +872,14 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { exh->handle = conn; exh->pThrd = conn->hostThrd; + SExHandle* self = transAcquireExHandle(transGetRefMgt(), exh->refId); + if (self != exh) { + taosMemoryFree(exh); + return TSDB_CODE_REF_INVALID_ID; + } + conn->refId = exh->refId; - if (conn->refId == -1) { + if (conn->refId < 0) { taosMemoryFree(exh); } return 0; @@ -848,8 +887,8 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { if (update) { - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); conn->refId = -1; } SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); @@ -864,14 +903,18 @@ static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { conn->refId = exh->refId; taosWUnLockLatch(&exh->latch); - transReleaseExHandle(transGetRefMgt(), handle); + (void)transReleaseExHandle(transGetRefMgt(), handle); return 0; } static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SCliConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; - transAllocBuffer(pBuf, buf); + int32_t code = transAllocBuffer(pBuf, buf); + if (code < 0) { + tError("conn %p failed to alloc buffer, since %s", conn, tstrerror(code)); + // cliDestroyConn(conn, true); + } } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { // impl later @@ -909,36 +952,69 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } } -static SCliConn* cliCreateConn(SCliThrd* pThrd) { +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { + int32_t code = 0; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); + if (conn == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); - uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream)); + if (conn->stream == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(code, NULL, _failed); + } + + code = uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream)); + if (code != 0) { + tError("failed to init tcp handle, code:%d, %s", code, uv_strerror(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + TAOS_CHECK_GOTO(code, NULL, _failed); + } conn->stream->data = conn; uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; if (timer == NULL) { timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + if (timer == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _failed); + } + tDebug("no available timer, create a timer %p", timer); - uv_timer_init(pThrd->loop, timer); + (void)uv_timer_init(pThrd->loop, timer); } timer->data = conn; conn->timer = timer; conn->connReq.data = conn; transReqQueueInit(&conn->wreqQueue); - transQueueInit(&conn->cliMsgs, NULL); - transInitBuffer(&conn->readBuf); + + TAOS_CHECK_GOTO(transQueueInit(&conn->cliMsgs, NULL), NULL, _failed); + + TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); + QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; conn->status = ConnNormal; conn->broken = false; transRefCliHandle(conn); - atomic_add_fetch_32(&pThrd->connCount, 1); - allocConnRef(conn, false); + (void)atomic_add_fetch_32(&pThrd->connCount, 1); - return conn; + TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); + + *pCliConn = conn; + return code; +_failed: + if (conn) { + taosMemoryFree(conn->stream); + transReqQueueClear(&conn->wreqQueue); + (void)transDestroyBuffer(&conn->readBuf); + transQueueDestroy(&conn->cliMsgs); + } + taosMemoryFree(conn); + return code; } static void cliDestroyConn(SCliConn* conn, bool clear) { SCliThrd* pThrd = conn->hostThrd; @@ -962,8 +1038,8 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { conn->list = NULL; - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); conn->refId = -1; if (conn->task != NULL) { @@ -971,15 +1047,15 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { conn->task = NULL; } if (conn->timer != NULL) { - uv_timer_stop(conn->timer); + (void)uv_timer_stop(conn->timer); conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer = NULL; } if (clear) { if (!uv_is_closing((uv_handle_t*)conn->stream)) { - uv_read_stop(conn->stream); + (void)uv_read_stop(conn->stream); uv_close((uv_handle_t*)conn->stream, cliDestroy); } } @@ -991,16 +1067,16 @@ static void cliDestroy(uv_handle_t* handle) { SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; if (conn->timer != NULL) { - uv_timer_stop(conn->timer); - taosArrayPush(pThrd->timerList, &conn->timer); + (void)uv_timer_stop(conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer->data = NULL; conn->timer = NULL; } - atomic_sub_fetch_32(&pThrd->connCount, 1); + (void)atomic_sub_fetch_32(&pThrd->connCount, 1); - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); @@ -1008,7 +1084,7 @@ static void cliDestroy(uv_handle_t* handle) { tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); - transDestroyBuffer(&conn->readBuf); + (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); } @@ -1017,7 +1093,7 @@ static bool cliHandleNoResp(SCliConn* conn) { if (!transQueueEmpty(&conn->cliMsgs)) { SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0); if (REQUEST_NO_RESP(&pMsg->msg)) { - transQueuePop(&conn->cliMsgs); + (void)transQueuePop(&conn->cliMsgs); destroyCmsg(pMsg); res = true; } @@ -1062,7 +1138,7 @@ static void cliSendCb(uv_write_t* req, int status) { tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); return; } - uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); + (void)uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); } void cliSendBatch(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; @@ -1121,7 +1197,7 @@ void cliSendBatch(SCliConn* pConn) { req->data = pConn; tDebug("%s conn %p start to send batch msg, batch size:%d, msgLen:%d", CONN_GET_INST_LABEL(pConn), pConn, pBatch->wLen, pBatch->batchSize); - uv_write(req, (uv_stream_t*)pConn->stream, wb, wLen, cliSendBatchCb); + (void)uv_write(req, (uv_stream_t*)pConn->stream, wb, wLen, cliSendBatchCb); taosMemoryFree(wb); } void cliSend(SCliConn* pConn) { @@ -1176,13 +1252,13 @@ void cliSend(SCliConn* pConn) { if (timer == NULL) { timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); tDebug("no available timer, create a timer %p", timer); - uv_timer_init(pThrd->loop, timer); + (void)uv_timer_init(pThrd->loop, timer); } timer->data = pConn; pConn->timer = timer; tGTrace("%s conn %p start timer for msg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType)); - uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0); + (void)uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0); } if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { @@ -1225,6 +1301,7 @@ static void cliDestroyBatch(SCliBatch* pBatch) { taosMemoryFree(pBatch); } static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { + int32_t code = 0; if (pThrd->quit == true) { cliDestroyBatch(pBatch); return; @@ -1249,22 +1326,33 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { return; } if (conn == NULL) { - conn = cliCreateConn(pThrd); - conn->pBatch = pBatch; - conn->dstAddr = taosStrdup(pList->dst); - - uint32_t ipaddr = 0; - int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip, &ipaddr); - if (code) { - uv_timer_stop(conn->timer); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - - cliHandleFastFail(conn, terrno); - terrno = 0; + code = cliCreateConn(pThrd, &conn); + if (code != 0) { + tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pTransInst->label, + pBatch->wLen, pBatch->batchSize, pTransInst->connLimitNum, tstrerror(code)); + cliDestroyBatch(pBatch); return; } + + conn->pBatch = pBatch; + conn->dstAddr = taosStrdup(pList->dst); + if (conn->dstAddr == NULL) { + tError("%s conn %p failed to send batch msg, reason:%s", transLabel(pTransInst), conn, + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + cliHandleFastFail(conn, -1); + return; + } + + uint32_t ipaddr = 0; + if ((code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip, &ipaddr)) != 0) { + (void)uv_timer_stop(conn->timer); + conn->timer->data = NULL; + (void)taosArrayPush(pThrd->timerList, &conn->timer); + conn->timer = NULL; + cliHandleFastFail(conn, code); + return; + } + struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = ipaddr; @@ -1293,16 +1381,16 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - uv_timer_stop(conn->timer); + (void)uv_timer_stop(conn->timer); conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer = NULL; cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, -1); return; } - uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); return; } @@ -1373,7 +1461,7 @@ static void cliHandleFastFail(SCliConn* pConn, int status) { } } else { SFailFastItem item = {.count = 1, .timestamp = cTimestamp}; - taosHashPut(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr), &item, sizeof(SFailFastItem)); + (void)taosHashPut(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr), &item, sizeof(SFailFastItem)); } } } else { @@ -1393,9 +1481,9 @@ void cliConnCb(uv_connect_t* req, int status) { if (pConn->timer == NULL) { timeout = true; } else { - uv_timer_stop(pConn->timer); + (void)uv_timer_stop(pConn->timer); pConn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &pConn->timer); + (void)taosArrayPush(pThrd->timerList, &pConn->timer); pConn->timer = NULL; } @@ -1411,12 +1499,12 @@ void cliConnCb(uv_connect_t* req, int status) { struct sockaddr peername, sockname; int addrlen = sizeof(peername); - uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); - transSockInfo2Str(&peername, pConn->dst); + (void)uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); + (void)transSockInfo2Str(&peername, pConn->dst); addrlen = sizeof(sockname); - uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen); - transSockInfo2Str(&sockname, pConn->src); + (void)uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen); + (void)transSockInfo2Str(&sockname, pConn->src); struct sockaddr_in addr = *(struct sockaddr_in*)&sockname; struct sockaddr_in saddr = *(struct sockaddr_in*)&peername; @@ -1466,8 +1554,8 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) { tDebug("cli work thread %p start to quit", pThrd); destroyCmsg(pMsg); - destroyConnPool(pThrd); - uv_walk(pThrd->loop, cliWalkCb, NULL); + (void)destroyConnPool(pThrd); + (void)uv_walk(pThrd->loop, cliWalkCb, NULL); } static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { int64_t refId = (int64_t)(pMsg->msg.info.handle); @@ -1482,7 +1570,7 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { SCliConn* conn = exh->handle; taosRUnLockLatch(&exh->latch); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); if (T_REF_VAL_GET(conn) == 2) { @@ -1521,7 +1609,7 @@ SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) conn = getConnFromPool2(pThrd, addr, pMsg); if (conn != NULL) specifyConnRef(conn, true, refId); } - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); } return conn; }; @@ -1553,37 +1641,45 @@ FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { if (pMsg == NULL) return -1; - memset(pResp, 0, sizeof(STransMsg)); + // memset(pResp, 0, sizeof(STransMsg)); - pResp->code = TSDB_CODE_RPC_BROKEN_LINK; + if (pResp->code == 0) { + pResp->code = TSDB_CODE_RPC_BROKEN_LINK; + } pResp->msgType = pMsg->msg.msgType + 1; pResp->info.ahandle = pMsg->ctx ? pMsg->ctx->ahandle : NULL; pResp->info.traceId = pMsg->msg.info.traceId; return 0; } + static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip) { + int32_t code = 0; + uint32_t addr = 0; size_t len = strlen(fqdn); uint32_t* v = taosHashGet(cache, fqdn, len); if (v == NULL) { - int32_t code = taosGetIpv4FromFqdn(fqdn, ip); - if (code) { - tError("failed to get ip from fqdn:%s since %s", fqdn, terrstr()); + code = taosGetIpv4FromFqdn(fqdn, &addr); + if (code != 0) { + code = TSDB_CODE_RPC_FQDN_ERROR; + tError("failed to get ip from fqdn:%s since %s", fqdn, tstrerror(code)); return code; } - taosHashPut(cache, fqdn, len, ip, sizeof(*ip)); + if ((code = taosHashPut(cache, fqdn, len, &addr, sizeof(addr)) != 0)) { + return code; + } + *ip = addr; } else { *ip = *v; } - - return TSDB_CODE_SUCCESS; + return 0; } -static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) { +static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn) { // impl later uint32_t addr = 0; - int32_t code = taosGetIpv4FromFqdn(fqdn, &addr); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = taosGetIpv4FromFqdn(fqdn, &addr); + if (code == 0) { size_t len = strlen(fqdn); uint32_t* v = taosHashGet(cache, fqdn, len); if (addr != *v) { @@ -1591,10 +1687,12 @@ static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) { tinet_ntoa(old, *v); tinet_ntoa(new, addr); tWarn("update ip of fqdn:%s, old: %s, new: %s", fqdn, old, new); - taosHashPut(cache, fqdn, strlen(fqdn), &addr, sizeof(addr)); + code = taosHashPut(cache, fqdn, strlen(fqdn), &addr, sizeof(addr)); } + } else { + code = TSDB_CODE_RPC_FQDN_ERROR; // TSDB_CODE_RPC_INVALID_FQDN; } - return; + return code; } static void cliMayUpdateFqdnCache(SHashObj* cache, char* dst) { @@ -1607,7 +1705,7 @@ static void cliMayUpdateFqdnCache(SHashObj* cache, char* dst) { if (i > 0) { char fqdn[TSDB_FQDN_LEN + 1] = {0}; memcpy(fqdn, dst, i); - cliUpdateFqdnCache(cache, fqdn); + (void)cliUpdateFqdnCache(cache, fqdn); } } @@ -1623,7 +1721,9 @@ static void doFreeTimeoutMsg(void* param) { doNotifyApp(pMsg, pThrd, code); taosMemoryFree(arg); } + void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { + int32_t code = 0; STrans* pTransInst = pThrd->pTransInst; cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); @@ -1641,8 +1741,8 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { SCliConn* conn = cliGetConn(&pMsg, pThrd, &ignore, addr); if (ignore == true) { // persist conn already release by server - STransMsg resp; - cliBuildExceptResp(pMsg, &resp); + STransMsg resp = {0}; + (void)cliBuildExceptResp(pMsg, &resp); // refactorr later resp.info.cliVer = pTransInst->compatibilityVer; @@ -1659,29 +1759,40 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { if (conn != NULL) { transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - transQueuePush(&conn->cliMsgs, pMsg); + (void)transQueuePush(&conn->cliMsgs, pMsg); cliSend(conn); } else { - conn = cliCreateConn(pThrd); + code = cliCreateConn(pThrd, &conn); + if (code != 0) { + tError("%s failed to create conn, reason:%s", pTransInst->label, tstrerror(code)); + STransMsg resp = {.code = code}; + (void)cliBuildExceptResp(pMsg, &resp); + + resp.info.cliVer = pTransInst->compatibilityVer; + if (pMsg->type != Release) { + pTransInst->cfp(pTransInst->parent, &resp, NULL); + } + destroyCmsg(pMsg); + return; + } int64_t refId = (int64_t)pMsg->msg.info.handle; if (refId != 0) specifyConnRef(conn, true, refId); transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - transQueuePush(&conn->cliMsgs, pMsg); + (void)transQueuePush(&conn->cliMsgs, pMsg); conn->dstAddr = taosStrdup(addr); - uint32_t ipaddr = 0; - int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); - if (code) { - uv_timer_stop(conn->timer); + uint32_t ipaddr; + int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); + if (code != 0) { + (void)uv_timer_stop(conn->timer); conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer = NULL; - cliHandleExcept(conn, terrno); - terrno = 0; + cliHandleExcept(conn, code); return; } @@ -1699,12 +1810,14 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { errno = 0; return; } + int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); if (ret != 0) { tGError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); cliHandleExcept(conn, -1); return; } + ret = transSetConnOption((uv_tcp_t*)conn->stream, tsKeepAliveIdle); if (ret != 0) { tGError("%s conn %p failed to set socket opt, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); @@ -1714,16 +1827,16 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - uv_timer_stop(conn->timer); + (void)uv_timer_stop(conn->timer); conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); + (void)taosArrayPush(pThrd->timerList, &conn->timer); conn->timer = NULL; cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, ret); return; } - uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); } tGTrace("%s conn %p ready", pTransInst->label, conn); } @@ -1810,7 +1923,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { QUEUE_PUSH(&pBatchList->wq, &pBatch->listq); - taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); + (void)taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); } else { if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); @@ -1876,9 +1989,9 @@ static void cliAsyncCb(uv_async_t* handle) { // batch process to avoid to lock/unlock frequently queue wq; - taosThreadMutexLock(&item->mtx); + (void)taosThreadMutexLock(&item->mtx); QUEUE_MOVE(&item->qmsg, &wq); - taosThreadMutexUnlock(&item->mtx); + (void)taosThreadMutexUnlock(&item->mtx); int8_t supportBatch = pTransInst->supportBatch; if (supportBatch == 0) { @@ -1899,9 +2012,9 @@ static void cliPrepareCb(uv_prepare_t* handle) { SAsyncItem* item = async->data; queue wq; - taosThreadMutexLock(&item->mtx); + (void)taosThreadMutexLock(&item->mtx); QUEUE_MOVE(&item->qmsg, &wq); - taosThreadMutexUnlock(&item->mtx); + (void)taosThreadMutexUnlock(&item->mtx); int count = 0; while (!QUEUE_IS_EMPTY(&wq)) { @@ -1955,7 +2068,7 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, conn->refId); - transClearBuffer(&conn->readBuf); + (void)transClearBuffer(&conn->readBuf); transFreeMsg(transContFromHead((char*)pHead)); for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { @@ -1981,37 +2094,47 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { } static void* cliWorkThread(void* arg) { + char threadName[TSDB_LABEL_LEN] = {0}; + SCliThrd* pThrd = (SCliThrd*)arg; pThrd->pid = taosGetSelfPthreadId(); - char threadName[TSDB_LABEL_LEN] = {0}; - STrans* pInst = pThrd->pTransInst; - strtolower(threadName, pInst->label); + (void)strtolower(threadName, pThrd->pTransInst->label); setThreadName(threadName); - uv_run(pThrd->loop, UV_RUN_DEFAULT); + (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); tDebug("thread quit-thread:%08" PRId64, pThrd->pid); return NULL; } void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { + int32_t code = 0; SCliObj* cli = taosMemoryCalloc(1, sizeof(SCliObj)); + if (cli == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); + } STrans* pTransInst = shandle; memcpy(cli->label, label, TSDB_LABEL_LEN); cli->numOfThreads = numOfThreads; + cli->pThreadObj = (SCliThrd**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrd*)); + if (cli->pThreadObj == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); + } for (int i = 0; i < cli->numOfThreads; i++) { - SCliThrd* pThrd = createThrdObj(shandle); - if (pThrd == NULL) { + SCliThrd* pThrd = NULL; + code = createThrdObj(shandle, &pThrd); + if (code != 0) { goto _err; } int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd)); if (err != 0) { - goto _err; + code = TAOS_SYSTEM_ERROR(errno); + TAOS_CHECK_GOTO(code, NULL, _err); } else { tDebug("success to create tranport-cli thread:%d", i); } @@ -2020,8 +2143,11 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, return cli; _err: - taosMemoryFree(cli->pThreadObj); - taosMemoryFree(cli); + if (cli) { + taosMemoryFree(cli->pThreadObj); + taosMemoryFree(cli); + } + terrno = code; return NULL; } @@ -2037,11 +2163,9 @@ static FORCE_INLINE void destroyCmsg(void* arg) { taosMemoryFree(pMsg); } static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param) { - SCliMsg* pMsg = arg; - if (pMsg == NULL) { - return; - } + if (arg == NULL) return; + SCliMsg* pMsg = arg; SCliThrd* pThrd = param; if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL) { if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pMsg->msg.info.ahandle); @@ -2064,76 +2188,133 @@ static FORCE_INLINE void destroyCmsgAndAhandle(void* param) { taosMemoryFree(pMsg); } -static SCliThrd* createThrdObj(void* trans) { +static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { + int32_t code = 0; STrans* pTransInst = trans; SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd)); + if (pThrd == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } QUEUE_INIT(&pThrd->msg); - taosThreadMutexInit(&pThrd->msgMtx, NULL); + (void)taosThreadMutexInit(&pThrd->msgMtx, NULL); pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); - int err = uv_loop_init(pThrd->loop); - if (err != 0) { - tError("failed to init uv_loop, reason:%s", uv_err_name(err)); - taosMemoryFree(pThrd->loop); - taosThreadMutexDestroy(&pThrd->msgMtx); - taosMemoryFree(pThrd); - return NULL; + if (pThrd->loop == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } - int32_t nSync = pTransInst->supportBatch ? 4 : 8; - pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, nSync, pThrd, cliAsyncCb); - if (pThrd->asyncPool == NULL) { - tError("failed to init async pool"); - uv_loop_close(pThrd->loop); - taosMemoryFree(pThrd->loop); - taosThreadMutexDestroy(&pThrd->msgMtx); - taosMemoryFree(pThrd); - return NULL; + code = uv_loop_init(pThrd->loop); + if (code != 0) { + tError("failed to init uv_loop, reason:%s", uv_err_name(code)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); + } + + int32_t nSync = pTransInst->supportBatch ? 4 : 8; + code = transAsyncPoolCreate(pThrd->loop, nSync, pThrd, cliAsyncCb, &pThrd->asyncPool); + if (code != 0) { + tError("failed to init async pool since:%s", tstrerror(code)); + TAOS_CHECK_GOTO(code, NULL, _end); } pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - uv_prepare_init(pThrd->loop, pThrd->prepare); + if (pThrd->prepare == NULL) { + tError("failed to create prepre since:%s", tstrerror(code)); + TAOS_CHECK_GOTO(code, NULL, _end); + } + + code = uv_prepare_init(pThrd->loop, pThrd->prepare); + if (code != 0) { + tError("failed to create prepre since:%s", uv_err_name(code)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); + } pThrd->prepare->data = pThrd; - // uv_prepare_start(pThrd->prepare, cliPrepareCb); int32_t timerSize = 64; pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); + if (pThrd->timerList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + for (int i = 0; i < timerSize; i++) { uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - uv_timer_init(pThrd->loop, timer); - taosArrayPush(pThrd->timerList, &timer); + if (timer == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + (void)uv_timer_init(pThrd->loop, timer); + (void)taosArrayPush(pThrd->timerList, &timer); } pThrd->pool = createConnPool(4); - transDQCreate(pThrd->loop, &pThrd->delayQueue); + if (pThrd->pool == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + if ((code = transDQCreate(pThrd->loop, &pThrd->delayQueue)) != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } - transDQCreate(pThrd->loop, &pThrd->timeoutQueue); + if ((code = transDQCreate(pThrd->loop, &pThrd->timeoutQueue)) != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } - transDQCreate(pThrd->loop, &pThrd->waitConnQueue); - - pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); - pThrd->pTransInst = trans; + if ((code = transDQCreate(pThrd->loop, &pThrd->waitConnQueue)) != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } pThrd->destroyAhandleFp = pTransInst->destroyFp; pThrd->fqdn2ipCache = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (pThrd->fqdn2ipCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } pThrd->failFastCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (pThrd->failFastCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } pThrd->batchCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (pThrd->batchCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); + pThrd->pTransInst = trans; pThrd->quit = false; - return pThrd; + *ppThrd = pThrd; + return code; + +_end: + if (pThrd) { + (void)uv_loop_close(pThrd->loop); + taosMemoryFree(pThrd->loop); + taosMemoryFree(pThrd->prepare); + (void)taosThreadMutexDestroy(&pThrd->msgMtx); + transAsyncPoolDestroy(pThrd->asyncPool); + for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { + uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); + taosMemoryFree(timer); + } + taosArrayDestroy(pThrd->timerList); + taosMemoryFree(pThrd->prepare); + taosHashCleanup(pThrd->fqdn2ipCache); + taosHashCleanup(pThrd->failFastCache); + taosHashCleanup(pThrd->batchCache); + + taosMemoryFree(pThrd); + } + return code; } static void destroyThrdObj(SCliThrd* pThrd) { if (pThrd == NULL) { return; } - taosThreadJoin(pThrd->thread, NULL); + (void)taosThreadJoin(pThrd->thread, NULL); CLI_RELEASE_UV(pThrd->loop); - taosThreadMutexDestroy(&pThrd->msgMtx); + (void)taosThreadMutexDestroy(&pThrd->msgMtx); TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsgWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); @@ -2177,21 +2358,32 @@ static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx) { taosMemoryFree(ctx); } -void cliSendQuit(SCliThrd* thrd) { +int32_t cliSendQuit(SCliThrd* thrd) { // cli can stop gracefully + int32_t code = 0; SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (msg == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + msg->type = Quit; - transAsyncSend(thrd->asyncPool, &msg->q); + if ((code = transAsyncSend(thrd->asyncPool, &msg->q)) != 0) { + code = (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); + taosMemoryFree(msg); + return code; + } + atomic_store_8(&thrd->asyncPool->stop, 1); + return 0; } void cliWalkCb(uv_handle_t* handle, void* arg) { if (!uv_is_closing(handle)) { if (uv_handle_get_type(handle) == UV_TIMER) { // do nothing } else { - uv_read_stop((uv_stream_t*)handle); + (void)uv_read_stop((uv_stream_t*)handle); } - uv_close(handle, cliDestroy); + (void)uv_close(handle, cliDestroy); } } @@ -2229,7 +2421,7 @@ static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { STransConnCtx* pCtx = pMsg->ctx; STraceId* trace = &pMsg->msg.info.traceId; char tbuf[512] = {0}; - epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); tGDebug("%s retry on next node,use:%s, step: %d,timeout:%" PRId64 "", label, tbuf, pCtx->retryStep, pCtx->retryNextInterval); return; @@ -2244,7 +2436,7 @@ static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { arg->param1 = pMsg; arg->param2 = pThrd; - transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + (void)transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); } FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { @@ -2462,7 +2654,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { if (hasEpSet) { if (rpcDebugFlag & DEBUG_TRACE) { char tbuf[512] = {0}; - epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); tGTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); } } @@ -2474,7 +2666,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } else { memcpy((char*)pCtx->pRsp, (char*)pResp, sizeof(*pResp)); } - tsem_post(pCtx->pSem); + (void)tsem_post(pCtx->pSem); pCtx->pRsp = NULL; } else { STransSyncMsg* pSyncMsg = taosAcquireRef(transGetSyncMsgMgt(), pCtx->syncMsgRef); @@ -2484,8 +2676,8 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pSyncMsg->hasEpSet = 1; epsetAssign(&pSyncMsg->epSet, &pCtx->epSet); } - tsem2_post(pSyncMsg->pSem); - taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef); + (void)tsem2_post(pSyncMsg->pSem); + (void)taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef); } else { rpcFreeCont(pResp->pCont); } @@ -2506,9 +2698,14 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } void transCloseClient(void* arg) { + int32_t code = 0; SCliObj* cli = arg; for (int i = 0; i < cli->numOfThreads; i++) { - cliSendQuit(cli->pThreadObj[i]); + code = cliSendQuit(cli->pThreadObj[i]); + if (code != 0) { + tError("failed to send quit to thread:%d, reason:%s", i, tstrerror(code)); + } + destroyThrdObj(cli->pThreadObj[i]); } taosMemoryFree(cli->pThreadObj); @@ -2549,7 +2746,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t pThrd = exh->pThrd; taosWUnLockLatch(&exh->latch); - transReleaseExHandle(transGetRefMgt(), handle); + (void)transReleaseExHandle(transGetRefMgt(), handle); return pThrd; } @@ -2563,9 +2760,7 @@ SCliThrd* transGetWorkThrd(STrans* trans, int64_t handle) { return pThrd; } int transReleaseCliHandle(void* handle) { - int idx = -1; - bool valid = false; - + int32_t code = 0; SCliThrd* pThrd = transGetWorkThrdFromHandle(NULL, (int64_t)handle); if (pThrd == NULL) { return TSDB_CODE_RPC_BROKEN_LINK; @@ -2575,9 +2770,17 @@ int transReleaseCliHandle(void* handle) { TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCtx->ahandle = tmsg.info.ahandle; SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (cmsg == NULL) { + taosMemoryFree(pCtx); + return TSDB_CODE_OUT_OF_MEMORY; + } cmsg->msg = tmsg; cmsg->st = taosGetTimestampUs(); cmsg->type = Release; @@ -2586,15 +2789,20 @@ int transReleaseCliHandle(void* handle) { STraceId* trace = &tmsg.info.traceId; tGDebug("send release request at thread:%08" PRId64 ", malloc memory:%p", pThrd->pid, cmsg); - if (0 != transAsyncSend(pThrd->asyncPool, &cmsg->q)) { + if ((code = transAsyncSend(pThrd->asyncPool, &cmsg->q)) != 0) { destroyCmsg(cmsg); - return TSDB_CODE_RPC_BROKEN_LINK; + return code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code; } - return 0; + return code; } -static SCliMsg* transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { + +static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliMsg** pCliMsg) { TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + epsetAssign(&pCtx->epSet, pEpSet); epsetAssign(&pCtx->origEpSet, pEpSet); @@ -2604,13 +2812,20 @@ static SCliMsg* transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pRe if (ctx != NULL) pCtx->appCtx = *ctx; SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (cliMsg == NULL) { + taosMemoryFree(pCtx); + return TSDB_CODE_OUT_OF_MEMORY; + } + cliMsg->ctx = pCtx; cliMsg->msg = *pReq; cliMsg->st = taosGetTimestampUs(); cliMsg->type = Normal; cliMsg->refId = (int64_t)shandle; QUEUE_INIT(&cliMsg->seqq); - return cliMsg; + *pCliMsg = cliMsg; + + return 0; } int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { @@ -2619,12 +2834,12 @@ int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STran transFreeMsg(pReq->pCont); return TSDB_CODE_RPC_BROKEN_LINK; } - + int32_t code = 0; int64_t handle = (int64_t)pReq->info.handle; SCliThrd* pThrd = transGetWorkThrd(pTransInst, handle); if (pThrd == NULL) { transFreeMsg(pReq->pCont); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); return TSDB_CODE_RPC_BROKEN_LINK; } if (handle != 0) { @@ -2632,55 +2847,80 @@ int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STran if (exh != NULL) { taosWLockLatch(&exh->latch); if (exh->handle == NULL && exh->inited != 0) { - SCliMsg* pCliMsg = transInitMsg(shandle, pEpSet, pReq, ctx); + SCliMsg* pCliMsg = NULL; + code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); + ASSERT(code == 0); + QUEUE_PUSH(&exh->q, &pCliMsg->seqq); taosWUnLockLatch(&exh->latch); tDebug("msg refId: %" PRId64 "", handle); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); return 0; } exh->inited = 1; taosWUnLockLatch(&exh->latch); - transReleaseExHandle(transGetRefMgt(), handle); + (void)transReleaseExHandle(transGetRefMgt(), handle); } } - SCliMsg* pCliMsg = transInitMsg(shandle, pEpSet, pReq, ctx); + + SCliMsg* pCliMsg = NULL; + code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); + if (code != 0) { + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return code; + } STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); - if (0 != transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) { + if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { destroyCmsg(pCliMsg); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - return TSDB_CODE_RPC_BROKEN_LINK; + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); return 0; } int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) { - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg)); + STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); if (pTransInst == NULL) { transFreeMsg(pReq->pCont); - taosMemoryFree(pTransRsp); return TSDB_CODE_RPC_BROKEN_LINK; } + int32_t code = 0; + + STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg)); + if (pTransRsp == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + } SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); if (pThrd == NULL) { - transFreeMsg(pReq->pCont); - taosMemoryFree(pTransRsp); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - return TSDB_CODE_RPC_BROKEN_LINK; + TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _RETURN1); } tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t)); - tsem_init(sem, 0, 0); + if (sem == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + } + + code = tsem_init(sem, 0, 0); + if (code != 0) { + taosMemoryFree(sem); + code = TAOS_SYSTEM_ERROR(errno); + TAOS_CHECK_GOTO(code, NULL, _RETURN1); + } TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + (void)tsem_destroy(sem); + taosMemoryFree(sem); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + } + epsetAssign(&pCtx->epSet, pEpSet); epsetAssign(&pCtx->origEpSet, pEpSet); pCtx->ahandle = pReq->info.ahandle; @@ -2689,6 +2929,13 @@ int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMs pCtx->pRsp = pTransRsp; SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (cliMsg == NULL) { + (void)tsem_destroy(sem); + taosMemoryFree(sem); + taosMemoryFree(pCtx); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1); + } + cliMsg->ctx = pCtx; cliMsg->msg = *pReq; cliMsg->st = taosGetTimestampUs(); @@ -2699,28 +2946,42 @@ int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMs tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); - int ret = transAsyncSend(pThrd->asyncPool, &cliMsg->q); - if (ret != 0) { + code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + if (code != 0) { destroyCmsg(cliMsg); - ret = TSDB_CODE_RPC_BROKEN_LINK; - goto _RETURN; + TAOS_CHECK_GOTO((code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code), NULL, _RETURN); } - tsem_wait(sem); + (void)tsem_wait(sem); memcpy(pRsp, pTransRsp, sizeof(STransMsg)); _RETURN: tsem_destroy(sem); taosMemoryFree(sem); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); taosMemoryFree(pTransRsp); - return ret; + return code; +_RETURN1: + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + taosMemoryFree(pTransRsp); + taosMemoryFree(pReq->pCont); + return code; } -int64_t transCreateSyncMsg(STransMsg* pTransMsg) { +int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { + int32_t code = 0; tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t)); - tsem2_init(sem, 0, 0); + if (sem == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if (tsem2_init(sem, 0, 0) != 0) { + TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _EXIT); + } STransSyncMsg* pSyncMsg = taosMemoryCalloc(1, sizeof(STransSyncMsg)); + if (pSyncMsg == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _EXIT); + } taosInitRWLatch(&pSyncMsg->latch); pSyncMsg->inited = 0; @@ -2728,39 +2989,69 @@ int64_t transCreateSyncMsg(STransMsg* pTransMsg) { pSyncMsg->pSem = sem; pSyncMsg->hasEpSet = 0; - return taosAddRef(transGetSyncMsgMgt(), pSyncMsg); + int64_t id = taosAddRef(transGetSyncMsgMgt(), pSyncMsg); + if (id < 0) { + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _EXIT); + } else { + *refId = id; + } + return 0; + +_EXIT: + (void)tsem2_destroy(sem); + taosMemoryFree(sem); + taosMemoryFree(pSyncMsg); + return code; } int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); - STransMsg* pTransMsg = taosMemoryCalloc(1, sizeof(STransMsg)); + int32_t code = 0; + STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); if (pTransInst == NULL) { transFreeMsg(pReq->pCont); - taosMemoryFree(pTransMsg); return TSDB_CODE_RPC_BROKEN_LINK; } + STransMsg* pTransMsg = taosMemoryCalloc(1, sizeof(STransMsg)); + if (pTransMsg == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + } + SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); if (pThrd == NULL) { - transFreeMsg(pReq->pCont); - taosMemoryFree(pTransMsg); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - return TSDB_CODE_RPC_BROKEN_LINK; + TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _RETURN2); } TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + } + epsetAssign(&pCtx->epSet, pEpSet); epsetAssign(&pCtx->origEpSet, pEpSet); pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; - pCtx->syncMsgRef = transCreateSyncMsg(pTransMsg); + + if ((code = transCreateSyncMsg(pTransMsg, &pCtx->syncMsgRef)) != 0) { + taosMemoryFree(pCtx); + TAOS_CHECK_GOTO(code, NULL, _RETURN2); + } int64_t ref = pCtx->syncMsgRef; STransSyncMsg* pSyncMsg = taosAcquireRef(transGetSyncMsgMgt(), ref); + if (pSyncMsg == NULL) { + taosMemoryFree(pCtx); + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _RETURN2); + } SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (cliMsg == NULL) { + taosMemoryFree(pCtx); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); + } + cliMsg->ctx = pCtx; cliMsg->msg = *pReq; cliMsg->st = taosGetTimestampUs(); @@ -2771,17 +3062,17 @@ int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STr tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); - int ret = transAsyncSend(pThrd->asyncPool, &cliMsg->q); - if (ret != 0) { + code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + if (code != 0) { destroyCmsg(cliMsg); - ret = TSDB_CODE_RPC_BROKEN_LINK; + TAOS_CHECK_GOTO(code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code, NULL, _RETURN); goto _RETURN; } - ret = tsem2_timewait(pSyncMsg->pSem, timeoutMs); - if (ret < 0) { + code = tsem2_timewait(pSyncMsg->pSem, timeoutMs); + if (code < 0) { pRsp->code = TSDB_CODE_TIMEOUT_ERROR; - ret = TSDB_CODE_TIMEOUT_ERROR; + code = TSDB_CODE_TIMEOUT_ERROR; } else { memcpy(pRsp, pSyncMsg->pRsp, sizeof(STransMsg)); pSyncMsg->pRsp->pCont = NULL; @@ -2789,13 +3080,18 @@ int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STr epsetAssign(pEpSet, &pSyncMsg->epSet); *epUpdated = 1; } - ret = 0; + code = 0; } _RETURN: - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - taosReleaseRef(transGetSyncMsgMgt(), ref); - taosRemoveRef(transGetSyncMsgMgt(), ref); - return ret; + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)taosReleaseRef(transGetSyncMsgMgt(), ref); + (void)taosRemoveRef(transGetSyncMsgMgt(), ref); + return code; +_RETURN2: + transFreeMsg(pReq->pCont); + taosMemoryFree(pTransMsg); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return code; } /* * @@ -2812,11 +3108,25 @@ int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { tstrncpy(cvtAddr.fqdn, fqdn, sizeof(cvtAddr.fqdn)); cvtAddr.cvt = true; } - for (int i = 0; i < pTransInst->numOfThreads; i++) { + + int32_t code = 0; + int8_t i = 0; + for (i = 0; i < pTransInst->numOfThreads; i++) { STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + pCtx->cvtAddr = cvtAddr; SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + if (cliMsg == NULL) { + taosMemoryFree(pCtx); + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + cliMsg->ctx = pCtx; cliMsg->type = Update; cliMsg->refId = (int64_t)shandle; @@ -2824,21 +3134,30 @@ int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { SCliThrd* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i]; tDebug("%s update epset at thread:%08" PRId64, pTransInst->label, thrd->pid); - if (transAsyncSend(thrd->asyncPool, &(cliMsg->q)) != 0) { + if ((code = transAsyncSend(thrd->asyncPool, &(cliMsg->q))) != 0) { destroyCmsg(cliMsg); - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + code = (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); + break; } } - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - return 0; + + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return code; } int64_t transAllocHandle() { SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); + if (exh == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } exh->refId = transAddExHandle(transGetRefMgt(), exh); + if (exh->refId < 0) { + taosMemoryFree(exh); + return TSDB_CODE_REF_INVALID_ID; + } + SExHandle* self = transAcquireExHandle(transGetRefMgt(), exh->refId); - ASSERT(exh == self); if (exh != self) { taosMemoryFree(exh); return TSDB_CODE_REF_INVALID_ID; @@ -2847,6 +3166,5 @@ int64_t transAllocHandle() { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); tDebug("pre alloc refId %" PRId64 "", exh->refId); - return exh->refId; } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index b9223e7b39..9df0ddb6f3 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -67,7 +67,11 @@ int32_t transDecompressMsg(char** msg, int32_t len) { STransCompMsg* pComp = (STransCompMsg*)pCont; int32_t oriLen = htonl(pComp->contLen); - char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); + char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); + if (buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + STransMsgHead* pNewHead = (STransMsgHead*)buf; int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content, len - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); @@ -78,7 +82,7 @@ int32_t transDecompressMsg(char** msg, int32_t len) { taosMemoryFree(pHead); *msg = buf; if (decompLen != oriLen) { - return -1; + return TSDB_CODE_INVALID_MSG; } return 0; } @@ -98,26 +102,33 @@ int transSockInfo2Str(struct sockaddr* sockname, char* dst) { sprintf(dst, "%s:%d", buf, ntohs(addr.sin_port)); return r; } -int transInitBuffer(SConnBuffer* buf) { - buf->cap = BUFFER_CAP; +int32_t transInitBuffer(SConnBuffer* buf) { buf->buf = taosMemoryCalloc(1, BUFFER_CAP); + if (buf->buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + buf->cap = BUFFER_CAP; buf->left = -1; buf->len = 0; buf->total = 0; buf->invalid = 0; return 0; } -int transDestroyBuffer(SConnBuffer* p) { +int32_t transDestroyBuffer(SConnBuffer* p) { taosMemoryFree(p->buf); p->buf = NULL; return 0; } -int transClearBuffer(SConnBuffer* buf) { +int32_t transClearBuffer(SConnBuffer* buf) { SConnBuffer* p = buf; if (p->cap > BUFFER_CAP) { p->cap = BUFFER_CAP; p->buf = taosMemoryRealloc(p->buf, BUFFER_CAP); + if (p->buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } } p->left = -1; p->len = 0; @@ -126,27 +137,31 @@ int transClearBuffer(SConnBuffer* buf) { return 0; } -int transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf) { +int32_t transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf) { static const int HEADSIZE = sizeof(STransMsgHead); - - SConnBuffer* p = connBuf; + int32_t code = 0; + SConnBuffer* p = connBuf; if (p->left != 0 || p->total <= 0) { - return -1; + return TSDB_CODE_INVALID_MSG; } int total = p->total; if (total >= HEADSIZE && !p->invalid) { *buf = taosMemoryCalloc(1, total); + if (*buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } memcpy(*buf, p->buf, total); - if (transResetBuffer(connBuf, resetBuf) < 0) { - return -1; + if ((code = transResetBuffer(connBuf, resetBuf)) < 0) { + return code; } } else { total = -1; + return TSDB_CODE_INVALID_MSG; } return total; } -int transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { +int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { SConnBuffer* p = connBuf; if (p->total < p->len) { int left = p->len - p->total; @@ -162,15 +177,18 @@ int transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { if (resetBuf) { p->cap = BUFFER_CAP; p->buf = taosMemoryRealloc(p->buf, p->cap); + if (p->buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } } } } else { ASSERTS(0, "invalid read from sock buf"); - return -1; + return TSDB_CODE_INVALID_MSG; } return 0; } -int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { +int32_t transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { /* * formate of data buffer: * |<--------------------------data from socket------------------------------->| @@ -187,6 +205,9 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { } else { p->cap = p->left + p->len; p->buf = taosMemoryRealloc(p->buf, p->cap); + if (p->buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } uvBuf->base = p->buf + p->len; uvBuf->len = p->left; } @@ -216,25 +237,25 @@ bool transReadComplete(SConnBuffer* connBuf) { int transSetConnOption(uv_tcp_t* stream, int keepalive) { #if defined(WINDOWS) || defined(DARWIN) #else - uv_tcp_keepalive(stream, 1, keepalive); + return uv_tcp_keepalive(stream, 1, keepalive); #endif return uv_tcp_nodelay(stream, 1); // int ret = uv_tcp_keepalive(stream, 5, 60); } -SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) { +int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAsyncPool** pPool) { SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool)); if (pool == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + return TSDB_CODE_OUT_OF_MEMORY; + // return NULL; } + int32_t code = 0; pool->nAsync = sz; pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync); if (pool->asyncs == NULL) { taosMemoryFree(pool); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + return TSDB_CODE_OUT_OF_MEMORY; } int i = 0, err = 0; @@ -243,18 +264,18 @@ SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem)); if (item == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; break; } item->pThrd = arg; QUEUE_INIT(&item->qmsg); - taosThreadMutexInit(&item->mtx, NULL); + (void)taosThreadMutexInit(&item->mtx, NULL); async->data = item; err = uv_async_init(loop, async, cb); if (err != 0) { tError("failed to init async, reason:%s", uv_err_name(err)); - terrno = TSDB_CODE_THIRDPARTY_ERROR; + code = TSDB_CODE_THIRDPARTY_ERROR; break; } } @@ -264,16 +285,20 @@ SAsyncPool* transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) pool = NULL; } - return pool; + *pPool = pool; + return 0; + // return pool; } void transAsyncPoolDestroy(SAsyncPool* pool) { + if (pool == NULL) return; + for (int i = 0; i < pool->nAsync; i++) { uv_async_t* async = &(pool->asyncs[i]); SAsyncItem* item = async->data; if (item == NULL) continue; - taosThreadMutexDestroy(&item->mtx); + (void)taosThreadMutexDestroy(&item->mtx); taosMemoryFree(item); } taosMemoryFree(pool->asyncs); @@ -289,7 +314,7 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool) { } int transAsyncSend(SAsyncPool* pool, queue* q) { if (atomic_load_8(&pool->stop) == 1) { - return -1; + return TSDB_CODE_RPC_ASYNC_MODULE_QUIT; } int idx = pool->index % pool->nAsync; @@ -300,10 +325,15 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { uv_async_t* async = &(pool->asyncs[idx]); SAsyncItem* item = async->data; - taosThreadMutexLock(&item->mtx); + (void)taosThreadMutexLock(&item->mtx); QUEUE_PUSH(&item->qmsg, q); - taosThreadMutexUnlock(&item->mtx); - return uv_async_send(async); + (void)taosThreadMutexUnlock(&item->mtx); + int ret = uv_async_send(async); + if (ret != 0) { + tError("failed to send async,reason:%s", uv_err_name(ret)); + return TSDB_CODE_THIRDPARTY_ERROR; + } + return 0; } void transCtxInit(STransCtx* ctx) { @@ -347,7 +377,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { // if (dVal) { // dst->freeFunc(dVal->val); // } - taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); + (void)taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); iter = taosHashIterate(src->args, iter); } taosHashCleanup(src->args); @@ -361,7 +391,7 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key) { return NULL; } void* ret = NULL; - (*cVal->clone)(cVal->val, &ret); + (void)(*cVal->clone)(cVal->val, &ret); return ret; } void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { @@ -369,7 +399,7 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { if (ctx->brokenVal.clone == NULL) { return ret; } - (*ctx->brokenVal.clone)(ctx->brokenVal.val, &ret); + (void)(*ctx->brokenVal.clone)(ctx->brokenVal.val, &ret); *msgType = ctx->brokenVal.msgType; @@ -408,15 +438,20 @@ void transReqQueueClear(queue* q) { } } -void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { +int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { queue->q = taosArrayInit(2, sizeof(void*)); queue->freeFunc = (void (*)(const void*))freeFunc; + + if (queue->q == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + return 0; } bool transQueuePush(STransQueue* queue, void* arg) { if (queue->q == NULL) { return true; } - taosArrayPush(queue->q, &arg); + (void)taosArrayPush(queue->q, &arg); if (taosArrayGetSize(queue->q) > 1) { return false; } @@ -510,23 +545,47 @@ static void transDQTimeout(uv_timer_t* timer) { } } while (1); if (timeout != 0) { - uv_timer_start(queue->timer, transDQTimeout, timeout, 0); + (void)uv_timer_start(queue->timer, transDQTimeout, timeout, 0); } } -int transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { - uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); - uv_timer_init(loop, timer); +int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { + int32_t code = 0; + Heap* heap = NULL; + uv_timer_t* timer = NULL; + SDelayQueue* q = NULL; - Heap* heap = heapCreate(timeCompare); + timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + if (timer == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } - SDelayQueue* q = taosMemoryCalloc(1, sizeof(SDelayQueue)); + heap = heapCreate(timeCompare); + if (heap == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _return1); + } + + q = taosMemoryCalloc(1, sizeof(SDelayQueue)); + if (q == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _return1); + } q->heap = heap; q->timer = timer; q->loop = loop; q->timer->data = q; + int err = uv_timer_init(loop, timer); + if (err != 0) { + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _return1); + } + *queue = q; return 0; + +_return1: + taosMemoryFree(timer); + heapDestroy(heap); + taosMemoryFree(q); + return TSDB_CODE_OUT_OF_MEMORY; } void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)) { @@ -551,7 +610,7 @@ void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)) { taosMemoryFree(queue); } void transDQCancel(SDelayQueue* queue, SDelayTask* task) { - uv_timer_stop(queue->timer); + (void)uv_timer_stop(queue->timer); if (heapSize(queue->heap) <= 0) { taosMemoryFree(task->arg); @@ -571,13 +630,17 @@ void transDQCancel(SDelayQueue* queue, SDelayTask* task) { SDelayTask* task = container_of(minNode, SDelayTask, node); uint64_t timeout = now > task->execTime ? now - task->execTime : 0; - uv_timer_start(queue->timer, transDQTimeout, timeout, 0); + (void)uv_timer_start(queue->timer, transDQTimeout, timeout, 0); } } SDelayTask* transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs) { uint64_t now = taosGetTimestampMs(); SDelayTask* task = taosMemoryCalloc(1, sizeof(SDelayTask)); + if (task == NULL) { + return NULL; + } + task->func = func; task->arg = arg; task->execTime = now + timeoutMs; @@ -592,7 +655,7 @@ SDelayTask* transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, tTrace("timer %p put task into delay queue, timeoutMs:%" PRIu64, queue->timer, timeoutMs); heapInsert(queue->heap, &task->node); - uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0); + (void)uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0); return task; } @@ -640,7 +703,7 @@ static void transInitEnv() { refMgt = transOpenRefMgt(50000, transDestroyExHandle); instMgt = taosOpenRef(50, rpcCloseImpl); transSyncMsgMgt = taosOpenRef(50, transDestroySyncMsg); - uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1"); + (void)uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1"); } static void transDestroyEnv() { transCloseRefMgt(refMgt); @@ -648,9 +711,13 @@ static void transDestroyEnv() { transCloseRefMgt(transSyncMsgMgt); } -void transInit() { +int32_t transInit() { // init env - taosThreadOnce(&transModuleInit, transInitEnv); + int32_t code = taosThreadOnce(&transModuleInit, transInitEnv); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + } + return code; } int32_t transGetRefMgt() { return refMgt; } @@ -667,7 +734,7 @@ int32_t transOpenRefMgt(int size, void (*func)(void*)) { } void transCloseRefMgt(int32_t mgt) { // close ref - taosCloseRef(mgt); + (void)taosCloseRef(mgt); } int64_t transAddExHandle(int32_t refMgt, void* p) { // acquire extern handle @@ -702,36 +769,13 @@ void transDestroySyncMsg(void* msg) { if (msg == NULL) return; STransSyncMsg* pSyncMsg = msg; - tsem2_destroy(pSyncMsg->pSem); + (void)tsem2_destroy(pSyncMsg->pSem); taosMemoryFree(pSyncMsg->pSem); transFreeMsg(pSyncMsg->pRsp->pCont); taosMemoryFree(pSyncMsg->pRsp); taosMemoryFree(pSyncMsg); } -// void subnetIp2int(const char* const ip_addr, uint8_t* dst) { -// char ip_addr_cpy[20]; -// char ip[5]; - -// tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); - -// char *s_start, *s_end; -// s_start = ip_addr_cpy; -// s_end = ip_addr_cpy; - -// int32_t k = 0; - -// for (k = 0; *s_start != '\0'; s_start = s_end) { -// for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) { -// } -// if (*s_end == '.') { -// *s_end = '\0'; -// s_end++; -// } -// dst[k++] = (char)atoi(s_start); -// } -// } - uint32_t subnetIpRang2Int(SIpV4Range* pRange) { uint32_t ip = pRange->ip; return ((ip & 0xFF) << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | ((ip >> 24) & 0xFF); @@ -778,7 +822,11 @@ int32_t transUtilSIpRangeToStr(SIpV4Range* pRange, char* buf) { struct in_addr addr; addr.s_addr = pRange->ip; - uv_inet_ntop(AF_INET, &addr, buf, 32); + int32_t err = uv_inet_ntop(AF_INET, &addr, buf, 32); + if (err != 0) { + tError("failed to convert ip to string, reason:%s", uv_strerror(err)); + return TSDB_CODE_THIRDPARTY_ERROR; + } len = strlen(buf); @@ -794,14 +842,23 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { *ppBuf = NULL; return 0; } + int32_t len = 0; char* pBuf = taosMemoryCalloc(1, pList->num * 36); + if (pBuf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } for (int i = 0; i < pList->num; i++) { SIpV4Range* pRange = &pList->pIpRange[i]; char tbuf[32] = {0}; int tlen = transUtilSIpRangeToStr(pRange, tbuf); + if (tlen < 0) { + taosMemoryFree(pBuf); + return tlen; + } + len += sprintf(pBuf + len, "%s,", tbuf); } if (len > 0) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 674bb86fb5..1e0d54eb5b 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -122,7 +122,7 @@ typedef struct SServerObj { SIpWhiteListTab* uvWhiteListCreate(); void uvWhiteListDestroy(SIpWhiteListTab* pWhite); -void uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* pList, int64_t ver); +int32_t uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* pList, int64_t ver); void uvWhiteListUpdate(SIpWhiteListTab* pWhite, SHashObj* pTable); bool uvWhiteListCheckConn(SIpWhiteListTab* pWhite, SSvrConn* pConn); bool uvWhiteListFilte(SIpWhiteListTab* pWhite, char* user, uint32_t ip, int64_t ver); @@ -164,7 +164,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd); static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear /*clear handle or not*/); static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn); -static int reallocConnRef(SSvrConn* conn); +static int32_t reallocConnRef(SSvrConn* conn); static void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd); static void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd); @@ -181,14 +181,14 @@ static void* transWorkerThread(void* arg); static void* transAcceptThread(void* arg); // add handle loop -static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); -static bool addHandleToAcceptloop(void* arg); +static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); +static int32_t addHandleToAcceptloop(void* arg); -#define SRV_RELEASE_UV(loop) \ - do { \ - uv_walk(loop, uvWalkCb, NULL); \ - uv_run(loop, UV_RUN_DEFAULT); \ - uv_loop_close(loop); \ +#define SRV_RELEASE_UV(loop) \ + do { \ + (void)uv_walk(loop, uvWalkCb, NULL); \ + (void)uv_run(loop, UV_RUN_DEFAULT); \ + (void)uv_loop_close(loop); \ } while (0); #define ASYNC_ERR_JRET(thrd) \ @@ -202,7 +202,11 @@ static bool addHandleToAcceptloop(void* arg); void uvAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SSvrConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; - transAllocBuffer(pBuf, buf); + int32_t code = transAllocBuffer(pBuf, buf); + if (code < 0) { + tError("conn %p failed to alloc buffer, since %s", conn, tstrerror(code)); + // destroyConn(conn, true); + } } // refers specifically to query or insert timeout @@ -221,8 +225,16 @@ static bool uvCheckIp(SIpV4Range* pRange, int32_t ip) { } SIpWhiteListTab* uvWhiteListCreate() { SIpWhiteListTab* pWhiteList = taosMemoryCalloc(1, sizeof(SIpWhiteListTab)); + if (pWhiteList == NULL) { + return NULL; + } pWhiteList->pList = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 0, HASH_NO_LOCK); + if (pWhiteList->pList == NULL) { + taosMemoryFree(pWhiteList); + return NULL; + } + pWhiteList->ver = -1; return pWhiteList; } @@ -240,17 +252,26 @@ void uvWhiteListDestroy(SIpWhiteListTab* pWhite) { taosMemoryFree(pWhite); } -void uvWhiteListToStr(SWhiteUserList* plist, char* user, char** ppBuf) { +int32_t uvWhiteListToStr(SWhiteUserList* plist, char* user, char** ppBuf) { char* tmp = NULL; int32_t tlen = transUtilSWhiteListToStr(plist->pList, &tmp); + if (tlen < 0) { + return tlen; + } + + char* pBuf = taosMemoryCalloc(1, tlen + 64); + if (pBuf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } - char* pBuf = taosMemoryCalloc(1, tlen + 64); int32_t len = sprintf(pBuf, "user: %s, ver: %" PRId64 ", ip: {%s}", user, plist->ver, tmp); taosMemoryFree(tmp); *ppBuf = pBuf; + return len; } void uvWhiteListDebug(SIpWhiteListTab* pWrite) { + int32_t code = 0; SHashObj* pWhiteList = pWrite->pList; void* pIter = taosHashIterate(pWhiteList, NULL); while (pIter) { @@ -262,23 +283,35 @@ void uvWhiteListDebug(SIpWhiteListTab* pWrite) { SWhiteUserList* pUserList = *(SWhiteUserList**)pIter; char* buf = NULL; - uvWhiteListToStr(pUserList, user, &buf); - tDebug("ip-white-list %s", buf); + + code = uvWhiteListToStr(pUserList, user, &buf); + if (code != 0) { + tDebug("ip-white-list failed to debug to str since %s", buf); + } taosMemoryFree(buf); pIter = taosHashIterate(pWhiteList, pIter); } } -void uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist, int64_t ver) { +int32_t uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist, int64_t ver) { + int32_t code = 0; SHashObj* pWhiteList = pWhite->pList; SWhiteUserList** ppUserList = taosHashGet(pWhiteList, user, strlen(user)); if (ppUserList == NULL || *ppUserList == NULL) { SWhiteUserList* pUserList = taosMemoryCalloc(1, sizeof(SWhiteUserList)); + if (pUserList == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pUserList->ver = ver; pUserList->pList = plist; - taosHashPut(pWhiteList, user, strlen(user), &pUserList, sizeof(void*)); + code = taosHashPut(pWhiteList, user, strlen(user), &pUserList, sizeof(void*)); + if (code != 0) { + taosMemoryFree(pUserList); + return code; + } } else { SWhiteUserList* pUserList = *ppUserList; @@ -287,6 +320,7 @@ void uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist, in pUserList->pList = plist; } uvWhiteListDebug(pWhite); + return 0; } void uvWhiteListUpdate(SIpWhiteListTab* pWhite, SHashObj* pTable) { @@ -450,7 +484,7 @@ static bool uvHandleReq(SSvrConn* pConn) { pConnInfo->clientPort = pConn->port; tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user)); - transReleaseExHandle(transGetRefMgt(), pConn->refId); + (void)transReleaseExHandle(transGetRefMgt(), pConn->refId); (*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL); return true; @@ -544,7 +578,7 @@ void uvOnSendCb(uv_write_t* req, int status) { (pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); memset(&conn->regArg, 0, sizeof(conn->regArg)); } - transQueuePop(&conn->srvMsgs); + (void)transQueuePop(&conn->srvMsgs); taosMemoryFree(msg); msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); @@ -584,6 +618,10 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { STransMsg* pMsg = &smsg->msg; if (pMsg->pCont == 0) { pMsg->pCont = (void*)rpcMallocCont(0); + if (pMsg->pCont == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pMsg->contLen = 0; } STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); @@ -596,9 +634,9 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { // handle invalid drop_task resp, TD-20098 if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - transQueuePop(&pConn->srvMsgs); + (void)transQueuePop(&pConn->srvMsgs); destroySmsg(smsg); - return -1; + return TSDB_CODE_INVALID_MSG; } if (pConn->status == ConnNormal) { @@ -652,7 +690,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { transRefSrvHandle(pConn); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); - uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); + (void)uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); } static void uvStartSendResp(SSvrMsg* smsg) { // impl @@ -704,9 +742,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) { queue wq; // batch process to avoid to lock/unlock frequently - taosThreadMutexLock(&item->mtx); + (void)taosThreadMutexLock(&item->mtx); QUEUE_MOVE(&item->qmsg, &wq); - taosThreadMutexUnlock(&item->mtx); + (void)taosThreadMutexUnlock(&item->mtx); while (!QUEUE_IS_EMPTY(&wq)) { queue* head = QUEUE_HEAD(&wq); @@ -729,12 +767,12 @@ void uvWorkerAsyncCb(uv_async_t* handle) { SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -764,11 +802,15 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { } static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - reallocConnRef(pConn); + int32_t code = reallocConnRef(pConn); + if (code != 0) { + destroyConn(pConn, true); + return true; + } tTrace("conn %p received release request", pConn); STraceId traceId = pHead->traceId; - transClearBuffer(&pConn->readBuf); + (void)transClearBuffer(&pConn->readBuf); transFreeMsg(transContFromHead((char*)pHead)); if (pConn->status != ConnAcquire) { return true; @@ -804,9 +846,9 @@ static void uvPrepareCb(uv_prepare_t* handle) { SAsyncItem* item = async->data; queue wq; - taosThreadMutexLock(&item->mtx); + (void)taosThreadMutexLock(&item->mtx); QUEUE_MOVE(&item->qmsg, &wq); - taosThreadMutexUnlock(&item->mtx); + (void)taosThreadMutexUnlock(&item->mtx); while (!QUEUE_IS_EMPTY(&wq)) { queue* head = QUEUE_HEAD(&wq); @@ -829,12 +871,12 @@ static void uvPrepareCb(uv_prepare_t* handle) { SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -893,7 +935,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { tTrace("new connection accepted by main server, dispatch to %dth worker-thread", pObj->workerIdx); - uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb); + (void)uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb); } else { if (!uv_is_closing((uv_handle_t*)cli)) { tError("failed to accept tcp: %s", uv_err_name(err)); @@ -935,27 +977,25 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { return; } - // uv_handle_type pending = uv_pipe_pending_type(pipe); - SSvrConn* pConn = createConn(pThrd); + if (pConn == NULL) { + uv_close((uv_handle_t*)q, NULL); + return; + } - pConn->pTransInst = pThrd->pTransInst; - /* init conn timer*/ - // uv_timer_init(pThrd->loop, &pConn->pTimer); - // pConn->pTimer.data = pConn; - - pConn->hostThrd = pThrd; - - // init client handle - pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); - uv_tcp_init(pThrd->loop, pConn->pTcp); - pConn->pTcp->data = pConn; - - // transSetConnOption((uv_tcp_t*)pConn->pTcp); + // pConn->pTransInst = pThrd->pTransInst; + // /* init conn timer*/ + // // uv_timer_init(pThrd->loop, &pConn->pTimer); + // // pConn->pTimer.data = pConn; + // pConn->hostThrd = pThrd; + // // init client handle + // pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); + // uv_tcp_init(pThrd->loop, pConn->pTcp); + // pConn->pTcp->data = pConn; if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { uv_os_fd_t fd; - uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); + (void)uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); tTrace("conn %p created, fd:%d", pConn, fd); struct sockaddr peername, sockname; @@ -965,7 +1005,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { transUnrefSrvHandle(pConn); return; } - transSockInfo2Str(&peername, pConn->dst); + (void)transSockInfo2Str(&peername, pConn->dst); addrlen = sizeof(sockname); if (0 != uv_tcp_getsockname(pConn->pTcp, (struct sockaddr*)&sockname, &addrlen)) { @@ -973,7 +1013,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { transUnrefSrvHandle(pConn); return; } - transSockInfo2Str(&sockname, pConn->src); + (void)transSockInfo2Str(&sockname, pConn->src); struct sockaddr_in addr = *(struct sockaddr_in*)&peername; struct sockaddr_in saddr = *(struct sockaddr_in*)&sockname; @@ -982,7 +1022,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { pConn->serverIp = saddr.sin_addr.s_addr; pConn->port = ntohs(addr.sin_port); - uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); + (void)uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); } else { tDebug("failed to create new connection"); @@ -994,7 +1034,7 @@ void* transAcceptThread(void* arg) { // opt setThreadName("trans-accept"); SServerObj* srv = (SServerObj*)arg; - uv_run(srv->loop, UV_RUN_DEFAULT); + (void)uv_run(srv->loop, UV_RUN_DEFAULT); return NULL; } @@ -1003,19 +1043,38 @@ void uvOnPipeConnectionCb(uv_connect_t* connect, int status) { return; } SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req); - uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); + (void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); } -static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { +static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { + int32_t code = 0; pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); - if (0 != uv_loop_init(pThrd->loop)) { - return false; + if (pThrd->loop == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if ((code = uv_loop_init(pThrd->loop)) != 0) { + tError("failed to init loop since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; } #if defined(WINDOWS) || defined(DARWIN) - uv_pipe_init(pThrd->loop, pThrd->pipe, 1); + code = uv_pipe_init(pThrd->loop, pThrd->pipe, 1); + if (code != 0) { + tError("failed to init pip since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } #else - uv_pipe_init(pThrd->loop, pThrd->pipe, 1); - uv_pipe_open(pThrd->pipe, pThrd->fd); + code = uv_pipe_init(pThrd->loop, pThrd->pipe, 1); + if (code != 0) { + tError("failed to init pip since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } + + code = uv_pipe_open(pThrd->pipe, pThrd->fd); + if (code != 0) { + tError("failed to open pip since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } #endif pThrd->pipe->data = pThrd; @@ -1023,88 +1082,173 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { QUEUE_INIT(&pThrd->msg); pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - uv_prepare_init(pThrd->loop, pThrd->prepare); - uv_prepare_start(pThrd->prepare, uvPrepareCb); + if (pThrd->prepare == NULL) { + tError("failed to init prepare"); + return TSDB_CODE_OUT_OF_MEMORY; + } + + code = uv_prepare_init(pThrd->loop, pThrd->prepare); + if (code != 0) { + tError("failed to init prepare since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } + + code = uv_prepare_start(pThrd->prepare, uvPrepareCb); + if (code != 0) { + tError("failed to start prepare since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } pThrd->prepare->data = pThrd; // conn set QUEUE_INIT(&pThrd->conn); - pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 8, pThrd, uvWorkerAsyncCb); + code = transAsyncPoolCreate(pThrd->loop, 8, pThrd, uvWorkerAsyncCb, &pThrd->asyncPool); + if (code != 0) { + tError("failed to init async pool since:%s", tstrerror(code)); + return code; + } #if defined(WINDOWS) || defined(DARWIN) uv_pipe_connect(&pThrd->connect_req, pThrd->pipe, pipeName, uvOnPipeConnectionCb); + #else - uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); + code = uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); + if (code != 0) { + tError("failed to start read pipe:%s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } #endif - return true; + return 0; } -static bool addHandleToAcceptloop(void* arg) { +static int32_t addHandleToAcceptloop(void* arg) { // impl later SServerObj* srv = arg; - int err = 0; - if ((err = uv_tcp_init(srv->loop, &srv->server)) != 0) { - tError("failed to init accept server:%s", uv_err_name(err)); - return false; + int code = 0; + if ((code = uv_tcp_init(srv->loop, &srv->server)) != 0) { + tError("failed to init accept server since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; } // register an async here to quit server gracefully srv->pAcceptAsync = taosMemoryCalloc(1, sizeof(uv_async_t)); - uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb); + if (srv->pAcceptAsync == NULL) { + tError("failed to create async since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + return TSDB_CODE_OUT_OF_MEMORY; + } + + code = uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb); + if (code != 0) { + tError("failed to init async since:%s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; + } srv->pAcceptAsync->data = srv; struct sockaddr_in bind_addr; - uv_ip4_addr("0.0.0.0", srv->port, &bind_addr); - if ((err = uv_tcp_bind(&srv->server, (const struct sockaddr*)&bind_addr, 0)) != 0) { - tError("failed to bind:%s", uv_err_name(err)); - return false; + if ((code = uv_ip4_addr("0.0.0.0", srv->port, &bind_addr)) != 0) { + tError("failed to bind addr since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; } - if ((err = uv_listen((uv_stream_t*)&srv->server, 4096 * 2, uvOnAcceptCb)) != 0) { - tError("failed to listen:%s", uv_err_name(err)); - terrno = TSDB_CODE_RPC_PORT_EADDRINUSE; - return false; + + if ((code = uv_tcp_bind(&srv->server, (const struct sockaddr*)&bind_addr, 0)) != 0) { + tError("failed to bind since %s", uv_err_name(code)); + return TSDB_CODE_THIRDPARTY_ERROR; } - return true; + if ((code = uv_listen((uv_stream_t*)&srv->server, 4096 * 2, uvOnAcceptCb)) != 0) { + tError("failed to listen since %s", uv_err_name(code)); + return TSDB_CODE_RPC_PORT_EADDRINUSE; + } + return 0; } + void* transWorkerThread(void* arg) { setThreadName("trans-svr-work"); SWorkThrd* pThrd = (SWorkThrd*)arg; - uv_run(pThrd->loop, UV_RUN_DEFAULT); + (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); return NULL; } static FORCE_INLINE SSvrConn* createConn(void* hThrd) { + int32_t code = 0; SWorkThrd* pThrd = hThrd; SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); + if (pConn == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); - QUEUE_PUSH(&pThrd->conn, &pConn->queue); - transQueueInit(&pConn->srvMsgs, NULL); + if ((code = transQueueInit(&pConn->srvMsgs, NULL)) != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } + + if ((code = transInitBuffer(&pConn->readBuf)) != 0) { + TAOS_CHECK_GOTO(code, NULL, _end); + } memset(&pConn->regArg, 0, sizeof(pConn->regArg)); pConn->broken = false; pConn->status = ConnNormal; - transInitBuffer(&pConn->readBuf); SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); + if (exh == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + exh->handle = pConn; exh->pThrd = pThrd; exh->refId = transAddExHandle(transGetRefMgt(), exh); + if (exh->refId < 0) { + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); + } + QUEUE_INIT(&exh->q); - transAcquireExHandle(transGetRefMgt(), exh->refId); + + SExHandle* pSelf = transAcquireExHandle(transGetRefMgt(), exh->refId); + if (pSelf != exh) { + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); + } STrans* pTransInst = pThrd->pTransInst; pConn->refId = exh->refId; QUEUE_INIT(&exh->q); transRefSrvHandle(pConn); tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pTransInst), exh, pConn, pConn->refId); + + pConn->pTransInst = pThrd->pTransInst; + /* init conn timer*/ + // uv_timer_init(pThrd->loop, &pConn->pTimer); + // pConn->pTimer.data = pConn; + pConn->hostThrd = pThrd; + // init client handle + pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); + if (pConn->pTcp == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + + code = uv_tcp_init(pThrd->loop, pConn->pTcp); + if (code != 0) { + tError("%s failed to create conn since %s" PRId64, transLabel(pTransInst), uv_strerror(code)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); + } + pConn->pTcp->data = pConn; + return pConn; +_end: + if (pConn) { + transQueueDestroy(&pConn->srvMsgs); + (void)transDestroyBuffer(&pConn->readBuf); + taosMemoryFree(pConn->pTcp); + taosMemoryFree(pConn); + pConn = NULL; + } + tError("%s failed to create conn since %s" PRId64, transLabel(pTransInst), tstrerror(code)); + return NULL; } static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear) { @@ -1125,16 +1269,33 @@ static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { conn->regArg.init = 0; } } -static int reallocConnRef(SSvrConn* conn) { - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); +static int32_t reallocConnRef(SSvrConn* conn) { + if (conn->refId > 0) { + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + } // avoid app continue to send msg on invalid handle SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); + if (exh == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + exh->handle = conn; exh->pThrd = conn->hostThrd; exh->refId = transAddExHandle(transGetRefMgt(), exh); + if (exh->refId < 0) { + taosMemoryFree(exh); + return TSDB_CODE_REF_INVALID_ID; + } + QUEUE_INIT(&exh->q); - transAcquireExHandle(transGetRefMgt(), exh->refId); + SExHandle* pSelf = transAcquireExHandle(transGetRefMgt(), exh->refId); + if (pSelf != exh) { + tError("conn %p failed to acquire handle", conn); + taosMemoryFree(exh); + return TSDB_CODE_REF_INVALID_ID; + } + conn->refId = exh->refId; return 0; @@ -1147,8 +1308,8 @@ static void uvDestroyConn(uv_handle_t* handle) { } SWorkThrd* thrd = conn->hostThrd; - transReleaseExHandle(transGetRefMgt(), conn->refId); - transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); STrans* pTransInst = thrd->pTransInst; tDebug("%s conn %p destroy", transLabel(pTransInst), conn); @@ -1163,7 +1324,7 @@ static void uvDestroyConn(uv_handle_t* handle) { QUEUE_REMOVE(&conn->queue); taosMemoryFree(conn->pTcp); destroyConnRegArg(conn); - transDestroyBuffer(&conn->readBuf); + (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) { @@ -1204,24 +1365,41 @@ static void uvPipeListenCb(uv_stream_t* handle, int status) { } void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { + int32_t code = 0; + SServerObj* srv = taosMemoryCalloc(1, sizeof(SServerObj)); - srv->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); + if (srv == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + tError("failed to init server since: %s", tstrerror(code)); + return NULL; + } + + srv->ip = ip; + srv->port = port; srv->numOfThreads = numOfThreads; srv->workerIdx = 0; srv->numOfWorkerReady = 0; + srv->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); srv->pThreadObj = (SWorkThrd**)taosMemoryCalloc(srv->numOfThreads, sizeof(SWorkThrd*)); srv->pipe = (uv_pipe_t**)taosMemoryCalloc(srv->numOfThreads, sizeof(uv_pipe_t*)); - srv->ip = ip; - srv->port = port; - uv_loop_init(srv->loop); + if (srv->loop == NULL || srv->pThreadObj == NULL || srv->pipe == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto End; + } - char pipeName[PATH_MAX]; + code = uv_loop_init(srv->loop); + if (code != 0) { + tError("failed to init server since: %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + goto End; + } if (false == taosValidIpAndPort(srv->ip, srv->port)) { - terrno = TAOS_SYSTEM_ERROR(errno); + code = TAOS_SYSTEM_ERROR(errno); tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); goto End; } + char pipeName[PATH_MAX]; #if defined(WINDOWS) || defined(DARWIN) int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0); @@ -1259,7 +1437,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); thrd->pipe = &(srv->pipe[i][1]); // init read - if (false == addHandleToWorkloop(thrd, pipeName)) { + if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) { goto End; } @@ -1276,27 +1454,53 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, for (int i = 0; i < srv->numOfThreads; i++) { SWorkThrd* thrd = (SWorkThrd*)taosMemoryCalloc(1, sizeof(SWorkThrd)); + if (thrd == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto End; + } thrd->pTransInst = shandle; thrd->quit = false; thrd->pTransInst = shandle; thrd->pWhiteList = uvWhiteListCreate(); - - srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); - srv->pThreadObj[i] = thrd; - - uv_os_sock_t fds[2]; - if (uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { + if (thrd->pWhiteList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto End; } - uv_pipe_init(srv->loop, &(srv->pipe[i][0]), 1); - uv_pipe_open(&(srv->pipe[i][0]), fds[1]); + srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); + if (srv->pipe[i] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto End; + } + + srv->pThreadObj[i] = thrd; + + uv_os_sock_t fds[2]; + if ((code = uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE)) != 0) { + tError("failed to create pipe, errmsg: %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + goto End; + } + + code = uv_pipe_init(srv->loop, &(srv->pipe[i][0]), 1); + if (code != 0) { + tError("failed to init pipe, errmsg: %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + goto End; + } + + code = uv_pipe_open(&(srv->pipe[i][0]), fds[1]); + if (code != 0) { + tError("failed to init pipe, errmsg: %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + goto End; + } thrd->pipe = &(srv->pipe[i][1]); // init read thrd->fd = fds[0]; - if (false == addHandleToWorkloop(thrd, pipeName)) { + if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) { goto End; } @@ -1311,15 +1515,17 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, } #endif - if (false == addHandleToAcceptloop(srv)) { + if ((code = addHandleToAcceptloop(srv)) != 0) { goto End; } - int err = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv); - if (err == 0) { + code = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv); + if (code == 0) { tDebug("success to create accept-thread"); } else { - tError("failed to create accept-thread"); + code = TAOS_SYSTEM_ERROR(errno); + tError("failed to create accept-thread since %s", tstrerror(code)); + goto End; // clear all resource later } @@ -1328,6 +1534,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, return srv; End: transCloseServer(srv); + terrno = code; return NULL; } @@ -1341,9 +1548,14 @@ void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) { taosMemoryFree(msg); } void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { + int32_t code = 0; SSvrConn* conn = msg->pConn; if (conn->status == ConnAcquire) { - reallocConnRef(conn); + code = reallocConnRef(conn); + if (code != 0) { + destroyConn(conn, true); + return; + } if (!transQueuePush(&conn->srvMsgs, msg)) { return; } @@ -1366,7 +1578,7 @@ void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { if (!transQueuePush(&conn->srvMsgs, msg)) { return; } - transQueuePop(&conn->srvMsgs); + (void)transQueuePop(&conn->srvMsgs); if (conn->regArg.init) { transFreeMsg(conn->regArg.msg.pCont); @@ -1387,35 +1599,48 @@ void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { } void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { SUpdateIpWhite* req = msg->arg; - if (req != NULL) { - for (int i = 0; i < req->numOfUser; i++) { - SUpdateUserIpWhite* pUser = &req->pUserIpWhite[i]; - - int32_t sz = pUser->numOfRange * sizeof(SIpV4Range); - SIpWhiteList* pList = taosMemoryCalloc(1, sz + sizeof(SIpWhiteList)); - pList->num = pUser->numOfRange; - - memcpy(pList->pIpRange, pUser->pIpRanges, sz); - uvWhiteListAdd(thrd->pWhiteList, pUser->user, pList, pUser->ver); - } - - thrd->pWhiteList->ver = req->ver; - thrd->enableIpWhiteList = 1; - - tFreeSUpdateIpWhiteReq(req); - taosMemoryFree(req); - } else { + if (req == NULL) { tDebug("ip-white-list disable on trans"); thrd->enableIpWhiteList = 0; + taosMemoryFree(msg); + return; } + int32_t code = 0; + for (int i = 0; i < req->numOfUser; i++) { + SUpdateUserIpWhite* pUser = &req->pUserIpWhite[i]; + + int32_t sz = pUser->numOfRange * sizeof(SIpV4Range); + + SIpWhiteList* pList = taosMemoryCalloc(1, sz + sizeof(SIpWhiteList)); + if (pList == NULL) { + tError("failed to create ip-white-list since %s", tstrerror(code)); + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + pList->num = pUser->numOfRange; + memcpy(pList->pIpRange, pUser->pIpRanges, sz); + code = uvWhiteListAdd(thrd->pWhiteList, pUser->user, pList, pUser->ver); + if (code != 0) { + break; + } + } + + if (code == 0) { + thrd->pWhiteList->ver = req->ver; + thrd->enableIpWhiteList = 1; + } else { + tError("failed to update ip-white-list since %s", tstrerror(code)); + } + tFreeSUpdateIpWhiteReq(req); + taosMemoryFree(req); taosMemoryFree(msg); - return; } + void destroyWorkThrd(SWorkThrd* pThrd) { if (pThrd == NULL) { return; } - taosThreadJoin(pThrd->thread, NULL); + (void)taosThreadJoin(pThrd->thread, NULL); SRV_RELEASE_UV(pThrd->loop); TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); transAsyncPoolDestroy(pThrd->asyncPool); @@ -1430,7 +1655,7 @@ void sendQuitToWorkThrd(SWorkThrd* pThrd) { SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); msg->type = Quit; tDebug("server send quit msg to work thread"); - transAsyncSend(pThrd->asyncPool, &msg->q); + (void)transAsyncSend(pThrd->asyncPool, &msg->q); } void transCloseServer(void* arg) { @@ -1439,8 +1664,8 @@ void transCloseServer(void* arg) { if (srv->inited) { tDebug("send quit msg to accept thread"); - uv_async_send(srv->pAcceptAsync); - taosThreadJoin(srv->thread, NULL); + (void)uv_async_send(srv->pAcceptAsync); + (void)taosThreadJoin(srv->thread, NULL); SRV_RELEASE_UV(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { @@ -1448,7 +1673,7 @@ void transCloseServer(void* arg) { destroyWorkThrd(srv->pThreadObj[i]); } } else { - uv_loop_close(srv->loop); + (void)uv_loop_close(srv->loop); } taosMemoryFree(srv->pThreadObj); @@ -1483,6 +1708,7 @@ void transUnrefSrvHandle(void* handle) { } int transReleaseSrvHandle(void* handle) { + int32_t code = 0; SRpcHandleInfo* info = handle; SExHandle* exh = info->handle; int64_t refId = info->refId; @@ -1495,26 +1721,35 @@ int transReleaseSrvHandle(void* handle) { STransMsg tmsg = {.code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId}; SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + if (m == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return1; + } + m->msg = tmsg; m->type = Release; tDebug("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle); - if (0 != transAsyncSend(pThrd->asyncPool, &m->q)) { + if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; } - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); return 0; _return1: tDebug("handle %p failed to send to release handle", exh); - transReleaseExHandle(transGetRefMgt(), refId); - return -1; + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; _return2: tDebug("handle %p failed to send to release handle", exh); - return -1; + return code; } int transSendResponse(const STransMsg* msg) { + int32_t code = 0; + if (msg->info.noResp) { rpcFreeCont(msg->pCont); tTrace("no need send resp"); @@ -1536,29 +1771,38 @@ int transSendResponse(const STransMsg* msg) { ASYNC_ERR_JRET(pThrd); SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + if (m == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return1; + } + m->msg = tmsg; m->type = Normal; STraceId* trace = (STraceId*)&msg->info.traceId; tGDebug("conn %p start to send resp (1/2)", exh->handle); - if (0 != transAsyncSend(pThrd->asyncPool, &m->q)) { + if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; } - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); return 0; _return1: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - transReleaseExHandle(transGetRefMgt(), refId); - return -1; + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; _return2: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - return -1; + return code; } int transRegisterMsg(const STransMsg* msg) { + int32_t code = 0; + SExHandle* exh = msg->info.handle; int64_t refId = msg->info.refId; ASYNC_CHECK_HANDLE(exh, refId); @@ -1572,45 +1816,79 @@ int transRegisterMsg(const STransMsg* msg) { ASYNC_ERR_JRET(pThrd); SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + if (m == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return1; + } + m->msg = tmsg; m->type = Register; STrans* pTransInst = pThrd->pTransInst; tDebug("%s conn %p start to register brokenlink callback", transLabel(pTransInst), exh->handle); - if (0 != transAsyncSend(pThrd->asyncPool, &m->q)) { + if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; } - transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(transGetRefMgt(), refId); return 0; _return1: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - transReleaseExHandle(transGetRefMgt(), refId); - return -1; + (void)transReleaseExHandle(transGetRefMgt(), refId); + return code; _return2: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - return -1; + return code; } -void transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { + +int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)thandle); + if (pTransInst == NULL) { + return TSDB_CODE_RPC_MODULE_QUIT; + } + + int32_t code = 0; tDebug("ip-white-list update on rpc"); SServerObj* svrObj = pTransInst->tcphandle; for (int i = 0; i < svrObj->numOfThreads; i++) { SWorkThrd* pThrd = svrObj->pThreadObj[i]; - SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); - SUpdateIpWhite* pReq = (arg != NULL ? cloneSUpdateIpWhiteReq((SUpdateIpWhite*)arg) : NULL); + SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + if (msg == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + break; + } + + SUpdateIpWhite* pReq = NULL; + code = cloneSUpdateIpWhiteReq((SUpdateIpWhite*)arg, &pReq); + if (code != 0) { + taosMemoryFree(msg); + break; + } msg->type = Update; msg->arg = pReq; - transAsyncSend(pThrd->asyncPool, &msg->q); + if ((code = transAsyncSend(pThrd->asyncPool, &msg->q)) != 0) { + code = (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); + tFreeSUpdateIpWhiteReq(pReq); + taosMemoryFree(pReq); + taosMemoryFree(msg); + break; + } } - transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); + + if (code != 0) { + tError("ip-white-list update failed since %s", tstrerror(code)); + } + return code; } int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 1b0deb1819..f9ae6c2157 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -941,7 +941,7 @@ int32_t taosBlockSIGPIPE() { #endif } -int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) { +int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { #ifdef WINDOWS // Initialize Winsock WSADATA wsaData; @@ -959,8 +959,8 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) { hints.ai_socktype = SOCK_STREAM; struct addrinfo *result = NULL; - bool inRetry = false; - + bool inRetry = false; + while (true) { int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result); if (ret) { @@ -972,7 +972,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) { return terrno; } - terrno = TAOS_SYSTEM_ERROR(ret); + terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } @@ -1011,7 +1011,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) { #else // printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret)); #endif - + *ip = 0xFFFFFFFF; return 0xFFFFFFFF; } diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 5d7ca0a53f..d38ef5841d 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -293,7 +293,7 @@ void taosArrayRemove(SArray* pArray, size_t index) { ASSERT(index < pArray->size); if (index == pArray->size - 1) { - taosArrayPop(pArray); + (void)taosArrayPop(pArray); return; } diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index 0d9352190b..c150ca3fbd 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -110,7 +110,7 @@ typedef struct SCacheObjTravSup { static FORCE_INLINE void __trashcan_wr_lock(SCacheObj *pCacheObj) { #if defined(LINUX) - taosThreadRwlockWrlock(&pCacheObj->lock); + (void)taosThreadRwlockWrlock(&pCacheObj->lock); #else (void)taosThreadMutexLock(&pCacheObj->lock); #endif @@ -118,7 +118,7 @@ static FORCE_INLINE void __trashcan_wr_lock(SCacheObj *pCacheObj) { static FORCE_INLINE void __trashcan_unlock(SCacheObj *pCacheObj) { #if defined(LINUX) - taosThreadRwlockUnlock(&pCacheObj->lock); + (void)taosThreadRwlockUnlock(&pCacheObj->lock); #else (void)taosThreadMutexUnlock(&pCacheObj->lock); #endif @@ -134,9 +134,9 @@ static FORCE_INLINE int32_t __trashcan_lock_init(SCacheObj *pCacheObj) { static FORCE_INLINE void __trashcan_lock_destroy(SCacheObj *pCacheObj) { #if defined(LINUX) - taosThreadRwlockDestroy(&pCacheObj->lock); + (void)taosThreadRwlockDestroy(&pCacheObj->lock); #else - taosThreadMutexDestroy(&pCacheObj->lock); + (void)taosThreadMutexDestroy(&pCacheObj->lock); #endif } @@ -155,18 +155,18 @@ static void *taosCacheTimedRefresh(void *handle); static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); - taosThreadMutexInit(&guard, NULL); + (void)taosThreadMutexInit(&guard, NULL); TdThreadAttr thattr; - taosThreadAttrInit(&thattr); - taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thattr); + (void)taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); - taosThreadCreate(&cacheRefreshWorker, &thattr, taosCacheTimedRefresh, NULL); - taosThreadAttrDestroy(&thattr); + (void)taosThreadCreate(&cacheRefreshWorker, &thattr, taosCacheTimedRefresh, NULL); + (void)taosThreadAttrDestroy(&thattr); } TdThread doRegisterCacheObj(SCacheObj *pCacheObj) { - taosThreadOnce(&cacheThreadInit, doInitRefreshThread); + (void)taosThreadOnce(&cacheThreadInit, doInitRefreshThread); (void)taosThreadMutexLock(&guard); (void)taosArrayPush(pCacheArrayList, &pCacheObj); @@ -215,7 +215,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheNode * return; } - atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); + (void)atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); uDebug("cache:%s, key:%p, %p is destroyed from cache, size:%dbytes, total num:%d size:%" PRId64 "bytes", pCacheObj->name, pNode->key, pNode->data, pNode->size, (int)pCacheObj->numOfElems - 1, pCacheObj->sizeInBytes); @@ -388,7 +388,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInMs, bool extendLi } pCacheObj->name = taosStrdup(cacheName); - doRegisterCacheObj(pCacheObj); + (void)doRegisterCacheObj(pCacheObj); return pCacheObj; } @@ -416,8 +416,8 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v if (pNode == NULL) { pushfrontNodeInEntryList(pe, pNode1); - atomic_add_fetch_ptr(&pCacheObj->numOfElems, 1); - atomic_add_fetch_ptr(&pCacheObj->sizeInBytes, pNode1->size); + (void)atomic_add_fetch_ptr(&pCacheObj->numOfElems, 1); + (void)atomic_add_fetch_ptr(&pCacheObj->sizeInBytes, pNode1->size); uDebug("cache:%s, key:%p, %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", totalNum:%d sizeInBytes:%" PRId64 "bytes size:%" PRId64 "bytes", pCacheObj->name, key, pNode1->data, pNode1->addedTime, pNode1->expireTime, (int32_t)pCacheObj->numOfElems, @@ -431,7 +431,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v pCacheObj->freeFp(pNode->data); } - atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); + (void)atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); taosMemoryFreeClear(pNode); } else { taosAddToTrashcan(pCacheObj, pNode); @@ -439,7 +439,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v } pushfrontNodeInEntryList(pe, pNode1); - atomic_add_fetch_64(&pCacheObj->sizeInBytes, pNode1->size); + (void)atomic_add_fetch_64(&pCacheObj->sizeInBytes, pNode1->size); uDebug("cache:%s, key:%p, %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", totalNum:%d sizeInBytes:%" PRId64 "bytes size:%" PRId64 "bytes", pCacheObj->name, key, pNode1->data, pNode1->addedTime, pNode1->expireTime, (int32_t)pCacheObj->numOfElems, @@ -456,7 +456,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen } if (pCacheObj->numOfElems == 0) { - atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1); + (void)atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1); return NULL; } @@ -474,15 +474,15 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen void *pData = (pNode != NULL) ? pNode->data : NULL; if (pData != NULL) { - atomic_add_fetch_64(&pCacheObj->statistics.hitCount, 1); + (void)atomic_add_fetch_64(&pCacheObj->statistics.hitCount, 1); uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(pNode)); } else { - atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1); + (void)atomic_add_fetch_64(&pCacheObj->statistics.missCount, 1); uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); } - atomic_add_fetch_64(&pCacheObj->statistics.totalAccess, 1); + (void)atomic_add_fetch_64(&pCacheObj->statistics.totalAccess, 1); return pData; } @@ -577,7 +577,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { ASSERT(pNode->pTNodeHeader->pData == pNode); __trashcan_wr_lock(pCacheObj); - doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader); + (void)doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader); __trashcan_unlock(pCacheObj); ref = T_REF_DEC(pNode); @@ -616,7 +616,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { if (ref > 0) { taosAddToTrashcan(pCacheObj, pNode); } else { // ref == 0 - atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); + (void)atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size); int32_t size = (int32_t)pCacheObj->numOfElems; uDebug("cache:%s, key:%p, %p is destroyed from cache, size:%dbytes, totalNum:%d size:%" PRId64 "bytes", @@ -670,7 +670,7 @@ void doTraverseElems(SCacheObj *pCacheObj, bool (*fp)(void *param, SCacheNode *p pEntry->num -= 1; ASSERT((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); - atomic_sub_fetch_ptr(&pCacheObj->numOfElems, 1); + (void)atomic_sub_fetch_ptr(&pCacheObj->numOfElems, 1); pNode = next; } } @@ -786,7 +786,7 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) { uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key, pElem->pData->data, pCacheObj->numOfElemsInTrash - 1); - doRemoveElemInTrashcan(pCacheObj, pElem); + (void)doRemoveElemInTrashcan(pCacheObj, pElem); doDestroyTrashcanElem(pCacheObj, pElem); pElem = pCacheObj->pTrash; } else { @@ -896,7 +896,7 @@ _end: taosArrayDestroy(pCacheArrayList); pCacheArrayList = NULL; - taosThreadMutexDestroy(&guard); + (void)taosThreadMutexDestroy(&guard); refreshWorkerNormalStopped = true; uDebug("cache refresh thread quits"); @@ -915,7 +915,7 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1) void taosStopCacheRefreshWorker(void) { stopRefreshWorker = true; TdThreadOnce tmp = PTHREAD_ONCE_INIT; - if (memcmp(&cacheThreadInit, &tmp, sizeof(TdThreadOnce)) != 0) taosThreadJoin(cacheRefreshWorker, NULL); + if (memcmp(&cacheThreadInit, &tmp, sizeof(TdThreadOnce)) != 0) (void)taosThreadJoin(cacheRefreshWorker, NULL); taosArrayDestroy(pCacheArrayList); } diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index 1f7a244a53..8402d2a658 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -823,9 +823,9 @@ int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelement return nelements * longBytes; } else if (input[0] == 1) { // Decompress if (tsSIMDEnable && tsAVX512Supported && tsAVX512Enable) { - tsDecompressTimestampAvx512(input, nelements, output, false); + (void)tsDecompressTimestampAvx512(input, nelements, output, false); } else if (tsSIMDEnable && tsAVX2Supported) { - tsDecompressTimestampAvx2(input, nelements, output, false); + (void)tsDecompressTimestampAvx2(input, nelements, output, false); } else { int64_t *ostream = (int64_t *)output; @@ -1199,9 +1199,9 @@ int32_t tsDecompressFloatImp(const char *const input, const int32_t nelements, c } if (tsSIMDEnable && tsAVX2Supported) { - tsDecompressFloatImplAvx2(input, nelements, output); + (void)tsDecompressFloatImplAvx2(input, nelements, output); } else if (tsSIMDEnable && tsAVX512Supported && tsAVX512Enable) { - tsDecompressFloatImplAvx512(input, nelements, output); + (void)tsDecompressFloatImplAvx512(input, nelements, output); } else { // alternative implementation without SIMD instructions. tsDecompressFloatHelper(input, nelements, (float *)output); } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index e68d86e232..87551e28e0 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -18,12 +18,12 @@ #include "cJSON.h" #include "taoserror.h" #include "tenv.h" +#include "tglobal.h" #include "tgrant.h" #include "tjson.h" #include "tlog.h" #include "tunit.h" #include "tutil.h" -#include "tglobal.h" #define CFG_NAME_PRINT_LEN 24 #define CFG_SRC_PRINT_LEN 12 @@ -1214,8 +1214,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { char *cfgLineBuf = NULL, *name, *value, *value2, *value3, *value4; + SJson *pJson = NULL; int32_t olen, vlen, vlen2, vlen3, vlen4; - int32_t code = 0; + int32_t code = 0, lino = 0; if (url == NULL || strlen(url) == 0) { uInfo("apoll url not load"); TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -1228,7 +1229,6 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { } p++; - SJson *pJson = NULL; if (strncmp(url, "jsonFile", 8) == 0) { char *filepath = p; if (!taosCheckExistFile(filepath)) { @@ -1238,7 +1238,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); if (pFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); } size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); char *buf = taosMemoryMalloc(fileSize + 1); @@ -1264,7 +1264,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { uError("load json file parse error: %s", jsonParseError); } taosMemoryFreeClear(buf); - TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT); + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT); } taosMemoryFreeClear(buf); @@ -1273,16 +1273,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { cJSON *item = tjsonGetArrayItem(pJson, i); if (item == NULL) break; char *itemName = NULL, *itemValueString = NULL; - TAOS_CHECK_GOTO(tjsonGetObjectName(item, &itemName), NULL, _err_json); - TAOS_CHECK_GOTO(tjsonGetObjectValueString(item, &itemValueString), NULL, _err_json); + if (tjsonGetObjectName(item, &itemName) != 0) { + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT); + } + if (tjsonGetObjectValueString(item, &itemValueString) != 0) { + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT); + } if (itemValueString != NULL && itemName != NULL) { size_t itemNameLen = strlen(itemName); size_t itemValueStringLen = strlen(itemValueString); - void* px = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3); + void *px = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3); if (NULL == px) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err_json; + TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); } cfgLineBuf = px; @@ -1321,6 +1324,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { } } tjsonDelete(pJson); + pJson = NULL; // } else if (strncmp(url, "jsonUrl", 7) == 0) { // } else if (strncmp(url, "etcdUrl", 7) == 0) { @@ -1333,8 +1337,12 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { uInfo("load from apoll url not implemented yet"); TAOS_RETURN(TSDB_CODE_SUCCESS); -_err_json: +_exit: + taosMemoryFree(cfgLineBuf); tjsonDelete(pJson); + if (code != 0) { + uError("failed to load from apollo url:%s at line %d since %s", url, lino, tstrerror(code)); + } TAOS_RETURN(code); } @@ -1420,7 +1428,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl } uInfo("fail get apollo url from cmd env file"); - TAOS_RETURN(TSDB_CODE_INVALID_PARA); + TAOS_RETURN(TSDB_CODE_NOT_FOUND); } struct SConfigIter { diff --git a/source/util/src/tdigest.c b/source/util/src/tdigest.c index 588c53537a..51b68f8f6b 100644 --- a/source/util/src/tdigest.c +++ b/source/util/src/tdigest.c @@ -256,7 +256,7 @@ double tdigestQuantile(TDigest *t, double q) { int64_t weight_so_far; SCentroid *a, *b, tmp; - tdigestCompress(t); + (void)tdigestCompress(t); if (t->num_centroids == 0) return NAN; if (t->num_centroids == 1) return t->centroids[0].mean; if (FLOAT_EQ(q, 0.0)) return t->min; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b9f8d590ea..089251bac5 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -55,8 +55,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TIMEOUT, "Conn read timeout") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED, "some vnode/qnode/mnode(s) out of service") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, "rpc open too many session") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_ERROR, "rpc network error") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_BUSY, "rpc network busy") -TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_MODULE_QUIT, "http-report already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_BUSY, "rpc network busy") +TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_MODULE_QUIT, "http-report already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MODULE_QUIT, "rpc module already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_MODULE_QUIT, "rpc async module already quit") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") @@ -357,6 +359,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VIEW_NOT_EXIST, "view not exists in db //mnode-compact TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_COMPACT_ID, "Invalid compact id") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COMPACT_DETAIL_NOT_EXIST, "compact detail doesn't exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_COMPACT_ALREADY_EXIST, "compact already exist") // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_OFFLINE, "Dnode is offline") @@ -598,7 +601,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist TAOS_DEFINE_ERROR(TSDB_CODE_PAR_AMBIGUOUS_COLUMN, "Column ambiguously defined") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Invalid value type") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, "There mustn't be aggregation") -TAOS_DEFINE_ERROR(TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, "ORDER BY item must be the number of a SELECT-list expression") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, "ORDER BY / GROUP BY item must be the number of a SELECT-list expression") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, "Not a GROUP BY expression") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, "Not SELECTed expression") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SINGLE_GROUP, "Not a single-group group function") @@ -837,7 +840,7 @@ static void tsSortError(void) { } const char* tstrerror(int32_t err) { - taosThreadOnce(&tsErrorInit, tsSortError); + (void)taosThreadOnce(&tsErrorInit, tsSortError); // this is a system errno if ((err & 0x00ff0000) == 0x00ff0000) { diff --git a/source/util/src/texception.c b/source/util/src/texception.c index 4723e34990..2c8ddf6a5f 100644 --- a/source/util/src/texception.c +++ b/source/util/src/texception.c @@ -52,7 +52,7 @@ static void cleanupWrapper_void_ptr(SCleanupAction* ca) { static void cleanupWrapper_int_int(SCleanupAction* ca) { int32_t (*func)(int32_t) = ca->func; - func(ca->arg1.Int); + (void)func(ca->arg1.Int); } static void cleanupWrapper_void(SCleanupAction* ca) { @@ -62,7 +62,7 @@ static void cleanupWrapper_void(SCleanupAction* ca) { static void cleanupWrapper_int_ptr(SCleanupAction* ca) { int32_t (*func)(void*) = ca->func; - func(ca->arg1.Ptr); + (void)func(ca->arg1.Ptr); } typedef void (*wrapper)(SCleanupAction*); diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 62a73cb38c..2daedfdf32 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -188,7 +188,7 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p */ static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry *pe, SHashNode *prev, SHashNode *pNode, SHashNode *pNewNode) { - atomic_sub_fetch_16(&pNode->refCount, 1); + (void)atomic_sub_fetch_16(&pNode->refCount, 1); if (prev != NULL) { prev->next = pNewNode; ASSERT(prev->next != prev); @@ -204,7 +204,7 @@ static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry *pe, SH } else { pNewNode->next = pNode; pe->num++; - atomic_add_fetch_64(&pHashObj->size, 1); + (void)atomic_add_fetch_64(&pHashObj->size, 1); } } @@ -359,7 +359,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo } pushfrontNodeInEntryList(pe, pNewNode); - atomic_add_fetch_64(&pHashObj->size, 1); + (void)atomic_add_fetch_64(&pHashObj->size, 1); } else { // not support the update operation, return error if (pHashObj->enableUpdate) { @@ -392,14 +392,14 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen) { int32_t taosHashGetDup(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf) { terrno = 0; - /*char* p = */ taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false); + (void)taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false); return terrno; } int32_t taosHashGetDup_m(SHashObj *pHashObj, const void *key, size_t keyLen, void **destBuf, int32_t *size) { terrno = 0; - /*char* p = */ taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false); + (void)taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false); return terrno; } @@ -454,7 +454,7 @@ void *taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void * } if (addRef) { - atomic_add_fetch_16(&pNode->refCount, 1); + (void)atomic_add_fetch_16(&pNode->refCount, 1); } if (*d != NULL) { @@ -501,7 +501,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) { pNode->removed == 0) { code = 0; // it is found - atomic_sub_fetch_16(&pNode->refCount, 1); + (void)atomic_sub_fetch_16(&pNode->refCount, 1); pNode->removed = 1; if (pNode->refCount <= 0) { if (prevNode == NULL) { @@ -512,7 +512,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) { } pe->num--; - atomic_sub_fetch_64(&pHashObj->size, 1); + (void)atomic_sub_fetch_64(&pHashObj->size, 1); FREE_HASH_NODE(pHashObj->freeFp, pNode); } } else { @@ -752,7 +752,7 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { pNode = pNode->next; } - atomic_sub_fetch_16(&pOld->refCount, 1); + (void)atomic_sub_fetch_16(&pOld->refCount, 1); if (pOld->refCount <= 0) { if (prevNode) { prevNode->next = pOld->next; @@ -766,7 +766,7 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { } pe->num--; - atomic_sub_fetch_64(&pHashObj->size, 1); + (void)atomic_sub_fetch_64(&pHashObj->size, 1); FREE_HASH_NODE(pHashObj->freeFp, pOld); } } else { @@ -840,7 +840,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { taosHashRLock(pHashObj); int slot; - taosHashReleaseNode(pHashObj, p, &slot); + (void)taosHashReleaseNode(pHashObj, p, &slot); SHashEntry *pe = pHashObj->hashList[slot]; diff --git a/source/util/src/theap.c b/source/util/src/theap.c index 1cd6463152..1064f8d583 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -258,9 +258,9 @@ static PriorityQueueNode* pqHeapify(PriorityQueue* pq, size_t from, size_t last) static void pqBuildHeap(PriorityQueue* pq) { if (pqContainerSize(pq) > 1) { for (size_t i = pqContainerSize(pq) - 1; i > 0; --i) { - pqHeapify(pq, i, pqContainerSize(pq)); + (void)pqHeapify(pq, i, pqContainerSize(pq)); } - pqHeapify(pq, 0, pqContainerSize(pq)); + (void)pqHeapify(pq, 0, pqContainerSize(pq)); } } @@ -276,21 +276,21 @@ static PriorityQueueNode* pqReverseHeapify(PriorityQueue* pq, size_t i) { static void pqUpdate(PriorityQueue* pq, size_t i) { if (i == 0 || pq->fn(pqContainerGetEle(pq, i)->data, pqContainerGetEle(pq, pqParent(i))->data, pq->param)) { // if value in pos i is smaller than parent, heapify down from i to the end - pqHeapify(pq, i, pqContainerSize(pq)); + (void)pqHeapify(pq, i, pqContainerSize(pq)); } else { // if value in pos i is big than parent, heapify up from i - pqReverseHeapify(pq, i); + (void)pqReverseHeapify(pq, i); } } static void pqRemove(PriorityQueue* pq, size_t i) { if (i == pqContainerSize(pq) - 1) { - taosArrayPop(pq->container); + (void)taosArrayPop(pq->container); return; } taosArraySet(pq->container, i, taosArrayGet(pq->container, pqContainerSize(pq) - 1)); - taosArrayPop(pq->container); + (void)taosArrayPop(pq->container); pqUpdate(pq, i); } diff --git a/source/util/src/tidpool.c b/source/util/src/tidpool.c index 46e68c0818..456078c4b5 100644 --- a/source/util/src/tidpool.c +++ b/source/util/src/tidpool.c @@ -33,7 +33,7 @@ void *taosInitIdPool(int32_t maxId) { pIdPool->numOfFree = maxId; pIdPool->freeSlot = 0; - taosThreadMutexInit(&pIdPool->mutex, NULL); + (void)taosThreadMutexInit(&pIdPool->mutex, NULL); uDebug("pool:%p is setup, maxId:%d", pIdPool, pIdPool->maxId); @@ -83,7 +83,7 @@ void taosIdPoolCleanUp(id_pool_t *pIdPool) { if (pIdPool->freeList) taosMemoryFree(pIdPool->freeList); - taosThreadMutexDestroy(&pIdPool->mutex); + (void)taosThreadMutexDestroy(&pIdPool->mutex); memset(pIdPool, 0, sizeof(id_pool_t)); diff --git a/source/util/src/tlockfree.c b/source/util/src/tlockfree.c index 6f7b6f6901..1961b404b5 100644 --- a/source/util/src/tlockfree.c +++ b/source/util/src/tlockfree.c @@ -30,7 +30,7 @@ void taosWLockLatch(SRWLatch *pLatch) { if (oLatch & TD_RWLATCH_WRITE_FLAG) { nLoops++; if (nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } continue; @@ -47,7 +47,7 @@ void taosWLockLatch(SRWLatch *pLatch) { if (oLatch == TD_RWLATCH_WRITE_FLAG) break; nLoops++; if (nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } } @@ -80,7 +80,7 @@ void taosRLockLatch(SRWLatch *pLatch) { if (oLatch & TD_RWLATCH_WRITE_FLAG) { nLoops++; if (nLoops > 1000) { - sched_yield(); + (void)sched_yield(); nLoops = 0; } continue; @@ -91,4 +91,4 @@ void taosRLockLatch(SRWLatch *pLatch) { } } -void taosRUnLockLatch(SRWLatch *pLatch) { atomic_fetch_sub_32(pLatch, 1); } +void taosRUnLockLatch(SRWLatch *pLatch) { (void)atomic_fetch_sub_32(pLatch, 1); } diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index fa2c2cc3ed..1946a0a274 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -136,7 +136,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum); static FORCE_INLINE void taosUpdateDaylight() { struct tm Tm, *ptm; struct timeval timeSecs; - taosGetTimeOfDay(&timeSecs); + (void)taosGetTimeOfDay(&timeSecs); time_t curTime = timeSecs.tv_sec; ptm = taosLocalTime(&curTime, &Tm, NULL); tsDaylightActive = ptm->tm_isdst; @@ -145,11 +145,11 @@ static FORCE_INLINE int32_t taosGetDaylight() { return tsDaylightActive; } static int32_t taosStartLog() { TdThreadAttr threadAttr; - taosThreadAttrInit(&threadAttr); + (void)taosThreadAttrInit(&threadAttr); if (taosThreadCreate(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) { return terrno; } - taosThreadAttrDestroy(&threadAttr); + (void)taosThreadAttrDestroy(&threadAttr); return 0; } @@ -179,7 +179,7 @@ int32_t taosInitSlowLog() { tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE); if (tsLogObj.slowHandle == NULL) return terrno; - taosUmaskFile(0); + (void)taosUmaskFile(0); tsLogObj.slowHandle->pFile = taosOpenFile(fullName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (tsLogObj.slowHandle->pFile == NULL) { printf("\nfailed to open slow log file:%s, reason:%s\n", fullName, strerror(errno)); @@ -231,13 +231,13 @@ void taosCloseLog() { taosStopLog(); if (tsLogObj.logHandle != NULL && taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) { - taosThreadJoin(tsLogObj.logHandle->asyncThread, NULL); + (void)taosThreadJoin(tsLogObj.logHandle->asyncThread, NULL); taosThreadClear(&tsLogObj.logHandle->asyncThread); } if (tsLogObj.slowHandle != NULL) { - taosThreadMutexDestroy(&tsLogObj.slowHandle->buffMutex); - taosCloseFile(&tsLogObj.slowHandle->pFile); + (void)taosThreadMutexDestroy(&tsLogObj.slowHandle->buffMutex); + (void)taosCloseFile(&tsLogObj.slowHandle->pFile); taosMemoryFreeClear(tsLogObj.slowHandle->buffer); taosMemoryFreeClear(tsLogObj.slowHandle); } @@ -245,10 +245,10 @@ void taosCloseLog() { if (tsLogObj.logHandle != NULL) { tsLogInited = 0; - taosThreadMutexDestroy(&tsLogObj.logHandle->buffMutex); - taosCloseFile(&tsLogObj.logHandle->pFile); + (void)taosThreadMutexDestroy(&tsLogObj.logHandle->buffMutex); + (void)taosCloseFile(&tsLogObj.logHandle->pFile); taosMemoryFreeClear(tsLogObj.logHandle->buffer); - taosThreadMutexDestroy(&tsLogObj.logMutex); + (void)taosThreadMutexDestroy(&tsLogObj.logMutex); taosMemoryFreeClear(tsLogObj.logHandle); tsLogObj.logHandle = NULL; } @@ -271,7 +271,7 @@ static void taosUnLockLogFile(TdFilePtr pFile) { if (pFile == NULL) return; if (tsLogObj.fileNum > 1) { - taosUnLockFile(pFile); + (void)taosUnLockFile(pFile); } } @@ -321,7 +321,7 @@ static OldFileKeeper *taosOpenNewFile() { char name[LOG_FILE_NAME_LEN + 20]; sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag); - taosUmaskFile(0); + (void)taosUmaskFile(0); TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -331,7 +331,7 @@ static OldFileKeeper *taosOpenNewFile() { return NULL; } - taosLockLogFile(pFile); + (void)taosLockLogFile(pFile); (void)taosLSeekFile(pFile, 0, SEEK_SET); TdFilePtr pOldFile = tsLogObj.logHandle->pFile; @@ -370,12 +370,12 @@ static int32_t taosOpenNewLogFile() { uInfo("open new log file ......"); TdThread thread; TdThreadAttr attr; - taosThreadAttrInit(&attr); - taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED); + (void)taosThreadAttrInit(&attr); + (void)taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED); OldFileKeeper *oldFileKeeper = taosOpenNewFile(); - taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper); - taosThreadAttrDestroy(&attr); + (void)taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper); + (void)taosThreadAttrDestroy(&attr); } (void)taosThreadMutexUnlock(&tsLogObj.logMutex); @@ -388,7 +388,7 @@ void taosResetLog() { tsLogObj.lines = tsNumOfLogLines + 10; if (tsLogObj.logHandle) { - taosOpenNewLogFile(); + (void)taosOpenNewLogFile(); uInfo("=================================="); uInfo(" reset log file "); } @@ -407,10 +407,10 @@ static bool taosCheckFileIsOpen(char *logFileName) { if (taosLockLogFile(pFile)) { taosUnLockLogFile(pFile); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return false; } else { - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); return true; } } @@ -478,16 +478,16 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) { char fileName[LOG_FILE_NAME_LEN + 50] = "\0"; sprintf(fileName, "%s.%d", tsLogObj.logName, tsLogObj.flag); - taosThreadMutexInit(&tsLogObj.logMutex, NULL); + (void)taosThreadMutexInit(&tsLogObj.logMutex, NULL); - taosUmaskFile(0); + (void)taosUmaskFile(0); tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE); if (tsLogObj.logHandle->pFile == NULL) { printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); return TAOS_SYSTEM_ERROR(errno); } - taosLockLogFile(tsLogObj.logHandle->pFile); + (void)taosLockLogFile(tsLogObj.logHandle->pFile); // only an estimate for number of lines int64_t filesize = 0; @@ -497,14 +497,14 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) { } tsLogObj.lines = (int32_t)(filesize / 60); - taosLSeekFile(tsLogObj.logHandle->pFile, 0, SEEK_END); + (void)taosLSeekFile(tsLogObj.logHandle->pFile, 0, SEEK_END); sprintf(name, "==================================================\n"); - taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); + (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); sprintf(name, " new log file \n"); - taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); + (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); sprintf(name, "==================================================\n"); - taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); + (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); return 0; } @@ -512,17 +512,17 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) { static void taosUpdateLogNums(ELogLevel level) { switch (level) { case DEBUG_ERROR: - atomic_add_fetch_64(&tsNumOfErrorLogs, 1); + (void)atomic_add_fetch_64(&tsNumOfErrorLogs, 1); break; case DEBUG_INFO: - atomic_add_fetch_64(&tsNumOfInfoLogs, 1); + (void)atomic_add_fetch_64(&tsNumOfInfoLogs, 1); break; case DEBUG_DEBUG: - atomic_add_fetch_64(&tsNumOfDebugLogs, 1); + (void)atomic_add_fetch_64(&tsNumOfDebugLogs, 1); break; case DEBUG_DUMP: case DEBUG_TRACE: - atomic_add_fetch_64(&tsNumOfTraceLogs, 1); + (void)atomic_add_fetch_64(&tsNumOfTraceLogs, 1); break; default: break; @@ -533,7 +533,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) { struct tm Tm, *ptm; struct timeval timeSecs; - taosGetTimeOfDay(&timeSecs); + (void)taosGetTimeOfDay(&timeSecs); time_t curTime = timeSecs.tv_sec; ptm = taosLocalTime(&curTime, &Tm, NULL); @@ -546,15 +546,15 @@ static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *b if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL && osLogSpaceAvailable()) { taosUpdateLogNums(level); if (tsAsyncLog) { - taosPushLogBuffer(tsLogObj.logHandle, buffer, len); + (void)taosPushLogBuffer(tsLogObj.logHandle, buffer, len); } else { - taosWriteFile(tsLogObj.logHandle->pFile, buffer, len); + (void)taosWriteFile(tsLogObj.logHandle->pFile, buffer, len); } if (tsNumOfLogLines > 0) { - atomic_add_fetch_32(&tsLogObj.lines, 1); + (void)atomic_add_fetch_32(&tsLogObj.lines, 1); if ((tsLogObj.lines > tsNumOfLogLines) && (tsLogObj.openInProgress == 0)) { - taosOpenNewLogFile(); + (void)taosOpenNewLogFile(); } } } @@ -562,7 +562,7 @@ static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *b if (dflag & DEBUG_SCREEN) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-result" - write(1, buffer, (uint32_t)len); + (void)write(1, buffer, (uint32_t)len); #pragma GCC diagnostic pop } } @@ -627,12 +627,12 @@ void taosPrintSlowLog(const char *format, ...) { buffer[len++] = '\n'; buffer[len] = 0; - atomic_add_fetch_64(&tsNumOfSlowLogs, 1); + (void)atomic_add_fetch_64(&tsNumOfSlowLogs, 1); if (tsAsyncLog) { - taosPushLogBuffer(tsLogObj.slowHandle, buffer, len); + (void)taosPushLogBuffer(tsLogObj.slowHandle, buffer, len); } else { - taosWriteFile(tsLogObj.slowHandle->pFile, buffer, len); + (void)taosWriteFile(tsLogObj.slowHandle->pFile, buffer, len); } taosMemoryFree(buffer); @@ -651,7 +651,7 @@ void taosDumpData(unsigned char *msg, int32_t len) { pos += 3; if (c >= 16) { temp[pos++] = '\n'; - taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos); + (void)taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos); c = 0; pos = 0; } @@ -659,13 +659,13 @@ void taosDumpData(unsigned char *msg, int32_t len) { temp[pos++] = '\n'; - taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos); + (void)taosWriteFile(tsLogObj.logHandle->pFile, temp, (uint32_t)pos); } static void taosCloseLogByFd(TdFilePtr pFile) { if (pFile != NULL) { taosUnLockLogFile(pFile); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); } } @@ -786,12 +786,12 @@ static void taosWriteLog(SLogBuff *pLogBuf) { pLogBuf->lastDuration = 0; if (start < end) { - taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, pollSize); + (void)taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, pollSize); } else { int32_t tsize = LOG_BUF_SIZE(pLogBuf) - start; - taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, tsize); + (void)taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, tsize); - taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf), end); + (void)taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf), end); } dbgWN++; @@ -914,11 +914,11 @@ void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, vo goto _return; } - taosLockFile(pFile); + (void)taosLockFile(pFile); int64_t writeSize = taosWriteFile(pFile, &msgLen, sizeof(msgLen)); if (sizeof(msgLen) != writeSize) { - taosUnLockFile(pFile); + (void)taosUnLockFile(pFile); taosPrintLog(flags, level, dflag, "failed to write len to file:%s,%p wlen:%" PRId64 " tlen:%lu since %s", filepath, pFile, writeSize, sizeof(msgLen), terrstr()); goto _return; @@ -926,18 +926,18 @@ void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, vo writeSize = taosWriteFile(pFile, pMsg, msgLen); if (msgLen != writeSize) { - taosUnLockFile(pFile); + (void)taosUnLockFile(pFile); taosPrintLog(flags, level, dflag, "failed to write file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s", filepath, pFile, writeSize, msgLen, terrstr()); goto _return; } - taosUnLockFile(pFile); + (void)taosUnLockFile(pFile); } _return: - if (pFile) taosCloseFile(&pFile); + if (pFile) (void)taosCloseFile(&pFile); terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "crash signal is %d", signum); @@ -990,7 +990,7 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr return; } - taosLockFile(pFile); + (void)taosLockFile(pFile); } else { pFile = *pFd; } @@ -1029,10 +1029,10 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr _return: if (truncateFile) { - taosFtruncateFile(pFile, 0); + (void)taosFtruncateFile(pFile, 0); } - taosUnLockFile(pFile); - taosCloseFile(&pFile); + (void)taosUnLockFile(pFile); + (void)taosCloseFile(&pFile); taosMemoryFree(buf); *pMsg = NULL; @@ -1042,11 +1042,11 @@ _return: void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile) { if (truncateFile) { - taosFtruncateFile(pFile, 0); + (void)taosFtruncateFile(pFile, 0); } - taosUnLockFile(pFile); - taosCloseFile(&pFile); + (void)taosUnLockFile(pFile); + (void)taosCloseFile(&pFile); } #ifdef NDEBUG diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index e08dc009fc..5d28eeafb1 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -320,7 +320,7 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old)); taosLRUCacheShardLRURemove(shard, old); - taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash); + (void)taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash); TAOS_LRU_ENTRY_SET_IN_CACHE(old, false); ASSERT(shard->usage >= old->totalCharge); @@ -531,7 +531,7 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) { SLRUEntry *old = shard->lru.next; ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old)); taosLRUCacheShardLRURemove(shard, old); - taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash); + (void)taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash); TAOS_LRU_ENTRY_SET_IN_CACHE(old, false); ASSERT(shard->usage >= old->totalCharge); shard->usage -= old->totalCharge; @@ -577,7 +577,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b if (shard->usage > shard->capacity || eraseIfLastRef) { ASSERT(shard->lru.next == &shard->lru || eraseIfLastRef); - taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash); + (void)taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash); TAOS_LRU_ENTRY_SET_IN_CACHE(e, false); } else { taosLRUCacheShardLRUInsert(shard, e); diff --git a/source/util/src/tpcre2.c b/source/util/src/tpcre2.c index 5f5e4ffde6..52991c58b8 100644 --- a/source/util/src/tpcre2.c +++ b/source/util/src/tpcre2.c @@ -8,7 +8,7 @@ int32_t doRegComp(pcre2_code** ppRegex, pcre2_match_data** ppMatchData, const ch *ppRegex = pcre2_compile((PCRE2_SPTR8)pattern, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL); if (*ppRegex == NULL) { PCRE2_UCHAR buffer[256]; - pcre2_get_error_message(errorcode, buffer, sizeof(buffer)); + (void)pcre2_get_error_message(errorcode, buffer, sizeof(buffer)); return 1; } @@ -22,7 +22,7 @@ int32_t doRegExec(const char* pString, pcre2_code* pRegex, pcre2_match_data* pMa ret = pcre2_match(pRegex, (PCRE2_SPTR)pString, PCRE2_ZERO_TERMINATED, 0, 0, pMatchData, NULL); if (ret < 0) { PCRE2_UCHAR buffer[256]; - pcre2_get_error_message(ret, buffer, sizeof(buffer)); + (void)pcre2_get_error_message(ret, buffer, sizeof(buffer)); return 1; } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index c6b029ea01..87d5680aa0 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -102,7 +102,7 @@ void taosCloseQueue(STaosQueue *queue) { taosMemoryFree(pTemp); } - taosThreadMutexDestroy(&queue->mutex); + (void)taosThreadMutexDestroy(&queue->mutex); taosMemoryFree(queue); uDebug("queue:%p is closed", queue); @@ -165,7 +165,7 @@ int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void ** if (alloced > tsRpcQueueMemoryAllowed) { uError("failed to alloc qitem, size:%" PRId64 " alloc:%" PRId64 " allowed:%" PRId64, size + dataSize, alloced, tsRpcQueueMemoryAllowed); - atomic_sub_fetch_64(&tsRpcQueueMemoryUsed, size + dataSize); + (void)atomic_sub_fetch_64(&tsRpcQueueMemoryUsed, size + dataSize); taosMemoryFree(pNode); return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE); } @@ -224,7 +224,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { queue->numOfItems++; queue->memOfItems += (pNode->size + pNode->dataSize); if (queue->qset) { - atomic_add_fetch_32(&queue->qset->numOfItems, 1); + (void)atomic_add_fetch_32(&queue->qset->numOfItems, 1); } uTrace("item:%p is put into queue:%p, items:%d mem:%" PRId64, pItem, queue, queue->numOfItems, queue->memOfItems); @@ -232,7 +232,7 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { (void)taosThreadMutexUnlock(&queue->mutex); if (queue->qset) { - tsem_post(&queue->qset->sem); + (void)tsem_post(&queue->qset->sem); } return code; } @@ -253,7 +253,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { queue->numOfItems--; queue->memOfItems -= (pNode->size + pNode->dataSize); if (queue->qset) { - atomic_sub_fetch_32(&queue->qset->numOfItems, 1); + (void)atomic_sub_fetch_32(&queue->qset->numOfItems, 1); } code = 1; uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems, @@ -301,7 +301,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, numOfItems, queue, queue->numOfItems, queue->memOfItems); if (queue->qset) { - atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems); + (void)atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems); } } @@ -344,8 +344,8 @@ int32_t taosOpenQset(STaosQset **qset) { return terrno = TSDB_CODE_OUT_OF_MEMORY; } - taosThreadMutexInit(&(*qset)->mutex, NULL); - tsem_init(&(*qset)->sem, 0, 0); + (void)taosThreadMutexInit(&(*qset)->mutex, NULL); + (void)tsem_init(&(*qset)->sem, 0, 0); uDebug("qset:%p is opened", qset); return 0; @@ -365,8 +365,8 @@ void taosCloseQset(STaosQset *qset) { } (void)taosThreadMutexUnlock(&qset->mutex); - taosThreadMutexDestroy(&qset->mutex); - tsem_destroy(&qset->sem); + (void)taosThreadMutexDestroy(&qset->mutex); + (void)tsem_destroy(&qset->sem); taosMemoryFree(qset); uDebug("qset:%p is closed", qset); } @@ -376,7 +376,7 @@ void taosCloseQset(STaosQset *qset) { // thread to exit. void taosQsetThreadResume(STaosQset *qset) { uDebug("qset:%p, it will exit", qset); - tsem_post(&qset->sem); + (void)tsem_post(&qset->sem); } int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) { @@ -390,7 +390,7 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) { qset->numOfQueues++; (void)taosThreadMutexLock(&queue->mutex); - atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems); + (void)atomic_add_fetch_32(&qset->numOfItems, queue->numOfItems); queue->qset = qset; (void)taosThreadMutexUnlock(&queue->mutex); @@ -428,7 +428,7 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) { qset->numOfQueues--; (void)taosThreadMutexLock(&queue->mutex); - atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems); + (void)atomic_sub_fetch_32(&qset->numOfItems, queue->numOfItems); queue->qset = NULL; queue->next = NULL; (void)taosThreadMutexUnlock(&queue->mutex); @@ -444,7 +444,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) STaosQnode *pNode = NULL; int32_t code = 0; - tsem_wait(&qset->sem); + (void)tsem_wait(&qset->sem); (void)taosThreadMutexLock(&qset->mutex); @@ -469,7 +469,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) if (queue->head == NULL) queue->tail = NULL; // queue->numOfItems--; queue->memOfItems -= (pNode->size + pNode->dataSize); - atomic_sub_fetch_32(&qset->numOfItems, 1); + (void)atomic_sub_fetch_32(&qset->numOfItems, 1); code = 1; uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems - 1, queue->memOfItems); @@ -488,7 +488,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * STaosQueue *queue; int32_t code = 0; - tsem_wait(&qset->sem); + (void)tsem_wait(&qset->sem); (void)taosThreadMutexLock(&qset->mutex); for (int32_t i = 0; i < qset->numOfQueues; ++i) { @@ -520,9 +520,9 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * queue->memOfItems = 0; uTrace("read %d items from queue:%p, items:0 mem:%" PRId64, code, queue, queue->memOfItems); - atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems); + (void)atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems); for (int32_t j = 1; j < qall->numOfItems; ++j) { - tsem_wait(&qset->sem); + (void)tsem_wait(&qset->sem); } } diff --git a/source/util/src/trbtree.c b/source/util/src/trbtree.c index e1000f7bc1..dddc2aea4b 100644 --- a/source/util/src/trbtree.c +++ b/source/util/src/trbtree.c @@ -412,7 +412,7 @@ void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *z) { pTree->max = tRBTreePredecessor(pTree, pTree->max); } - rbtree_delete(pTree, z); + (void)rbtree_delete(pTree, z); pTree->n--; } diff --git a/source/util/src/tref.c b/source/util/src/tref.c index fe55335fce..f1d9a24757 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -63,7 +63,7 @@ int32_t taosOpenRef(int32_t max, RefFp fp) { int64_t *lockedBy; int32_t i, rsetId; - taosThreadOnce(&tsRefModuleInit, taosInitRefModule); + (void)taosThreadOnce(&tsRefModuleInit, taosInitRefModule); nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max); if (nodeList == NULL) { @@ -450,7 +450,7 @@ static void taosLockList(int64_t *lockedBy) { int32_t i = 0; while (atomic_val_compare_exchange_64(lockedBy, 0, tid) != 0) { if (++i % 100 == 0) { - sched_yield(); + (void)sched_yield(); } } } @@ -462,10 +462,10 @@ static void taosUnlockList(int64_t *lockedBy) { } } -static void taosInitRefModule(void) { taosThreadMutexInit(&tsRefMutex, NULL); } +static void taosInitRefModule(void) { (void)taosThreadMutexInit(&tsRefMutex, NULL); } static void taosIncRsetCount(SRefSet *pSet) { - atomic_add_fetch_32(&pSet->count, 1); + (void)atomic_add_fetch_32(&pSet->count, 1); // uTrace("rsetId:%d inc count:%d", pSet->rsetId, count); } diff --git a/source/util/src/tskiplist.c b/source/util/src/tskiplist.c index 27e6fd6224..e5e52e44d9 100644 --- a/source/util/src/tskiplist.c +++ b/source/util/src/tskiplist.c @@ -103,7 +103,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ void tSkipListDestroy(SSkipList *pSkipList) { if (pSkipList == NULL) return; - tSkipListWLock(pSkipList); + (void)tSkipListWLock(pSkipList); SSkipListNode *pNode = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, 0); @@ -113,9 +113,9 @@ void tSkipListDestroy(SSkipList *pSkipList) { tSkipListFreeNode(pTemp); } - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); if (pSkipList->lock != NULL) { - taosThreadRwlockDestroy(pSkipList->lock); + (void)taosThreadRwlockDestroy(pSkipList->lock); taosMemoryFreeClear(pSkipList->lock); } @@ -130,12 +130,12 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) { SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0}; SSkipListNode *pNode = NULL; - tSkipListWLock(pSkipList); + (void)tSkipListWLock(pSkipList); bool hasDup = tSkipListGetPosToPut(pSkipList, backward, pData); pNode = tSkipListPutImpl(pSkipList, pData, backward, false, hasDup); - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); return pNode; } @@ -293,11 +293,11 @@ SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char * return iter; } - tSkipListRLock(pSkipList); + (void)tSkipListRLock(pSkipList); iter->cur = getPriorNode(pSkipList, val, order, &(iter->next)); - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); return iter; } @@ -307,13 +307,13 @@ bool tSkipListIterNext(SSkipListIterator *iter) { SSkipList *pSkipList = iter->pSkipList; - tSkipListRLock(pSkipList); + (void)tSkipListRLock(pSkipList); if (iter->order == TSDB_ORDER_ASC) { // no data in the skip list if (iter->cur == pSkipList->pTail || iter->next == NULL) { iter->cur = pSkipList->pTail; - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); return false; } @@ -329,7 +329,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) { } else { if (iter->cur == pSkipList->pHead) { iter->cur = pSkipList->pHead; - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); return false; } @@ -344,7 +344,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) { iter->step++; } - tSkipListUnlock(pSkipList); + (void)tSkipListUnlock(pSkipList); return (iter->order == TSDB_ORDER_ASC) ? (iter->cur != pSkipList->pTail) : (iter->cur != pSkipList->pHead); } diff --git a/source/util/src/tthread.c b/source/util/src/tthread.c index 17f49ea0a8..ee038f18f4 100644 --- a/source/util/src/tthread.c +++ b/source/util/src/tthread.c @@ -24,10 +24,10 @@ TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) { } TdThreadAttr thattr; - taosThreadAttrInit(&thattr); - taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thattr); + (void)taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); int32_t ret = taosThreadCreate(pthread, &thattr, __start_routine, param); - taosThreadAttrDestroy(&thattr); + (void)taosThreadAttrDestroy(&thattr); if (ret != 0) { taosMemoryFree(pthread); @@ -40,8 +40,8 @@ TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) { bool taosDestroyThread(TdThread* pthread) { if (pthread == NULL) return false; if (taosThreadRunning(pthread)) { - taosThreadCancel(*pthread); - taosThreadJoin(*pthread, NULL); + (void)taosThreadCancel(*pthread); + (void)taosThreadJoin(*pthread, NULL); } taosMemoryFree(pthread); diff --git a/source/util/src/ttimer.c b/source/util/src/ttimer.c index 777eb23caa..6ade226cd8 100644 --- a/source/util/src/ttimer.c +++ b/source/util/src/ttimer.c @@ -138,7 +138,7 @@ static uintptr_t getNextTimerId() { return id; } -static void timerAddRef(tmr_obj_t* timer) { atomic_add_fetch_8(&timer->refCount, 1); } +static void timerAddRef(tmr_obj_t* timer) { (void)atomic_add_fetch_8(&timer->refCount, 1); } static void timerDecRef(tmr_obj_t* timer) { if (atomic_sub_fetch_8(&timer->refCount, 1) == 0) { @@ -151,7 +151,7 @@ static void lockTimerList(timer_list_t* list) { int32_t i = 0; while (atomic_val_compare_exchange_64(&(list->lockedBy), 0, tid) != 0) { if (++i % 1000 == 0) { - sched_yield(); + (void)sched_yield(); } } } @@ -314,7 +314,7 @@ static void addToExpired(tmr_obj_t* head) { schedMsg.msg = NULL; schedMsg.ahandle = head; schedMsg.thandle = NULL; - taosScheduleTask(tmrQhandle, &schedMsg); + (void)taosScheduleTask(tmrQhandle, &schedMsg); tmrDebug("timer[id=%" PRIuPTR "] has been added to queue.", id); head = next; @@ -458,7 +458,7 @@ bool taosTmrStop(tmr_h timerId) { } uint8_t state = atomic_val_compare_exchange_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_CANCELED); - doStopTimer(timer, state); + (void)doStopTimer(timer, state); timerDecRef(timer); return state == TIMER_STATE_WAITING; @@ -501,7 +501,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* han // so that we can reuse this timer safely. for (int32_t i = 1; atomic_load_8(&timer->refCount) > 1; ++i) { if (i % 1000 == 0) { - sched_yield(); + (void)sched_yield(); } } @@ -528,7 +528,7 @@ static int32_t taosTmrModuleInit(void) { (tmrCtrls + tsMaxTmrCtrl - 1)->next = NULL; unusedTmrCtrl = tmrCtrls; - taosThreadMutexInit(&tmrCtrlMutex, NULL); + (void)taosThreadMutexInit(&tmrCtrlMutex, NULL); int64_t now = taosGetMonotonicMs(); for (int32_t i = 0; i < tListLen(wheels); i++) { @@ -555,7 +555,7 @@ static int32_t taosTmrModuleInit(void) { } tmrQhandle = taosInitScheduler(10000, taosTmrThreads, "tmr", NULL); - taosInitTimer(taosTimerLoopFunc, MSECONDS_PER_TICK); + (void)taosInitTimer(taosTimerLoopFunc, MSECONDS_PER_TICK); tmrDebug("timer module is initialized, number of threads: %d", taosTmrThreads); @@ -638,11 +638,11 @@ void taosTmrCleanUp(void* handle) { for (int32_t i = 0; i < tListLen(wheels); i++) { time_wheel_t* wheel = wheels + i; - taosThreadMutexDestroy(&wheel->mutex); + (void)taosThreadMutexDestroy(&wheel->mutex); taosMemoryFree(wheel->slots); } - taosThreadMutexDestroy(&tmrCtrlMutex); + (void)taosThreadMutexDestroy(&tmrCtrlMutex); for (size_t i = 0; i < timerMap.size; i++) { timer_list_t* list = timerMap.slots + i; diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index a14ea1a3cd..94f514e208 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -320,7 +320,7 @@ char *strbetween(char *string, char *begin, char *end) { int32_t size = (int32_t)(_end - _begin); if (_end != NULL && size > 0) { result = (char *)taosMemoryCalloc(1, size); - if (result) { + if (!result) { return NULL; } memcpy(result, _begin + strlen(begin), size - +strlen(begin)); diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 885813f527..d66628d46d 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -58,15 +58,15 @@ void tQWorkerCleanup(SQWorkerPool *pool) { SQueueWorker *worker = pool->workers + i; if (taosCheckPthreadValid(worker->thread)) { uInfo("worker:%s:%d is stopping", pool->name, worker->id); - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); uInfo("worker:%s:%d is stopped", pool->name, worker->id); } } taosMemoryFreeClear(pool->workers); taosCloseQset(pool->qset); - taosThreadMutexDestroy(&pool->mutex); + (void)taosThreadMutexDestroy(&pool->mutex); uInfo("worker:%s is closed", pool->name); } @@ -77,7 +77,7 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) { void *msg = NULL; int32_t code = 0; - taosBlockSIGPIPE(); + (void)taosBlockSIGPIPE(); setThreadName(pool->name); worker->pid = taosGetSelfPthreadId(); uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); @@ -122,7 +122,7 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { (void)taosThreadMutexLock(&pool->mutex); taosSetQueueFp(queue, fp, NULL); - taosAddIntoQset(pool->qset, queue, ahandle); + (void)taosAddIntoQset(pool->qset, queue, ahandle); // spawn a thread to process queue if (pool->num < pool->max) { @@ -130,8 +130,8 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { SQueueWorker *worker = pool->workers + pool->num; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tQWorkerThreadFp, worker) != 0) { taosCloseQueue(queue); @@ -140,7 +140,7 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { break; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); pool->num++; uInfo("worker:%s:%d is launched, total:%d", pool->name, worker->id, pool->num); } while (pool->num < pool->min); @@ -190,8 +190,8 @@ void tAutoQWorkerCleanup(SAutoQWorkerPool *pool) { SQueueWorker *worker = taosArrayGetP(pool->workers, i); if (taosCheckPthreadValid(worker->thread)) { uInfo("worker:%s:%d is stopping", pool->name, worker->id); - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); uInfo("worker:%s:%d is stopped", pool->name, worker->id); } taosMemoryFree(worker); @@ -199,7 +199,7 @@ void tAutoQWorkerCleanup(SAutoQWorkerPool *pool) { taosArrayDestroy(pool->workers); taosCloseQset(pool->qset); - taosThreadMutexDestroy(&pool->mutex); + (void)taosThreadMutexDestroy(&pool->mutex); uInfo("worker:%s is closed", pool->name); } @@ -210,7 +210,7 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) { void *msg = NULL; int32_t code = 0; - taosBlockSIGPIPE(); + (void)taosBlockSIGPIPE(); setThreadName(pool->name); worker->pid = taosGetSelfPthreadId(); uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); @@ -253,7 +253,7 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem (void)taosThreadMutexLock(&pool->mutex); taosSetQueueFp(queue, fp, NULL); - taosAddIntoQset(pool->qset, queue, ahandle); + (void)taosAddIntoQset(pool->qset, queue, ahandle); int32_t queueNum = taosGetQueueNumber(pool->qset); int32_t curWorkerNum = taosArrayGetSize(pool->workers); @@ -275,8 +275,8 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem worker->pool = pool; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tAutoQWorkerThreadFp, worker) != 0) { uError("worker:%s:%d failed to create thread, total:%d", pool->name, worker->id, curWorkerNum); @@ -287,7 +287,7 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem return NULL; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); int32_t numOfThreads = taosArrayGetSize(pool->workers); uInfo("worker:%s:%d is launched, total:%d, expect:%d", pool->name, worker->id, numOfThreads, dstWorkerNum); @@ -340,8 +340,8 @@ void tWWorkerCleanup(SWWorkerPool *pool) { SWWorker *worker = pool->workers + i; if (taosCheckPthreadValid(worker->thread)) { uInfo("worker:%s:%d is stopping", pool->name, worker->id); - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); taosFreeQall(worker->qall); taosCloseQset(worker->qset); uInfo("worker:%s:%d is stopped", pool->name, worker->id); @@ -349,7 +349,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) { } taosMemoryFreeClear(pool->workers); - taosThreadMutexDestroy(&pool->mutex); + (void)taosThreadMutexDestroy(&pool->mutex); uInfo("worker:%s is closed", pool->name); } @@ -361,7 +361,7 @@ static void *tWWorkerThreadFp(SWWorker *worker) { int32_t code = 0; int32_t numOfMsgs = 0; - taosBlockSIGPIPE(); + (void)taosBlockSIGPIPE(); setThreadName(pool->name); worker->pid = taosGetSelfPthreadId(); uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); @@ -406,23 +406,23 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { code = taosOpenQset(&worker->qset); if (code) goto _OVER; - taosAddIntoQset(worker->qset, queue, ahandle); + (void)taosAddIntoQset(worker->qset, queue, ahandle); code = taosAllocateQall(&worker->qall); if (code) goto _OVER; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) goto _OVER; uInfo("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); pool->nextId = (pool->nextId + 1) % pool->max; - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); pool->num++; if (pool->num > pool->max) pool->num = pool->max; } else { - taosAddIntoQset(worker->qset, queue, ahandle); + (void)taosAddIntoQset(worker->qset, queue, ahandle); pool->nextId = (pool->nextId + 1) % pool->max; } @@ -628,7 +628,7 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) { void *msg = NULL; int32_t code = 0; - taosBlockSIGPIPE(); + (void)taosBlockSIGPIPE(); setThreadName(pool->name); worker->pid = taosGetSelfPthreadId(); uDebug("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); @@ -647,7 +647,7 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) { } } - tQueryAutoQWorkerWaitingCheck(pool); + (void)tQueryAutoQWorkerWaitingCheck(pool); if (qinfo.fp != NULL) { qinfo.workerId = worker->id; @@ -676,7 +676,7 @@ static bool tQueryAutoQWorkerTrySignalWaitingAfterBlock(void *p) { int32_t waitingNew = atomic_val_compare_exchange_32(&pPool->waitingAfterBlockN, waiting, waiting - 1); if (waitingNew == waiting) { (void)taosThreadMutexLock(&pPool->waitingAfterBlockLock); - taosThreadCondSignal(&pPool->waitingAfterBlockCond); + (void)taosThreadCondSignal(&pPool->waitingAfterBlockCond); (void)taosThreadMutexUnlock(&pPool->waitingAfterBlockLock); ret = true; break; @@ -694,7 +694,7 @@ static bool tQueryAutoQWorkerTrySignalWaitingBeforeProcess(void *p) { int32_t waitingNew = atomic_val_compare_exchange_32(&pPool->waitingBeforeProcessMsgN, waiting, waiting - 1); if (waitingNew == waiting) { (void)taosThreadMutexLock(&pPool->waitingBeforeProcessMsgLock); - taosThreadCondSignal(&pPool->waitingBeforeProcessMsgCond); + (void)taosThreadCondSignal(&pPool->waitingBeforeProcessMsgCond); (void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock); ret = true; break; @@ -713,7 +713,7 @@ static bool tQueryAutoQWorkerTryDecActive(void *p, int32_t minActive) { if (atomicCompareExchangeActiveAndRunning(&pPool->activeRunningN, &active, active - 1, &running, running - 1)) return true; } - atomicFetchSubRunning(&pPool->activeRunningN, 1); + (void)atomicFetchSubRunning(&pPool->activeRunningN, 1); return false; } @@ -732,8 +732,8 @@ static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) { } // to wait for process (void)taosThreadMutexLock(&pPool->waitingBeforeProcessMsgLock); - atomic_fetch_add_32(&pPool->waitingBeforeProcessMsgN, 1); - if (!pPool->exit) taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock); + (void)atomic_fetch_add_32(&pPool->waitingBeforeProcessMsgN, 1); + if (!pPool->exit) (void)taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock); // recovered from waiting (void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock); return TSDB_CODE_SUCCESS; @@ -744,15 +744,15 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ tQueryAutoQWorkerTryDecActive(pPool, pPool->num)) { (void)taosThreadMutexLock(&pPool->poolLock); SListNode *pNode = listNode(pWorker); - tdListPopNode(pPool->workers, pNode); + (void)tdListPopNode(pPool->workers, pNode); // reclaim some workers if (pWorker->id >= pPool->maxInUse) { while (listNEles(pPool->exitedWorkers) > pPool->maxInUse - pPool->num) { SListNode *head = tdListPopHead(pPool->exitedWorkers); SQueryAutoQWorker *pWorker = (SQueryAutoQWorker *)head->data; if (pWorker && taosCheckPthreadValid(pWorker->thread)) { - taosThreadJoin(pWorker->thread, NULL); - taosThreadClear(&pWorker->thread); + (void)taosThreadJoin(pWorker->thread, NULL); + (void)taosThreadClear(&pWorker->thread); } taosMemoryFree(head); } @@ -767,8 +767,8 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ // start to wait at backup cond (void)taosThreadMutexLock(&pPool->backupLock); - atomic_fetch_add_32(&pPool->backupNum, 1); - if (!pPool->exit) taosThreadCondWait(&pPool->backupCond, &pPool->backupLock); + (void)atomic_fetch_add_32(&pPool->backupNum, 1); + if (!pPool->exit) (void)taosThreadCondWait(&pPool->backupCond, &pPool->backupLock); (void)taosThreadMutexUnlock(&pPool->backupLock); // recovered from backup @@ -777,7 +777,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ (void)taosThreadMutexUnlock(&pPool->poolLock); return false; } - tdListPopNode(pPool->backupWorkers, pNode); + (void)tdListPopNode(pPool->backupWorkers, pNode); tdListAppendNode(pPool->workers, pNode); (void)taosThreadMutexUnlock(&pPool->poolLock); @@ -832,15 +832,15 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) { (void)taosThreadMutexUnlock(&pPool->poolLock); (void)taosThreadMutexLock(&pPool->backupLock); - taosThreadCondBroadcast(&pPool->backupCond); + (void)taosThreadCondBroadcast(&pPool->backupCond); (void)taosThreadMutexUnlock(&pPool->backupLock); (void)taosThreadMutexLock(&pPool->waitingAfterBlockLock); - taosThreadCondBroadcast(&pPool->waitingAfterBlockCond); + (void)taosThreadCondBroadcast(&pPool->waitingAfterBlockCond); (void)taosThreadMutexUnlock(&pPool->waitingAfterBlockLock); (void)taosThreadMutexLock(&pPool->waitingBeforeProcessMsgLock); - taosThreadCondBroadcast(&pPool->waitingBeforeProcessMsgCond); + (void)taosThreadCondBroadcast(&pPool->waitingBeforeProcessMsgCond); (void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock); int32_t idx = 0; @@ -855,8 +855,8 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) { worker = (SQueryAutoQWorker *)pNode->data; (void)taosThreadMutexUnlock(&pPool->poolLock); if (worker && taosCheckPthreadValid(worker->thread)) { - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); } taosMemoryFree(pNode); } @@ -865,8 +865,8 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) { SListNode *pNode = tdListPopHead(pPool->backupWorkers); worker = (SQueryAutoQWorker *)pNode->data; if (worker && taosCheckPthreadValid(worker->thread)) { - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); } taosMemoryFree(pNode); } @@ -875,25 +875,25 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) { SListNode *pNode = tdListPopHead(pPool->exitedWorkers); worker = (SQueryAutoQWorker *)pNode->data; if (worker && taosCheckPthreadValid(worker->thread)) { - taosThreadJoin(worker->thread, NULL); - taosThreadClear(&worker->thread); + (void)taosThreadJoin(worker->thread, NULL); + (void)taosThreadClear(&worker->thread); } taosMemoryFree(pNode); } - tdListFree(pPool->workers); - tdListFree(pPool->backupWorkers); - tdListFree(pPool->exitedWorkers); + (void)tdListFree(pPool->workers); + (void)tdListFree(pPool->backupWorkers); + (void)tdListFree(pPool->exitedWorkers); taosMemoryFree(pPool->pCb); - taosThreadMutexDestroy(&pPool->poolLock); - taosThreadMutexDestroy(&pPool->backupLock); - taosThreadMutexDestroy(&pPool->waitingAfterBlockLock); - taosThreadMutexDestroy(&pPool->waitingBeforeProcessMsgLock); + (void)taosThreadMutexDestroy(&pPool->poolLock); + (void)taosThreadMutexDestroy(&pPool->backupLock); + (void)taosThreadMutexDestroy(&pPool->waitingAfterBlockLock); + (void)taosThreadMutexDestroy(&pPool->waitingBeforeProcessMsgLock); - taosThreadCondDestroy(&pPool->backupCond); - taosThreadCondDestroy(&pPool->waitingAfterBlockCond); - taosThreadCondDestroy(&pPool->waitingBeforeProcessMsgCond); + (void)taosThreadCondDestroy(&pPool->backupCond); + (void)taosThreadCondDestroy(&pPool->waitingAfterBlockCond); + (void)taosThreadCondDestroy(&pPool->waitingBeforeProcessMsgCond); taosCloseQset(pPool->qset); } @@ -907,7 +907,7 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand (void)taosThreadMutexLock(&pool->poolLock); taosSetQueueFp(queue, fp, NULL); - taosAddIntoQset(pool->qset, queue, ahandle); + (void)taosAddIntoQset(pool->qset, queue, ahandle); SQueryAutoQWorker worker = {0}; SQueryAutoQWorker *pWorker = NULL; @@ -927,8 +927,8 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand pWorker = (SQueryAutoQWorker *)pNode->data; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pWorker->thread, &thAttr, (ThreadFp)tQueryAutoQWorkerThreadFp, pWorker) != 0) { taosCloseQueue(queue); @@ -937,9 +937,9 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand break; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); pool->num++; - atomicFetchAddActive(&pool->activeRunningN, 1); + (void)atomicFetchAddActive(&pool->activeRunningN, 1); uInfo("worker:%s:%d is launched, total:%d", pool->name, pWorker->id, pool->num); } while (pool->num < pool->min); } @@ -958,7 +958,7 @@ static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool) { while (backup > 0) { int32_t backupNew = atomic_val_compare_exchange_32(&pool->backupNum, backup, backup - 1); if (backupNew == backup) { - taosThreadCondSignal(&pool->backupCond); + (void)taosThreadCondSignal(&pool->backupCond); return TSDB_CODE_SUCCESS; } backup = backupNew; @@ -980,14 +980,14 @@ static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool) { pWorker = (SQueryAutoQWorker *)pNode->data; TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + (void)taosThreadAttrInit(&thAttr); + (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&pWorker->thread, &thAttr, (ThreadFp)tQueryAutoQWorkerThreadFp, pWorker) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } - taosThreadAttrDestroy(&thAttr); + (void)taosThreadAttrDestroy(&thAttr); return TSDB_CODE_SUCCESS; } @@ -1016,8 +1016,8 @@ static int32_t tQueryAutoQWorkerRecoverFromBlocking(void *p) { } } (void)taosThreadMutexLock(&pPool->waitingAfterBlockLock); - atomic_fetch_add_32(&pPool->waitingAfterBlockN, 1); - if (!pPool->exit) taosThreadCondWait(&pPool->waitingAfterBlockCond, &pPool->waitingAfterBlockLock); + (void)atomic_fetch_add_32(&pPool->waitingAfterBlockN, 1); + if (!pPool->exit) (void)taosThreadCondWait(&pPool->waitingAfterBlockCond, &pPool->waitingAfterBlockLock); (void)taosThreadMutexUnlock(&pPool->waitingAfterBlockLock); if (pPool->exit) return TSDB_CODE_QRY_QWORKER_QUIT; return TSDB_CODE_SUCCESS; diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index c0f1d6e443..e3f5e54698 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -560,6 +560,8 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/max.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/min.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/min.py -R +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/normal.py +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/normal.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/mode.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/mode.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/Now.py @@ -739,6 +741,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/Today.py -Q 2 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/max.py -Q 2 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/min.py -Q 2 +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/normal.py -Q 2 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/mode.py -Q 2 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count.py -Q 2 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2 @@ -837,6 +840,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/Today.py -Q 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/max.py -Q 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/min.py -Q 3 +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/normal.py -Q 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/mode.py -Q 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count.py -Q 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3 @@ -934,6 +938,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/Today.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/max.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/min.py -Q 4 +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/normal.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/mode.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/count.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4 diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index 38adae4261..0d92070d10 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -189,11 +189,11 @@ run tsim/stream/checkTaskStatus.sim sql insert into t2 values(1648791213001,1,1,3,1.0,1); sql insert into t2 values(1648791213002,2,2,6,3.4,2); sql insert into t2 values(1648791213003,4,9,3,4.8,3); -sql insert into t2 values(1648791233003,3,4,3,2.1,4); -sql insert into t2 values(1648791233004,3,5,3,3.4,5); -sql insert into t2 values(1648791233005,3,6,3,7.6,6); -# +sql insert into t2 values(1648791233003,3,4,3,2.1,4) (1648791233004,3,5,3,3.4,5) (1648791233005,3,6,3,7.6,6); + +sleep 1000 + sql insert into t2 values(1648791223003,20,7,3,10.1,7); $loop_count = 0 diff --git a/tests/system-test/2-query/ceil.py b/tests/system-test/2-query/ceil.py index aabc716a74..e719d819d8 100644 --- a/tests/system-test/2-query/ceil.py +++ b/tests/system-test/2-query/ceil.py @@ -57,7 +57,7 @@ class TDTestCase: ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, -0.444, 44.44, 1, "binary4", "nchar4", now()+4a ) ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) @@ -223,6 +223,9 @@ class TDTestCase: tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) + tdSql.query(f"select ceil(c5) from {dbname}.t1") + tdSql.checkData(4 , 0, 0) + self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from {dbname}.t1") # used for sub table diff --git a/tests/system-test/2-query/distinct.py b/tests/system-test/2-query/distinct.py index 5c07544d5d..5025b39753 100644 --- a/tests/system-test/2-query/distinct.py +++ b/tests/system-test/2-query/distinct.py @@ -144,8 +144,8 @@ class TDTestCase: tdSql.query(f"select distinct c1, c2 from (select c2, c1 from {dbname}.stb1 where c1 > 2 order by ts)") tdSql.query(f"select distinct c1, c2 from (select c2, c1 from {dbname}.t1 where c1 > 2 order by ts)") tdSql.error(f"select distinct c1, c2 from (select c2, c1 from {dbname}.stb1 where c1 > 2 group by c1)") - tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.stb1 group by c1)") - tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.t1 group by c1)") + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.stb1 group by stb1.c1)") + tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.t1 group by t1.c1)") tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.stb1 )") tdSql.checkRows(1) tdSql.query(f"select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from {dbname}.t1 )") @@ -245,7 +245,7 @@ class TDTestCase: tdSql.query(f"select distinct t1 from (select t0, t1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") tdSql.checkRows(1) tdSql.error(f"select distinct t1, t0 from (select t1 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") - tdSql.query(f"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from {dbname}.stb1 group by t1)") + tdSql.query(f"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from {dbname}.stb1 group by stb1.t1)") tdSql.query(f"select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from {dbname}.stb1)") tdSql.query(f"select distinct t1, t0 from (select t1,t0 from {dbname}.stb1 where t0 > 2 ) where t1 < 3") tdSql.checkRows(1) diff --git a/tests/system-test/2-query/explain.py b/tests/system-test/2-query/explain.py index 92cd28a929..55f484884c 100644 --- a/tests/system-test/2-query/explain.py +++ b/tests/system-test/2-query/explain.py @@ -77,7 +77,7 @@ class TDTestCase: ) query_condition.extend( ( - 1010, + 1010.1, ''' "test1234!@#$%^&*():'> 0: num = self.row_nums tdSql.checkRows(num) + + tdSql.query(f"select c1, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by c1 having c1 >= 0") + num = 0 + if nonempty_tb_num > 0: + num = self.row_nums + tdSql.checkRows(num) tdSql.query(f"select ts, count(*) from {self.dbname}.{self.stable} {keyword} by ts ") tdSql.checkRows(nonempty_tb_num * self.row_nums) @@ -91,6 +97,157 @@ class TDTestCase: tdSql.query(f"select t2, t3, c1, count(*) from {self.dbname}.{self.stable} {keyword} by t2, t3, c1 ") tdSql.checkRows(nonempty_tb_num * self.row_nums) + def test_groupby_position(self, keyword, check_num, nonempty_tb_num): + ####### by tbname + tdSql.query(f"select tbname, count(*) from {self.dbname}.{self.stable} {keyword} by 1 ") + tdSql.checkRows(check_num) + + tdSql.query(f"select tbname from {self.dbname}.{self.stable} {keyword} by 1 order by count(*)") + tdSql.checkRows(check_num) + + # last + tdSql.query(f"select tbname from {self.dbname}.{self.stable} {keyword} by 1 having count(*)>=0") + tdSql.checkRows(check_num) + + # having filter out empty + tdSql.query(f"select tbname, count(*) from {self.dbname}.{self.stable} {keyword} by 1 having count(*) <= 0") + tdSql.checkRows(check_num - nonempty_tb_num) + + ####### by tag + tdSql.query(f"select t2, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by 1 ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2, count(*) from {self.dbname}.{self.stable} {keyword} by 1 having count(*) <= 0") + tdSql.checkRows(check_num - nonempty_tb_num) + + # where + tdSql.query(f"select t2, count(*) from {self.dbname}.{self.stable} where ts < now {keyword} by 1 ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2, count(*) from {self.dbname}.{self.stable} where ts > 1737146000000 {keyword} by 1 ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2, count(*) from {self.dbname}.{self.stable} where c1 = 1 {keyword} by 1 ") + tdSql.checkRows(check_num) + + ####### by col + tdSql.query(f"select c1, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by 1 ") + num = 0 + if nonempty_tb_num > 0: + num = self.row_nums + tdSql.checkRows(num) + + tdSql.query(f"select ts, count(*) from {self.dbname}.{self.stable} {keyword} by 1 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + # col + tag + tdSql.query(f"select t2, c1, count(*) from {self.dbname}.{self.stable} {keyword} by 1, 2 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2, c1, count(*) from {self.dbname}.{self.stable} {keyword} by 1, c1 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2, c1, count(*) from {self.dbname}.{self.stable} {keyword} by t2, 2 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + tdSql.query(f"select t2, t3, c1, count(*) from {self.dbname}.{self.stable} {keyword} by 1, 2, 3 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2, t3, c1, count(*) from {self.dbname}.{self.stable} {keyword} by t2, 2, 3 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2, t3, c1, count(*) from {self.dbname}.{self.stable} {keyword} by 1, t3, 3 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + tdSql.query(f"select sum(t0.sumc2) from (select c1, sum(c2) as sumc2 from {self.dbname}.{self.stable} {keyword} by 1) t0") + num = 0 + if nonempty_tb_num > 0: + num = 1 + tdSql.checkRows(num) + + tdSql.query(f"select abs(c1), count(*) from {self.dbname}.{self.stable} {keyword} by 1") + num = 0 + if nonempty_tb_num > 0: + num = self.row_nums + tdSql.checkRows(num) + + ####### error case + tdSql.error(f"select c1, count(*) from {self.dbname}.{self.stable} {keyword} by 10") + tdSql.error(f"select c1, count(*) from {self.dbname}.{self.stable} {keyword} by 0") + tdSql.error(f"select c1, c2, count(*) from {self.dbname}.{self.stable} {keyword} by 0, 1") + tdSql.error(f"select c1, count(*) from {self.dbname}.{self.stable} {keyword} by 1.2") + tdSql.error(f"select c1, c2, c3, count(*) from {self.dbname}.{self.stable} {keyword} by 1, 2.2, 3") + tdSql.error(f"select c1, c2, count(*) from {self.dbname}.{self.stable} {keyword} by 1") + tdSql.error(f"select c1, avg(c2), count(*) from {self.dbname}.{self.stable} {keyword} by 1, 2") + + def test_groupby_alias(self, keyword, check_num, nonempty_tb_num): + tdSql.query(f"select t1 as t1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t1_alias ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t1 as t1_alias from {self.dbname}.{self.stable} {keyword} by t1_alias order by count(*)") + tdSql.checkRows(check_num) + + # last + tdSql.query(f"select t1 as t1_alias from {self.dbname}.{self.stable} {keyword} by t1_alias having count(*)>=0") + tdSql.checkRows(check_num) + + # having filter out empty + tdSql.query(f"select t1 as t1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t1_alias having count(*) <= 0") + tdSql.checkRows(check_num - nonempty_tb_num) + + ####### by tag + tdSql.query(f"select t2 as t2_alias, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by t2_alias ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2 as t2_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t2_alias having count(*) <= 0") + tdSql.checkRows(check_num - nonempty_tb_num) + + # where + tdSql.query(f"select t2 as t2_alias, count(*) from {self.dbname}.{self.stable} where ts < now {keyword} by t2_alias ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2 as t2_alias, count(*) from {self.dbname}.{self.stable} where ts > 1737146000000 {keyword} by t2_alias ") + tdSql.checkRows(check_num) + + tdSql.query(f"select t2 as t2_alias, count(*) from {self.dbname}.{self.stable} where c1 = 1 {keyword} by t2_alias ") + tdSql.checkRows(check_num) + + ####### by col + tdSql.query(f"select c1 as c1_alias, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by c1_alias ") + num = 0 + if nonempty_tb_num > 0: + num = self.row_nums + tdSql.checkRows(num) + + tdSql.query(f"select ts as ts_alias, count(*) from {self.dbname}.{self.stable} {keyword} by ts_alias ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + # col + tag + tdSql.query(f"select t2 as t2_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by 1, 2 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2 as t2_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by 1, c1 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2 as t2_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t2, 2 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + tdSql.query(f"select t2 as t2_alias, t3 as t3_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t2_alias, t3_alias, 3 ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2 as t2_alias, t3 as t3_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t2, t3_alias, c1_alias ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + tdSql.query(f"select t2 as t2_alias, t3 as t3_alias, c1 as c1_alias, count(*) from {self.dbname}.{self.stable} {keyword} by t2_alias, t3, c1_alias ") + tdSql.checkRows(nonempty_tb_num * self.row_nums) + + tdSql.query(f"select sum(t0.sumc2) from (select c1 as c1_alias, sum(c2) as sumc2 from {self.dbname}.{self.stable} {keyword} by c1_alias) t0") + num = 0 + if nonempty_tb_num > 0: + num = 1 + tdSql.checkRows(num) + + tdSql.query(f"select abs(c1) as abs_alias, count(*) from {self.dbname}.{self.stable} {keyword} by abs_alias") + num = 0 + if nonempty_tb_num > 0: + num = self.row_nums + tdSql.checkRows(num) + + ####### error case + tdSql.error(f"select c1, avg(c2) as avg_alias, count(*) from {self.dbname}.{self.stable} {keyword} by 1, avg_alias") + def test_groupby_sub_table(self): for i in range(self.tb_nums): tbname = f"{self.dbname}.sub_{self.stable}_{i}" @@ -270,6 +427,10 @@ class TDTestCase: # empty table only self.test_groupby('group', self.tb_nums, 0) self.test_groupby('partition', self.tb_nums, 0) + self.test_groupby_position('group', self.tb_nums, 0) + self.test_groupby_position('partition', self.tb_nums, 0) + self.test_groupby_alias('group', self.tb_nums, 0) + self.test_groupby_alias('partition', self.tb_nums, 0) self.test_innerSelect(self.tb_nums) self.test_multi_group_key(self.tb_nums, 0) self.test_multi_agg(self.tb_nums, 0) @@ -281,6 +442,10 @@ class TDTestCase: self.test_groupby('group', self.tb_nums, nonempty_tb_num) self.test_groupby('partition', self.tb_nums, nonempty_tb_num) + self.test_groupby_position('group', self.tb_nums, nonempty_tb_num) + self.test_groupby_position('partition', self.tb_nums, nonempty_tb_num) + self.test_groupby_alias('group', self.tb_nums, nonempty_tb_num) + self.test_groupby_alias('partition', self.tb_nums, nonempty_tb_num) self.test_groupby_sub_table() self.test_innerSelect(self.tb_nums) self.test_multi_group_key(self.tb_nums, nonempty_tb_num) diff --git a/tests/system-test/2-query/leastsquares.py b/tests/system-test/2-query/leastsquares.py index 3dfd1f6aca..91cd02bf8f 100644 --- a/tests/system-test/2-query/leastsquares.py +++ b/tests/system-test/2-query/leastsquares.py @@ -77,7 +77,7 @@ class TDTestCase: ) query_condition.extend( ( - 1010, + 1010.1, ''' "test1234!@#$%^&*():'> 0 and col2 > 0 from stb') + tdSql.checkRows(12) def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/round.py b/tests/system-test/2-query/round.py index d647f516ae..f87f234fa3 100644 --- a/tests/system-test/2-query/round.py +++ b/tests/system-test/2-query/round.py @@ -53,7 +53,7 @@ class TDTestCase: ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, -0.444, 44.44, 1, "binary4", "nchar4", now()+4a ) ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) @@ -232,6 +232,9 @@ class TDTestCase: tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) + tdSql.query(f"select round(c5) from {dbname}.t1") + tdSql.checkData(4 , 0, 0) + self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select (c1), round(c2) ,round(c3), round(c4), round(c5) from {dbname}.t1") # used for sub table diff --git a/tests/system-test/2-query/spread.py b/tests/system-test/2-query/spread.py index 61fe6793f9..8a8843548b 100644 --- a/tests/system-test/2-query/spread.py +++ b/tests/system-test/2-query/spread.py @@ -75,7 +75,7 @@ class TDTestCase: ) query_condition.extend( ( - 1010, + 1010.1, ) ) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index f449597841..5abd58d3f9 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -42,8 +42,7 @@ class TDTestCase: sum_condition.extend( f"{num_col} + {num_col_2}" for num_col_2 in NUM_COL ) sum_condition.extend( f"{num_col} + {un_num_col} " for un_num_col in UN_NUM_COL ) - sum_condition.append(1) - + sum_condition.append(1.1) return sum_condition def __where_condition(self, col): diff --git a/tests/system-test/2-query/td-28068.py b/tests/system-test/2-query/td-28068.py index 0a7e75fef2..e7d1682890 100644 --- a/tests/system-test/2-query/td-28068.py +++ b/tests/system-test/2-query/td-28068.py @@ -20,32 +20,32 @@ class TDTestCase: tdSql.execute("insert into td_28068.ct4 using td_28068.st (branch, scenario) tags ('3.1', 'scenario2') values (1717122950000, 'query1', 9,10);") def run(self): - tdSql.query('select last(ts) as ts, last(branch) as branch, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch);') + tdSql.query('select last(ts) as ts, last(branch) as branch, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by last(branch);') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch), last(scenario); ') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by last(branch), last(scenario); ') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch); ') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by last(branch); ') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) from td_28068.st group by branch, scenario order by last(branch), last(test_case);') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario, last(test_case) from td_28068.st group by st.branch, st.scenario order by last(branch), last(test_case);') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by branch, scenario order by last(branch), last(scenario);') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by last(branch), last(scenario);') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by branch, scenario order by branch1, scenario1;') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by branch1, scenario1;') tdSql.checkRows(4) tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by tbname; ') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by branch, scenario order by test_case;') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case from td_28068.st group by st.branch, st.scenario order by test_case;') tdSql.checkRows(4) - tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case1 from td_28068.st group by branch, scenario order by last(test_case);') + tdSql.query('select last(ts) as ts, last(branch) as branch1, last(scenario) as scenario1, last(test_case) as test_case1 from td_28068.st group by st.branch, st.scenario order by last(test_case);') tdSql.checkRows(4) - tdSql.query('select time_cost, num, time_cost + num as final_cost from td_28068.st partition by branch; ') + tdSql.query('select time_cost, num, time_cost + num as final_cost from td_28068.st partition by st.branch; ') tdSql.checkRows(8) tdSql.query('select count(*) from td_28068.st partition by branch order by branch; ') diff --git a/tests/system-test/2-query/tsma2.py b/tests/system-test/2-query/tsma2.py index ded30412a5..5af75b6fb9 100644 --- a/tests/system-test/2-query/tsma2.py +++ b/tests/system-test/2-query/tsma2.py @@ -615,6 +615,8 @@ class TDTestCase: self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) + tdSql.execute('alter local "debugFlag" "143"') + tdSql.execute('alter dnode 1 "debugFlag" "143"') self.tsma_tester: TSMATester = TSMATester(tdSql) self.tsma_sql_generator: TSMATestSQLGenerator = TSMATestSQLGenerator() diff --git a/tests/system-test/8-stream/snode_restart_with_checkpoint.py b/tests/system-test/8-stream/snode_restart_with_checkpoint.py index 9eb8c09ca3..28875df035 100644 --- a/tests/system-test/8-stream/snode_restart_with_checkpoint.py +++ b/tests/system-test/8-stream/snode_restart_with_checkpoint.py @@ -51,7 +51,9 @@ class TDTestCase: for i in range(rowCnt): results.append(tdSql.getData(i,1)) - tdSql.query("select * from st1 order by groupid,_wstart") + sql = "select * from st1 order by groupid,_wstart" + tdSql.check_rows_loop(rowCnt, sql, loopCount=100, waitTime=0.5) + tdSql.checkRows(rowCnt) for i in range(rowCnt): data1 = tdSql.getData(i,1) diff --git a/tests/system-test/8-stream/stream_multi_agg.py b/tests/system-test/8-stream/stream_multi_agg.py index 1386814f0c..ede3ef427a 100644 --- a/tests/system-test/8-stream/stream_multi_agg.py +++ b/tests/system-test/8-stream/stream_multi_agg.py @@ -41,8 +41,9 @@ class TDTestCase: time.sleep(10) tdSql.execute("use test", queryTimes=100) tdSql.query("create stream if not exists s1 trigger at_once ignore expired 0 ignore update 0 fill_history 1 into st1 as select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s)") - tdLog.debug("========create stream and insert data ok========") + time.sleep(5) + tdLog.debug("========create stream and insert data ok========") tdSql.query("select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s) order by groupid,_wstart") rowCnt = tdSql.getRows() results_meters = tdSql.queryResult diff --git a/tests/system-test/runAllOne.sh b/tests/system-test/runAllOne.sh index 79fc2cd363..3bb128ea28 100644 --- a/tests/system-test/runAllOne.sh +++ b/tests/system-test/runAllOne.sh @@ -243,6 +243,8 @@ python3 ./test.py -f 2-query/max.py -P python3 ./test.py -f 2-query/max.py -P -R python3 ./test.py -f 2-query/min.py -P python3 ./test.py -f 2-query/min.py -P -R +python3 ./test.py -f 2-query/normal.py -P +python3 ./test.py -f 2-query/normal.py -P -R python3 ./test.py -f 2-query/mode.py -P python3 ./test.py -f 2-query/mode.py -P -R python3 ./test.py -f 2-query/Now.py -P @@ -424,6 +426,7 @@ python3 ./test.py -f 2-query/Now.py -P -Q 2 python3 ./test.py -f 2-query/Today.py -P -Q 2 python3 ./test.py -f 2-query/max.py -P -Q 2 python3 ./test.py -f 2-query/min.py -P -Q 2 +python3 ./test.py -f 2-query/normal.py -P -Q 2 python3 ./test.py -f 2-query/mode.py -P -Q 2 python3 ./test.py -f 2-query/count.py -P -Q 2 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 2 @@ -522,6 +525,7 @@ python3 ./test.py -f 2-query/Now.py -P -Q 3 python3 ./test.py -f 2-query/Today.py -P -Q 3 python3 ./test.py -f 2-query/max.py -P -Q 3 python3 ./test.py -f 2-query/min.py -P -Q 3 +python3 ./test.py -f 2-query/normal.py -P -Q 3 python3 ./test.py -f 2-query/mode.py -P -Q 3 python3 ./test.py -f 2-query/count.py -P -Q 3 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 3 @@ -619,6 +623,7 @@ python3 ./test.py -f 2-query/Now.py -P -Q 4 python3 ./test.py -f 2-query/Today.py -P -Q 4 python3 ./test.py -f 2-query/max.py -P -Q 4 python3 ./test.py -f 2-query/min.py -P -Q 4 +python3 ./test.py -f 2-query/normal.py -P -Q 4 python3 ./test.py -f 2-query/mode.py -P -Q 4 python3 ./test.py -f 2-query/count.py -P -Q 4 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -P -Q 4 diff --git a/tests/system-test/simpletest.bat b/tests/system-test/simpletest.bat index 31b76cad4a..a1f7273ad4 100644 --- a/tests/system-test/simpletest.bat +++ b/tests/system-test/simpletest.bat @@ -46,6 +46,7 @@ python3 .\test.py -f 2-query\between.py @REM python3 .\test.py -f 2-query\Today.py @REM python3 .\test.py -f 2-query\max.py @REM python3 .\test.py -f 2-query\min.py +@REM python3 .\test.py -f 2-query\normal.py @REM python3 .\test.py -f 2-query\count.py @REM python3 .\test.py -f 2-query\last.py @REM python3 .\test.py -f 2-query\first.py diff --git a/tests/system-test/win-test-file b/tests/system-test/win-test-file index cdc4e27f20..69688e7450 100644 --- a/tests/system-test/win-test-file +++ b/tests/system-test/win-test-file @@ -382,6 +382,8 @@ python3 ./test.py -f 2-query/max.py python3 ./test.py -f 2-query/max.py -R python3 ./test.py -f 2-query/min.py python3 ./test.py -f 2-query/min.py -R +python3 ./test.py -f 2-query/normal.py +python3 ./test.py -f 2-query/normal.py -R python3 ./test.py -f 2-query/mode.py python3 ./test.py -f 2-query/mode.py -R python3 ./test.py -f 2-query/Now.py @@ -550,6 +552,7 @@ python3 ./test.py -f 2-query/Now.py -Q 2 python3 ./test.py -f 2-query/Today.py -Q 2 python3 ./test.py -f 2-query/max.py -Q 2 python3 ./test.py -f 2-query/min.py -Q 2 +python3 ./test.py -f 2-query/normal.py -Q 2 python3 ./test.py -f 2-query/mode.py -Q 2 python3 ./test.py -f 2-query/count.py -Q 2 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2 @@ -646,6 +649,7 @@ python3 ./test.py -f 2-query/Now.py -Q 3 python3 ./test.py -f 2-query/Today.py -Q 3 python3 ./test.py -f 2-query/max.py -Q 3 python3 ./test.py -f 2-query/min.py -Q 3 +python3 ./test.py -f 2-query/normal.py -Q 3 python3 ./test.py -f 2-query/mode.py -Q 3 python3 ./test.py -f 2-query/count.py -Q 3 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3 @@ -742,6 +746,7 @@ python3 ./test.py -f 2-query/Now.py -Q 4 python3 ./test.py -f 2-query/Today.py -Q 4 python3 ./test.py -f 2-query/max.py -Q 4 python3 ./test.py -f 2-query/min.py -Q 4 +python3 ./test.py -f 2-query/normal.py -Q 4 python3 ./test.py -f 2-query/mode.py -Q 4 python3 ./test.py -f 2-query/count.py -Q 4 python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4 diff --git a/utils/test/c/tmq_taosx_ci.c b/utils/test/c/tmq_taosx_ci.c index 51d134a463..2f6a5fa59b 100644 --- a/utils/test/c/tmq_taosx_ci.c +++ b/utils/test/c/tmq_taosx_ci.c @@ -596,6 +596,7 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "enable.auto.commit", "true"); tmq_conf_set(conf, "auto.offset.reset", "earliest"); tmq_conf_set(conf, "msg.consume.excluded", "1"); +// tmq_conf_set(conf, "max.poll.interval.ms", "20000"); if (g_conf.snapShot) { tmq_conf_set(conf, "experimental.snapshot.enable", "true");