From 7ad701cc5e48681226cccecf4760f5a306c836ca Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 10:37:39 +0800 Subject: [PATCH 1/4] [td-11818] add rsp error check. --- source/client/src/clientMsgHandler.c | 53 ++++++++++++++++++---------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index f4cec5c627..9ee890afd9 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -22,19 +22,23 @@ int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); +static void setErrno(SRequestObj* pRequest, int32_t code) { + pRequest->code = code; + terrno = code; +} + int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; - pRequest->code = code; + setErrno(pRequest, code); + sem_post(&pRequest->body.rspSem); - return 0; + return code; } int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; - + setErrno(pRequest, code); sem_post(&pRequest->body.rspSem); return code; } @@ -115,7 +119,7 @@ SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) { int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } @@ -157,19 +161,18 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { } int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) { - assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - - SRequestObj* pRequest = param; - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - + SRequestObj *pRequest = param; + SReqResultInfo *pResInfo = &pRequest->body.resInfo; tfree(pResInfo->pRspMsg); + if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } + assert(pMsg->len >= sizeof(SRetrieveTableRsp)); + SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData; pRetrieve->numOfRows = htonl(pRetrieve->numOfRows); pRetrieve->precision = htons(pRetrieve->precision); @@ -195,8 +198,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { tfree(pRequest->body.resInfo.pRspMsg); if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; - terrno = code; + setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; } @@ -209,7 +211,6 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { SReqResultInfo* pResInfo = &pRequest->body.resInfo; - tfree(pResInfo->pRspMsg); pResInfo->pRspMsg = pMsg->pData; pResInfo->numOfRows = pFetchRsp->numOfRows; pResInfo->pData = pFetchRsp->data; @@ -231,6 +232,14 @@ int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { } int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg->pData; SName name = {0}; tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB); @@ -238,17 +247,23 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { char db[TSDB_DB_NAME_LEN] = {0}; tNameGetDbName(&name, db); - SRequestObj* pRequest = param; setConnectionDB(pRequest->pTscObj, db); - tsem_post(&pRequest->body.rspSem); return 0; } int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { - assert(pMsg != NULL); + assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; + + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + tsem_post(&pRequest->body.rspSem); + return code; } int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { From 6a55262ba6255845e9a99e5ac37e6667736a2726 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 10:38:32 +0800 Subject: [PATCH 2/4] [td-11818]check error in rsp. --- source/client/src/clientMsgHandler.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 9ee890afd9..07a7286173 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -269,7 +269,14 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo: Remove cache in catalog cache. SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + tsem_post(&pRequest->body.rspSem); + return code; } void initMsgHandleFp() { From a1f65e9c4f7f25c82606c4a98a4d297080a573a1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 10:39:41 +0800 Subject: [PATCH 3/4] [td-11818] refactor. --- source/client/src/clientMsgHandler.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 07a7286173..6575102f81 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -18,7 +18,6 @@ #include "tname.h" #include "clientInt.h" #include "clientLog.h" -#include "trpc.h" int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); From 8ca61bdf48193e8ffb02d7ffb8e6c638e8399864 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 10:43:29 +0800 Subject: [PATCH 4/4] [td-11818] fix compiler warning. --- source/util/test/hashTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/util/test/hashTest.cpp b/source/util/test/hashTest.cpp index d31fcfb7ef..ac1bae2434 100644 --- a/source/util/test/hashTest.cpp +++ b/source/util/test/hashTest.cpp @@ -154,9 +154,9 @@ void acquireRleaseTest() { int32_t code = 0; int32_t num = 0; TESTSTRUCT data = {0}; - char *str1 = "abcdefg"; - char *str2 = "aaaaaaa"; - char *str3 = "123456789"; + const char *str1 = "abcdefg"; + const char *str2 = "aaaaaaa"; + const char *str3 = "123456789"; data.p = (char *)malloc(10); strcpy(data.p, str1);