From 06af61d9755ea4ae08486cb57c8b1806e4ceb2d0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 25 Nov 2022 12:03:08 +0800 Subject: [PATCH 1/5] add debug info --- include/os/osSocket.h | 2 ++ source/libs/transport/inc/transComm.h | 17 +++++++++-------- source/libs/transport/src/transCli.c | 10 ++++++++++ source/libs/transport/src/transSvr.c | 24 +++++++++++++++++++----- source/os/src/osSocket.c | 16 ++++++++++++++++ 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 2c7c579401..799a281269 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -169,6 +169,8 @@ void taosSetMaskSIGPIPE(); uint32_t taosInetAddr(const char *ipAddr); const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); +uint64_t taosHton64(uint64_t val); +uint64_t taosNtoh64(uint64_t val); #ifdef __cplusplus } #endif diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index ac54749ae1..c3062b6120 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -152,14 +152,15 @@ typedef struct { #pragma pack(push, 1) typedef struct { - char version : 4; // RPC version - char comp : 2; // compression algorithm, 0:no compression 1:lz4 - char noResp : 2; // noResp bits, 0: resp, 1: resp - char persist : 2; // persist handle,0: no persit, 1: persist handle - char release : 2; - char secured : 2; - char spi : 2; - char hasEpSet : 2; // contain epset or not, 0(default): no epset, 1: contain epset + char version : 4; // RPC version + char comp : 2; // compression algorithm, 0:no compression 1:lz4 + char noResp : 2; // noResp bits, 0: resp, 1: resp + char persist : 2; // persist handle,0: no persit, 1: persist handle + char release : 2; + char secured : 2; + char spi : 2; + char hasEpSet : 2; // contain epset or not, 0(default): no epset, 1: contain epset + uint64_t timestamp; char user[TSDB_UNI_LEN]; uint32_t magicNum; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 55bfb57a82..0d70a2ad6f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -757,6 +757,14 @@ static void cliSendCb(uv_write_t* req, int status) { SCliConn* pConn = transReqQueueRemove(req); if (pConn == NULL) return; + SCliMsg* pMsg = !transQueueEmpty(&pConn->cliMsgs) ? transQueueGet(&pConn->cliMsgs, 0) : NULL; + if (pMsg != NULL) { + int64_t cost = taosGetTimestampUs() - pMsg->st; + if (cost > 1000) { + tWarn("%s conn %p send exception, cost:%dus", cost); + } + } + if (status == 0) { tTrace("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); } else { @@ -805,6 +813,7 @@ void cliSend(SCliConn* pConn) { pHead->traceId = pMsg->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); } + pHead->timestamp = taosHton64(taosGetTimestampUs()); if (pHead->persist == 1) { CONN_SET_PERSIST_BY_APP(pConn); @@ -1567,6 +1576,7 @@ int transReleaseCliHandle(void* handle) { SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cmsg->msg = tmsg; + cliMsg->st = taosGetTimestampUs(); cmsg->type = Release; cmsg->ctx = pCtx; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index f093d84db6..09e3aba22f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -231,14 +231,28 @@ static bool uvHandleReq(SSvrConn* pConn) { } } STraceId* trace = &pHead->traceId; + + int64_t cost = taosGetTimestampUs() - taosNtoh64(pHead->timestamp); + static int64_t EXCEPTION_LIMIT_US = 100 * 1000; if (pConn->status == ConnNormal && pHead->noResp == 0) { transRefSrvHandle(pConn); - - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d", transLabel(pTransInst), pConn, - TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen); + if (cost > EXCEPTION_LIMIT_US) { + tGWarn("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", transLabel(pTransInst), + pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, cost); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus", transLabel(pTransInst), pConn, + TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, cost); + } } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, resp:%d, code:%d", transLabel(pTransInst), pConn, - TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, transMsg.code); + if (cost > EXCEPTION_LIMIT_US) { + tGWarn("%s conn %p %s received from %s, local info:%s, len:%d, resp:%d, code:%d, cost:%dus, recv exception", + transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, + transMsg.code, cost); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, resp:%d, code:%d, cost:%dus", + transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, + transMsg.code, cost); + } } // pHead->noResp = 1, diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index fd5bde90ba..72e367be9f 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1101,5 +1101,21 @@ void taosWinSocketInit() { } } #else + #endif } + +uint64_t taosHton64(uint64_t val) { + if (__BYTE_ORDER == __LITTLE_ENDIAN) { + return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32)); + } else if (__BYTE_ORDER == __BIG_ENDIAN) { + return val; + } +} +uint64_t taosNtoh64(uint64_t val) { + if (__BYTE_ORDER == __LITTLE_ENDIAN) { + return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32)); + } else if (__BYTE_ORDER == __BIG_ENDIAN) { + return val; + } +} From 44a33ffad0874b57fdce1d44eaee7e87643d4b9f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 25 Nov 2022 13:17:09 +0800 Subject: [PATCH 2/5] add debug info --- source/libs/transport/src/transCli.c | 4 ++-- source/libs/transport/src/transSvr.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0d70a2ad6f..7934fc29fc 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -761,7 +761,7 @@ static void cliSendCb(uv_write_t* req, int status) { if (pMsg != NULL) { int64_t cost = taosGetTimestampUs() - pMsg->st; if (cost > 1000) { - tWarn("%s conn %p send exception, cost:%dus", cost); + tWarn("%s conn %p send exception, cost:%dus", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); } } @@ -1576,7 +1576,7 @@ int transReleaseCliHandle(void* handle) { SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); cmsg->msg = tmsg; - cliMsg->st = taosGetTimestampUs(); + cmsg->st = taosGetTimestampUs(); cmsg->type = Release; cmsg->ctx = pCtx; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 09e3aba22f..9835538cb2 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -238,20 +238,20 @@ static bool uvHandleReq(SSvrConn* pConn) { transRefSrvHandle(pConn); if (cost > EXCEPTION_LIMIT_US) { tGWarn("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", transLabel(pTransInst), - pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, cost); + pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, (int)cost); } else { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus", transLabel(pTransInst), pConn, - TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, cost); + TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, (int)cost); } } else { if (cost > EXCEPTION_LIMIT_US) { tGWarn("%s conn %p %s received from %s, local info:%s, len:%d, resp:%d, code:%d, cost:%dus, recv exception", transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, cost); + transMsg.code, (int)cost); } else { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, resp:%d, code:%d, cost:%dus", transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, cost); + transMsg.code, (int)cost); } } From 421aa1a8c3762254d43bdc569ac05bdc3114274b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 25 Nov 2022 20:28:52 +0800 Subject: [PATCH 3/5] fix mem leak --- source/os/src/osSocket.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 72e367be9f..a4264a7e88 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1106,16 +1106,28 @@ void taosWinSocketInit() { } uint64_t taosHton64(uint64_t val) { +#if defined(WINDOWS) || defined(DARWIN) + ((val & 0x00000000000000ff) << 7 * 8) | ((val & 0x000000000000ff00) << 5 * 8) | + ((val & 0x0000000000ff0000) << 3 * 8) | ((val & 0x00000000ff000000) << 1 * 8) | + ((val & 0x000000ff00000000) >> 1 * 8) | ((val & 0x0000ff0000000000) >> 3 * 8) | + ((val & 0x00ff000000000000) >> 5 * 8) | ((val & 0xff00000000000000) >> 7 * 8) +#else if (__BYTE_ORDER == __LITTLE_ENDIAN) { return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32)); } else if (__BYTE_ORDER == __BIG_ENDIAN) { return val; } +#endif } + uint64_t taosNtoh64(uint64_t val) { +#if defined(WINDOWS) || defined(DARWIN) + taosHton64(val); +#else if (__BYTE_ORDER == __LITTLE_ENDIAN) { return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32)); } else if (__BYTE_ORDER == __BIG_ENDIAN) { return val; } +#endif } From 561baa37bced47e334082d2f62d20ef504060c44 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 25 Nov 2022 21:29:29 +0800 Subject: [PATCH 4/5] fix TD-20751 mem leak --- source/os/src/osSocket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index a4264a7e88..679fd8a8b6 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1107,10 +1107,10 @@ void taosWinSocketInit() { uint64_t taosHton64(uint64_t val) { #if defined(WINDOWS) || defined(DARWIN) - ((val & 0x00000000000000ff) << 7 * 8) | ((val & 0x000000000000ff00) << 5 * 8) | - ((val & 0x0000000000ff0000) << 3 * 8) | ((val & 0x00000000ff000000) << 1 * 8) | - ((val & 0x000000ff00000000) >> 1 * 8) | ((val & 0x0000ff0000000000) >> 3 * 8) | - ((val & 0x00ff000000000000) >> 5 * 8) | ((val & 0xff00000000000000) >> 7 * 8) + return ((val & 0x00000000000000ff) << 7 * 8) | ((val & 0x000000000000ff00) << 5 * 8) | + ((val & 0x0000000000ff0000) << 3 * 8) | ((val & 0x00000000ff000000) << 1 * 8) | + ((val & 0x000000ff00000000) >> 1 * 8) | ((val & 0x0000ff0000000000) >> 3 * 8) | + ((val & 0x00ff000000000000) >> 5 * 8) | ((val & 0xff00000000000000) >> 7 * 8); #else if (__BYTE_ORDER == __LITTLE_ENDIAN) { return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32)); From e23b3cf870e12fd1db49b29f7f258dd93cb2ae16 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 26 Nov 2022 09:21:15 +0800 Subject: [PATCH 5/5] fix compile failure --- source/os/src/osSocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 679fd8a8b6..5a97343e87 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1122,7 +1122,7 @@ uint64_t taosHton64(uint64_t val) { uint64_t taosNtoh64(uint64_t val) { #if defined(WINDOWS) || defined(DARWIN) - taosHton64(val); + return taosHton64(val); #else if (__BYTE_ORDER == __LITTLE_ENDIAN) { return (((uint64_t)htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32));